mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 12:22:03 +08:00
45 lines
926 B
JavaScript
45 lines
926 B
JavaScript
import { InstancedMesh } from 'three';
|
|
import { setFromProp } from '../tools.js';
|
|
|
|
export default {
|
|
inject: ['three', 'scene'],
|
|
props: {
|
|
materialId: String,
|
|
count: Number,
|
|
position: Object,
|
|
castShadow: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
receiveShadow: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
},
|
|
setup() {
|
|
return {
|
|
conf: {},
|
|
};
|
|
},
|
|
provide() {
|
|
return {
|
|
parent: this.conf,
|
|
};
|
|
},
|
|
beforeMount() {
|
|
if (!this.$slots.default) {
|
|
console.error('Missing Geometry');
|
|
}
|
|
},
|
|
mounted() {
|
|
this.mesh = new InstancedMesh(this.conf.geometry, this.three.materials[this.materialId], this.count);
|
|
setFromProp(this.mesh.position, this.position);
|
|
this.mesh.castShadow = this.castShadow;
|
|
this.mesh.receiveShadow = this.receiveShadow;
|
|
this.scene.add(this.mesh);
|
|
},
|
|
render() {
|
|
return this.$slots.default();
|
|
},
|
|
};
|