示例#1
0
        public bool IsMdxInstanceSelected(MDX.M2Info info, uint id)
        {
            if (mMdxResult == null)
            {
                return(false);
            }

            return(mMdxResult.Model == info && mMdxResult.InstanceID == id);
        }
示例#2
0
        public M2BoneAnimator(Stormlib.MPQFile file, M2Info parent)
        {
            string AnimPath = parent.FileDirectory + parent.ModelName;

            M2Animation[] anims = new M2Animation[parent.Header.nAnimations];
            file.Position = parent.Header.ofsAnimations;
            file.Read(anims);

            Stormlib.MPQFile[] AnimFiles = new Stormlib.MPQFile[parent.Header.nAnimations];
            for (int i = 0; i < parent.Header.nAnimations; ++i)
            {
                string full = AnimPath + anims[i].AnimationID.ToString("D4") + "-" + anims[i].SubAnimationID.ToString("D2") + ".anim";
                if (Stormlib.MPQFile.Exists(full))
                {
                    Console.WriteLine(full);
                    AnimFiles[i] = new Stormlib.MPQFile(full);
                }
            }

            Animations.AddRange(anims);

            this.file = file;
            var bones = new M2Bone[parent.Header.nBones];

            file.Position = parent.Header.ofsBones;
            file.Read(bones);

            foreach (var bone in bones)
            {
                M2AnimationBone ab = new M2AnimationBone(bone, this, file, parent.GlobalSequences, AnimFiles);
                Bones.Add(ab);
                ab.BoneIndex = Bones.Count - 1;
            }
            foreach (var bone in Bones)
            {
                bone.Init();
            }
        }
示例#3
0
        /// <summary>
        /// Loads a batch renderer for a doodad in a render context
        /// </summary>
        /// <param name="mgr">The render context</param>
        /// <param name="doodadName">Name of the doodad (case insensitive)</param>
        public M2BatchRender(string doodadName)
        {
            Intersector = new ModelIntersector(this);
            ModelName   = doodadName;
            M2Info inf = Game.GameManager.M2ModelCache.GetInfo(doodadName);

            mModelInfo = inf;
            Game.GameManager.GraphicsThread.CallOnThread(
                () =>
            {
                for (int i = 0; i < inf.Passes.Count; ++i)
                {
                    Models.MDX.M2RenderPass pass = inf.Passes[i];
                    Mesh mesh = new Mesh(
                        Game.GameManager.GraphicsThread.GraphicsManager.Device,
                        pass.Vertices.Length / 3,
                        pass.Vertices.Length,
                        MeshFlags.Managed,
                        MdxVertex.FVF
                        );

                    VertexBuffer vb = new VertexBuffer(Game.GameManager.GraphicsThread.GraphicsManager.Device, pass.Vertices.Length * Marshal.SizeOf(typeof(Models.MDX.MdxVertex)), Usage.None,
                                                       Models.MDX.MdxVertex.FVF, Pool.Managed);
                    DataStream strm = vb.Lock(0, 0, LockFlags.None);
                    strm.WriteRange(pass.Vertices);
                    vb.Unlock();

                    strm = mesh.VertexBuffer.Lock(0, 0, LockFlags.None);
                    strm.WriteRange(pass.Vertices);
                    mesh.VertexBuffer.Unlock();

                    IndexBuffer ib = new IndexBuffer(Game.GameManager.GraphicsThread.GraphicsManager.Device, pass.Vertices.Length * 2, Usage.None, Pool.Managed, true);
                    strm           = ib.Lock(0, 0, LockFlags.None);
                    for (int j = 0; j < pass.Vertices.Length; ++j)
                    {
                        strm.Write((short)j);
                    }
                    ib.Unlock();

                    strm = mesh.IndexBuffer.Lock(0, 0, LockFlags.None);
                    for (int j = 0; j < pass.Vertices.Length; ++j)
                    {
                        strm.Write((short)j);
                    }
                    mesh.IndexBuffer.Unlock();

                    try
                    {
                        Textures.Add(Video.TextureManager.GetTexture(pass.Texture));
                    }
                    catch (Exception)
                    {
                        Textures.Add(Video.TextureManager.Default.ErrorTexture);
                    }
                    NumTriangles.Add(pass.Vertices.Length / 3);
                    Indices.Add(ib);
                    Meshes.Add(vb);
                    mMeshPasses.Add(mesh);
                }
            }
                );
            InstanceDeclaration = new VertexDeclaration(Game.GameManager.GraphicsThread.GraphicsManager.Device, ElemDecl);
            InstanceLoader      = new M2InstanceLoader(this);

            Game.GameManager.GraphicsThread.OnFrame += new Game.VideoThread.FrameRenderDelegate(_OnFrame);
        }
