如何使用Forge Viewer鲷鱼? [英] How to use Forge Viewer Snapper?
问题描述
我正在尝试使用Forge Viewer中的快照程序功能,以要求用户选择一个点,然后检索所选点的点世界坐标.
I'm trying to use Snapper functionnalities from Forge Viewer in order to ask user to pick a point and then retrieve point world coordinates of selected point.
我正在查看此主题,但不适用于我:如何激活Autodesk锻造鲷鱼?
I look at this topic but doesn't work for me : How to activate Autodesk Forge Snapper?
我像这样加载扩展名: this.viewer.loadExtension('Autodesk.Snapping');
I load the extension like that :
this.viewer.loadExtension('Autodesk.Snapping');
然后尝试像这样使用快照程序:
And then try to use the Snapper like that:
console.log(this._viewer.toolController.getActiveToolName());
var snapper = new Autodesk.Viewing.Extensions.Snapping.Snapper(this._viewer, {});
this._viewer.toolController.registerTool(snapper);
this._viewer.toolController.activateTool('snapper');
console.log(this._viewer.toolController.getToolNames());
console.log(this._viewer.toolController.getActiveToolName());
var a = snapper.getSnapResult();
console.log(a);
在日志中,快照程序已激活,但是我可以在查看器中选择一个点,以使用getSnapResult函数获取结果.
In the log the snapper is activated but i am enable to pick a point in viewer ann to get results with getSnapResult function.
提前谢谢
推荐答案
Snapper工具适用于2d和3d模型,您将需要提供通过(例如)测试为阳性的匹配测试结果.在画布上单击,然后说:
The snapper tool works with both 2d and 3d models and you will need to provide a hit test result that is tested positive by e.g. a click on the canvas, so say:
const snapper = new Autodesk.Viewing.Extensions.Snapping.Snapper(NOP_VIEWER)
const hitTestResult = NOP_VIEWER.impl.snappingHitTest(clickEvent.x, clickEvent.y)
snapper.snapping3D(hitTestResult)
snapper.getSnapResult()
您可以使用自定义工具订阅画布点击事件-有关详细信息,请参见此处.
You may subscribe to canvas click events with your custom tool - see here for details.
这篇关于如何使用Forge Viewer鲷鱼?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!