我正在为 Navisworks 进行锻造集成,但我一直坚持如何将剖切面从 Navisworks 引入到 Forge。我按照这篇博文中的说明设置了剖切面,但我没有看到它们出现在查看器中。为了设置平面,我从 Navisworks ActiveView 中提取 SectionData 并从返回的 json 对象中提取法线向量和距离,然后通过 url 参数将数据传递给我的 forge 查看器。代码如下:
//set cut planes
if (planes.length > 0)
{
var three_planes = [];
var i;
for (i = 0; i < planes.length; i += 4)
{
var a = String(planes[i]);
var b = String(planes[i+1]);
var c = String(planes[i+2]);
var distance = String(planes[i+3]);
if (a.includes("E") || a.includes("e"))
{
a = "0.00";
}
if (b.includes("E") || b.includes("e"))
{
b = "0.00";
}
if (c.includes("E") || c.includes("e"))
{
c = "0.00";
}
if (distance.includes("E") || distance.includes("e"))
{
distance = "0.00";
}
var afloat = parseFloat(a);
var bfloat = parseFloat(b);
var cfloat = parseFloat(c);
var distancefloat = parseFloat(distance);
// create a THREE.Vector4
var vector4 = new THREE.Vector4(
afloat, bfloat,
cfloat, distancefloat);
three_planes.push(vector4);
}
viewer.setCutPlanes(three_planes);
}
查看器状态显示飞机在那里但看不到它们。是否需要进行任何特殊的坐标转换才能完成这项工作?
编辑:我尝试了下面给出的解决方案,但我仍然没有在 Forge 中看到切割面。我已经确认来自 Navis 的剖切面变量(afloat、bfloat、cfloat、distancefloat)正确输入。我修改后的代码如下。知道我可能做错了什么吗?
//set cut planes
if (planes.length > 0)
{
var three_planes = [];
var i;
for (i = 0; i < planes.length; i += 4)
{
var a = String(planes[i]);
var b = String(planes[i+1]);
var c = String(planes[i+2]);
var distance = String(planes[i+3]);
if (a.includes("E") || a.includes("e"))
{
a = "0.00";
}
if (b.includes("E") || b.includes("e"))
{
b = "0.00";
}
if (c.includes("E") || c.includes("e"))
{
c = "0.00";
}
if (distance.includes("E") || distance.includes("e"))
{
distance = "0.00";
}
var afloat = parseFloat(a);
var bfloat = parseFloat(b);
var cfloat = parseFloat(c);
var distancefloat = parseFloat(distance);
var forge_model_offset = NOP_VIEWER.model.getData().globalOffset;
//calculate exact distance in Forge Viewer
var dis_in_forge = (forge_model_offset.x * afloat + forge_model_offset.y * bfloat + forge_model_offset.z * cfloat) -
distancefloat;
//build the plane for Forge Viewer sectioning.
var vector4 = new THREE.Vector4(-afloat, -bfloat, -cfloat, -dis_in_forge);
three_planes.push(vector4);
}
NOP_VIEWER.setCutPlanes(three_planes);
}
编辑2:让它工作。在这里发帖以防有人遇到这个问题。setCutPlanes 必须在加载过程的后期调用。我的代码最初是从 onModelLoadSuccess 调用它,但它不起作用。但是当我将它移到 TEXTURES_LOADED 事件时它工作得很好。