Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Vector3 as DclVector3 } from '@dcl/ecs-math'
import { SceneContext } from './SceneContext'
import { EcsEntity } from './EcsEntity'
import { GizmoType } from '../../utils/gizmo'
import { GizmoType as TransformerType } from './gizmos/types'
import { FreeGizmo, PositionGizmo, RotationGizmo, ScaleGizmo, IGizmoTransformer } from './gizmos'
import { snapManager, snapPosition, snapRotation, snapScale } from './snap-manager'

Expand Down Expand Up @@ -179,11 +180,14 @@ export function createGizmoManager(context: SceneContext) {
node.rotationQuaternion = Quaternion.Identity()
}

// Update rotation based on current transformer type
if (gizmoManager.rotationGizmoEnabled) {
// For rotation gizmo, sync the rotation
syncGizmoRotation(node, selectedEntities, isGizmoWorldAligned)
} else {
if (currentTransformer) {
if (currentTransformer.type === TransformerType.ROTATION) {
// Update rotation based on current transformer type
syncGizmoRotation(node, selectedEntities, isGizmoWorldAligned)
} else if (currentTransformer.type === TransformerType.FREE) {
// Update free gizmo indicator with ECS updates
;(currentTransformer as FreeGizmo).updateGizmoIndicator()
}
// For non-rotation gizmos, let the transformers handle rotation
// Don't reset rotation if it already exists
}
Expand Down Expand Up @@ -387,10 +391,7 @@ export function createGizmoManager(context: SceneContext) {

// Pass GizmoManager reference to FreeGizmo for centroid calculation
if ('setGizmoManager' in currentTransformer) {
;(currentTransformer as any).setGizmoManager({
calculateCentroid,
updateGizmoPosition
})
;(currentTransformer as any).setGizmoManager(calculateCentroid)
}

// Set up callbacks for ECS updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import {
} from '@babylonjs/core'
import { Entity } from '@dcl/ecs'
import { EcsEntity } from '../EcsEntity'
import { IGizmoTransformer } from './types'
import { GizmoType, IGizmoTransformer } from './types'
import { LEFT_BUTTON } from '../mouse-utils'
import { snapVector } from '../snap-manager'

interface GizmoManagerInterface {
calculateCentroid: () => Vector3
updateGizmoPosition: () => void
}

export class FreeGizmo implements IGizmoTransformer {
type = GizmoType.FREE
private selectedEntities: EcsEntity[] = []
private isDragging = false
private snapDistance = 0
Expand Down Expand Up @@ -467,7 +467,7 @@ export class FreeGizmo implements IGizmoTransformer {
return material
}

private updateGizmoIndicator(): void {
updateGizmoIndicator(): void {
if (!this.gizmoIndicator || this.selectedEntities.length === 0) return
const center = this.getCentroid()
this.gizmoIndicator.position = center
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Vector3, TransformNode, GizmoManager, Quaternion } from '@babylonjs/core'
import { Entity } from '@dcl/ecs'
import { EcsEntity } from '../EcsEntity'
import { IGizmoTransformer } from './types'
import { GizmoType, IGizmoTransformer } from './types'
import { LEFT_BUTTON } from '../mouse-utils'
import { configureGizmoButtons } from './utils'

Expand All @@ -13,6 +13,7 @@ interface EntityState {
}

export class PositionGizmo implements IGizmoTransformer {
type = GizmoType.POSITION
private entityStates = new Map<Entity, EntityState>()
private pivotPosition: Vector3 | null = null
private isDragging = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Entity } from '@dcl/ecs'
import { EcsEntity } from '../EcsEntity'
import { snapManager } from '../snap-manager'
import { IGizmoTransformer } from './types'
import { GizmoType, IGizmoTransformer } from './types'
import { LEFT_BUTTON } from '../mouse-utils'
import { configureGizmoButtons } from './utils'

Expand Down Expand Up @@ -159,6 +159,7 @@
}

export class RotationGizmo implements IGizmoTransformer {
type = GizmoType.ROTATION
private rotationGizmo: Nullable<IRotationGizmo> = null
private currentEntities: EcsEntity[] = []
private currentEntityIds = new Set<Entity>()
Expand Down Expand Up @@ -345,7 +346,7 @@
this.dragState = null
}

private initializeDragState(entities: EcsEntity[], gizmoNode: TransformNode): void {

Check warning on line 349 in packages/@dcl/inspector/src/lib/babylon/decentraland/gizmos/RotationGizmo.ts

View workflow job for this annotation

GitHub Actions / lint

'gizmoNode' is defined but never used. Allowed unused args must match /^_/u
const transformData = new Map<Entity, EntityTransformData>()

if (entities.length === 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Vector3, TransformNode, GizmoManager, Quaternion } from '@babylonjs/core'
import { Entity } from '@dcl/ecs'
import { EcsEntity } from '../EcsEntity'
import { IGizmoTransformer } from './types'
import { GizmoType, IGizmoTransformer } from './types'
import { LEFT_BUTTON } from '../mouse-utils'
import { configureGizmoButtons } from './utils'

export class ScaleGizmo implements IGizmoTransformer {
type = GizmoType.SCALE
private initialOffsets = new Map<Entity, Vector3>()
private initialScales = new Map<Entity, Vector3>()
private initialRotations = new Map<Entity, Quaternion>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IAxisDragGizmo, TransformNode } from '@babylonjs/core'
import { EcsEntity } from '../EcsEntity'

export interface IGizmoTransformer {
type: GizmoType
setup(): void
cleanup(): void
setEntities(entities: EcsEntity[]): void
Expand Down
Loading