Example #1
0
File: Model.cs Project: ywscr/Tools
        public static void ExtractSet(WMODoodadData doodadData, MODF wmo, bool isGlobalWmo, uint mapID, uint originalMapId, BinaryWriter writer, List <ADTOutputCache> dirfileCache)
        {
            if (wmo.DoodadSet >= doodadData.Sets.Count)
            {
                return;
            }

            Vector3 wmoPosition = new Vector3(wmo.Position.Z, wmo.Position.X, wmo.Position.Y);
            Matrix3 wmoRotation = Matrix3.fromEulerAnglesZYX(MathFunctions.toRadians(wmo.Rotation.Y), MathFunctions.toRadians(wmo.Rotation.X), MathFunctions.toRadians(wmo.Rotation.Z));

            if (isGlobalWmo)
            {
                wmoPosition += new Vector3(533.33333f * 32, 533.33333f * 32, 0.0f);
            }

            ushort doodadId      = 0;
            MODS   doodadSetData = doodadData.Sets[wmo.DoodadSet];

            using (BinaryReader reader = new BinaryReader(new MemoryStream(doodadData.Paths)))
            {
                foreach (ushort doodadIndex in doodadData.References)
                {
                    if (doodadIndex < doodadSetData.StartIndex ||
                        doodadIndex >= doodadSetData.StartIndex + doodadSetData.Count)
                    {
                        continue;
                    }

                    MODD doodad = doodadData.Spawns[doodadIndex];

                    reader.BaseStream.Position = doodad.NameIndex;
                    string ModelInstName = reader.ReadCString().GetPlainName();

                    if (ModelInstName.Length > 3)
                    {
                        string extension = ModelInstName.Substring(ModelInstName.Length - 4);
                        if (extension == ".mdx" || extension == ".mdl")
                        {
                            ModelInstName  = ModelInstName.Remove(ModelInstName.Length - 2, 2);
                            ModelInstName += "2";
                        }
                    }

                    if (!File.Exists(Program.WmoDirectory + ModelInstName))
                    {
                        continue;
                    }

                    using (BinaryReader binaryReader = new BinaryReader(File.Open(Program.WmoDirectory + ModelInstName, FileMode.Open, FileAccess.Read, FileShare.Read)))
                    {
                        binaryReader.BaseStream.Seek(8, SeekOrigin.Begin); // get the correct no of vertices
                        int nVertices = binaryReader.ReadInt32();
                        if (nVertices == 0)
                        {
                            continue;
                        }
                    }
                    ++doodadId;

                    Vector3 position = wmoPosition + (wmoRotation * new Vector3(doodad.Position.X, doodad.Position.Y, doodad.Position.Z));

                    Vector3 rotation;
                    (new Quaternion(doodad.Rotation.X, doodad.Rotation.Y, doodad.Rotation.Z, doodad.Rotation.W).toRotationMatrix() * wmoRotation).toEulerAnglesXYZ(out rotation.Z, out rotation.X, out rotation.Y);

                    rotation.Z = MathFunctions.toDegrees(rotation.Z);
                    rotation.X = MathFunctions.toDegrees(rotation.X);
                    rotation.Y = MathFunctions.toDegrees(rotation.Y);

                    ushort nameSet  = 0;    // not used for models
                    uint   uniqueId = VmapFile.GenerateUniqueObjectId(wmo.UniqueId, doodadId);
                    uint   flags    = ModelFlags.M2;
                    if (mapID != originalMapId)
                    {
                        flags |= ModelFlags.ParentSpawn;
                    }

                    //write mapID, Flags, NameSet, UniqueId, Pos, Rot, Scale, name
                    writer.Write(mapID);
                    writer.Write(flags);
                    writer.Write(nameSet);
                    writer.Write(uniqueId);
                    writer.WriteVector3(position);
                    writer.WriteVector3(rotation);
                    writer.Write(doodad.Scale);
                    writer.Write(ModelInstName.GetByteCount());
                    writer.WriteString(ModelInstName);

                    if (dirfileCache != null)
                    {
                        ADTOutputCache cacheModelData = new ADTOutputCache();
                        cacheModelData.Flags = flags & ~ModelFlags.ParentSpawn;

                        MemoryStream stream    = new MemoryStream();
                        BinaryWriter cacheData = new BinaryWriter(stream);
                        cacheData.Write(nameSet);
                        cacheData.Write(uniqueId);
                        cacheData.WriteVector3(position);
                        cacheData.WriteVector3(rotation);
                        cacheData.Write(doodad.Scale);
                        cacheData.Write(ModelInstName.GetByteCount());
                        cacheData.WriteString(ModelInstName);

                        cacheModelData.Data = stream.ToArray();
                        dirfileCache.Add(cacheModelData);
                    }
                }
            }
        }
