Пример #1
0
        bool calculateTransformedBound(ModelSpawn spawn)
        {
            string modelFilename = iSrcDir + spawn.name.TrimEnd('\0');

            ModelPosition modelPosition = new ModelPosition();

            modelPosition.iDir   = spawn.iRot;
            modelPosition.iScale = spawn.iScale;
            modelPosition.init();

            WorldModel_Raw raw_model = new WorldModel_Raw();

            if (!raw_model.Read(modelFilename))
            {
                return(false);
            }

            int groups = raw_model.groupsArray.Length;

            if (groups != 1)
            {
                Console.WriteLine($"Warning: '{modelFilename}' does not seem to be a M2 model!");
            }

            AxisAlignedBox modelBound = AxisAlignedBox.Zero();

            modelBound.merge(modelPosition.transform(raw_model.groupsArray[0].bounds.Lo));
            modelBound.merge(modelPosition.transform(raw_model.groupsArray[0].bounds.Hi));

            spawn.iBound = modelBound + spawn.iPos;
            spawn.flags |= ModelFlags.HasBound;
            return(true);
        }
Пример #2
0
        void convertRawFile(string pModelFilename)
        {
            string filename = iSrcDir + pModelFilename;

            WorldModel_Raw raw_model = new WorldModel_Raw();

            if (!raw_model.Read(filename))
            {
                return;
            }

            // write WorldModel
            WorldModel model = new WorldModel();

            model.setRootWmoID(raw_model.RootWMOID);
            if (!raw_model.groupsArray.Empty())
            {
                List <GroupModel> groupsArray = new List <GroupModel>();

                int groups = raw_model.groupsArray.Length;
                for (uint g = 0; g < groups; ++g)
                {
                    GroupModel_Raw raw_group  = raw_model.groupsArray[g];
                    var            groupModel = new GroupModel(raw_group.mogpflags, raw_group.GroupWMOID, raw_group.bounds);
                    groupModel.SetMeshData(raw_group.vertexArray, raw_group.triangles.ToList());
                    groupModel.SetLiquidData(raw_group.liquid);
                    groupsArray.Add(groupModel);
                }

                model.setGroupModels(groupsArray);
            }

            model.writeFile(iDestDir + "/" + pModelFilename + ".vmo");
        }
Пример #3
0
        bool calculateTransformedBound(ModelSpawn spawn)
        {
            string modelFilename = iSrcDir + spawn.name;

            ModelPosition modelPosition = new ModelPosition();

            modelPosition.iDir   = spawn.iRot;
            modelPosition.iScale = spawn.iScale;
            modelPosition.init();

            WorldModel_Raw raw_model = new WorldModel_Raw();

            if (!raw_model.Read(modelFilename))
            {
                return(false);
            }

            int groups = raw_model.groupsArray.Length;

            if (groups != 1)
            {
                Console.WriteLine($"Warning: '{modelFilename}' does not seem to be a M2 model!");
            }

            AxisAlignedBox modelBound = AxisAlignedBox.Zero();
            bool           boundEmpty = true;

            for (uint g = 0; g < groups; ++g) // should be only one for M2 files...
            {
                var vertices = raw_model.groupsArray[g].vertexArray;

                if (vertices.Empty())
                {
                    Console.WriteLine($"error: model {spawn.name} has no geometry!");
                    continue;
                }

                int nvectors = vertices.Count;
                for (int i = 0; i < nvectors; ++i)
                {
                    Vector3 v = modelPosition.transform(vertices[i]);

                    if (boundEmpty)
                    {
                        modelBound = new AxisAlignedBox(v, v);
                        boundEmpty = false;
                    }
                    else
                    {
                        modelBound.merge(v);
                    }
                }
            }
            spawn.iBound = modelBound + spawn.iPos;
            spawn.flags |= ModelFlags.HasBound;
            return(true);
        }
Пример #4
0
        void exportGameobjectModels()
        {
            if (!File.Exists(iSrcDir + "/" + "temp_gameobject_models"))
            {
                return;
            }

            using (BinaryReader reader = new BinaryReader(File.Open(iSrcDir + "/" + "temp_gameobject_models", FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                string magic = reader.ReadCString();
                if (magic != SharedConst.RAW_VMAP_MAGIC)
                {
                    return;
                }

                using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(iDestDir + "/" + "GameObjectModels.dtree")))
                {
                    writer.WriteString(SharedConst.VMAP_MAGIC);

                    long fileLength = reader.BaseStream.Length;
                    while (reader.BaseStream.Position < fileLength)
                    {
                        uint   displayId   = reader.ReadUInt32();
                        bool   isWmo       = reader.ReadBoolean();
                        int    name_length = reader.ReadInt32();
                        string model_name  = reader.ReadString(name_length);

                        WorldModel_Raw raw_model = new WorldModel_Raw();
                        if (!raw_model.Read((iSrcDir + "/" + model_name)))
                        {
                            continue;
                        }

                        spawnedModelFiles.Add(model_name);
                        AxisAlignedBox bounds     = AxisAlignedBox.Zero();
                        bool           boundEmpty = true;
                        for (uint g = 0; g < raw_model.groupsArray.Length; ++g)
                        {
                            var vertices = raw_model.groupsArray[g].vertexArray;
                            if (vertices == null)
                            {
                                continue;
                            }

                            for (int i = 0; i < vertices.Count; ++i)
                            {
                                Vector3 v = vertices[i];
                                if (boundEmpty)
                                {
                                    bounds     = new AxisAlignedBox(v, v);
                                    boundEmpty = false;
                                }
                                else
                                {
                                    bounds.merge(v);
                                }
                            }
                        }

                        if (bounds.isEmpty())
                        {
                            Console.WriteLine($"Model {model_name} has empty bounding box");
                            continue;
                        }

                        if (bounds.isFinite())
                        {
                            Console.WriteLine($"Model {model_name} has invalid bounding box");
                            continue;
                        }

                        writer.Write(displayId);
                        writer.Write(isWmo);
                        writer.Write(name_length);
                        writer.WriteString(model_name);
                        writer.WriteVector3(bounds.Lo);
                        writer.WriteVector3(bounds.Hi);
                    }
                }
            }
        }