示例#1
0
            public void Read(MemoryStream ms)
            {
                id = (uint)ms.ReadInt32();
                position.X = ms.ReadFloat(); position.Y = ms.ReadFloat(); position.Z = ms.ReadFloat();
                rotation.X = ms.ReadFloat(); rotation.Y = ms.ReadFloat(); rotation.Z = ms.ReadFloat(); rotation.W = ms.ReadFloat();
                scale = ms.ReadFloat();
                color = (uint) ms.ReadInt32();

                file = "";
            }
        public void TestStreamfloat()
        {
            float obj = 100;

            using (MemoryStream ms = new MemoryStream())
            {
                ms.WriteFloat(obj);
                ms.Seek(0, SeekOrigin.Begin);
                float res = ms.ReadFloat();

                Assert.IsTrue(obj.Equals(res), "Streaming failed!");
            }
        }
示例#3
0
文件: Adt.cs 项目: ostapus/WoW2Mesh
 public void Read(MemoryStream ms)
 {
     base.Read(ms, "MCNK");
     flags = (uint) ms.ReadInt32();
     indexX = (uint)ms.ReadInt32();
     indexY = (uint)ms.ReadInt32();
     numLayers = (uint)ms.ReadInt32();
     numDoodads = (uint)ms.ReadInt32();
     mcvtOff = (uint)ms.ReadInt32();
     mcnrOff = (uint)ms.ReadInt32();
     mclyOff = (uint)ms.ReadInt32();
     mcrfOff = (uint)ms.ReadInt32();
     mcalOff = (uint)ms.ReadInt32();
     mcalSize = (uint)ms.ReadInt32();
     mcshOff = (uint)ms.ReadInt32();
     mcshSize = (uint)ms.ReadInt32();
     areaId = (uint)ms.ReadInt32();
     numWmos = (uint)ms.ReadInt32();
     holes = (uint)ms.ReadInt32();
     texmap0 = (ulong)ms.ReadInt64();
     texmap1 = (ulong)ms.ReadInt64();
     predTex = (uint)ms.ReadInt32();
     noEffectDoodad = (uint)ms.ReadInt32();
     msceOff = (uint)ms.ReadInt32();
     numSoundEmitters = (uint)ms.ReadInt32();
     mclqOff = (uint)ms.ReadInt32();
     mclqSize = (uint)ms.ReadInt32();
     float x = ms.ReadFloat();
     float y = ms.ReadFloat();
     float z = ms.ReadFloat();
     position = new Vector3(x, y, z);
     mccvOff = (uint)ms.ReadInt32();
     ms.Read(pad, 0, pad.Length);
 }
示例#4
0
文件: Adt.cs 项目: ostapus/WoW2Mesh
        public McnkChunk_s parseMcnkChunk(MemoryStream ms, Terrain_s terrain)
        {
            long mcnk_off = ms.Position;
            McnkChunk_s mcnk_chunk = new McnkChunk_s();
            mcnk_chunk.Read(ms);

            // set stream position to MCVT chunk
            ms.Position = mcnk_off + mcnk_chunk.mcvtOff;
            McvtChunk_s mcvt_chunk = new McvtChunk_s();
            mcvt_chunk.Read(ms, "MCVT");

            // read all height values
            uint num_heights = mcvt_chunk.size / sizeof(float);
            HeightMap_t height_map = terrain.heightMap;
            height_map.Capacity = (int) num_heights;
            for (int i = 0; i < num_heights; i++)
            {
                height_map.Add(ms.ReadFloat());
            }

            // set stream position to MCNR chunk
            McnrChunk_s mcnr_chunk = new McnrChunk_s();
            ms.Position = mcnk_off + mcnk_chunk.mcnrOff;
            mcnr_chunk.Read(ms);

            // read all normal values
            //int num_normals = mcnr_chunk.size / sizeof( char ); // size is wrong
            Normals_t normals = terrain.normals;
            normals.Capacity = (int) num_heights;
            byte normal;
            for (int i = 0; i < num_heights; i++)
            {
                Vector3 v = new Vector3();
                normal = (byte) ms.ReadByte();
                v.X = normal * 0.00787401574803149606299212598425f;
                normal = (byte)ms.ReadByte();
                v.Z = normal * 0.00787401574803149606299212598425f;
                normal = (byte)ms.ReadByte();
                v.Y = normal * 0.00787401574803149606299212598425f;
                normals.Add(v);
            }
            ms.Position = mcnk_off + 0x8 + mcnk_chunk.size;
            return mcnk_chunk;
        }
