[英]Forge Viewer - getting wrong x y z coordinates while using instranceTree of viewer
当用户点击 dbId 时,我正在绘制一个标签,为此我使用下面的函数来查找坐标,但它给了我一些错误的坐标而不是正确的坐标。 例如,要获得接近 400 的 x 坐标,我只能得到 12.85。
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;
}
看来我找到了解决方案。
最后我们必须使用 worldToClient 来获取对应的坐标。 但我想知道为什么这些东西没有记录在适当的地方来解释像我这样的新手探索这个领域?
position =viewer.worldToClient(new THREE.Vector3(position.x,position.y,position.z))
尝试通过在加载选项中设置以下内容来取消全局偏移:
const options={
globalOffset:{x:0,y:0,z:0}
//...
}
viewer.loadModel/start(svf, options)
viewer.loadDocumentNode(doc, geo, options)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.