Advertisement
Guest User

Untitled

a guest
Oct 6th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. public void DrawMesh(Mesh mesh, int frame, Material mat, Vector3 position, Vector3 rotation, Vector3 scale,
  2.             float morphFactor, Vector2 uv)
  3.         {
  4.             if(mesh != null)
  5.             {
  6.                 Matrix matrix = Matrix.Identity;
  7.  
  8.                 matrix *= Matrix.Scaling(scale) *
  9.                     Matrix.RotationY(rotation.Y * Mathf.DegToRad) *
  10.                     Matrix.RotationZ(rotation.Z * Mathf.DegToRad) *
  11.                     Matrix.RotationX(rotation.X * Mathf.DegToRad) *
  12.                     Matrix.Translation(position);
  13.  
  14.                 if (mat.Flags.HasFlag(MaterialFlags.ShadowMesh))
  15.                     matrix *= Matrix.Shadow(new Vector4(0, 1, 1, 0), new Plane(new Vector3(0, 1, 0), 0.95f)); // Note: This is hardcoded. We should calculate mesh height by it's bounding box(not implemented yet)
  16.  
  17.                 device.SetTransform(TransformState.World, matrix);
  18.  
  19.                 SetRenderState(mat);
  20.                
  21.                 if (mat.Flags.HasFlag(MaterialFlags.ShadowMesh))
  22.                 {
  23.                     SetShadowMeshState();
  24.                 }
  25.                 else
  26.                 {
  27.                     device.SetRenderState(RenderState.Lighting, !mat.NonLit);
  28.                     SetTextureState(mat);
  29.                 }
  30.  
  31.                 bool lerpEnable = Game.Current.Config.GetBool("renderer.lerp");
  32.  
  33.                 if (morphFactor > 0)
  34.                 {
  35.                     if (frame < mesh.Frames.Length && lerpEnable)
  36.                     {
  37.                         mesh.UpdateMorphTarget(frame, frame + 1, morphFactor);
  38.                     }
  39.                 }
  40.  
  41.                 if (morphFactor > 0 && lerpEnable)
  42.                     device.DrawUserPrimitives<Vertex>(PrimitiveType.TriangleList, mesh.Frames[frame].Length / 3, mesh.MorphVerts);
  43.                 else
  44.                     device.DrawUserPrimitives<Vertex>(PrimitiveType.TriangleList, mesh.Frames[frame].Length / 3, mesh.Frames[frame]);
  45.             }
  46.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement