1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

improve instanced mesh

This commit is contained in:
Kevin Levron 2021-03-20 21:16:24 +01:00
parent f90cb8d6f8
commit eb1ca16b8a

View File

@ -1,6 +1,6 @@
import { watch } from 'vue';
import { InstancedMesh } from 'three'; import { InstancedMesh } from 'three';
import Object3D from '../core/Object3D.js'; import Object3D from '../core/Object3D.js';
import { bindProp } from '../tools.js';
export default { export default {
extends: Object3D, extends: Object3D,
@ -19,17 +19,15 @@ export default {
console.error('Missing Geometry'); console.error('Missing Geometry');
} }
}, },
created() { mounted() {
this.initMesh(); this.initMesh();
}, },
methods: { methods: {
initMesh() { initMesh() {
this.mesh = new InstancedMesh(this.geometry, this.material, this.count); this.mesh = new InstancedMesh(this.geometry, this.material, this.count);
['castShadow', 'receiveShadow'].forEach(p => { bindProp(this, 'castShadow', this.mesh);
this.mesh[p] = this[p]; bindProp(this, 'receiveShadow', this.mesh);
watch(() => this[p], () => { this.mesh[p] = this[p]; });
});
this.initObject3D(this.mesh); this.initObject3D(this.mesh);
}, },
@ -39,6 +37,7 @@ export default {
}, },
setMaterial(material) { setMaterial(material) {
this.material = material; this.material = material;
this.material.instancingColor = true;
if (this.mesh) this.mesh.material = material; if (this.mesh) this.mesh.material = material;
}, },
}, },