将Navisworks剖面转换为伪造

时间:2019-04-08 20:01:34

标签: autodesk-viewer autodesk-navisworks

我正在为Navisworks进行伪造集成,并坚持如何将剖切飞机从Navisworks引入Forge。我按照this blog post中的说明设置了剖切平面,但是我没有看到它们显示在查看器中。要设置飞机,我要从Navisworks ActiveView中提取SectionData并从返回的json对象中提取法线向量和距离,然后通过url参数将数据传递给我的伪造查看器。代码如下:

                  //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事件时,效果很好。

1 个答案:

答案 0 :(得分: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)