/// <summary> /// Draws the tree's bones as lines. Useful for testing and debugging. /// </summary> /// <param name="world">World matrix.</param> /// <param name="view">View matrix.</param> /// <param name="projection">Projection matrix.</param> public void DrawBonesAsLines(Matrix world, Matrix view, Matrix projection) { if (skeleton == null) { throw new InvalidOperationException("A skeleton must be set before bones can be rendered."); } if (leafEffect == null) { throw new InvalidOperationException("LeafEffect must be set before leaves can be rendered."); } if (skeleton.Bones.Count == 0) { return; } BoneEffect.World = world; BoneEffect.View = view; BoneEffect.Projection = projection; bool wasDepthBufferOn = device.RenderState.DepthBufferEnable; device.RenderState.DepthBufferEnable = false; device.RenderState.AlphaTestEnable = false; device.RenderState.AlphaBlendEnable = false; var transforms = new Matrix[skeleton.Bones.Count]; skeleton.CopyAbsoluteBoneTranformsTo(transforms, animationState.BoneRotations); var vertices = new VertexPositionColor[skeleton.Bones.Count * 2]; for (int i = 0; i < skeleton.Bones.Count; i++) { vertices[2 * i] = new VertexPositionColor(transforms[i].Translation, Color.Red); vertices[2 * i + 1] = new VertexPositionColor(transforms[i].Translation + transforms[i].Up * skeleton.Bones[i].Length, Color.Red); } BoneEffect.Begin(); foreach (EffectPass pass in BoneEffect.CurrentTechnique.Passes) { pass.Begin(); device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, skeleton.Bones.Count); pass.End(); } BoneEffect.End(); device.RenderState.DepthBufferEnable = wasDepthBufferOn; }
/// <summary> /// Draws the tree's bones as lines. Useful for testing and debugging. /// </summary> /// <param name="world">World matrix.</param> /// <param name="view">View matrix.</param> /// <param name="projection">Projection matrix.</param> public void DrawBonesAsLines(Matrix world, Matrix view, Matrix projection) { if (skeleton == null) { throw new InvalidOperationException("A skeleton must be set before bones can be rendered."); } if (leafEffect == null) { throw new InvalidOperationException("LeafEffect must be set before leaves can be rendered."); } if (skeleton.Bones.Count == 0) { return; } boneEffect.World = world; boneEffect.View = view; boneEffect.Projection = projection; bool wasDepthBufferOn = device.DepthStencilState.DepthBufferEnable; device.DepthStencilState = DepthStencilState.None; device.BlendState = BlendState.Opaque; Matrix[] transforms = new Matrix[skeleton.Bones.Count]; skeleton.CopyAbsoluteBoneTranformsTo(transforms, animationState.BoneRotations); VertexPositionColor[] vertices = new VertexPositionColor[skeleton.Bones.Count * 2]; for (int i = 0; i < skeleton.Bones.Count; i++) { vertices[2 * i] = new VertexPositionColor(transforms[i].Translation, Color.Red); vertices[2 * i + 1] = new VertexPositionColor(transforms[i].Translation + transforms[i].Up * skeleton.Bones[i].Length, Color.Red); } foreach (EffectPass pass in boneEffect.CurrentTechnique.Passes) { pass.Apply(); device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, skeleton.Bones.Count); } if (wasDepthBufferOn) { device.DepthStencilState = DepthStencilState.Default; } }