Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MODL"/> class.
        /// </summary>
        /// <param name="from">The <see cref="BaseChunk" /> to use for creating this Chunk. The given data will be interpreted respectively.</param>
        public MODL(BaseChunk from) : base(from)
        {
            while (!EndOfData)
            {
                BaseChunk nextChunk = ReadChunk();

                switch (nextChunk.ChunkName)
                {
                case "MTYP":
                    Type = (MTYP)nextChunk.ReadInt32();
                    break;

                case "MNDX":
                    index = nextChunk.ReadInt32();
                    break;

                case "NAME":
                    Name = nextChunk.ReadString(nextChunk.Data.Length);
                    break;

                case "PRNT":
                    parentName = nextChunk.ReadString(nextChunk.Data.Length);
                    break;

                case "FLGS":
                    Flag = new ModelFlag(true, nextChunk.ReadInt32());
                    break;

                case "TRAN":
                    Scale       = nextChunk.ReadVector3();
                    Rotation    = nextChunk.ReadVector3();
                    Translation = nextChunk.ReadVector3();
                    UnknownTRAN = nextChunk.ReadFloat();
                    break;

                case "GEOM":
                    Geometry = new GEOM(nextChunk);
                    break;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SEGM"/> class.
        /// </summary>
        /// <param name="from">The <see cref="BaseChunk" /> to use for creating this Chunk. The given data will be interpreted respectively.</param>
        public SEGM(BaseChunk from) : base(from)
        {
            List <Vector3> verts   = new List <Vector3>();
            List <Vector3> normals = new List <Vector3>();
            List <Vector2> uvs     = new List <Vector2>();

            Polygon currentPoly = new Polygon(vertices);
            bool    lastBoundry = false;

            while (!EndOfData)
            {
                BaseChunk nextChunk = ReadChunk();
                int       count     = 0;

                switch (nextChunk.ChunkName)
                {
                case "MATI":
                    matIndex = nextChunk.ReadInt32();
                    break;

                case "POSL":
                    count = nextChunk.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        verts.Add(nextChunk.ReadVector3());
                    }
                    break;

                case "NRML":
                    count = nextChunk.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        normals.Add(nextChunk.ReadVector3());
                    }
                    break;

                case "UV0L":
                    count = nextChunk.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        uvs.Add(nextChunk.ReadVector2());
                    }
                    break;

                case "STRP":
                    count = nextChunk.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        VertexIndex next = nextChunk.ReadVertexIndex();

                        if (next.polyBoundary && !lastBoundry)
                        {
                            //polygon finished, add to buffer
                            if (currentPoly.VertexIndices.Count > 0)
                            {
                                polygons.Add(currentPoly);
                            }

                            //start new polygon
                            currentPoly = new Polygon(vertices);

                            //write first index value to polygon
                            currentPoly.VertexIndices.Add(next.index);
                        }
                        else
                        {
                            if (currentPoly != null)
                            {
                                currentPoly.VertexIndices.Add(next.index);
                            }
                            else
                            {
                                //this should never happen
                                Log.Add("Warning: Lone Vertex in Strip Buffer!", LogType.Warning);
                            }
                        }

                        lastBoundry = next.polyBoundary;
                    }
                    break;
                }
            }

            if (uvs.Count > 0)
            {
                hasUVs = true;
            }

            for (int i = 0; i < verts.Count; i++)
            {
                //since uv coordinates are optional, deliver empty ones if non existent
                Vector2 uv = (i < uvs.Count) ? uvs[i] : new Vector2();

                vertices.Add(new Vertex(verts[i], normals[i], uv));
            }

            //Add last Polygon
            if (currentPoly != null && currentPoly.VertexIndices.Count > 0)
            {
                polygons.Add(currentPoly);
            }
        }