public M2RenderInstance(int uuid, Vector3 position, Vector3 rotation, Vector3 scale, M2BatchRenderer renderer) { mScale = scale; mPosition = position; mRotation = rotation; NumReferences = 1; Uuid = uuid; BoundingBox = renderer.BoundingBox; mOrigBoundingBox = BoundingBox; mInstanceMatrix = Matrix.RotationYawPitchRoll(MathUtil.DegreesToRadians(rotation.Y), MathUtil.DegreesToRadians(rotation.X), MathUtil.DegreesToRadians(rotation.Z)) * Matrix.Scaling(scale) * Matrix.Translation(position); BoundingBox = BoundingBox.Transform(ref mInstanceMatrix); Matrix.Invert(ref mInstanceMatrix, out InverseMatrix); }
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); }
public M2RenderInstance AddInstance(string model, int uuid, Vector3 position, Vector3 rotation, Vector3 scaling) { var hash = model.ToUpperInvariant().GetHashCode(); lock(mRenderer) { if (mRenderer.ContainsKey(hash)) { var renderer = mRenderer[hash]; return renderer.AddInstance(uuid, position, rotation, scaling); } var file = LoadModel(model); if (file == null) return null; var batch = new M2BatchRenderer(file); lock (mAddLock) mRenderer.Add(hash, batch); return batch.AddInstance(uuid, position, rotation, scaling); } }
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; }