From eb1ca16b8af7483f6fc5561e5e1a684d3a6580ea Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sat, 20 Mar 2021 21:16:24 +0100 Subject: [PATCH] improve instanced mesh --- src/meshes/InstancedMesh.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/meshes/InstancedMesh.js b/src/meshes/InstancedMesh.js index 1e802de..d038dd2 100644 --- a/src/meshes/InstancedMesh.js +++ b/src/meshes/InstancedMesh.js @@ -1,6 +1,6 @@ -import { watch } from 'vue'; import { InstancedMesh } from 'three'; import Object3D from '../core/Object3D.js'; +import { bindProp } from '../tools.js'; export default { extends: Object3D, @@ -19,17 +19,15 @@ export default { console.error('Missing Geometry'); } }, - created() { + mounted() { this.initMesh(); }, methods: { initMesh() { this.mesh = new InstancedMesh(this.geometry, this.material, this.count); - ['castShadow', 'receiveShadow'].forEach(p => { - this.mesh[p] = this[p]; - watch(() => this[p], () => { this.mesh[p] = this[p]; }); - }); + bindProp(this, 'castShadow', this.mesh); + bindProp(this, 'receiveShadow', this.mesh); this.initObject3D(this.mesh); }, @@ -39,6 +37,7 @@ export default { }, setMaterial(material) { this.material = material; + this.material.instancingColor = true; if (this.mesh) this.mesh.material = material; }, },