Beispiel #1
0
        public I3DNavMesh(BigEndianBinaryReader br)
        {
            try
            {
                Unknown1 = br.ReadUInt32();
                Name     = br.BaseStream.ReadNullTerminatedString();

                br.BaseStream.Align(2); // Align the stream to short

                do
                {
                    ShapeId = br.ReadUInt16();
                } while (ShapeId == 0);

                GridCellSize   = br.ReadSingle();
                GridCellHeight = br.ReadSingle();

                BoundsMin = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                BoundsMax = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());

                VertexCount        = br.ReadUInt32();
                PolygonCount       = br.ReadUInt32();
                PolygonVertexCount = br.ReadUInt32();

                Vertices = new Vector3[VertexCount];
                for (int i = 0; i < VertexCount; i++)
                {
                    Vertices[i] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                }

                Polygons = new I3DNavMeshPolygon[PolygonCount];
                for (int i = 0; i < PolygonCount; i++)
                {
                    Polygons[i] = new I3DNavMeshPolygon(br);
                }
            }
            catch (Exception e)
            {
                if (string.IsNullOrEmpty(Name))
                {
                    throw;
                }

                if (ShapeId > 0)
                {
                    throw new Exception($"Failed to parse I3DNavMesh {Name}, ShapeID: {ShapeId}", e);
                }

                throw new Exception($"Failed to parse I3DNavMesh {Name}", e);
            }
        }
Beispiel #2
0
        public I3DNavMeshPolygon(BigEndianBinaryReader br)
        {
            Unknown1 = br.ReadUInt32();

            VertexCount = br.ReadUInt32();

            Polygon = new short[VertexCount];
            for (int i = 0; i < VertexCount; i++)
            {
                Polygon[i] = br.ReadInt16();
            }

            Unknown2 = new short[VertexCount];
            for (int i = 0; i < VertexCount; i++)
            {
                Unknown2[i] = br.ReadInt16();
            }
        }
Beispiel #3
0
        public I3DSpline(BigEndianBinaryReader br)
        {
            try
            {
                Unknown1 = br.ReadUInt32();
                Name     = br.BaseStream.ReadNullTerminatedString();

                br.BaseStream.Align(2); // Align the stream to short

                do
                {
                    ShapeId = br.ReadUInt16();
                } while (ShapeId == 0);

                Unknown2    = br.ReadUInt32();
                VertexCount = br.ReadUInt32();

                Vertices = new Vector3[VertexCount];
                for (int i = 0; i < VertexCount; i++)
                {
                    Vertices[i] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                }
            }
            catch (Exception e)
            {
                if (string.IsNullOrEmpty(Name))
                {
                    throw;
                }

                if (ShapeId > 0)
                {
                    throw new Exception($"Failed to parse I3DSpline {Name}, ShapeID: {ShapeId}", e);
                }

                throw new Exception($"Failed to parse I3DSpline {Name}", e);
            }
        }
Beispiel #4
0
        public I3DShape(BigEndianBinaryReader br)
        {
            try
            {
                Unknown1 = br.ReadUInt32();
                Name     = br.BaseStream.ReadNullTerminatedString();

                br.BaseStream.Align(2); // Align the stream to short

                //This is pretty ugly, but they pretty much zero-pad after the alignment
                //So we read the padding until we found the shapeid
                do
                {
                    ShapeId = br.ReadUInt16();
                } while (ShapeId == 0);

                BVCenterX    = br.ReadSingle();
                BVCenterY    = br.ReadSingle();
                BVCenterZ    = br.ReadSingle();
                BVRadius     = br.ReadSingle();
                VertexCount  = br.ReadUInt32();
                Unknown6     = br.ReadUInt32();
                Vertices     = br.ReadUInt32();
                Unknown7     = br.ReadUInt32();
                Unknown8     = br.ReadUInt32();
                UvCount      = br.ReadUInt32();
                Unknown9     = br.ReadUInt32();
                VertexCount2 = br.ReadUInt32();

                Mesh = new Mesh();

                int[] tris = new int[VertexCount];
                for (int i = 0; i < VertexCount; i++)
                {
                    tris[i] = br.ReadUInt16();
                }

                br.BaseStream.Align(4);

                Vector3[] vertices = new Vector3[Vertices];
                for (int i = 0; i < Vertices; i++)
                {
                    vertices[i] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                }

                Vector3[] normals = new Vector3[Vertices];
                for (int i = 0; i < Vertices; i++)
                {
                    normals[i] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                }

                Vector2[] uvs = new Vector2[UvCount];
                for (int i = 0; i < UvCount; i++)
                {
                    uvs[i] = new Vector2(br.ReadSingle(), br.ReadSingle());
                }

                Mesh.vertices  = vertices;
                Mesh.normals   = normals;
                Mesh.triangles = tris;
                Mesh.uv        = uvs;
            }
            catch (Exception e)
            {
                if (string.IsNullOrEmpty(Name))
                {
                    throw;
                }

                if (ShapeId > 0)
                {
                    throw new Exception($"Failed to parse I3DShape {Name}, ShapeID: {ShapeId}", e);
                }

                throw new Exception($"Failed to parse I3DShape {Name}", e);
            }
        }