How to use Forge Viewer Snapper?

℡╲_俬逩灬. 提交于 2021-02-05 07:44:31

问题


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.

I look at this topic but doesn't work for me : How to activate Autodesk Forge Snapper?

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);

In the log the snapper is activated but i am enable to pick a point in viewer ann to get results with getSnapResult function.

Thank you in advance


回答1:


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.



来源:https://stackoverflow.com/questions/60400113/how-to-use-forge-viewer-snapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!