public static void Parse(List <CmpPart> constructs, byte[] data)
        {
            int pos = 0;

            while (pos != data.Length)
            {
                CmpPart part = new CmpPart();

                part.ParentName = CmpParser.ParseString(data, ref pos);
                part.Name       = CmpParser.ParseString(data, ref pos);

                Vector3D origin = CmpParser.ParseVector3D(data, ref pos);
                Vector3D offset = CmpParser.ParseVector3D(data, ref pos);

                part.Matrix = CmpParser.ParseRotation(data, ref pos);
                part.Matrix.Translate(origin + offset);

                CmpParser.ParseFloat(data, ref pos); //Min1
                CmpParser.ParseFloat(data, ref pos); //Max1
                CmpParser.ParseFloat(data, ref pos); //Min2
                CmpParser.ParseFloat(data, ref pos); //Max2
                CmpParser.ParseFloat(data, ref pos); //Min3
                CmpParser.ParseFloat(data, ref pos); //Max3

                constructs.Add(part);
            }
        }
Exemplo n.º 2
0
        public void Read(byte[] data)
        {
            int pos = 0;

            CmpParser.ParseUInt32(data, ref pos); //HeaderSize
            VMeshLibId  = CmpParser.ParseUInt32(data, ref pos);
            VertexStart = CmpParser.ParseUInt16(data, ref pos);
            CmpParser.ParseUInt16(data, ref pos); //VertexCount
            CmpParser.ParseUInt16(data, ref pos); //IndexStart
            CmpParser.ParseUInt16(data, ref pos); //IndexCount
            MeshStart = CmpParser.ParseUInt16(data, ref pos);
            MeshCount = CmpParser.ParseUInt16(data, ref pos);

            CmpParser.ParseFloat(data, ref pos); //boundingBoxMaxX
            CmpParser.ParseFloat(data, ref pos); //boundingBoxMinX
            CmpParser.ParseFloat(data, ref pos); //boundingBoxMaxY
            CmpParser.ParseFloat(data, ref pos); //boundingBoxMinY
            CmpParser.ParseFloat(data, ref pos); //boundingBoxMaxZ
            CmpParser.ParseFloat(data, ref pos); //boundingBoxMinZ

            //BoundingBoxMin = new Vector3D(boundingBoxMinX, boundingBoxMinZ, boundingBoxMinY);
            //BoundingBoxMax = new Vector3D(boundingBoxMaxX, boundingBoxMaxZ, boundingBoxMaxY);

            CmpParser.ParseVector3D(data, ref pos); //Center

            CmpParser.ParseFloat(data, ref pos);    //Radius
        }
