Пример #1
0
        public void ShiftVertices(vec3 shift, int index)
        {
            if (!MobPieces.ContainsKey(index))
            {
                return;
            }

            MobVertexPiece mobPiece = MobPieces[index];

            for (int i = 0; i < mobPiece.Count; ++i)
            {
                Vertices[mobPiece.Start + i] = Vertices[mobPiece.Start + i] + shift;
            }
        }
Пример #2
0
        public override void Initialize(int index, int id, int size, byte[] data,
                                        Dictionary <int, WldFragment> fragments,
                                        Dictionary <int, string> stringHash, ILogger logger)
        {
            base.Initialize(index, id, size, data, fragments, stringHash, logger);

            var reader = new BinaryReader(new MemoryStream(data));

            Name = stringHash[-reader.ReadInt32()];

            int flags = reader.ReadInt32();

            if (flags == 0x00018003)
            {
                // zone mesh
            }
            else if (flags == 0x00014003)
            {
                // placeable object
            }

            int textureList = reader.ReadInt32();

            MaterialList = fragments[textureList - 1] as MaterialList;

            int meshAnimation = reader.ReadInt32();

            if (meshAnimation != 0)
            {
                AnimatedVertices = fragments[meshAnimation - 2] as MeshAnimatedVertices;
            }

            int unknown = reader.ReadInt32();

            // maybe references the first 0x03 in the WLD - unknown
            int unknown2 = reader.ReadInt32();

            Center = new vec3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

            // 3 unknown dwords
            reader.BaseStream.Position += (4 * 3);

            MaxDistance = reader.ReadSingle();

            MinPosition = new vec3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            MaxPosition = new vec3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

            Vertices             = new List <vec3>();
            TextureUvCoordinates = new List <vec2>();

            short vertexCount = reader.ReadInt16();

            short textureCoordinateCount = reader.ReadInt16();

            short normalsCount = reader.ReadInt16();

            short colorsCount = reader.ReadInt16();

            short polygonCount = reader.ReadInt16();

            short vertexPieceCount = reader.ReadInt16();

            short polygonTextureCount = reader.ReadInt16();

            short vertexTextureCount = reader.ReadInt16();

            short size9 = reader.ReadInt16();

            float scale = 1.0f / (1 << reader.ReadInt16());

            for (int i = 0; i < vertexCount; ++i)
            {
                Vertices.Add(new vec3(reader.ReadInt16() * scale, reader.ReadInt16() * scale,
                                      reader.ReadInt16() * scale));
            }

            for (int i = 0; i < textureCoordinateCount; ++i)
            {
                TextureUvCoordinates.Add(new vec2(reader.ReadInt16() / 256.0f, reader.ReadInt16() / 256.0f));
            }

            for (int i = 0; i < normalsCount; ++i)
            {
                reader.BaseStream.Position += 3;
            }

            for (int i = 0; i < colorsCount; ++i)
            {
                reader.BaseStream.Position += 4;
            }

            Polygons = new List <Polygon>();

            for (int i = 0; i < polygonCount; ++i)
            {
                bool isSolid = (reader.ReadInt16() == 0);

                if (!isSolid)
                {
                    ExportSeparateCollision = true;
                }

                Polygons.Add(new Polygon()
                {
                    Solid   = isSolid,
                    Vertex1 = reader.ReadInt16(),
                    Vertex2 = reader.ReadInt16(),
                    Vertex3 = reader.ReadInt16(),
                });
            }

            MobPieces = new Dictionary <int, MobVertexPiece>();
            int mobStart = 0;

            for (int i = 0; i < vertexPieceCount; ++i)
            {
                int count          = reader.ReadInt16();
                int index1         = reader.ReadInt16();
                var mobVertexPiece = new MobVertexPiece
                {
                    Count = count,
                    Start = mobStart
                };

                mobStart += count;

                MobPieces[index1] = mobVertexPiece;
            }

            RenderGroups = new List <RenderGroup>();

            for (int i = 0; i < polygonTextureCount; ++i)
            {
                var group = new RenderGroup();
                group.PolygonCount = reader.ReadUInt16();
                group.TextureIndex = reader.ReadUInt16();
                RenderGroups.Add(group);
            }

            for (int i = 0; i < vertexTextureCount; ++i)
            {
                reader.BaseStream.Position += 4;
            }

            for (int i = 0; i < size9; ++i)
            {
                reader.BaseStream.Position += 12;
            }
        }