Beispiel #1
0
        public M2Renderer(M2File model)
        {
            Model            = model;
            VisibleInstances = new List <M2RenderInstance>();

            if (!model.NeedsPerInstanceAnimation)
            {
                mAnimationMatrices = new Matrix[model.GetNumberOfBones()];
                Animator           = ModelFactory.Instance.CreateAnimator(model);
                if (Animator.SetAnimation(AnimationType.Stand) == false)
                {
                    Animator.SetAnimationByIndex(0);
                }
                StaticAnimationThread.Instance.AddAnimator(Animator);
            }

            mBatchRenderer    = new M2BatchRenderer(model);
            mSingleRenderer   = new M2SingleRenderer(model);
            mPortraitRenderer = new M2PortraitRenderer(model);
        }
Beispiel #2
0
        private void Dispose(bool disposing)
        {
            mSkipRendering = true;
            if (mBatchRenderer != null)
            {
                mBatchRenderer.Dispose();
                mBatchRenderer = null;
            }

            if (mSingleRenderer != null)
            {
                mSingleRenderer.Dispose();
                mSingleRenderer = null;
            }

            if (mPortraitRenderer != null)
            {
                mPortraitRenderer.Dispose();
                mPortraitRenderer = null;
            }

            if (mFullInstances != null)
            {
                lock (mFullInstances)
                {
                    foreach (var inst in mFullInstances.Values)
                    {
                        inst.Dispose();
                    }

                    mFullInstances.Clear();
                    mFullInstances = null;
                }
            }

            var vb = VertexBuffer;
            var ib = IndexBuffer;
            var ab = AnimBuffer;

            WorldFrame.Instance.Dispatcher.BeginInvoke(() =>
            {
                if (vb != null)
                {
                    vb.Dispose();
                }
                if (ib != null)
                {
                    ib.Dispose();
                }
                if (ab != null)
                {
                    ab.Dispose();
                }
            });

            VertexBuffer = null;
            IndexBuffer  = null;
            AnimBuffer   = null;

            if (Animator != null)
            {
                StaticAnimationThread.Instance.RemoveAnimator(Animator);
                Animator = null;
            }

            // Sync load can be called even after the object has been disposed.
            if (mSyncLoadToken != null)
            {
                WorldFrame.Instance.Dispatcher.Remove(mSyncLoadToken);
                mSyncLoadToken = null;
            }

            mAnimationMatrices = null;
        }