Orthographic camera and selecting objects with raycast

Here is the pattern to use when raycasting with either an orthographic camera or perspective camera: var raycaster = new THREE.Raycaster(); // create once var mouse = new THREE.Vector2(); // create once … mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 – 1; mouse.y = – ( event.clientY / renderer.domElement.clientHeight ) * 2 + … Read more

three.js – Adjusting opacity of individual particles

EDIT – This answer shows how to set per-point opacity using a custom ShaderMaterial. See https://stackoverflow.com/a/67892506/1461008 for an approach using PointsMaterial. ParticleSystem has been renamed to PointCloud and then to Points. Yes, you can create a Point Cloud and vary the alpha value of each particle’s color dynamically. In three.js, you can do this by … Read more

Replicating MeshLambertMaterial Using ShaderMaterial ignores textures

three.js was designed to be easy to use, not easy to modify. This may change in the future… You need to set the material.defines like so: var defines = {}; defines[ “USE_MAP” ] = “”;. Then specify defines in the material constructor. var material = new THREE.ShaderMaterial({ name: “TerrainShader”, defines : defines, uniforms : shaderUniforms, … Read more

Three.js – Geometry on top of another

Yes. First do this: renderer.autoClear = false; Then create a second scene that contains just the objects you want to be on top. Then, in your render loop: renderer.clear(); // clear buffers renderer.render( scene, camera ); // render scene 1 renderer.clearDepth(); // clear depth buffer renderer.render( scene2, camera ); // render scene 2 three.js r.152

How to save canvas animation as gif or webm?

In modern browsers you can use a conjunction of the MediaRecorder API and the HTMLCanvasElement.captureStream method. The MediaRecorder API will be able to encode a MediaStream in a video or audio media file on the fly, resulting in far less memory needed than when you grab still images. const ctx = canvas.getContext(‘2d’); var x = … Read more