Ejemplo n.º 1
0
        private short GetVerticeForPolyUV(short P, float U, float V, Dictionary <short, Tuple <float, float> > VerticeToUV)
        {
            P3DVertex orgVertex = Vertices[P];

            if (orgVertex.NextToCheck != null)
            {
                var UVS = VerticeToUV[orgVertex.NextToCheck.Value];
                if ((Math.Abs(UVS.Item1 - U) < 0.00001f && Math.Abs(UVS.Item2 - V) < 0.00001f))
                {
                    return(orgVertex.NextToCheck.Value);
                }
                else
                {
                    return(GetVerticeForPolyUV(orgVertex.NextToCheck.Value, U, V, VerticeToUV));
                }
            }

            P3DVertex newVert = new P3DVertex(orgVertex.x, orgVertex.y, orgVertex.z);

            orgVertex.NextToCheck = (short)Vertices.Count;
            VerticeToUV[(short)Vertices.Count] = new Tuple <float, float>(U, V);
            Vertices.Add(newVert);
            NumVertices++;
            return((short)(Vertices.Count - 1));
        }
Ejemplo n.º 2
0
        public Light(LightsChunk parent, string name, float x, float y, float z, float radius, Int32 color, bool showCorona, bool showLensFlare, bool lightUpEnvivornment)
        {
            Parent = parent;

            Name                = name;
            Position            = new P3DVertex(x, y, z);
            Radius              = radius;
            Color               = color;
            ShowCorona          = showCorona;
            ShowLensFlare       = showLensFlare;
            LightUpEnvivornment = lightUpEnvivornment;

            Application.Current.Dispatcher.BeginInvoke((Action)(() => addTreeItem()));
        }
Ejemplo n.º 3
0
        public bool Parse3DSMesh(Lib3dsFile file, Lib3dsMesh mesh)
        {
            foreach (Lib3dsVertex vert in mesh.vertices)
            {
                Vertices.Add(new P3DVertex(vert.x, vert.z, vert.y));
            }

            foreach (Lib3dsFace face in mesh.faces)
            {
                if (face.index.Length > 3)
                {
                    //MessageBox.Show("SHIT.");
                }
                TexturePolygon texPoly = new TexturePolygon();

                texPoly.Texture   = GetTextureFrom3dsID(file, face.material).Name;
                texPoly.Material  = MaterialFrom3DS(file.materials[face.material], (face.smoothing_group != 0));
                texPoly.SGFrom3DS = face.smoothing_group;
                texPoly.U1        = mesh.texcos[face.index[0]].s;
                texPoly.U2        = mesh.texcos[face.index[2]].s;
                texPoly.U3        = mesh.texcos[face.index[1]].s;
                texPoly.V1        = mesh.texcos[face.index[0]].t;
                texPoly.V2        = mesh.texcos[face.index[2]].t;
                texPoly.V3        = mesh.texcos[face.index[1]].t;

                texPoly.P1 = Convert.ToInt16(face.index[0]);
                texPoly.P2 = Convert.ToInt16(face.index[2]);
                texPoly.P3 = Convert.ToInt16(face.index[1]);



                Polygons.Add(texPoly);
            }

            Name = mesh.name;
            Application.Current.Dispatcher.BeginInvoke((Action)(() => ((P3DElementView)TreeItem.Header).content.Text = Name));
            Size        = 1;
            Flags       = FlagFrom3DSName(mesh.name);
            NumVertices = Convert.ToInt16(Vertices.Count);
            NumPolys    = Convert.ToInt16(Polygons.Count);
            LocalPos    = new P3DVertex(mesh.matrix[3, 0], mesh.matrix[3, 1], mesh.matrix[3, 2]);
            Length      = 0;
            Height      = 0;
            Depth       = 0;
            return(true);
        }
Ejemplo n.º 4
0
 public void CalculateLocalPos(P3DVertex origin)
 {
     LocalPos.x -= origin.x;
     LocalPos.y -= origin.y;
     LocalPos.z -= origin.z;
 }
