Skip to content

Commit

Permalink
Added fix to zoneconfig + added map for all gizmos attached to mirabu…
Browse files Browse the repository at this point in the history
…fSceneObject
  • Loading branch information
Dhruv-0-Arora committed Aug 23, 2024
1 parent 980bf10 commit 2f8c826
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
11 changes: 10 additions & 1 deletion fission/src/systems/scene/GizmoSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
21 changes: 16 additions & 5 deletions fission/src/systems/scene/SceneRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SceneRenderer extends WorldSystem {
private _antiAliasPass: EffectPass

private _sceneObjects: Map<number, SceneObject>
private _gizmosOnMirabuf: Map<number, GizmoSceneObject> // maps of all the gizmos that are attached to a mirabuf scene object

private _orbitControls: OrbitControls

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ const ZoneConfigInterface: React.FC<ZoneConfigProps> = ({ selectedField, selecte
>
<ToggleButton value={"translate"}>Move</ToggleButton>
<ToggleButton value={"scale"}>Scale</ToggleButton>
<ToggleButton value={"rotate"}>Rotate</ToggleButton>
</ToggleButtonGroup>
<ToggleButton value={"rotate"}>Rotate</ToggleButton>
</div>
)
}
Expand Down

0 comments on commit 2f8c826

Please sign in to comment.