From 2f8c826aa6ea7fca1853a8d216e2081c1dc4995c Mon Sep 17 00:00:00 2001 From: Dhruv Arora Date: Thu, 22 Aug 2024 18:10:28 -0700 Subject: [PATCH] Added fix to zoneconfig + added map for all gizmos attached to mirabufSceneObject --- fission/src/systems/scene/GizmoSceneObject.ts | 11 +++++++++- fission/src/systems/scene/SceneRenderer.ts | 21 ++++++++++++++----- .../scoring/ZoneConfigInterface.tsx | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/fission/src/systems/scene/GizmoSceneObject.ts b/fission/src/systems/scene/GizmoSceneObject.ts index c47ecd07e..e27883ee9 100644 --- a/fission/src/systems/scene/GizmoSceneObject.ts +++ b/fission/src/systems/scene/GizmoSceneObject.ts @@ -19,18 +19,22 @@ class GizmoSceneObject extends SceneObject { private _size: number + /** @returns the instance of the transform gizmo itself */ public get gizmo() { return this._gizmo } + /** @returns Object3D that is attached to transform gizmo */ public get obj() { return this._obj } + /** @returns true if gizmo is currently being dragged */ public get isDragging() { return this._gizmo.dragging } + /** @returns the id of the parent scene object */ public get parentObjectId() { return this._parentObject?.id } @@ -55,7 +59,7 @@ class GizmoSceneObject extends SceneObject { this._gizmo = new TransformControls(World.SceneRenderer.mainCamera, World.SceneRenderer.renderer.domElement) this._gizmo.setMode(mode) - World.SceneRenderer.RegisterSceneObject(this) + World.SceneRenderer.RegisterGizmoSceneObject(this) } public Setup(): void { @@ -180,6 +184,11 @@ class GizmoSceneObject extends SceneObject { this._obj.position.setFromMatrixPosition(gizmoTransformation) this._obj.quaternion.setFromRotationMatrix(gizmoTransformation) } + + /** @return true if gizmo is attached to mirabufSceneObject */ + public HasParent(): boolean { + return this._parentObject !== undefined + } } export default GizmoSceneObject diff --git a/fission/src/systems/scene/SceneRenderer.ts b/fission/src/systems/scene/SceneRenderer.ts index 0ee2164eb..e552493e1 100644 --- a/fission/src/systems/scene/SceneRenderer.ts +++ b/fission/src/systems/scene/SceneRenderer.ts @@ -31,6 +31,7 @@ class SceneRenderer extends WorldSystem { private _antiAliasPass: EffectPass private _sceneObjects: Map + private _gizmosOnMirabuf: Map // maps of all the gizmos that are attached to a mirabuf scene object private _orbitControls: OrbitControls @@ -60,6 +61,7 @@ class SceneRenderer extends WorldSystem { super() this._sceneObjects = new Map() + this._gizmosOnMirabuf = new Map() this._mainCamera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000) this._mainCamera.position.set(-2.5, 2, 2.5) @@ -229,20 +231,29 @@ class SceneRenderer extends WorldSystem { return id } + /** Registers gizmos that are attached to a parent mirabufsceneobject */ + public RegisterGizmoSceneObject(obj: GizmoSceneObject): number { + if (obj.HasParent()) this._gizmosOnMirabuf.set(obj.parentObjectId!, obj) + return this.RegisterSceneObject(obj) + } + public RemoveAllSceneObjects() { this._sceneObjects.forEach(obj => obj.Dispose()) + this._gizmosOnMirabuf.clear() this._sceneObjects.clear() } public RemoveSceneObject(id: number) { const obj = this._sceneObjects.get(id) + + // If the object is a mirabuf object, remove the gizmo as well if (obj instanceof MirabufSceneObject) { - Array.from(this._sceneObjects.values()) - .filter(x => x instanceof GizmoSceneObject) - .forEach(x => { - if ((x as GizmoSceneObject).parentObjectId === obj.id) this.RemoveSceneObject(x.id) - }) + const objGizmo = this._gizmosOnMirabuf.get(id) + if (this._gizmosOnMirabuf.delete(id)) objGizmo!.Dispose() + } else if (obj instanceof GizmoSceneObject && obj.HasParent()) { + this._gizmosOnMirabuf.delete(obj.parentObjectId!) } + if (this._sceneObjects.delete(id)) { obj!.Dispose() } diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx index 2cf604724..2c184c8bb 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx @@ -279,8 +279,8 @@ const ZoneConfigInterface: React.FC = ({ selectedField, selecte > Move Scale + Rotate - Rotate ) }