如何使用 Forge Viewer Snapper? [英] How to use Forge Viewer Snapper?
问题描述
我正在尝试使用 Forge Viewer 中的 Snapper 功能来要求用户选择一个点,然后检索所选点的点世界坐标.
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');
然后尝试像这样使用 Snapper:
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 Snapper?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!