1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-25 04:42:01 +08:00
trois/src/meshes/Mesh.js

41 lines
934 B
JavaScript
Raw Normal View History

2020-09-14 22:57:11 +08:00
import { Mesh } from 'three';
import { setFromProp } from '../tools.js';
export default {
inject: ['three', 'scene'],
props: {
material: String,
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() {
this.mesh = new Mesh(this.geometry, this.three.materials[this.material]);
setFromProp(this.mesh.position, this.position);
setFromProp(this.mesh.rotation, this.rotation);
setFromProp(this.mesh.scale, this.scale);
this.mesh.castShadow = this.castShadow;
this.mesh.receiveShadow = this.receiveShadow;
this.scene.add(this.mesh);
},
2020-09-16 01:50:51 +08:00
},
2020-09-14 22:57:11 +08:00
render() {
return [];
},
};