本文介绍了Autodesk Forge 查看器如何管理多个场景以选择多个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解 Autodesk Forge 查看器如何将节点元素存储在多个 THREE.Scene 对象中.有几个场景:

I want to understand how Autodesk Forge viewer stores node elements in multiple THREE.Scene objects. There are several scenes:

viewer.impl.scene // The main scene
viewer.impl.overlayScenes // Three overlay scenes: selection, pivot and roll

每当在 Forge 查看器中选择一个元素时,它的 THREE.Mesh 对象就会添加到 viewer.impl.overlayScenes.selection.scene.children 中.然而,它的边界几何总是为零,不像原始的 THREE.Mesh 对象在执行 geometry.computeBoundaryBox() 后会有边界

Whenever an element is selected in Forge viewer, its THREE.Mesh object is added to viewer.impl.overlayScenes.selection.scene.children. However its boundary geometry is always zero, unlike primitive THREE.Mesh objects will have boundaries after executing geometry.computeBoundaryBox()

由于 Forge 元素的零边界,我不能使用 THREE.Raycaster 来投射覆盖元素以在鼠标选择时获取它们的 dbId.我如何选择内部 dbId 因为它将获得外部 dbId?Forge 查看器不允许在单击外部对象时选择内部对象.如何在另一个元素中选择一个元素?

Because of the zero boundary of Forge elements, I cannot use THREE.Raycaster to project through overlay elements to get their dbIds on mouse pick. How can I select the inner dbId because it will get the outer dbId? The Forge viewer does not allow to select inner object on click on outer object. How to select an element within another element?

主场景也有空孩子.所有元素都在哪里,它们如何在屏幕上呈现?

The main scene also has empty children. Where are all elements and how can they render on the screen?

了解 Forge 查看器数据结构以获得完整的 API 控制会有更好的文档.必须自己用Autodesk Forge viewer的viewer3D.js和wgs.js自学.

It would have better documentation to understand the Forge viewer data structure to have the full API control. I have to learn by myself with viewer3D.js and wgs.js of Autodesk Forge viewer.

推荐答案

这里有两种方法向您展示如何根据特定组件的 fragmentId 访问其边界框:

Here are two methods that shows you how to access the bounding boxes of specific components based on their fragmentIds:

//returns bounding box as it appears in the viewer
// (transformations could be applied)
function getModifiedWorldBoundingBox(fragIds, fragList) {

  var fragbBox = new THREE.Box3();
  var nodebBox = new THREE.Box3();

  fragIds.forEach(function(fragId) {

    fragList.getWorldBounds(fragId, fragbBox);
    nodebBox.union(fragbBox);
  });

  return nodebBox;
 }

 // Returns bounding box as loaded in the file
 // (no explosion nor transformation)
function getOriginalWorldBoundingBox(fragIds, fragList) {

  var fragBoundingBox = new THREE.Box3();
  var nodeBoundingBox = new THREE.Box3();

  var fragmentBoxes = fragList.boxes;

  fragIds.forEach(function(fragId) {
    var boffset = fragId * 6;
    fragBoundingBox.min.x = fragmentBoxes[boffset];
    fragBoundingBox.min.y = fragmentBoxes[boffset+1];
    fragBoundingBox.min.z = fragmentBoxes[boffset+2];
    fragBoundingBox.max.x = fragmentBoxes[boffset+3];
    fragBoundingBox.max.y = fragmentBoxes[boffset+4];
    fragBoundingBox.max.z = fragmentBoxes[boffset+5];
    nodeBoundingBox.union(fragBoundingBox);
  });

  return nodeBoundingBox;
 }

您可以从下面的博客文章中找到全面的示例:

You can find a comprehensive sample from the blog post below:

获取查看器中每个组件的边界框

这篇关于Autodesk Forge 查看器如何管理多个场景以选择多个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 08:11