コード例 #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
        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);
        }
コード例 #3
0
        bool initialize(GameObjectModelOwnerBase modelOwner)
        {
            var modelData = StaticModelList.models.LookupByKey(modelOwner.GetDisplayId());

            if (modelData == null)
            {
                return(false);
            }

            AxisAlignedBox mdl_box = new AxisAlignedBox(modelData.bound);

            // ignore models with no bounds
            if (mdl_box == AxisAlignedBox.Zero())
            {
                Log.outError(LogFilter.Server, "GameObject model {0} has zero bounds, loading skipped", modelData.name);
                return(false);
            }

            iModel = Global.VMapMgr.acquireModelInstance(modelData.name);

            if (iModel == null)
            {
                return(false);
            }

            name      = modelData.name;
            iPos      = modelOwner.GetPosition();
            iScale    = modelOwner.GetScale();
            iInvScale = 1.0f / iScale;

            Matrix3 iRotation = Matrix3.fromEulerAnglesZYX(modelOwner.GetOrientation(), 0, 0);

            iInvRot = iRotation.inverse();
            // transform bounding box:
            mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale);
            AxisAlignedBox rotated_bounds = new AxisAlignedBox();

            for (int i = 0; i < 8; ++i)
            {
                rotated_bounds.merge(iRotation * mdl_box.corner(i));
            }

            iBound = rotated_bounds + iPos;
            owner  = modelOwner;
            isWmo  = modelData.isWmo;
            return(true);
        }
コード例 #4
0
        public bool UpdatePosition()
        {
            if (iModel == null)
            {
                return(false);
            }

            var it = StaticModelList.models.LookupByKey(owner.GetDisplayId());

            if (it == null)
            {
                return(false);
            }

            AxisAlignedBox mdl_box = new AxisAlignedBox(it.bound);

            // ignore models with no bounds
            if (mdl_box == AxisAlignedBox.Zero())
            {
                Log.outError(LogFilter.Server, "GameObject model {0} has zero bounds, loading skipped", it.name);
                return(false);
            }

            iPos = owner.GetPosition();

            Matrix3 iRotation = Matrix3.fromEulerAnglesZYX(owner.GetOrientation(), 0, 0);

            iInvRot = iRotation.inverse();
            // transform bounding box:
            mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale);
            AxisAlignedBox rotated_bounds = new AxisAlignedBox();

            for (int i = 0; i < 8; ++i)
            {
                rotated_bounds.merge(iRotation * mdl_box.corner(i));
            }

            iBound = rotated_bounds + iPos;

            return(true);
        }
コード例 #5
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);
                    }
                }
            }
        }