Example #1
0
 public static Vector3 GetMovedPoint(Vector3 pPoint)
 {
     //for better visualization:
     //- move to array center be at 0,0,0
     pPoint -= arrayCenter;
     //- move to 0 height, flip Y axis (to match OBJ view format)
     //changed
     pPoint -= new Vector3(0, 0, CProjectData.GetMinHeight());
     //pPoint -= new Vector3(0, CProjectData.GetMinHeight(), 0);
     return(pPoint);
 }
Example #2
0
        /// <summary>
        /// Sets position, scale and rotation of tree obj to match given pTargetTree
        /// </summary>
        private static void SetRefTreeObjTransform(ref CRefTree pRefTree, CTree pTargetTree, int pAngleOffset)
        {
            Vector3 arrayCenter = CProjectData.GetArrayCenter();
            float   minHeight   = CProjectData.GetMinHeight();

            //float treeHeight = pTargetTree.peak.maxHeight.Y - (float)groundHeight;
            float treeHeight  = pTargetTree.GetTreeHeight();
            float heightRatio = treeHeight / pRefTree.GetTreeHeight();

            pRefTree.Obj.Scale = heightRatio * Vector3.One;

            //align position to tree
            pRefTree.Obj.Position    = pTargetTree.peak.Center;
            pRefTree.Obj.Position.Z -= pRefTree.GetTreeHeight() * heightRatio;

            //move obj so it is at 0,0,0
            pRefTree.Obj.Position -= arrayCenter;
            pRefTree.Obj.Position -= Vector3.UnitZ * minHeight;

            pRefTree.Obj.Rotation = new Vector3(0, -pAngleOffset, 0);

            //in OBJ format Y = height
            CUtils.SwapYZ(ref pRefTree.Obj.Position);
        }
Example #3
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);
        }