I am currently working on a project using Typescript within the Autodesk Forge Viewer environment. My goal is to restrict the movement of the ThreeJS transform control to a specific area defined by min and max values for X, Y, and Z coordinates. Additionally, I keep track of any changes in the mesh position using a variable called prev_pos.
Within the 'change' event listener of the Transform Control, I compare the current mesh position to the specified min and max values.
If the mesh position falls outside of the designated area, I reset it to the limit and update prev_pos accordingly. However, I also want to release the control from the transform control so that it resets its position to match the attached mesh.
Currently, even though the attached mesh resets to the limit, the control can still be dragged. Subsequently, the control's position becomes offset from the mesh, causing unintended movements when hovering over the control. I attempted resetting the control position with transformControl.position.copy(mesh.position) but this approach proved ineffective. Below is the code snippet for the 'change' event:
public onTxChange() {
console.log("TxChange");
if (!this.allowUpdate) {
return;
}
let position: THREE.Vector3 = new THREE.Vector3(0, 0, 0);
if (this.m_mesh !== null) {
position.x = this.m_mesh.position.x;
position.y = this.m_mesh.position.y;
position.z = this.m_mesh.position.z;
}
else {
return;
}
const scaffoldGroupInfo: scaffold_group_info = g_scaffold_docking_panel_cmn.getScaffoldGroupInfo();
const color: string = scaffoldGroupInfo.color;
let deltaX: number = position.x - this.m_prevPos.x;
let deltaY: number = position.y - this.m_prevPos.y;
let deltaZ: number = position.z - this.m_prevPos.z;
console.log("DeltaX");
console.log(deltaX);
if (deltaX > 0) {
scaffold_cmn.cubeExpantion(g_scaffold_docking_panel_cmn.getsetHomePosition(), "X", false, color, deltaX);
}
else if (deltaX < 0) {
scaffold_cmn.cubeExpantion(g_scaffold_docking_panel_cmn.getsetHomePosition(), "X", true, color, deltaX * -1);
}
if (deltaY > 0) {
scaffold_cmn.cubeExpantion(g_scaffold_docking_panel_cmn.getsetHomePosition(), "Y", false, color, deltaY * 1);
}
else if (deltaY < 0) {
<scaffold_cmn.cubeExpantion(g_scaffold_docking_panel_cmn.getsetHomePosition(), "Y", true, color, deltaY * -1);
}
if (deltaZ > 0) {
scaffold_cmn.cubeExpantion(g_scaffold_docking_panel_cmn.getsetHomePosition(), "Z", true, color, deltaZ);
}
else if (deltaZ < 0) {
scaffold_cmn.cubeExpansion(g_scaffold_docking_panel_cmn.getsetHomePosition(), "Z", false, color, deltaZ * -1);
}
if (!scaffold_cmn.CubeResizable) {
scaffold_cmn.ResetAttachedMeshPositionRotation();
return;
}
this.m_prevPos = position;
}