Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Translation Controls #529

Merged
merged 25 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a05883f
i can transform cube
arjxn-py Oct 23, 2024
e40db3a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
232e2dc
use name
arjxn-py Oct 23, 2024
8cc8601
transform working but transform axes exaggerates
arjxn-py Oct 24, 2024
680f9cd
It's better
arjxn-py Oct 24, 2024
b5f318d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 24, 2024
01df5cc
Do something on trannform control change
arjxn-py Oct 24, 2024
a91f16e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 24, 2024
ceb3863
Positioning works
arjxn-py Oct 25, 2024
e41826c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2024
8301256
Merge branch 'main' into transform-controls
arjxn-py Oct 26, 2024
9f6000e
Merge branch 'main' into transform-controls
arjxn-py Nov 3, 2024
0d9e709
Finally the mess is clear (Atleast)
arjxn-py Nov 4, 2024
51632be
Use sharedModel for translation
arjxn-py Nov 5, 2024
5989336
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
1f82bbd
Dont recenter
arjxn-py Nov 5, 2024
f13b94b
A little cleanup
arjxn-py Nov 5, 2024
12795ed
Merge branch 'main' into transform-controls
arjxn-py Nov 5, 2024
c7530a6
limit to translation for now
arjxn-py Nov 5, 2024
a6d618d
Compatible with clipplane
arjxn-py Nov 5, 2024
8777b46
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
9c1e5ea
fix
arjxn-py Nov 5, 2024
a742a0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2024
0f65631
Refactor transformation logic to allow only when single object is sel…
arjxn-py Nov 6, 2024
dc2b011
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 6, 2024
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
94 changes: 88 additions & 6 deletions packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ export class MainView extends React.Component<IProps, IStates> {
this._transformControls.enabled = false;
this._transformControls.visible = false;
this._createViewHelper();
this._updateTransformControls();
}
};

Expand Down Expand Up @@ -813,6 +814,7 @@ export class MainView extends React.Component<IProps, IStates> {

this._scene.add(this._clippingPlaneMesh);
this._scene.add(this._meshGroup);

if (this._loadingTimeout) {
clearTimeout(this._loadingTimeout);
this._loadingTimeout = null;
Expand Down Expand Up @@ -1019,7 +1021,16 @@ export class MainView extends React.Component<IProps, IStates> {
return mesh;
}

private _previousSelection: { [key: string]: ISelection } | null = null;
private _updateSelected(selection: { [key: string]: ISelection }) {
const selectionChanged =
JSON.stringify(selection) !== JSON.stringify(this._previousSelection);

if (!selectionChanged) {
return;
}
this._previousSelection = { ...selection };

// Reset original color and remove bounding boxes for old selection
for (const selectedMesh of this._selectedMeshes) {
let originalColor = selectedMesh.userData.originalColor;
Expand Down Expand Up @@ -1048,20 +1059,25 @@ export class MainView extends React.Component<IProps, IStates> {
if (material?.linewidth) {
material.linewidth = DEFAULT_LINEWIDTH;
}

// Detach TransformControls from the previous selection
if (!this._clipSettings.enabled) {
{
this._transformControls.detach();
}
}
}

// Set new selection
this._selectedMeshes = [];
for (const selectionName in selection) {
const selectedNames = Object.keys(selection);

for (const selectionName of selectedNames) {
const selectedMesh = this._meshGroup?.getObjectByName(
selectionName
) as BasicMesh;

if (!selectedMesh) {
continue;
}

if (!selectedMesh.visible) {
if (!selectedMesh || !selectedMesh.visible) {
continue;
}

Expand Down Expand Up @@ -1099,6 +1115,70 @@ export class MainView extends React.Component<IProps, IStates> {
}
}
}

if (selectedNames.length === 1 && !this._clipSettings.enabled) {
const selectedMeshName = selectedNames[0];
const matchingChild = this._meshGroup?.children.find(child =>
child.name.startsWith(selectedMeshName)
);

if (matchingChild) {
this._transformControls.attach(matchingChild as BasicMesh);

const obj = this._model.sharedModel.getObjectByName(selectedMeshName);
const positionArray = obj?.parameters?.Placement?.Position;

if (positionArray && positionArray.length === 3) {
const positionVector = new THREE.Vector3(
positionArray[0],
positionArray[1],
positionArray[2]
);
this._transformControls.position.copy(positionVector);
}

this._transformControls.setMode('translate');
this._transformControls.visible = true;
this._transformControls.enabled = true;
}
}
}

private _updateTransformControls() {
this._transformControls.addEventListener('mouseUp', () => {
if (this._clipSettings.enabled) {
return;
}
const updatedObject = this._selectedMeshes[0];
const objectName = updatedObject.name;

const updatedPosition = new THREE.Vector3();
updatedObject.getWorldPosition(updatedPosition);

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

if (obj && obj.parameters && obj.parameters.Placement) {
const positionArray = obj?.parameters?.Placement?.Position;
const newPosition = [
positionArray[0] + updatedPosition.x,
positionArray[1] + updatedPosition.y,
positionArray[2] + updatedPosition.z
];

this._model.sharedModel.updateObjectByName(objectName, {
data: {
key: 'parameters',
value: {
...obj.parameters,
Placement: {
...obj.parameters.Placement,
Position: newPosition
}
}
}
});
}
});
}

private _onSharedMetadataChanged = (
Expand Down Expand Up @@ -1450,6 +1530,8 @@ export class MainView extends React.Component<IProps, IStates> {
this._renderer.localClippingEnabled = true;
this._transformControls.enabled = true;
this._transformControls.visible = true;
this._transformControls.attach(this._clippingPlaneMeshControl);
this._transformControls.position.copy(new THREE.Vector3(0, 0, 0));
this._clippingPlaneMeshControl.visible = this._clipSettings.showClipPlane;
if (this._clippingPlaneMesh) {
this._clippingPlaneMesh.visible = true;
Expand Down
Loading