コード例 #1
0
        public static void AddPointsToObj(ref Obj obj, List <Vector3> pPoints, Vector3 pOffset, bool pMoveToCenter = true)
        {
            foreach (Vector3 p in pPoints)
            {
                Vector3 clonePoint = p;
                if (pMoveToCenter)
                {
                    MoveToCenter(ref clonePoint);
                }
                else
                {
                    MoveByOffset(ref clonePoint, pOffset);
                }

                //swap yz in obj
                //SwapYZ(ref clonePoint);

                Vertex v1 = new Vertex(clonePoint, obj.GetNextVertexIndex());
                obj.AddVertex(v1);

                Vertex v2 = new Vertex(clonePoint + Vector3.UnitX * POINT_OFFSET, obj.GetNextVertexIndex());
                obj.AddVertex(v2);

                Vertex v3 = new Vertex(clonePoint + Vector3.UnitZ * POINT_OFFSET, obj.GetNextVertexIndex());
                obj.AddVertex(v3);

                obj.FaceList.Add(new Face(new List <Vertex> {
                    v1, v2, v3
                }));

                //create 4-side representation of point - otherwise just triangle - big data save
                if (!simplePointsObj)
                {
                    Vertex v4 = new Vertex(clonePoint + Vector3.UnitY * POINT_OFFSET, obj.GetNextVertexIndex());
                    obj.AddVertex(v4);
                    obj.FaceList.Add(new Face(new List <Vertex> {
                        v1, v2, v4
                    }));
                    obj.FaceList.Add(new Face(new List <Vertex> {
                        v1, v3, v4
                    }));
                    obj.FaceList.Add(new Face(new List <Vertex> {
                        v2, v3, v4
                    }));
                }
            }
        }
コード例 #2
0
        public static void AddLineToObj(ref Obj obj, Vector3 pFrom, Vector3 pTo, float pWidthMultiply = 1)
        {
            MoveToCenter(ref pFrom);
            //SwapYZ(ref pFrom);
            float pointOffset = POINT_OFFSET * pWidthMultiply;

            Vertex v1 = new Vertex(pFrom, obj.GetNextVertexIndex());

            obj.AddVertex(v1);
            Vertex v2 = new Vertex(pFrom + Vector3.UnitX * pointOffset, obj.GetNextVertexIndex());

            obj.AddVertex(v2);
            Vertex v3 = new Vertex(pFrom + Vector3.UnitZ * pointOffset, obj.GetNextVertexIndex());

            obj.AddVertex(v3);

            MoveToCenter(ref pTo);
            //SwapYZ(ref pTo);

            Vertex v4 = new Vertex(pTo, obj.GetNextVertexIndex());

            obj.AddVertex(v4);

            /*Vertex v5 = new Vertex(nextP + Vector3.UnitX * POINT_OFFSET, vertexIndex);
             * pointVertices.Add(v5);
             * vertexIndex++;
             * Vertex v6 = new Vertex(p + Vector3.UnitZ * POINT_OFFSET, vertexIndex);
             * pointVertices.Add(v6);
             * vertexIndex++;*/

            //create 4-side representation of point
            obj.FaceList.Add(new Face(new List <Vertex> {
                v1, v2, v4
            }));
            obj.FaceList.Add(new Face(new List <Vertex> {
                v2, v3, v4
            }));
            obj.FaceList.Add(new Face(new List <Vertex> {
                v3, v1, v4
            }));

            //obj.FaceList.Add(new Face(new List<Vertex> { v4, v5, v3 }));
            //obj.FaceList.Add(new Face(new List<Vertex> { v5, v6, v3 }));
            //obj.FaceList.Add(new Face(new List<Vertex> { v6, v4, v3 }));
        }
