Example #1
0
        public override void Calculate(TerrainModel model, MeshGeometry3D mesh)
        {
            var normals   = MeshGeometryHelper.CalculateNormals(mesh);
            var texcoords = new PointCollection();

            for (int i = 0; i < normals.Count; i++)
            {
                double slopedir = Math.Atan2(normals[i].Y, normals[i].X) * 180 / Math.PI;
                if (slopedir < 0)
                {
                    slopedir += 360;
                }
                double u = slopedir / 360;
                texcoords.Add(new Point(u, u));
            }
            TextureCoordinates = texcoords;
            Material           = MaterialHelper.CreateMaterial(Brush);
        }
Example #2
0
        public void UpdateModel()
        {
            CreateGeometry();
            var c   = new Model3DGroup();
            var mat = MaterialHelper.CreateMaterial(Fill);

            for (int i = 0; i < Segments; i++)
            {
                var p0        = Positions[SegmentIndices[i * 2]];
                var p1        = Positions[SegmentIndices[i * 2 + 1]];
                var d         = p1 - p0;
                var tubeModel = new GeometryModel3D
                {
                    Geometry  = _tube,
                    Material  = mat,
                    Transform = CreateSegmentTransform(p0, d)
                };
                c.Children.Add(tubeModel);
            }

            _element.Content = c;
        }
Example #3
0
        public void ReadB(Stream s)
        {
            long length = binaryReader.BaseStream.Length;

            if (length < 84)
            {
                throw new FileFormatException("Incomplete file");
            }

            String header          = ReadHeaderB();
            UInt32 numberTriangles = ReadNumberTrianglesB();

            index = 0;
            Meshes.Add(new MeshBuilder(true, true));
            Materials.Add(MaterialHelper.CreateMaterial(Brushes.Blue));

            for (int i = 0; i < numberTriangles; i++)
            {
                ReadTriangleB();
            }

            binaryReader.Close();
        }
Example #4
0
        public override void Calculate(TerrainModel model, MeshGeometry3D mesh)
        {
            var normals   = MeshGeometryHelper.CalculateNormals(mesh);
            var texcoords = new PointCollection();
            var up        = new Vector3D(0, 0, 1);

            for (int i = 0; i < normals.Count; i++)
            {
                double slope = Math.Acos(Vector3D.DotProduct(normals[i], up)) * 180 / Math.PI;
                double u     = slope / 40;
                if (u > 1)
                {
                    u = 1;
                }
                if (u < 0)
                {
                    u = 0;
                }
                texcoords.Add(new Point(u, u));
            }
            TextureCoordinates = texcoords;
            Material           = MaterialHelper.CreateMaterial(Brush);
        }
Example #5
0
        private void ReadTriangleA(String normal)
        {
            Vector3D n = ParseNormalA(normal);

            ReadLineA("outer");
            Point3D v1 = ReadVertexA();
            Point3D v2 = ReadVertexA();
            Point3D v3 = ReadVertexA();

            ReadLineA("endloop");
            ReadLineA("endfacet");

            if (Materials.Count < index + 1)
            {
                Materials.Add(MaterialHelper.CreateMaterial(Brushes.Blue));
            }

            if (Meshes.Count < index + 1)
            {
                Meshes.Add(new MeshBuilder(true, true));
            }

            Meshes[index].AddTriangle(v1, v2, v3);
        }
Example #6
0
        private void ReadSurface(int size)
        {
            Surfaces  = new Collection <string>();
            Meshes    = new Collection <MeshBuilder>();
            Materials = new Collection <Material>();

            string name  = ReadString(size);
            var    names = name.Split('\0');

            for (int i = 0; i < names.Length; i++)
            {
                string n = names[i];
                Surfaces.Add(n);
                Meshes.Add(new MeshBuilder());
                Materials.Add(MaterialHelper.CreateMaterial(Brushes.Blue));

                // If the length of the string (including the null) is odd, an extra null byte is added.
                // Then skip the next empty string.
                if ((n.Length + 1) % 2 == 1)
                {
                    i++;
                }
            }
        }
Example #7
0
        private void ReadTriangleB()
        {
            Color current;
            bool  hasColor  = false;
            bool  sameColor = true;

            float    ni = ReadFloatB();
            float    nj = ReadFloatB();
            float    nk = ReadFloatB();
            Vector3D n  = new Vector3D(ni, nj, nk);

            float   v1x = ReadFloatB();
            float   v1y = ReadFloatB();
            float   v1z = ReadFloatB();
            Point3D v1  = new Point3D(v1x, v1y, v1z);

            float   v2x = ReadFloatB();
            float   v2y = ReadFloatB();
            float   v2z = ReadFloatB();
            Point3D v2  = new Point3D(v2x, v2y, v2z);

            float   v3x = ReadFloatB();
            float   v3y = ReadFloatB();
            float   v3z = ReadFloatB();
            Point3D v3  = new Point3D(v3x, v3y, v3z);

            //UInt16 attrib = ReadUInt16();
            var attrib = Convert.ToString(ReadUInt16B(), 2).PadLeft(16, '0').ToCharArray();

            hasColor = attrib[0].Equals('1');

            if (hasColor)
            {
                int blue = attrib[15].Equals('1') ? 1 : 0;
                blue = attrib[14].Equals('1') ? blue + 2 : blue;
                blue = attrib[13].Equals('1') ? blue + 4 : blue;
                blue = attrib[12].Equals('1') ? blue + 8 : blue;
                blue = attrib[11].Equals('1') ? blue + 16 : blue;
                int b = blue * 8;

                int green = attrib[10].Equals('1') ? 1 : 0;
                green = attrib[9].Equals('1') ? green + 2 : green;
                green = attrib[8].Equals('1') ? green + 4 : green;
                green = attrib[7].Equals('1') ? green + 8 : green;
                green = attrib[6].Equals('1') ? green + 16 : green;
                int g = green * 8;

                int red = attrib[5].Equals('1') ? 1 : 0;
                red = attrib[4].Equals('1') ? red + 2 : red;
                red = attrib[3].Equals('1') ? red + 4 : red;
                red = attrib[2].Equals('1') ? red + 8 : red;
                red = attrib[1].Equals('1') ? red + 16 : red;
                int r = red * 8;

                current   = Color.FromRgb(Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b));
                sameColor = Color.Equals(last, current);

                if (!sameColor)
                {
                    last = current;
                    index++;
                }

                if (Materials.Count < index + 1)
                {
                    Materials.Add(MaterialHelper.CreateMaterial(current));
                }
            }
            else
            {
                if (Materials.Count < index + 1)
                {
                    Materials.Add(MaterialHelper.CreateMaterial(Brushes.Blue));
                }
            }

            if (Meshes.Count < index + 1)
            {
                Meshes.Add(new MeshBuilder(true, true));
            }

            Meshes[index].AddTriangle(v1, v2, v3);
        }
 public override object ProvideValue(System.IServiceProvider serviceProvider)
 {
     return(MaterialHelper.CreateImageMaterial(path, Opacity));
 }
Example #9
0
 public Group(string name)
 {
     Name        = name;
     Material    = MaterialHelper.CreateMaterial(Brushes.Green);
     MeshBuilder = new MeshBuilder();
 }
Example #10
0
 public MapTexture(string source)
 {
     Material = MaterialHelper.CreateImageMaterial(source, 1);
 }