Example #2
0
File: Wmo.cs Project: ywscr/Tools
        public static void Extract(MODF mapObjDef, string WmoInstName, bool isGlobalWmo, uint mapID, uint originalMapId, BinaryWriter writer, List <ADTOutputCache> dirfileCache)
        {
            // destructible wmo, do not dump. we can handle the vmap for these
            // in dynamic tree (gameobject vmaps)
            if ((mapObjDef.Flags & 0x01) != 0)
            {
                return;
            }

            if (!File.Exists(Program.WmoDirectory + WmoInstName))
            {
                Console.WriteLine($"WMOInstance.WMOInstance: couldn't open {WmoInstName}");
                return;
            }

            //-----------add_in _dir_file----------------
            using (BinaryReader binaryReader = new BinaryReader(File.Open(Program.WmoDirectory + WmoInstName, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                binaryReader.BaseStream.Seek(8, SeekOrigin.Begin); // get the correct no of vertices
                int nVertices = binaryReader.ReadInt32();
                if (nVertices == 0)
                {
                    return;
                }

                Vector3        position = fixCoords(mapObjDef.Position);
                AxisAlignedBox bounds   = new AxisAlignedBox(fixCoords(mapObjDef.Bounds.Lo), fixCoords(mapObjDef.Bounds.Hi));

                if (isGlobalWmo)
                {
                    position += new Vector3(533.33333f * 32, 533.33333f * 32, 0.0f);
                    bounds   += new Vector3(533.33333f * 32, 533.33333f * 32, 0.0f);
                }

                float scale = 1.0f;
                if (Convert.ToBoolean(mapObjDef.Flags & 0x4))
                {
                    scale = mapObjDef.Scale / 1024.0f;
                }
                uint uniqueId = VmapFile.GenerateUniqueObjectId(mapObjDef.UniqueId, 0);
                uint flags    = ModelFlags.HasBound;
                if (mapID != originalMapId)
                {
                    flags |= ModelFlags.ParentSpawn;
                }

                if (uniqueId == 198660)
                {
                }

                //write mapID, Flags, ID, Pos, Rot, Scale, Bound_lo, Bound_hi, name
                writer.Write(mapID);
                writer.Write(flags);
                writer.Write(mapObjDef.NameSet);
                writer.Write(uniqueId);
                writer.WriteVector3(position);
                writer.WriteVector3(mapObjDef.Rotation);
                writer.Write(scale);
                writer.WriteVector3(bounds.Lo);
                writer.WriteVector3(bounds.Hi);
                writer.Write(WmoInstName.GetByteCount());
                writer.WriteString(WmoInstName);

                if (dirfileCache != null)
                {
                    ADTOutputCache cacheModelData = new ADTOutputCache();
                    cacheModelData.Flags = flags & ~ModelFlags.ParentSpawn;

                    MemoryStream stream    = new MemoryStream();
                    BinaryWriter cacheData = new BinaryWriter(stream);
                    cacheData.Write(mapObjDef.NameSet);
                    cacheData.Write(uniqueId);
                    cacheData.WriteVector3(position);
                    cacheData.WriteVector3(mapObjDef.Rotation);
                    cacheData.Write(scale);
                    cacheData.WriteVector3(bounds.Lo);
                    cacheData.WriteVector3(bounds.Hi);
                    cacheData.Write(WmoInstName.GetByteCount());
                    cacheData.WriteString(WmoInstName);

                    cacheModelData.Data = stream.ToArray();
                    dirfileCache.Add(cacheModelData);
                }
            }
        }
Example #3
0
File: Model.cs Project: ywscr/Tools
        public static void Extract(MDDF doodadDef, string ModelInstName, uint mapID, uint originalMapId, BinaryWriter writer, List <ADTOutputCache> dirfileCache)
        {
            if (!File.Exists(Program.WmoDirectory + ModelInstName))
            {
                return;
            }

            using (BinaryReader binaryReader = new BinaryReader(File.Open(Program.WmoDirectory + ModelInstName, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                binaryReader.BaseStream.Seek(8, SeekOrigin.Begin); // get the correct no of vertices
                int nVertices = binaryReader.ReadInt32();
                if (nVertices == 0)
                {
                    return;
                }
            }

            // scale factor - divide by 1024. blizzard devs must be on crack, why not just use a float?
            float sc = doodadDef.Scale / 1024.0f;

            Vector3 position = fixCoords(doodadDef.Position);

            ushort nameSet  = 0;// not used for models
            uint   uniqueId = VmapFile.GenerateUniqueObjectId(doodadDef.UniqueId, 0);
            uint   flags    = ModelFlags.M2;

            if (mapID != originalMapId)
            {
                flags |= ModelFlags.ParentSpawn;
            }


            //write mapID, Flags, NameSet, UniqueId, Pos, Rot, Scale, name
            writer.Write(mapID);
            writer.Write(flags);
            writer.Write(nameSet);
            writer.Write(uniqueId);
            writer.WriteVector3(position);
            writer.WriteVector3(doodadDef.Rotation);
            writer.Write(sc);
            writer.Write(ModelInstName.GetByteCount());
            writer.WriteString(ModelInstName);

            if (dirfileCache != null)
            {
                ADTOutputCache cacheModelData = new ADTOutputCache();
                cacheModelData.Flags = flags & ~ModelFlags.ParentSpawn;

                MemoryStream stream    = new MemoryStream();
                BinaryWriter cacheData = new BinaryWriter(stream);
                cacheData.Write(nameSet);
                cacheData.Write(uniqueId);
                cacheData.WriteVector3(position);
                cacheData.WriteVector3(doodadDef.Rotation);
                cacheData.Write(sc);
                cacheData.Write(ModelInstName.GetByteCount());
                cacheData.WriteString(ModelInstName);

                cacheModelData.Data = stream.ToArray();
                dirfileCache.Add(cacheModelData);
            }
        }