Skip to content

Commit

Permalink
refactor gizmo manager
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoecheza committed Nov 21, 2024
1 parent d0759ef commit 558813b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,14 @@ export const setGizmoManager = (entity: EcsEntity, value: { gizmo: number }) =>

toggleSelection(entity, true)

const selectedEntities = Array.from(context.engine.getEntitiesWith(context.editorComponents.Selection))
const types = context.gizmos.getGizmoTypes()
const type = types[value?.gizmo || 0]
context.gizmos.setGizmoType(type)

if (selectedEntities.length === 1) {
context.gizmos.setEntity(entity)
} else if (selectedEntities.length > 1) {
context.gizmos.repositionGizmoOnCentroid()
}
context.gizmos.addEntity(entity)
}

export const unsetGizmoManager = (entity: EcsEntity) => {
const context = entity.context.deref()!
const selectedEntities = Array.from(context.engine.getEntitiesWith(context.editorComponents.Selection))
const currentEntity = context.gizmos.getEntity()

toggleSelection(entity, false)

if (currentEntity?.entityId === entity.entityId || selectedEntities.length === 0) {
context.gizmos.unsetEntity()
} else {
context.gizmos.repositionGizmoOnCentroid()
}
context.gizmos.removeEntity(entity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ describe('GizmoManager', () => {
babylonEntity.rotationQuaternion = new Quaternion(0, 0, 0, 1)
handler = jest.fn()
gizmos.onChange(handler)
gizmos.setEntity(babylonEntity)
gizmos.addEntity(babylonEntity)
entities = [dclEntity]
nodes.push({ entity: dclEntity, children: [] })
})
afterEach(() => {
babylonEntity.dispose()
context.engine.removeEntity(dclEntity)
gizmos.unsetEntity()
gizmos.removeEntity(context.getOrCreateEntity(dclEntity))
entities = []
nodes = nodes.filter(($) => $.entity !== dclEntity)
})
Expand All @@ -86,16 +86,11 @@ describe('GizmoManager', () => {
it('should skip setting the entity', () => {
const handler = jest.fn()
gizmos.onChange(handler)
gizmos.setEntity(babylonEntity)
gizmos.addEntity(babylonEntity)
expect(handler).not.toHaveBeenCalled()
})
})
describe('and dragging a gizmo', () => {
it('should not execute SDK operations if transform was not changed', () => {
gizmos.gizmoManager.gizmos.positionGizmo?.onDragEndObservable.notifyObservers({} as any)
expect(context.operations.updateValue).toBeCalledTimes(0)
expect(context.operations.dispatch).toBeCalledTimes(0)
})
it('should execute SDK operations if transform was changed', () => {
babylonEntity.position = new Vector3(10, 10, 10)
gizmos.gizmoManager.gizmos.positionGizmo?.onDragEndObservable.notifyObservers({} as any)
Expand Down
Loading

0 comments on commit 558813b

Please sign in to comment.