示例#5
0
文件: Adt.cs 项目: ostapus/WoW2Mesh
                public uint Read(MemoryStream ms, long data_offset = 0)
                {
                    type = (ushort)ms.ReadShort();
                    flags = (ushort)ms.ReadShort();
                    heightLevel1 = ms.ReadFloat();
                    heightLevel2 = ms.ReadFloat();
                    xOffset = (byte)ms.ReadByte();
                    yOffset = (byte)ms.ReadByte();
                    width = (byte)ms.ReadByte();
                    height = (byte)ms.ReadByte();
                    mask2_offset = (uint)ms.ReadInt32();
                    heightMap_offset = (uint)ms.ReadInt32();

                    long save_point = ms.Position;
                    if (mask2_offset != 0 && height > 0)
                    {
                        ms.Position = data_offset + mask2_offset;
                        mask2 = new List<byte>(sizeof(byte) * height);
                        for (int i = 0; i < height; i++)
                            mask2.Add((byte)ms.ReadByte());
                    }

                    if (heightMap_offset != 0 && width * height > 0)
                    {
                        ms.Position = data_offset + heightMap_offset;
                        heightMap = new List<float>(width * height);
                        for (int i = 0; i < width * height; i++)
                            heightMap.Add(ms.ReadFloat());
                    }
                    ms.Position = save_point;

                    return 0;
                }
示例#6
0
 public uint Read(MemoryStream ms)
 {
     base.Read(ms, "MOVT");
     long end_chunk = ms.Position + size;
     while (ms.Position < end_chunk)
     {
         Vector3 v;
         v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
         vertices.Add(v);
     }
     return size;
 }
示例#7
0
 public uint Read(MemoryStream ms)
 {
     base.Read(ms, "MOTV");
     long end_chunk = ms.Position + size;
     while (ms.Position < end_chunk)
     {
         Vector2 v;
         v.X = ms.ReadFloat(); v.Y = ms.ReadFloat();
         texCoords.Add(v);
     }
     return size;
 }
示例#8
0
        public uint Read(MemoryStream ms)
        {
            base.Read(ms, "MOGP");
            nameIndex = (uint)ms.ReadInt32();
            descriptionIndex = (uint)ms.ReadInt32();
            flags = (uint)ms.ReadInt32();
            bboxMin.X = ms.ReadFloat(); bboxMin.Y = ms.ReadFloat(); bboxMin.Z = ms.ReadFloat();
            bboxMax.X = ms.ReadFloat(); bboxMax.Y = ms.ReadFloat(); bboxMax.Z = ms.ReadFloat();
            moprIndex = (ushort)ms.ReadShort();
            numMoprItems = (ushort)ms.ReadShort();
            numBatchesA = (ushort)ms.ReadShort();
            numBatchesB = (ushort)ms.ReadShort();
            numBatchesC = (ushort)ms.ReadShort();
            ms.Read(fogIndices, 0, fogIndices.Length);
            liquid = (uint)ms.ReadInt32();
            wmoGroupId = (uint)ms.ReadInt32();
            ms.Read(unknown, 0, unknown.Length);

            return size;
        }
示例#9
0
文件: m2.cs 项目: ostapus/WoW2Mesh
        public M2(mpq.Wrapper mpq_h, string name)
        {
            MemoryStream ms = new MemoryStream(mpq_h.GetFile(name));

            // read in chunk by chunk
            ms.Read(id, 0, id.Length);
            ms.Read(version, 0, id.Length);
            nameLength = (uint) ms.ReadInt32();
            nameOff = (uint)ms.ReadInt32();
            flags = (uint)ms.ReadInt32();

            ms.Read(pad0, 0, pad0.Length);

            numVertices = (uint) ms.ReadInt32();
            verticesOff = (uint)ms.ReadInt32();

            ms.Read(pad1, 0, pad1.Length);

            numBoundingTriangles = (uint)ms.ReadInt32();
            boundingTriangleOff = (uint)ms.ReadInt32();
            numBoundingVertices = (uint)ms.ReadInt32();
            boundingVerticesOff = (uint)ms.ReadInt32();
            numBoundingNormals = (uint)ms.ReadInt32();
            boundingNormalsOff = (uint)ms.ReadInt32();

            isCollide = numBoundingTriangles > 0;

            // ignore non collidable M2s
            if (!isCollide)
                return;

            // get M2 model name
            ms.Position = nameOff;
            byte[] _b = new byte[nameLength];
            ms.Read(_b, 0, (int) nameLength);
            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            _m2name = enc.GetString(_b);

            if (numVertices > 0)
            {
                ms.Position = verticesOff;
                for (int i = 0; i < numVertices; i++)
                {
                    Vector3 v;
                    v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
                    _vertices.Add(v);
                }
            }

            // get bounding triangles
            if (numBoundingTriangles > 0)
            {
                ms.Position = boundingTriangleOff;
                for (int i = 0; i < numBoundingTriangles; i++)
                {
                    // in the file those are 16bit, so read short
                    _boundingIndices.Add(ms.ReadShort());
                }
            }

            // get bounding vertices
            if (numBoundingVertices > 0)
            {
                ms.Position = boundingVerticesOff;
                for (int i = 0; i < numBoundingVertices; i++)
                {
                    Vector3 v;
                    v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
                    _boundingVertices.Add(v);
                }
            }

            // get bounding normals
            if (numBoundingNormals > 0)
            {
                ms.Position = boundingNormalsOff;
                for (int i = 0; i < numBoundingNormals; i++)
                {
                    Vector3 v;
                    v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
                    _boundingNormals.Add(v);
                }
            }

            bbox = BoundingBox.CreateFromPoints(_boundingVertices);
        }
