public void OnFrame() { if (mSkipRendering) { return; } if (mIsSyncLoaded == false) { SyncLoad(); } mAnimator.Update(); Mesh.BeginDraw(); Mesh.Program.SetPixelSampler(0, Sampler); Mesh.UpdateIndexBuffer(mIndexBuffer); Mesh.UpdateVertexBuffer(mVertexBuffer); if (mAnimator.GetBones(mAnimationMatrices)) { mAnimBuffer.UpdateData(mAnimationMatrices); } Mesh.Program.SetVertexConstantBuffer(2, mAnimBuffer); Mesh.Program.SetVertexConstantBuffer(3, mPerPassBuffer); foreach (var pass in mModel.Passes) { var cullingDisabled = (pass.RenderFlag & 0x04) != 0; Mesh.UpdateRasterizerState(cullingDisabled ? gNoCullState : gCullState); Mesh.UpdateBlendState(BlendStates[pass.BlendMode]); var oldProgram = Mesh.Program; Mesh.Program = (pass.BlendMode > 0 ? gBlendProgram : gNoBlendProgram); if (Mesh.Program != oldProgram) { Mesh.Program.Bind(); } var unlit = ((pass.RenderFlag & 0x01) != 0) ? 0.0f : 1.0f; var unfogged = ((pass.RenderFlag & 0x02) != 0) ? 0.0f : 1.0f; Matrix uvAnimMat; mAnimator.GetUvAnimMatrix(pass.TexAnimIndex, out uvAnimMat); mPerPassBuffer.UpdateData(new PerModelPassBuffer() { uvAnimMatrix = uvAnimMat, modelPassParams = new Vector4(unlit, unfogged, 0.0f, 0.0f) }); Mesh.StartVertex = 0; Mesh.StartIndex = pass.StartIndex; Mesh.IndexCount = pass.IndexCount; Mesh.Program.SetPixelTexture(0, pass.Textures.First()); Mesh.Draw(); } }
public M2ModelRenderer(M2File model) { mModel = model; mAnimator = ModelFactory.Instance.CreateAnimator(model); mAnimator.SetAnimationByIndex(0); mAnimator.Update(); }
private void UpdateAnimations(M2RenderInstance instance) { var camera = WorldFrame.Instance.ActiveCamera; mAnimator.Update(new BillboardParameters { Forward = camera.Forward, Right = camera.Right, Up = camera.Up, InverseRotation = instance.InverseRotation }); if (mAnimator.GetBones(mAnimationMatrices)) { mAnimBuffer.UpdateData(mAnimationMatrices); } }