From cc777f0ac05797c2e3b508d72e16206cff7cca65 Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Thu, 17 Sep 2020 22:56:02 +0200 Subject: [PATCH] wip --- src/components/Test2.vue | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/components/Test2.vue b/src/components/Test2.vue index fbd8ad7..09474bd 100644 --- a/src/components/Test2.vue +++ b/src/components/Test2.vue @@ -4,8 +4,8 @@ - - + + @@ -38,10 +38,11 @@ export default { EffectComposer, RenderPass, UnrealBloomPass, }, setup() { - const NUM_INSTANCES = 2500; + const NUM_INSTANCES = 2000; const instances = []; const target = new Vector3(); - const dummy = new Object3D(); + const dummyO = new Object3D(); + const dummyV = new Vector3(); for (let i = 0; i < NUM_INSTANCES; i++) { instances.push({ @@ -58,7 +59,8 @@ export default { NUM_INSTANCES, instances, target, - dummy, + dummyO, + dummyV, }; }, mounted() { @@ -71,11 +73,11 @@ export default { init() { // init instanced mesh matrix for (let i = 0; i < this.NUM_INSTANCES; i++) { - const { position, scale } = this.instances[i]; - this.dummy.position.copy(position); - this.dummy.scale.set(scale, scale, scale); - this.dummy.updateMatrix(); - this.imesh.setMatrixAt(i, this.dummy.matrix); + const { position, scale, scaleZ } = this.instances[i]; + this.dummyO.position.copy(position); + this.dummyO.scale.set(scale, scale, scaleZ); + this.dummyO.updateMatrix(); + this.imesh.setMatrixAt(i, this.dummyO.matrix); } this.imesh.instanceMatrix.needsUpdate = true; @@ -86,19 +88,18 @@ export default { this.target.copy(this.renderer.three.mouseV3); this.light.position.copy(this.target); - const v = new Vector3(); for (let i = 0; i < this.NUM_INSTANCES; i++) { const { position, scale, scaleZ, velocity, attraction, vlimit } = this.instances[i]; - v.copy(this.target).sub(position).normalize().multiplyScalar(attraction); - velocity.add(v).clampScalar(-vlimit, vlimit); + this.dummyV.copy(this.target).sub(position).normalize().multiplyScalar(attraction); + velocity.add(this.dummyV).clampScalar(-vlimit, vlimit); position.add(velocity); - this.dummy.position.copy(position); - this.dummy.scale.set(scale, scale, scaleZ); - this.dummy.lookAt(v.copy(position).add(velocity)); - this.dummy.updateMatrix(); - this.imesh.setMatrixAt(i, this.dummy.matrix); + this.dummyO.position.copy(position); + this.dummyO.scale.set(scale, scale, scaleZ); + this.dummyO.lookAt(this.dummyV.copy(position).add(velocity)); + this.dummyO.updateMatrix(); + this.imesh.setMatrixAt(i, this.dummyO.matrix); } this.imesh.instanceMatrix.needsUpdate = true; },