Exemplo n.º 3
0
        public void Read(byte[] data)
        {
            int pos = 0;

            // read the data header
            CmpParser.ParseUInt32(data, ref pos); //MeshType
            CmpParser.ParseUInt32(data, ref pos); //SurfaceType
            MeshCount            = CmpParser.ParseUInt16(data, ref pos);
            NumRefVertices       = CmpParser.ParseUInt16(data, ref pos);
            FlexibleVertexFormat = (D3DFVF)CmpParser.ParseUInt16(data, ref pos);
            VertexCount          = CmpParser.ParseUInt16(data, ref pos);

            // the FVF defines what fields are included for each vertex

            /*switch (FlexibleVertexFormat)
             * {
             *  case D3DFVF.XYZ:
             *  case D3DFVF.XYZ | D3DFVF.NORMAL:
             *  case D3DFVF.XYZ | D3DFVF.TEX1:
             *  case D3DFVF.XYZ | D3DFVF.NORMAL  | D3DFVF.TEX1:
             *  case D3DFVF.XYZ | D3DFVF.DIFFUSE | D3DFVF.TEX1:
             *  case D3DFVF.XYZ | D3DFVF.NORMAL  | D3DFVF.DIFFUSE | D3DFVF.TEX1:
             *  case D3DFVF.XYZ | D3DFVF.NORMAL  | D3DFVF.TEX2:
             *  case D3DFVF.XYZ | D3DFVF.NORMAL  | D3DFVF.DIFFUSE | D3DFVF.TEX2:
             *      break;
             *  default:
             *      throw new Exception(string.Format("FVF 0x{0:X} not supported.", FlexibleVertexFormat));
             * }*/

            // read the mesh headers
            int triangleStartOffset = 0;

            Meshes = new TMeshHeader[MeshCount];
            for (int i = 0; i < MeshCount; ++i)
            {
                TMeshHeader mesh = new TMeshHeader();
                CmpParser.ParseUInt32(data, ref pos); //MaterialId
                mesh.StartVertex    = CmpParser.ParseUInt16(data, ref pos);
                mesh.EndVertex      = CmpParser.ParseUInt16(data, ref pos);
                mesh.NumRefVertices = CmpParser.ParseUInt16(data, ref pos);
                CmpParser.ParseUInt16(data, ref pos); //Padding

                mesh.TriangleStart   = triangleStartOffset;
                triangleStartOffset += mesh.NumRefVertices;

                Meshes[i] = mesh;
            }

            // read the triangle data
            int triangleCount = NumRefVertices / 3;

            Triangles = new TTriangle[triangleCount];
            for (int i = 0; i < triangleCount; ++i)
            {
                TTriangle triangle = new TTriangle();
                triangle.Vertex1 = CmpParser.ParseUInt16(data, ref pos);
                triangle.Vertex3 = CmpParser.ParseUInt16(data, ref pos);
                triangle.Vertex2 = CmpParser.ParseUInt16(data, ref pos);
                Triangles[i]     = triangle;
            }

            // read the vertex data
            try
            {
                Vertices = new TVertex[VertexCount];
                for (int i = 0; i < VertexCount; ++i)
                {
                    TVertex vertex = new TVertex();
                    vertex.FVF = FlexibleVertexFormat;

                    vertex.Position = CmpParser.ParsePoint3D(data, ref pos);

                    if ((FlexibleVertexFormat & D3DFVF.Normal) == D3DFVF.Normal)
                    {
                        vertex.Normal = CmpParser.ParseVector3D(data, ref pos);
                    }
                    if ((FlexibleVertexFormat & D3DFVF.Diffuse) == D3DFVF.Diffuse)
                    {
                        CmpParser.ParseUInt32(data, ref pos); //Diffuse
                    }
                    if ((FlexibleVertexFormat & D3DFVF.Tex1) == D3DFVF.Tex1)
                    {
                        CmpParser.ParseFloat(data, ref pos); //S
                        CmpParser.ParseFloat(data, ref pos); //T
                    }
                    if ((FlexibleVertexFormat & D3DFVF.Tex2) == D3DFVF.Tex2)
                    {
                        CmpParser.ParseFloat(data, ref pos); //S
                        CmpParser.ParseFloat(data, ref pos); //T
                        CmpParser.ParseFloat(data, ref pos); //U
                        CmpParser.ParseFloat(data, ref pos); //V
                    }
                    if ((FlexibleVertexFormat & D3DFVF.Tex4) == D3DFVF.Tex4)
                    {
                        CmpParser.ParseFloat(data, ref pos); //S
                        CmpParser.ParseFloat(data, ref pos); //T
                        CmpParser.ParseFloat(data, ref pos); //TangentX
                        CmpParser.ParseFloat(data, ref pos); //TangentY
                        CmpParser.ParseFloat(data, ref pos); //TangentZ
                        CmpParser.ParseFloat(data, ref pos); //BinormalX
                        CmpParser.ParseFloat(data, ref pos); //BinormalY
                        CmpParser.ParseFloat(data, ref pos); //BinormalZ
                    }
                    if ((FlexibleVertexFormat & D3DFVF.Tex5) == D3DFVF.Tex5)
                    {
                        CmpParser.ParseFloat(data, ref pos); //S
                        CmpParser.ParseFloat(data, ref pos); //T
                        CmpParser.ParseFloat(data, ref pos); //U
                        CmpParser.ParseFloat(data, ref pos); //V
                        CmpParser.ParseFloat(data, ref pos); //TangentX
                        CmpParser.ParseFloat(data, ref pos); //TangentY
                        CmpParser.ParseFloat(data, ref pos); //TangentZ
                        CmpParser.ParseFloat(data, ref pos); //BinormalX
                        CmpParser.ParseFloat(data, ref pos); //BinormalY
                        CmpParser.ParseFloat(data, ref pos); //BinormalZ
                    }

                    Vertices[i] = vertex;
                }
            }
            catch
            {
                //MessageBox.Show("Header has more vertices then data", "Error");
            }
        }