问题
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