1

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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.