iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
600 stars 210 forks source link

unable to snap bounding box #5896

Closed abhijitpatil181171 closed 7 months ago

abhijitpatil181171 commented 1 year ago

i have created bounding box and gltf graphic . i also have enable the snap but when i hover my cursor on both gltf as well as bounding box i am unable to snap points out of them .any suggestion to enable snap on them


⚠ Do not edit this section. It is required for imodeljs.github.io ➟ GitHub issue linking

pmconne commented 1 year ago

You need to make a pickable graphic and tell AccuSnap what its snappable geometry looks like. https://www.itwinjs.org/reference/core-frontend/views/decorator/getdecorationgeometry/ If problems persist, show your code.

YashodipD commented 1 year ago

Hi @abhijitpatil181171 , below are my assumptions while answering to this question,

My answer starts here - GltfGraphic returned by readGltf() contains 2 bounding boxes. The type of bounding box is [Range3d] (https://www.itwinjs.org/reference/core-geometry/cartesiangeometry/range3d/). Range3d is an Axis Aligned Bounding Box (AABB) which does not have additional information which Mesh provides for solid primitives. For snapping purpose, you would want to use Oriented Bounding Box (OBB). In iTwin.js closest possible OBB is solid primitive Box . Solid Primitives are snappable also we can transform them in any direction you want.

In snapping - when testDecorationHit() returns true, you can return OBB using getDecorationGeometry(). Here is my example -


  public testDecorationHit(id: Id64String): boolean {
    return this._placedGraphics.has(id); // using Map to store id, RenderGraphic + Solid Bounding Box (Not Axis Aligned)
  }
  public getDecorationGeometry(hit: HitDetail): GeometryStreamProps | undefined {
    if (0 === this._placedGraphics.size) return; // Here I am assuming we are using Map data structure
    if (!this._placedGraphics.has(hit.sourceId)) return undefined; // checking if we have graphics with hit details
    const geometryStream: GeometryStreamProps = []; 
    const gltfGraphic = this._placedGraphics.get(hit.sourceId);
    geometryStream.push(IModelJson.Writer.toIModelJson(gltfGraphic?.OBB));
    return geometryStream;
  }

If still it does not help, please add more details here. Soon we will be releasing official sample for similar glTF snapping, stay tuned!

abhijitpatil181171 commented 1 year ago

thanks