I try to show snap icon (some yellow icon go with cursor appear when make measurement) when the cursor hover on the 3d model. This is my function and it not work for me at all. Do i miss some thing ?
onMouseMove = (event) => {
const snapper = new Autodesk.Viewing.Extensions.Snapping.Snapper(this.viewer);
const worldCoordinate = this.viewer.impl.hitTest(event.clientX, event.clientY);
if (worldCoordinate === null) return;
const hitTestResult = this.viewer.impl.snappingHitTest(
worldCoordinate.x,
worldCoordinate.y,
worldCoordinate.z
);
if (hitTestResult === null) return;
snapper.snapping3D(hitTestResult);
const result = snapper.getSnapResult();
}
I'm also reference some of these topic but not work for me. How to use Forge Viewer Snapper? How to activate Autodesk Forge Snapper? https://autodeskviewer.com/viewers/latest/docs/extensions_Measure_Measure.js.html . Thank in advance !
I would think this issue is caused from the missing of container offset of the viewer. The world coordinates cannot be tested correctly. Please check the code below if it helps. If I misunderstood the question,could you share a bit more information on what it is not working?
UPDATE:
onMouseMove = (event) => {
const snapper = new Autodesk.Viewing.Extensions.Snapping.Snapper(this.viewer);
const viewer_pos = this.viewer.container.getBoundingClientRect();
const worldCoordinate = this.viewer.impl.hitTest(event.clientX-viewer_pos.x, event.clientY-viewer_pos.y);
if (worldCoordinate === null) return;
// const hitTestResult = this.viewer.impl.snappingHitTest(
// worldCoordinate.point.x,
// worldCoordinate.point.y,
// worldCoordinate.point.z
// );
//if (hitTestResult === null) return;
snapper.snapping3D(worldCoordinate);
const result = snapper.getSnapResult();
snapper.indicator.render()
}