2020-09-14 22:57:11 +08:00
|
|
|
import { Mesh } from 'three';
|
2020-09-19 18:16:16 +08:00
|
|
|
import useBindProp from '../use/useBindProp.js';
|
2020-09-14 22:57:11 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
inject: ['three', 'scene'],
|
2020-09-19 03:52:39 +08:00
|
|
|
emits: ['ready'],
|
2020-09-14 22:57:11 +08:00
|
|
|
props: {
|
2020-09-19 17:24:03 +08:00
|
|
|
materialId: String,
|
2020-09-14 22:57:11 +08:00
|
|
|
position: Object,
|
|
|
|
rotation: Object,
|
|
|
|
scale: Object,
|
2020-09-15 17:48:29 +08:00
|
|
|
castShadow: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
receiveShadow: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-09-14 22:57:11 +08:00
|
|
|
},
|
|
|
|
mounted() {
|
2020-09-18 04:37:19 +08:00
|
|
|
if (this.geometry) this.initMesh();
|
2020-09-14 22:57:11 +08:00
|
|
|
},
|
2020-09-16 01:50:51 +08:00
|
|
|
unmounted() {
|
2020-09-18 04:37:19 +08:00
|
|
|
if (this.geometry) this.geometry.dispose();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
initMesh() {
|
2020-09-19 17:24:03 +08:00
|
|
|
if (!this.material && this.materialId) {
|
|
|
|
this.material = this.three.materials[this.materialId];
|
|
|
|
}
|
|
|
|
this.mesh = new Mesh(this.geometry, this.material);
|
|
|
|
|
2020-09-19 18:16:16 +08:00
|
|
|
useBindProp(this, 'position', this.mesh.position);
|
|
|
|
useBindProp(this, 'rotation', this.mesh.rotation);
|
|
|
|
useBindProp(this, 'scale', this.mesh.scale);
|
|
|
|
|
2020-09-18 04:37:19 +08:00
|
|
|
this.mesh.castShadow = this.castShadow;
|
|
|
|
this.mesh.receiveShadow = this.receiveShadow;
|
2020-09-19 18:16:16 +08:00
|
|
|
|
|
|
|
this.scene.add(this.mesh);
|
|
|
|
this.$emit('ready');
|
2020-09-18 04:37:19 +08:00
|
|
|
},
|
2020-09-16 01:50:51 +08:00
|
|
|
},
|
2020-09-14 22:57:11 +08:00
|
|
|
render() {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
};
|