0

我正在为 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 事件时它工作得很好。

4

1 回答 1

0

我做了一些调查,发现了一些在 Navisworks 和 Forge Viewer 之间映射剖面的技巧。这是关于该主题的博客: https ://forge.autodesk.com/blog/map-sectioning-plane-navisworks-forge-viewer-2

核心代码是

//get offset of the model
let forge_model_offset = NOP_VIEWER.model.getData().globalOffset

 // assume the param of Navisworks clip plane is available 
//I copied from the XML file
let navis_clip_plane = 
   {x:0.1368226246,y:0.4334009763,z:0.8907542664,d:886.2418151801}

//calculate exact distance in Forge Viewer
dis_in_forge =( forge_model_offset.x * navis_clip_plane.x  +   
                    forge_model_offset.y * navis_clip_plane.y + 
                    forge_model_offset.z * navis_clip_plane.z) - 
                navis_clip_plane.d

//build the plane for Forge Viewer sectioning.
cutplanes = [
new THREE.Vector4( -navis_clip_plane.x, 
                   -navis_clip_plane.y, 
                   - navis_clip_plane.z, -dis_in_forge) 
  ];

 //apply the plane to sectioning
 NOP_VIEWER.setCutPlanes(cutplanes)
于 2019-04-10T07:59:11.103 回答