From a77e7e7af9b84e4f06e9db9d4927589797eb2886 Mon Sep 17 00:00:00 2001 From: Yuki Shimada Date: Sun, 28 Nov 2021 10:50:46 +0900 Subject: [PATCH 1/2] fix: excludes gizmo children for worldAABB updating --- src/foundation/components/SceneGraphComponent.ts | 9 +++++++++ src/foundation/gizmos/AABBGizmo.ts | 2 +- src/foundation/gizmos/LocatorGizmo.ts | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/foundation/components/SceneGraphComponent.ts b/src/foundation/components/SceneGraphComponent.ts index 95b3ccc0e..515ba10c9 100644 --- a/src/foundation/components/SceneGraphComponent.ts +++ b/src/foundation/components/SceneGraphComponent.ts @@ -24,6 +24,7 @@ export default class SceneGraphComponent extends Component { private static __sceneGraphs: SceneGraphComponent[] = []; public isAbleToBeParent: boolean; private __children: Array = []; + private __gizmoChildren: Array = []; private _worldMatrix: MutableMatrix44 = MutableMatrix44.dummy(); private _normalMatrix: MutableMatrix33 = MutableMatrix33.dummy(); private __isWorldMatrixUpToDate = false; @@ -171,6 +172,14 @@ export default class SceneGraphComponent extends Component { } else { console.error('This is not allowed to have children.'); } + + /** + * add a SceneGraph component as a child of this (But Gizmo only) + * @param sg a SceneGraph component of Gizmo + */ + _addGizmoChild(sg: SceneGraphComponent): void { + sg.__parent = this; + this.__gizmoChildren.push(sg); } get isTopLevel() { diff --git a/src/foundation/gizmos/AABBGizmo.ts b/src/foundation/gizmos/AABBGizmo.ts index 42192904f..ca47ced0c 100644 --- a/src/foundation/gizmos/AABBGizmo.ts +++ b/src/foundation/gizmos/AABBGizmo.ts @@ -63,7 +63,7 @@ export default class AABBGizmo extends Gizmo { ]); this.__topEntity.tryToSetUniqueName(`AABBGizmo_of_${this.__target.uniqueName}`, true); this.__topEntity.getSceneGraph().toMakeWorldMatrixTheSameAsLocalMatrix = true; - this.__target.getSceneGraph().addChild(this.__topEntity.getSceneGraph()); + this.__target.getSceneGraph()._addGizmoChild(this.__topEntity.getSceneGraph()); const meshComponent = this.__topEntity.getMesh(); AABBGizmo.__mesh = new Mesh(); diff --git a/src/foundation/gizmos/LocatorGizmo.ts b/src/foundation/gizmos/LocatorGizmo.ts index 4a9409287..54f2f787a 100644 --- a/src/foundation/gizmos/LocatorGizmo.ts +++ b/src/foundation/gizmos/LocatorGizmo.ts @@ -71,7 +71,7 @@ export default class LocatorGizmo extends Gizmo { ]); this.__topEntity.tryToSetUniqueName(`LocatorGizmo_of_${this.__target.uniqueName}`, true); this.__topEntity.getSceneGraph().toMakeWorldMatrixTheSameAsLocalMatrix = true; - this.__target.getSceneGraph().addChild(this.__topEntity.getSceneGraph()); + this.__target.getSceneGraph()._addGizmoChild(this.__topEntity.getSceneGraph()); const meshComponent = this.__topEntity.getMesh(); LocatorGizmo.__mesh = new Mesh(); From 7d3106b1385092fecd7bb736ba74eadc435ef864 Mon Sep 17 00:00:00 2001 From: Yuki Shimada Date: Sun, 28 Nov 2021 10:51:04 +0900 Subject: [PATCH 2/2] refactor: addChild method of SceneGraphComponent --- src/foundation/components/SceneGraphComponent.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/foundation/components/SceneGraphComponent.ts b/src/foundation/components/SceneGraphComponent.ts index 515ba10c9..3a74b0e9a 100644 --- a/src/foundation/components/SceneGraphComponent.ts +++ b/src/foundation/components/SceneGraphComponent.ts @@ -165,13 +165,14 @@ export default class SceneGraphComponent extends Component { this.parent?.setWorldAABBDirtyParentRecursively(); } - addChild(sg: SceneGraphComponent) { - if (this.__children != null) { - sg.__parent = this; - this.__children.push(sg); - } else { - console.error('This is not allowed to have children.'); - } + /** + * add a SceneGraph component as a child of this + * @param sg a SceneGraph component of Gizmo + */ + public addChild(sg: SceneGraphComponent): void { + sg.__parent = this; + this.__children.push(sg); + } /** * add a SceneGraph component as a child of this (But Gizmo only)