|
@@ -41,7 +41,7 @@
|
|
|
let camera, controls, scene, renderer;
|
|
|
let geometries, mesh;
|
|
|
const ids = [];
|
|
|
- const dummy = new THREE.Object3D();
|
|
|
+ const matrix = new THREE.Matrix4();
|
|
|
|
|
|
//
|
|
|
|
|
@@ -172,6 +172,7 @@
|
|
|
const vertexCount = api.count * 512;
|
|
|
const indexCount = api.count * 1024;
|
|
|
|
|
|
+ const euler = new THREE.Euler();
|
|
|
const matrix = new THREE.Matrix4();
|
|
|
mesh = new BatchedMesh( geometryCount, vertexCount, indexCount, createMaterial() );
|
|
|
mesh.userData.rotationSpeeds = [];
|
|
@@ -181,7 +182,11 @@
|
|
|
|
|
|
const id = mesh.applyGeometry( geometries[ i % geometries.length ] );
|
|
|
mesh.setMatrixAt( id, randomizeMatrix( matrix ) );
|
|
|
- mesh.userData.rotationSpeeds.push( randomizeRotationSpeed( new THREE.Euler() ) );
|
|
|
+
|
|
|
+ const rotationMatrix = new THREE.Matrix4();
|
|
|
+ rotationMatrix.makeRotationFromEuler( randomizeRotationSpeed( euler ) );
|
|
|
+ mesh.userData.rotationSpeeds.push( rotationMatrix );
|
|
|
+
|
|
|
ids.push( id );
|
|
|
|
|
|
}
|
|
@@ -274,18 +279,12 @@
|
|
|
|
|
|
for ( let i = 0; i < loopNum; i ++ ) {
|
|
|
|
|
|
- const rotationSpeed = mesh.userData.rotationSpeeds[ i ];
|
|
|
+ const rotationMatrix = mesh.userData.rotationSpeeds[ i ];
|
|
|
const id = ids[ i ];
|
|
|
|
|
|
- mesh.getMatrixAt( id, dummy.matrix );
|
|
|
- dummy.matrix.decompose( dummy.position, dummy.quaternion, dummy.scale );
|
|
|
- dummy.rotation.set(
|
|
|
- dummy.rotation.x + rotationSpeed.x,
|
|
|
- dummy.rotation.y + rotationSpeed.y,
|
|
|
- dummy.rotation.z + rotationSpeed.z
|
|
|
- );
|
|
|
- dummy.updateMatrix();
|
|
|
- mesh.setMatrixAt( id, dummy.matrix );
|
|
|
+ mesh.getMatrixAt( id, matrix );
|
|
|
+ matrix.multiply( rotationMatrix );
|
|
|
+ mesh.setMatrixAt( id, matrix );
|
|
|
|
|
|
}
|
|
|
|