Example #1
0
        public override void Read(RW4Model m, RW4Section s, Stream r)
        {
            var p0 = r.Position;

            bbox.Read(m, null, r);
            r.expect(0xd59208, "SM001");      // most but not all creature models
            this.unk1 = r.ReadU32();
            var tri_count = r.ReadU32();

            r.expect(0, "SM002");
            var vertexcount = r.ReadU32();

            var p2 = r.ReadU32();
            var p1 = r.ReadU32();
            var p4 = r.ReadU32();
            var p3 = r.ReadU32();

            if (p1 != (uint)((r.Position + 15) & ~15))
            {
                throw new ModelFormatException(r, "SM010", null);
            }

            r.ReadPadding(p1 - r.Position);

            if (p2 != p1 + vertexcount * 16)
            {
                throw new ModelFormatException(r, "SM101", null);
            }
            if (p3 != p2 + tri_count * 16)
            {
                throw new ModelFormatException(r, "SM102", null);
            }
            if (p4 != p3 + (((tri_count / 2) + 15) & ~15))
            {
                throw new ModelFormatException(r, "SM103", null);
            }

            vertices = new Vertex[vertexcount];
            for (int i = 0; i < vertexcount; i++)
            {
                vertices[i].Read4(r);
            }

            triangles = new Triangle[tri_count];
            for (int t = 0; t < tri_count; t++)
            {
                var index = r.ReadU32(); if (index >= vertexcount)
                {
                    throw new ModelFormatException(r, "SM200", t);
                }
                triangles[t].i = (UInt16)index;
                index          = r.ReadU32(); if (index >= vertexcount)
                {
                    throw new ModelFormatException(r, "SM200", t);
                }
                triangles[t].j = (UInt16)index;
                index          = r.ReadU32(); if (index >= vertexcount)
                {
                    throw new ModelFormatException(r, "SM200", t);
                }
                triangles[t].k = (UInt16)index;
                r.expect(0, "SM201");
            }

            UInt32 x = 0;

            for (int t = 0; t < tri_count; t++)
            {
                if ((t & 7) == 0)
                {
                    x = r.ReadU32();
                }
                triangles[t].unk1 = (byte)((x >> ((t & 7) * 4)) & 0xf);
            }
            for (int t = (int)tri_count; t < ((tri_count + 7) & ~7); t++)
            {
                if ((byte)((x >> ((t & 7) * 4)) & 0xf) != 0xf)
                {
                    throw new ModelFormatException(r, "SM210", t);
                }
            }
            r.ReadPadding(p4 - r.Position);
            //if (r.Position != p4) throw new ModelFormatException(r, "SM299", r.Position - p4);

            r.expect(p1 - 8 * 4, "SM301");
            var u2_count = r.ReadU32();

            r.expect(tri_count, "SM302");
            r.expect(0, "SM303");

            var bbox2 = new RW4BBox();

            bbox2.Read(m, null, r);
            if (!bbox.IsIdentical(bbox2))
            {
                throw new ModelFormatException(r, "SM310", bbox2);
            }

            unknown_data_2 = new uint[u2_count * 8];  // Actually this is int*6 + float*2
            for (int i = 0; i < unknown_data_2.Length; i++)
            {
                unknown_data_2[i] = r.ReadU32();
            }
        }
Example #2
0
 public bool IsIdentical(RW4BBox b)
 {
     return(minx == b.minx && miny == b.miny && minz == b.minz && maxx == b.maxx && maxy == b.maxy && maxz == b.maxz &&
            unk1 == b.unk1 && unk2 == b.unk2);
 }