我想了解Autodesk Forge查看器如何在多个THREE.Scene对象中存储节点元素。有几个场景:
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()之后会有边界。
由于Forge元素的零边界,我不能使用THREE.Raycaster投影覆盖元素来获取鼠标选择的dbIds。如何选择内部dbId,因为它将获得外部dbId? Forge查看器不允许在单击外部对象时选择内部对象。如何在另一个元素中选择一个元素?
主场景也有空子。所有元素在哪里?它们如何在屏幕上呈现?
有了更好的文档来理解Forge查看器数据结构以获得完整的API控件。我必须自己学习Autodesk Forge查看器的viewer3D.js和wgs.js。
答案 0 :(得分:1)
以下两种方法向您展示如何根据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;
}
您可以从以下博客文章中找到全面的示例:
Getting bounding boxes of each component in the viewer
现场演示there。