为什么我不能悬停并单击 Threejs 转换工具?
Why can't I hover and click the Threejs transformation tools?
我正在尝试制作一个工具来移动我创建的自定义模型。我做的第一步是显示转换工具并执行更改操作。但我无法悬停或单击转换工具。我的代码中是否遗漏了什么?
activateTheTransformTool() {
let bbox = this.viewer.model.getBoundingBox();
this.viewer.impl.createOverlayScene("Dotty.Viewing.Tool.TransformTool");
this.transformControlTx = new THREE.TransformControls(
this.viewer.impl.camera,
this.viewer.impl.canvas,
"translate"
);
this.transformControlTx.setSize(bbox.getBoundingSphere().radius * 5);
this.transformControlTx.visible = false;
this.viewer.impl.addOverlay(
"Dotty.Viewing.Tool.TransformTool",
this.transformControlTx
);
this.transformMesh = this.createTransformMesh();
this.transformControlTx.attach(this.transformMesh);
this.onItemSelected();
}
handleMouseMove(event) {
if (this.transformControlTx) {
if (this.isDragging) {
console.log(this.transformControlTx);
if (this.transformControlTx.onPointerMove(event)) {
return true;
}
return false;
}
if (this.transformControlTx.onPointerHover(event)) return true;
}
//return _transRotControl.onPointerHover(event);
}
onTxChange() {
console.log("onTx change");
this.viewer.impl.sceneUpdated(true);
}
onItemSelected() {
if (this.hitPoint) {
this.transformControlTx.visible = true;
this.transformControlTx.setPosition(this.hitPoint);
this.transformControlTx.addEventListener("change", this.onTxChange);
this.hitPoint = null;
} else {
this.transformControlTx.visible = false;
}
}
您共享的代码似乎没问题(可能取自此 TransformationExtension,对吗?)但由于它只是实现的一部分,所以很难说出哪里出了问题。您是否可能在控制台中看到任何错误或警告?
顺便说一句。我最近在我的一个代码示例中实现了类似的转换 tool/extension:https://github.com/petrbroz/forge-simple-viewer-nodejs/tree/experiment/xform-tool. You should be able to drop the TransformToolExtension.js into your Forge app, include the extension's ID when initializing the viewer (like I do here),一切顺利。
我正在尝试制作一个工具来移动我创建的自定义模型。我做的第一步是显示转换工具并执行更改操作。但我无法悬停或单击转换工具。我的代码中是否遗漏了什么?
activateTheTransformTool() {
let bbox = this.viewer.model.getBoundingBox();
this.viewer.impl.createOverlayScene("Dotty.Viewing.Tool.TransformTool");
this.transformControlTx = new THREE.TransformControls(
this.viewer.impl.camera,
this.viewer.impl.canvas,
"translate"
);
this.transformControlTx.setSize(bbox.getBoundingSphere().radius * 5);
this.transformControlTx.visible = false;
this.viewer.impl.addOverlay(
"Dotty.Viewing.Tool.TransformTool",
this.transformControlTx
);
this.transformMesh = this.createTransformMesh();
this.transformControlTx.attach(this.transformMesh);
this.onItemSelected();
}
handleMouseMove(event) {
if (this.transformControlTx) {
if (this.isDragging) {
console.log(this.transformControlTx);
if (this.transformControlTx.onPointerMove(event)) {
return true;
}
return false;
}
if (this.transformControlTx.onPointerHover(event)) return true;
}
//return _transRotControl.onPointerHover(event);
}
onTxChange() {
console.log("onTx change");
this.viewer.impl.sceneUpdated(true);
}
onItemSelected() {
if (this.hitPoint) {
this.transformControlTx.visible = true;
this.transformControlTx.setPosition(this.hitPoint);
this.transformControlTx.addEventListener("change", this.onTxChange);
this.hitPoint = null;
} else {
this.transformControlTx.visible = false;
}
}
您共享的代码似乎没问题(可能取自此 TransformationExtension,对吗?)但由于它只是实现的一部分,所以很难说出哪里出了问题。您是否可能在控制台中看到任何错误或警告?
顺便说一句。我最近在我的一个代码示例中实现了类似的转换 tool/extension:https://github.com/petrbroz/forge-simple-viewer-nodejs/tree/experiment/xform-tool. You should be able to drop the TransformToolExtension.js into your Forge app, include the extension's ID when initializing the viewer (like I do here),一切顺利。