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

Merge pull request #18 from SaFrMo/child-components

Create troisjs object/group in separate component

Thanks @SaFrMo
This commit is contained in:
Kevin LEVRON 2021-03-11 23:59:55 +01:00 committed by GitHub
commit ef8a4d779f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,7 @@ export default {
// can't use setup because it will not be used in sub components
// setup() {},
unmounted() {
if (this.$parent.remove) this.$parent.remove(this.o3d);
if (this._parent) this._parent.remove(this.o3d);
},
methods: {
initObject3D(o3d) {
@ -23,11 +23,20 @@ export default {
bindProp(this, 'rotation', this.o3d);
bindProp(this, 'scale', this.o3d);
// fix lookat.x
// TODO : fix lookat.x
if (this.lookAt) this.o3d.lookAt(this.lookAt.x, this.lookAt.y, this.lookAt.z);
watch(() => this.lookAt, (v) => { this.o3d.lookAt(v.x, v.y, v.z); }, { deep: true });
if (this.$parent.add) this.$parent.add(this.o3d);
let parent = this.$parent;
while (parent) {
if (parent.add) {
parent.add(this.o3d);
this._parent = parent;
break;
}
parent = parent.$parent;
}
if (!this._parent) console.error('Missing parent (Scene, Group...)');
},
add(o) { this.o3d.add(o); },
remove(o) { this.o3d.remove(o); },