/// <summary> /// Draws all of the ModelMeshPart objects in this mesh, using their current Effect settings. /// </summary> /// <param name="context">The graphics context.</param> /// <param name="boneTransforms">The model's bone transforms.</param> /// <param name="effectOverride">The effect to use instead of the effect attached to each mesh part. Default is null (use Effect in MeshPart)</param> /// <exception cref="System.InvalidOperationException">Model has no effect</exception> public void Draw(GraphicsDevice context, Matrix[] boneTransforms, Effect effectOverride = null) { int count = this.MeshParts.Count; for (int i = 0; i < count; i++) { ModelMeshPart part = MeshParts[i]; Effect effect = effectOverride ?? part.Effect; if (effect == null) { throw new InvalidOperationException("ModelMeshPart has no effect and effectOverride is null"); } var skinnedEffect = effect as SkinnedEffect; int boneCount = part.SkinnedBones.Count; if (skinnedEffect != null && boneCount > 0) { var transforms = new Matrix[boneCount]; for (int j = 0; j < boneCount; j++) { var skinnedBone = part.SkinnedBones[j]; Matrix.Multiply(ref skinnedBone.OffsetMatrix, ref boneTransforms[skinnedBone.Bone.Index], out transforms[j]); } skinnedEffect.SetBoneTransforms(transforms); } int passCount = effect.CurrentTechnique.Passes.Count; for (int j = 0; j < passCount; j++) { effect.CurrentTechnique.Passes[j].Apply(); part.Draw(context); } } }
/// <summary> /// Draws all of the ModelMeshPart objects in this mesh, using their current Effect settings. /// </summary> /// <param name="context">The graphics context.</param> /// <param name="effectOverride">The effect to use instead of the effect attached to each mesh part. Default is null (use Effect in MeshPart)</param> /// <exception cref="System.InvalidOperationException">Model has no effect</exception> public void Draw(GraphicsDevice context, Effect effectOverride = null) { int count = this.MeshParts.Count; for (int i = 0; i < count; i++) { ModelMeshPart part = MeshParts[i]; Effect effect = effectOverride ?? part.Effect; if (effect == null) { throw new InvalidOperationException("ModelMeshPart has no effect and effectOverride is null"); } int passCount = effect.CurrentTechnique.Passes.Count; for (int j = 0; j < passCount; j++) { effect.CurrentTechnique.Passes[j].Apply(); part.Draw(context); } } }