示例#4
0
        public M2BoneAnimator(Stormlib.MPQFile file, M2Info parent)
        {
            string AnimPath = parent.FileDirectory + parent.ModelName;

            M2Animation[] anims = new M2Animation[parent.Header.nAnimations];
            file.Position = parent.Header.ofsAnimations;
            file.Read(anims);

            Stormlib.MPQFile[] AnimFiles = new Stormlib.MPQFile[parent.Header.nAnimations];
            for (int i = 0; i < parent.Header.nAnimations; ++i)
            {
                string full = AnimPath + anims[i].AnimationID.ToString("D4") + "-" + anims[i].SubAnimationID.ToString("D2") + ".anim";
                if (Stormlib.MPQFile.Exists(full))
                {
                    Console.WriteLine(full);
                    AnimFiles[i] = new Stormlib.MPQFile(full);
                }
            }

            Animations.AddRange(anims);

            this.file = file;
            var bones = new M2Bone[parent.Header.nBones];
            file.Position = parent.Header.ofsBones;
            file.Read(bones);

            foreach (var bone in bones)
            {
                M2AnimationBone ab = new M2AnimationBone(bone, this, file, parent.GlobalSequences, AnimFiles);
                Bones.Add(ab);
                ab.BoneIndex = Bones.Count - 1;
            }
            foreach (var bone in Bones)
            {
                bone.Init();
            }
        }
示例#5
0
        /// <summary>
        /// Loads a batch renderer for a doodad in a render context
        /// </summary>
        /// <param name="mgr">The render context</param>
        /// <param name="doodadName">Name of the doodad (case insensitive)</param>
        public M2BatchRender(string doodadName)
        {
            Intersector = new ModelIntersector(this);
            ModelName = doodadName;
            M2Info inf = Game.GameManager.M2ModelCache.GetInfo(doodadName);
            mModelInfo = inf;
            Game.GameManager.GraphicsThread.CallOnThread(
                () =>
                {
                    for (int i = 0; i < inf.Passes.Count; ++i)
                    {
                        Models.MDX.M2RenderPass pass = inf.Passes[i];
                        Mesh mesh = new Mesh(
                           Game.GameManager.GraphicsThread.GraphicsManager.Device,
                           pass.Vertices.Length / 3,
                           pass.Vertices.Length,
                           MeshFlags.Managed,
                           MdxVertex.FVF
                       );

                        VertexBuffer vb = new VertexBuffer(Game.GameManager.GraphicsThread.GraphicsManager.Device, pass.Vertices.Length * Marshal.SizeOf(typeof(Models.MDX.MdxVertex)), Usage.None,
                            Models.MDX.MdxVertex.FVF, Pool.Managed);
                        DataStream strm = vb.Lock(0, 0, LockFlags.None);
                        strm.WriteRange(pass.Vertices);
                        vb.Unlock();

                        strm = mesh.VertexBuffer.Lock(0, 0, LockFlags.None);
                        strm.WriteRange(pass.Vertices);
                        mesh.VertexBuffer.Unlock();

                        IndexBuffer ib = new IndexBuffer(Game.GameManager.GraphicsThread.GraphicsManager.Device, pass.Vertices.Length * 2, Usage.None, Pool.Managed, true);
                        strm = ib.Lock(0, 0, LockFlags.None);
                        for (int j = 0; j < pass.Vertices.Length; ++j)
                            strm.Write((short)j);
                        ib.Unlock();

                        strm = mesh.IndexBuffer.Lock(0, 0, LockFlags.None);
                        for (int j = 0; j < pass.Vertices.Length; ++j)
                            strm.Write((short)j);
                        mesh.IndexBuffer.Unlock();

                        try
                        {
                            Textures.Add(Video.TextureManager.GetTexture(pass.Texture));
                        }
                        catch (Exception)
                        {
                            Textures.Add(Video.TextureManager.Default.ErrorTexture);
                        }
                        NumTriangles.Add(pass.Vertices.Length / 3);
                        Indices.Add(ib);
                        Meshes.Add(vb);
                        mMeshPasses.Add(mesh);
                    }
                }
            );
            InstanceDeclaration = new VertexDeclaration(Game.GameManager.GraphicsThread.GraphicsManager.Device, ElemDecl);
            InstanceLoader = new M2InstanceLoader(this);

            Game.GameManager.GraphicsThread.OnFrame += new Game.VideoThread.FrameRenderDelegate(_OnFrame);
        }