WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit b930ffe

Browse files
authored
Keep the chosen tool in the 3D editor even when selection changes
1 parent 766afee commit b930ffe

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

GDJS/Runtime/InGameEditor/InGameEditor.tsx

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,8 @@ namespace gdjs {
812812
dummyThreeObject: THREE.Object3D;
813813
threeTransformControls: THREE_ADDONS.TransformControls;
814814
} | null = null;
815+
private _transformControlsMode: 'translate' | 'rotate' | 'scale' =
816+
'translate';
815817
private _editorGrid: EditorGrid;
816818
private _selectionControlsMovementTotalDelta: {
817819
translationX: float;
@@ -2091,20 +2093,14 @@ namespace gdjs {
20912093
this._selectionBoxes.set(object, objectBoxHelper);
20922094
}
20932095

2094-
private _getTransformControlsMode():
2095-
| 'translate'
2096-
| 'rotate'
2097-
| 'scale'
2098-
| null {
2099-
if (!this._selectionControls) {
2100-
return null;
2101-
}
2102-
return this._selectionControls.threeTransformControls.mode;
2096+
private _getTransformControlsMode(): 'translate' | 'rotate' | 'scale' {
2097+
return this._transformControlsMode;
21032098
}
21042099

21052100
private _setTransformControlsMode(
21062101
mode: 'translate' | 'rotate' | 'scale'
21072102
): void {
2103+
this._transformControlsMode = mode;
21082104
if (!this._selectionControls) {
21092105
return;
21102106
}
@@ -2124,22 +2120,17 @@ namespace gdjs {
21242120
return;
21252121
}
21262122
dummyThreeObject.rotation.copy(threeObject.rotation);
2127-
if (threeTransformControls.mode === 'rotate') {
2123+
if (this._transformControlsMode === 'rotate') {
21282124
dummyThreeObject.rotation.y = -dummyThreeObject.rotation.y;
21292125
dummyThreeObject.rotation.z = -dummyThreeObject.rotation.z;
21302126
}
21312127
}
21322128

21332129
private _forceUpdateSelectionControls() {
2134-
let mode: 'translate' | 'rotate' | 'scale' | null = null;
21352130
if (this._selectionControls) {
2136-
mode = this._selectionControls.threeTransformControls.mode;
21372131
this._removeSelectionControls();
21382132
}
21392133
this._updateSelectionControls();
2140-
if (mode && this._selectionControls) {
2141-
this._setTransformControlsMode(mode);
2142-
}
21432134
}
21442135

21452136
private _updateSelectionControls() {
@@ -2212,6 +2203,7 @@ namespace gdjs {
22122203

22132204
threeTransformControls.rotation.order = 'ZYX';
22142205
threeTransformControls.scale.y = -1;
2206+
threeTransformControls.mode = this._transformControlsMode;
22152207
threeTransformControls.traverse((obj) => {
22162208
// To be detected correctly by OutlinePass.
22172209
// @ts-ignore
@@ -2267,7 +2259,7 @@ namespace gdjs {
22672259
let translationZ =
22682260
dummyThreeObject.position.z - initialDummyPosition.z;
22692261
if (
2270-
threeTransformControls.mode === 'translate' &&
2262+
this._transformControlsMode === 'translate' &&
22712263
threeTransformControls.axis
22722264
) {
22732265
if (threeTransformControls.axis === 'XYZ') {
@@ -2428,7 +2420,7 @@ namespace gdjs {
24282420
this._editorGrid.setTreeScene(threeScene);
24292421
}
24302422
this._editorGrid.setVisible(
2431-
threeTransformControls.mode === 'translate'
2423+
this._transformControlsMode === 'translate'
24322424
);
24332425
}
24342426
}
@@ -2443,7 +2435,7 @@ namespace gdjs {
24432435
dummyThreeObject.position.copy(threeObject.position);
24442436
dummyThreeObject.rotation.copy(threeObject.rotation);
24452437
dummyThreeObject.scale.copy(threeObject.scale);
2446-
if (threeTransformControls.mode === 'rotate') {
2438+
if (this._transformControlsMode === 'rotate') {
24472439
// This is only done for the rotate mode because it messes with the
24482440
// orientation of the scale mode.
24492441
dummyThreeObject.rotation.y = -dummyThreeObject.rotation.y;
@@ -3550,11 +3542,7 @@ namespace gdjs {
35503542
orbitCameraButton: HTMLButtonElement;
35513543
} | null = null;
35523544
private _parent: HTMLElement | null = null;
3553-
private _getTransformControlsMode: () =>
3554-
| 'translate'
3555-
| 'rotate'
3556-
| 'scale'
3557-
| null;
3545+
private _getTransformControlsMode: () => 'translate' | 'rotate' | 'scale';
35583546
private _setTransformControlsMode: (
35593547
mode: 'translate' | 'rotate' | 'scale'
35603548
) => void;
@@ -3653,7 +3641,7 @@ namespace gdjs {
36533641
getSvgIconUrl,
36543642
hasSelectionControlsShown,
36553643
}: {
3656-
getTransformControlsMode: () => 'translate' | 'rotate' | 'scale' | null;
3644+
getTransformControlsMode: () => 'translate' | 'rotate' | 'scale';
36573645
setTransformControlsMode: (
36583646
mode: 'translate' | 'rotate' | 'scale'
36593647
) => void;

0 commit comments

Comments
 (0)