コード例 #3
0
        public static void AddFaceToObj(ref Obj obj, Vector3 pPoint1, Vector3 pPoint2, Vector3 pPoint3)
        {
            MoveToCenter(ref pPoint1);
            MoveToCenter(ref pPoint2);
            MoveToCenter(ref pPoint3);
            //float pointOffset = POINT_OFFSET;

            Vertex v1 = new Vertex(pPoint1, obj.GetNextVertexIndex());

            obj.AddVertex(v1);
            Vertex v2 = new Vertex(pPoint2, obj.GetNextVertexIndex());

            obj.AddVertex(v2);
            Vertex v3 = new Vertex(pPoint3, obj.GetNextVertexIndex());

            obj.AddVertex(v3);

            obj.FaceList.Add(new Face(new List <Vertex> {
                v1, v2, v3
            }));
        }
コード例 #4
0
        public static Obj ExportToObj(string pArrayName, EExportStrategy pStrategy, bool pUseSmoothHeight,
                                      Tuple <int, int> pStartIndex, Tuple <int, int> pEndIndex)
        {
            CGroundArray pArray    = CProjectData.Points.groundArray;
            Obj          obj       = new Obj(pArrayName);
            float        minHeight = CProjectData.GetMinHeight();

            int missingCoordCount = 0;

            int xStart = pStartIndex.Item1;
            int yStart = pStartIndex.Item2;
            int xEnd   = pEndIndex.Item1 + 1;
            int yEnd   = pEndIndex.Item2 + 1;

            xEnd = Math.Min(xEnd, pArray.arrayXRange);
            yEnd = Math.Min(yEnd, pArray.arrayYRange);

            //prepare vertices
            for (int x = xStart; x < xEnd; x++)
            {
                for (int y = yStart; y < yEnd; y++)
                {
                    Vertex       v      = new Vertex();
                    CGroundField el     = pArray.GetField(x, y);
                    float?       height = el.GetHeight(pUseSmoothHeight ? CField.EHeight.Smooth : CField.EHeight.MaxZ);

                    height = GetHeight(pStrategy, y, el, height);

                    //create vertex only if height is defined
                    if (height != null)
                    {
                        //TODO: ATTENTION! in OBJ the height value = Y, while in LAS format it is Z and X,Y are space coordinates
                        //move heights so the lowest point touches the 0
                        //if (pHeight != EHeight.Tree)
                        {
                            height -= minHeight;
                        }

                        v.LoadFromStringArray(new[] { "v", pArray.GetFieldXCoord(x).ToString(),
                                                      height.ToString(), pArray.GetFieldYCoord(y).ToString() });
                        obj.AddVertex(v);
                        //record the index of vertex associated with this field position
                        el.VertexIndex = obj.VertexList.Count;                         //first index = 1 (not 0)!
                    }
                    else
                    {
                        missingCoordCount++;
                    }
                }
            }
            int faceCount = 0;

            //generate faces
            for (int x = xStart; x < xEnd - 1; x++)
            {
                for (int y = yStart; y < yEnd - 1; y++)
                {
                    //create face only if all necessary vertices has been defined. -1 = not defined
                    //| /|	3:[0,1]	2:[1,1]
                    //|/ |  1:[0,0] 4:[1,0]
                    //we create 2 faces: (1,2,3) and (1,2,4)
                    int ind1 = pArray.GetField(x, y).VertexIndex;
                    if (ind1 != -1)
                    {
                        int ind2 = pArray.GetField(x + 1, y + 1).VertexIndex;
                        if (ind2 != -1)
                        {
                            int ind3 = pArray.GetField(x, y + 1).VertexIndex;
                            if (ind3 != -1)
                            {
                                Face f = new Face();
                                f.LoadFromStringArray(new[]
                                {
                                    "f", ind1.ToString(), ind2.ToString(), ind3.ToString()                                     //ind1+"//"+ind3, ind3+"//"+ind2, ind2+"//"+ind1
                                });

                                obj.FaceList.Add(f);
                                faceCount++;
                            }
                            int ind4 = pArray.GetField(x + 1, y).VertexIndex;
                            if (ind4 != -1)
                            {
                                Face f = new Face();
                                f.LoadFromStringArray(new[]
                                {
                                    "f", ind1.ToString(), ind4.ToString(), ind2.ToString()
                                });

                                obj.FaceList.Add(f);
                            }
                        }
                    }
                }
            }

            return(obj);
        }