Ejemplo n.º 1
0
        /// <summary>
        /// Creates the 3D model of the terrain.
        /// </summary>
        /// <param name="lod">The level of detail.</param>
        /// <returns></returns>
        public GeometryModel3D CreateModel(int lod)
        {

            int ni = Height / lod;
            int nj = Width / lod;
            var pts = new Point3DCollection(ni * nj);

            double mx = (Left + Right) / 2;
            double my = (Top + Bottom) / 2;
            double mz = (MinimumZ + MaximumZ) / 2;

            Offset = new Point3D(mx, my, mz);

            for (int i = 0; i < ni; i++)
                for (int j = 0; j < nj; j++)
                {
                    double x = Left + (Right - Left) * j / (nj - 1);
                    double y = Top + (Bottom - Top) * i / (ni - 1);
                    double z = Data[i * lod * Width + j * lod];

                    x -= Offset.X;
                    y -= Offset.Y;
                    z -= Offset.Z;
                    pts.Add(new Point3D(x, y, z));
                }

            var mb = new MeshBuilder(false, false);
            mb.AddRectangularMesh(pts, nj);
            var mesh = mb.ToMesh();

            var material = Materials.Green;

            if (Texture != null)
            {
                Texture.Calculate(this, mesh);
                material = Texture.Material;
                mesh.TextureCoordinates = Texture.TextureCoordinates;
            }

            var model = new GeometryModel3D();
            model.Geometry = mesh;
            model.Material = material;
            model.BackMaterial = material;
            return model;
        }
Ejemplo n.º 2
0
        private void CreateInitialMesh()
        {
            var pts = new Point3D[n, m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                {
                    pts[i, j] = new Point3D(-Length * j / (m - 1), 0, PoleHeight - Height * i / (n - 1));
                }

            var mb = new MeshBuilder(false, true);
            mb.AddRectangularMesh(pts, false, false);
            Mesh = mb.ToMesh();
        }
Ejemplo n.º 3
0
        protected override MeshGeometry3D Tessellate()
        {

            Vector3D u = LengthDirection;
            Vector3D w = Normal;
            Vector3D v = Vector3D.CrossProduct(w, u);
            u = Vector3D.CrossProduct(v, w);

            u.Normalize();
            v.Normalize();
            w.Normalize();

            double le = Length;
            double wi = Width;

            var pts = new Point3DCollection();
            for (int i = 0; i < DivLength; i++)
            {
                double fi = -0.5 + (double)i / (DivLength - 1);
                for (int j = 0; j < DivWidth; j++)
                {
                    double fj = -0.5 + (double)j / (DivWidth - 1);
                    pts.Add(Origin + u * le * fi + v * wi * fj);
                }
            }

            var builder = new MeshBuilder();
            builder.AddRectangularMesh(pts, DivWidth);

            return builder.ToMesh();
        }