1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-23 20:02:32 +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 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;
},
},