Ejemplo n.º 5
0
        public bool ParseMesh(BinaryReader reader)
        {
            byte[] submeshHeader = reader.ReadBytes(7);
            if (!Utility.ByteArrayCompare(submeshHeader, ChunkIdTemplate))
            {
                MessageBox.Show("Expected SUBMESH chunk header, got " + Encoding.ASCII.GetString(submeshHeader));
                return(false);
            }
            Size = reader.ReadInt32();

            StringBuilder builder = new StringBuilder();
            byte          readen  = reader.ReadByte();

            while (readen != 0)
            {
                builder.Append(Convert.ToChar(readen));
                readen = reader.ReadByte();
            }
            Name = builder.ToString();
            Application.Current.Dispatcher.BeginInvoke((Action)(() => ((P3DElementView)TreeItem.Header).content.Text = Name));
            // ((P3DElementView)TreeItem.Header).content.Text = Name;
            builder.Clear();

            Flags = reader.ReadUInt32();

            LocalPos = new P3DVertex(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            Length   = reader.ReadSingle();
            Height   = reader.ReadSingle();
            Depth    = reader.ReadSingle();

            for (int i = 0; i < Parent.Parent.TextureChunk.TexNum; i++)
            {
                Info.Insert(i, new TextureInfo(this));
                Info[i].TextureStart       = reader.ReadInt16();
                Info[i].NumFlat            = reader.ReadInt16();
                Info[i].NumFlatMetal       = reader.ReadInt16();
                Info[i].NumGouraud         = reader.ReadInt16();
                Info[i].NumGouraudMetal    = reader.ReadInt16();
                Info[i].NumGouraudMetalEnv = reader.ReadInt16();
                Info[i].NumShining         = reader.ReadInt16();
            }

            NumVertices = reader.ReadInt16();
            if (NumVertices < 1)
            {
                MessageBox.Show("Mesh doesn't have vertices");
                return(false);
            }

            for (int i = 0; i < NumVertices; i++)
            {
                Vertices.Insert(i, new P3DVertex(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
            }

            NumPolys = reader.ReadInt16();
            if (NumPolys < 1)
            {
                MessageBox.Show("Mesh doesn't have polygons");
                return(false);
            }

            for (int i = 0; i < NumPolys; i++)
            {
                Polygons.Insert(i, new TexturePolygon());

                Polygons[i].P1 = reader.ReadInt16();
                Polygons[i].U1 = reader.ReadSingle();
                Polygons[i].V1 = reader.ReadSingle();

                Polygons[i].P2 = reader.ReadInt16();
                Polygons[i].U2 = reader.ReadSingle();
                Polygons[i].V2 = reader.ReadSingle();

                Polygons[i].P3 = reader.ReadInt16();
                Polygons[i].U3 = reader.ReadSingle();
                Polygons[i].V3 = reader.ReadSingle();
            }

            for (int i = 0; i < Parent.Parent.TextureChunk.TexNum; i++)
            {
                short polyInTex = Info[i].TextureStart;

                for (int j = 0; j < Info[i].NumFlat; j++)
                {
                    Polygons[polyInTex + j].Material = P3DMaterial.MAT_FLAT;
                    Polygons[polyInTex + j].Texture  = GetTextureList()[i].Name;
                }
                polyInTex += Info[i].NumFlat;

                for (int j = 0; j < Info[i].NumFlatMetal; j++)
                {
                    Polygons[polyInTex + j].Material = P3DMaterial.MAT_FLAT_METAL;
                    Polygons[polyInTex + j].Texture  = GetTextureList()[i].Name;
                }
                polyInTex += Info[i].NumFlatMetal;

                for (int j = 0; j < Info[i].NumGouraud; j++)
                {
                    Polygons[polyInTex + j].Material = P3DMaterial.MAT_GORAUD;
                    Polygons[polyInTex + j].Texture  = GetTextureList()[i].Name;
                }
                polyInTex += Info[i].NumGouraud;

                for (int j = 0; j < Info[i].NumGouraudMetal; j++)
                {
                    Polygons[polyInTex + j].Material = P3DMaterial.MAT_GORAUD_METAL;
                    Polygons[polyInTex + j].Texture  = GetTextureList()[i].Name;
                }
                polyInTex += Info[i].NumGouraudMetal;

                for (int j = 0; j < Info[i].NumGouraudMetalEnv; j++)
                {
                    Polygons[polyInTex + j].Material = P3DMaterial.MAT_GORAUD_METAL_ENV;
                    Polygons[polyInTex + j].Texture  = GetTextureList()[i].Name;
                }
                polyInTex += Info[i].NumGouraudMetalEnv;

                for (int j = 0; j < Info[i].NumShining; j++)
                {
                    Polygons[polyInTex + j].Material = P3DMaterial.MAT_SHINING;
                    Polygons[polyInTex + j].Texture  = GetTextureList()[i].Name;
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
 public void CalculateLocalPos(P3DVertex origin)
 {
     Position.x -= origin.x;
     Position.y -= origin.y;
     Position.z -= origin.z;
 }