示例#10
0
文件: wmo.cs 项目: ostapus/WoW2Mesh
 public uint Read(MemoryStream ms)
 {
     id = (uint)ms.ReadInt32();
     uid = (uint)ms.ReadInt32();
     pos.X = ms.ReadFloat(); pos.Y = ms.ReadFloat(); pos.Z = ms.ReadFloat();
     rot.X = ms.ReadFloat(); rot.Y = ms.ReadFloat(); rot.Z = ms.ReadFloat();
     scale = (ushort)ms.ReadShort();
     flags = (ushort)ms.ReadShort();
     return 0;
 }
示例#11
0
文件: wmo.cs 项目: ostapus/WoW2Mesh
 public uint Read(MemoryStream ms)
 {
     id = (uint)ms.ReadInt32();
     uid = (uint)ms.ReadInt32();
     pos.X = ms.ReadFloat(); pos.Y = ms.ReadFloat(); pos.Z = ms.ReadFloat();
     rot.X = ms.ReadFloat(); rot.Y = ms.ReadFloat(); rot.Z = ms.ReadFloat();
     bbmin.X = ms.ReadFloat(); bbmin.Y = ms.ReadFloat(); bbmin.Z = ms.ReadFloat();
     bbmax.X = ms.ReadFloat(); bbmax.Y = ms.ReadFloat(); bbmax.Z = ms.ReadFloat();
     flags = (ushort)ms.ReadShort();
     doodadSet = (ushort)ms.ReadShort();
     nameSet = (ushort)ms.ReadShort();
     padding = (ushort)ms.ReadShort();
     if (doodadSet != 0)
     {
         int i = 0;
     }
     return 0;
 }
示例#12
0
 public void Read(MemoryStream ms)
 {
     for (int i = 0; i < vertex.Length; i++)
     {
         vertex[i].X = ms.ReadFloat();
         vertex[i].Y = ms.ReadFloat();
         vertex[i].Z = ms.ReadFloat();
     }
 }
示例#13
0
 public void Read(MemoryStream ms)
 {
     startVertex = (ushort)ms.ReadShort();
     numVertices = (ushort)ms.ReadShort();
     normal.X = ms.ReadFloat(); normal.Y = ms.ReadFloat(); normal.Z = ms.ReadFloat();
     unknown = (uint)ms.ReadInt32();
 }
示例#14
0
 public uint Read(MemoryStream ms)
 {
     base.Read(ms, "MOHD");
     numMaterials = (uint)ms.ReadInt32();
     numGroups = (uint)ms.ReadInt32();
     numPortals = (uint)ms.ReadInt32();
     numLights = (uint)ms.ReadInt32();
     numModels = (uint)ms.ReadInt32();
     numDoodads = (uint)ms.ReadInt32();
     numSets = (uint)ms.ReadInt32();
     ambientColor = (uint)ms.ReadInt32();
     wmoId = (uint)ms.ReadInt32();
     bboxMin.X = ms.ReadFloat(); bboxMin.Y = ms.ReadFloat(); bboxMin.Z = ms.ReadFloat();
     bboxMax.X = ms.ReadFloat(); bboxMax.Y = ms.ReadFloat(); bboxMax.Z = ms.ReadFloat();
     liquidType = (uint)ms.ReadInt32();
     return size;
 }
示例#15
0
 public void Read(MemoryStream ms)
 {
     flags = (uint)ms.ReadInt32();
     bboxMin.X = ms.ReadFloat(); bboxMin.Y = ms.ReadFloat(); bboxMin.Z = ms.ReadFloat();
     bboxMax.X = ms.ReadFloat(); bboxMax.Y = ms.ReadFloat(); bboxMax.Z = ms.ReadFloat();
     nameOffset = ms.ReadInt32();
 }