0

I am plotting a label when user clicks on a dbId, for that I use below function to find coordinates but it gives me back some wrong coordinates instead proper ones. for example to get x coordinate as somewhere near 400, am getting 12.85 only.

function getObjPosition(dbId) {
    const model = viewer.model;
    const instanceTree = model.getData().instanceTree;
    const fragList = model.getFragmentList();

    let bounds = new THREE.Box3();

    instanceTree.enumNodeFragments( dbId, ( fragId ) => {
        let box = new THREE.Box3();
        fragList.getWorldBounds( fragId, box );
        bounds.union( box );
    }, true );

    const position = bounds.center();
    return position;
}
A DEv
  • 255
  • 1
  • 19

2 Answers2

0

It seems like I find out the solution.

Finally we have to use worldToClient to get corresponding coordinates. But am wondering why these things are not documented in a proper place to explain newbies like me to explore this domain?

position =viewer.worldToClient(new THREE.Vector3(position.x,position.y,position.z))

A DEv
  • 255
  • 1
  • 19
-1

Try cancel the global offsets by setting the below in your load options:

const options={
   globalOffset:{x:0,y:0,z:0}
   //...
}
viewer.loadModel/start(svf, options)
viewer.loadDocumentNode(doc, geo, options)
Bryan Huang
  • 5,247
  • 2
  • 15
  • 20
  • No, its not working. now x coordinate became to 90 as earlier it was only 12, but actual position of dbId is some 400 for x coordinate. Tried for some other dbId's but same issue. – A DEv Feb 24 '20 at 05:19