Last active
March 28, 2020 10:03
-
-
Save RenaudRohlinger/67475b125bc5a1e225833bcbd209ab71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mesh = null; | |
var dummy = new THREE.Object3D(); | |
var sectionWidth = 200; | |
function addInstancedMesh() { | |
// An InstancedMesh of 4 cubes | |
mesh = new THREE.InstancedMesh(new THREE.BoxBufferGeometry(50,50,50), new THREE.MeshNormalMaterial(), 4); | |
scene.add(mesh); | |
setInstancedMeshPositions(mesh); | |
} | |
function setInstancedMeshPositions(mesh) { | |
for ( var i = 0; i < mesh.count; i ++ ) { | |
// we add 200 units of distance (the width of the section) between each. | |
var xStaticPosition = -sectionWidth * (i - 1) | |
dummy.position.set(xStaticPosition, 0, 0); | |
dummy.updateMatrix(); | |
mesh.setMatrixAt( i, dummy.matrix ); | |
} | |
mesh.instanceMatrix.needsUpdate = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment