Moving the camera, lookAt and rotations in three.js

To fix the problem you can specify the up vector for the camera before executing the lookAt() command. // Place camera on x axis camera.position.set(30,0,0); camera.up = new THREE.Vector3(0,0,1); camera.lookAt(new THREE.Vector3(0,0,0)); Change the vector to your needs. You can even turn it upside down by specifying a negative value: (0,0,-1). It is important to set … Read more

three.js – How can I dynamically change object’s opacity?

THREE.MeshLambertMaterial extends THREE.Material which means it inherits the opacity property, so all you need to do is access the material on your object, and change the opacity of the material: object.materials[0].opacity = 1 + Math.sin(new Date().getTime() * .0025);//or any other value you like Also note that the material must have it’s transparent property set to … Read more

Three.JS wireframe material – all polygons vs. just edges

If you want to render a wireframe of a given geometry, you can now use this pattern: var geo = new THREE.EdgesGeometry( geometry ); // or WireframeGeometry( geometry ) var mat = new THREE.LineBasicMaterial( { color: 0xffffff, linewidth: 2 } ); var wireframe = new THREE.LineSegments( geo, mat ); scene.add( wireframe ); WireframeGeometry will render … Read more

Three.js Resizing Canvas

So the canvas element can be resized like every other element. What you want to do is tell the render and camera to resize the contents of your canvas as well. window.addEventListener( ‘resize’, onWindowResize, false ); function onWindowResize(){ camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); }