Skip to content
Open
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
44 changes: 38 additions & 6 deletions GDJS/Runtime/InGameEditor/InGameEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ namespace gdjs {
class ObjectMover {
private editor: InGameEditor;
private _changeHappened = false;
private startTime = 0;
private _isMoving = false;

constructor(editor: InGameEditor) {
this.editor = editor;
Expand All @@ -648,15 +648,17 @@ namespace gdjs {
> = new Map();

startMove() {
if (this._isMoving) return;
this._isMoving = true;
this._changeHappened = false;
this._objectInitialPositions.clear();
this.startTime = Date.now();
}

endMove(): boolean {
const changeHappened = this._changeHappened;
this._objectInitialPositions.clear();
this._changeHappened = false;
this._isMoving = false;
return changeHappened;
}

Expand All @@ -674,10 +676,6 @@ namespace gdjs {
scaleZ: float;
}
) {
if (Date.now() - this.startTime < 150) {
// Avoid miss-clicks gizmo dragging point to change object positions.
return;
}
selectedObjects.forEach((object) => {
if (this.editor.isInstanceLocked(object)) {
return;
Expand Down Expand Up @@ -2276,9 +2274,13 @@ namespace gdjs {
const initialDummyPosition = new THREE.Vector3();
const initialDummyRotation = new THREE.Euler();
const initialDummyScale = new THREE.Vector3();
let xyzClickCursorX: float | null = null;
let xyzClickCursorY: float | null = null;
threeTransformControls.addEventListener('change', (e) => {
if (!threeTransformControls.dragging) {
this._selectionControlsMovementTotalDelta = null;
xyzClickCursorX = null;
xyzClickCursorY = null;

this._updateDummyLocation(
dummyThreeObject,
Expand All @@ -2298,6 +2300,27 @@ namespace gdjs {
return;
}

// Avoid moving the object on an XYZ-handle click without drag.
if (
this._transformControlsMode === 'translate' &&
threeTransformControls.axis === 'XYZ'
) {
const inputManager = this._runtimeGame.getInputManager();
const cursorX = inputManager.getCursorX();
const cursorY = inputManager.getCursorY();
if (xyzClickCursorX === null) {
xyzClickCursorX = cursorX;
xyzClickCursorY = cursorY;
}
if (
cursorX === xyzClickCursorX &&
cursorY === xyzClickCursorY
) {
initialDummyPosition.copy(dummyThreeObject.position);
return;
}
}

let translationX =
dummyThreeObject.position.x - initialDummyPosition.x;
let translationY =
Expand Down Expand Up @@ -2403,6 +2426,15 @@ namespace gdjs {
!dummyThreeObject.position.equals(initialDummyPosition) ||
!dummyThreeObject.rotation.equals(initialDummyRotation) ||
!dummyThreeObject.scale.equals(initialDummyScale);

// Apply the movement to the selected objects right away,
// in the same tick as the gizmo update, so the object
// follows the gizmo without any visible delay.
this._objectMover.startMove();
this._objectMover.move(
this._selection.getSelectedObjects(),
this._selectionControlsMovementTotalDelta
);
});

this._selectionControls = {
Expand Down
Loading