three.js

How to call .render and .animate functions inside object class?

醉酒当歌 提交于 2019-12-13 16:05:11
问题 It's my 7th day of searching for an answer. I want to write a simple game and I want to call for an Object. My thinking is that I want a modular game, so I invoke scene and all that the usual way: main.js: var scene, controls, camera, renderer; var SCREEN_WIDTH, SCREEN_HEIGHT; ..... var thing; init(); animate(); function init() { ..... thing = new Player(); ..... } function animate() { ..... } function render() { ...... } and then I have my ( lets say it's-> ) Player.js class: function Player

Changing proportionally the size of a geometry when the window size changes using onWindowResize() function

别说谁变了你拦得住时间么 提交于 2019-12-13 16:02:14
问题 I am making my first steps coding with javascript. I made some courses and now I am exploring the webgl world using Three.js I am experimenting with this function very used in all the examples of threes.org: function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); } With this function I can center my geometry when I reduce or increase the width of my browser's window and I can

What is the best practice for loading multiple textures in three.js?

浪子不回头ぞ 提交于 2019-12-13 15:49:02
问题 Having recently switched to three.js as my renderer, I am now wanting to set up a system for mapping textures. However, I'm not too sure on what the best practice for this is. Here is my use case I have levels made of a lot of box geometries I need to be able to map a wide variety of textures to each face of each box geometry (grass, water, stone, rock etc.,) I would like to do this in the most efficient, performance conscious way as possible, so offloading this to the GPU would be best if

Internet Explorer 11 does not open local three.js, not even with local server

我只是一个虾纸丫 提交于 2019-12-13 15:45:13
问题 That includes three.js examples too, while they do open online. I tried both python and node.js servers, it receives the file list, but when the HTML is clicked, the screen remains black. They open fine in Firefox, Chrome, SeaMonkey etc. Of course, it's IE 11 the problem, NOT three.js. Any ideas how to make IE 11 open local three.js files? 回答1: IE 11 started to run local three.js files directly (with drag and drop the HTML file) after I did the following: Internet Options/Advanced/Security

Moving objects parallel to projection plane in three.js

烈酒焚心 提交于 2019-12-13 15:07:39
问题 I want to move objects along a plane parallel to the projection plane with the mouse. This means during the movement the distance between any picked object and camera projection plane (not camera position) must remain constant. A similar question has been asked: Mouse / Canvas X, Y to Three.js World X, Y, Z , but unlike there I need a solution working for arbitrary camera angles and camera/object positions not only for the plane with z=0. It also has to work for orthographic projection. Now I

THREE.js check if object is in frustum

 ̄綄美尐妖づ 提交于 2019-12-13 15:05:55
问题 i've been tinkering around with three.js and i have a canvas i'd like to use as kind of a GUI. for that i have to check if an object is in the camera frustum. my current code: camera.updateMatrix(); camera.updateMatrixWorld(); var frustum = new THREE.Frustum(); var projScreenMatrix = new THREE.Matrix4(); projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ); frustum.setFromMatrix( camera.projectionMatrix ); if(frustum.containsPoint( mesh.position )){ //stuff

Texture is not generated valid (probably)

本小妞迷上赌 提交于 2019-12-13 14:43:24
问题 My app for volume ray casting in WebGL is almost done. But i have found a problem. I have to simulate 3D texture by 2D texture. It is not problem. I am creating a huge texture from small slices. Dimensions of huge texture are about 4096x4096px. Problem is, that in some examples (it depends on number of slices) there is creating sth. like on the image bellow (i filled huge texture to white to be the fragment more visible). I know that num of stripes depends on num of rows in huge texture. I am

Flip Normals Three.JS after flipping geometry

匆匆过客 提交于 2019-12-13 14:27:56
问题 I followed this stackoverflow example: ThreeJS geometry flipping I successfully mirrored my geometry. However now my geometry is black. Can I flip my normals at the same time as the geometry to correct this? Or should I have used a different approach to mirror the geometry from the beginning? EDIT: Tried adding the updates to this code and still have inverted geometry. #transformation mS.elements[5] = -1; mesh.applyMatrix(mS); #updates mesh.geometry.verticesNeedUpdate = true; mesh.geometry

Three.js line disappears if one point is outside of the camera's view

爷,独闯天下 提交于 2019-12-13 13:11:50
问题 I created a line as explained in the docs: http://threejs.org/docs/#Reference/Objects/Line. But when one of the line points is outside of the camera's view, the line disappears. I also tried to use https://github.com/spite/THREE.MeshLine, but I still have the same problem. How can I fix it? 回答1: If you update the vertices of your line, you must also update the bounding sphere of your line for frustum culling to work correctly. line.geometry.computeBoundingSphere(); Alternatively, you can

THREE.js: Why is my object flipping whilst travelling along a spline?

风格不统一 提交于 2019-12-13 12:52:35
问题 Following up from my original post Three.JS Object following a spline path - rotation / tangent issues & constant speed issue, I am still having the issue that the object flips at certain points along the path. View this happening on this fiddle: http://jsfiddle.net/jayfield1979/T2t59/7/ function moveBox() { if (counter <= 1) { box.position.x = spline.getPointAt(counter).x; box.position.y = spline.getPointAt(counter).y; tangent = spline.getTangentAt(counter).normalize(); axis.cross(up,