From 5bc13469f1ff5a5592dc7dc39109d06993dcf6b5 Mon Sep 17 00:00:00 2001 From: Sander Moolin Date: Thu, 11 Mar 2021 10:02:56 -0500 Subject: [PATCH] Create troisjs object/group in separate component --- src/core/Object3D.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 22e57d1..5635d7d 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -27,7 +27,15 @@ export default { 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); + // traverse parents until we find something we can add to + let parent = this.$parent; + while (parent) { + if (parent.add) { + parent.add(this.o3d); + break; + } + parent = parent.$parent; + } }, add(o) { this.o3d.add(o); }, remove(o) { this.o3d.remove(o); },