Skip to content

Commit b5b6029

Browse files
arjxn-pypre-commit-ci[bot]martinRenou
authored
Rotation Controls (#603)
* undo opencascade positioning and rotation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use Math.PI * Recentering done * Translation is smooth * Apply suggestions from code review Co-authored-by: martinRenou <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add helping comment * Try fixing exploded view * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * create interface `IMeshGroupMetadata` and assign originalPosition in buildShape * Rotation works * refactor exploded view logic * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * only `newGeometryCenter` is not right * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * expand boundingGroup via meshGroup * Refactoring * Merge review suggestions * `getQuaternion` method * fallback not needed * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * rebase issue * more refactoring * Remove originalPosition refactor groupMetadata * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * in theory, this seems correct * rebase issue fixes * Update packages/base/src/3dview/mainview.tsx Co-authored-by: martinRenou <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * prevent default enabling transform controls * fix rebasing issue * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update packages/base/src/3dview/mainview.tsx Co-authored-by: martinRenou <[email protected]> * Add fallback for updatedRotation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: martinRenou <[email protected]>
1 parent 6d6ba9c commit b5b6029

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

packages/base/src/3dview/mainview.tsx

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,24 @@ export class MainView extends React.Component<IProps, IStates> {
423423

424424
const updatedPosition = new THREE.Vector3();
425425
updatedObject.getWorldPosition(updatedPosition);
426+
const updatedQuaternion = new THREE.Quaternion();
427+
updatedObject.getWorldQuaternion(updatedQuaternion);
428+
429+
const s = Math.sqrt(1 - updatedQuaternion.w * updatedQuaternion.w);
430+
431+
let updatedRotation;
432+
if (s > 1e-6) {
433+
updatedRotation = [
434+
[
435+
updatedQuaternion.x / s,
436+
updatedQuaternion.y / s,
437+
updatedQuaternion.z / s
438+
],
439+
2 * Math.acos(updatedQuaternion.w) * (180 / Math.PI)
440+
];
441+
} else {
442+
updatedRotation = [[0, 0, 1], 0];
443+
}
426444

427445
const obj = this._model.sharedModel.getObjectByName(objectName);
428446

@@ -437,7 +455,9 @@ export class MainView extends React.Component<IProps, IStates> {
437455
...obj.parameters,
438456
Placement: {
439457
...obj.parameters.Placement,
440-
Position: newPosition
458+
Position: newPosition,
459+
Axis: updatedRotation[0],
460+
Angle: updatedRotation[1]
441461
}
442462
});
443463
}
@@ -724,18 +744,21 @@ export class MainView extends React.Component<IProps, IStates> {
724744

725745
private _onKeyDown(event: KeyboardEvent) {
726746
// TODO Make these Lumino commands? Or not?
727-
if (this._clipSettings.enabled) {
728-
switch (event.key) {
729-
case 'r':
730-
event.preventDefault();
731-
event.stopPropagation();
747+
if (this._clipSettings.enabled || this._transformControls.enabled) {
748+
const toggleMode = (control: any) => {
749+
control.setMode(control.mode === 'rotate' ? 'translate' : 'rotate');
750+
};
732751

733-
if (this._clipPlaneTransformControls.mode === 'rotate') {
734-
this._clipPlaneTransformControls.setMode('translate');
735-
} else {
736-
this._clipPlaneTransformControls.setMode('rotate');
737-
}
738-
break;
752+
if (event.key === 'r' && this._clipSettings.enabled) {
753+
event.preventDefault();
754+
event.stopPropagation();
755+
toggleMode(this._clipPlaneTransformControls);
756+
}
757+
758+
if (event.key === 'r' && this._transformControls.enabled) {
759+
event.preventDefault();
760+
event.stopPropagation();
761+
toggleMode(this._transformControls);
739762
}
740763
}
741764
}

0 commit comments

Comments
 (0)