Search Unity

[SOLVED] DrawMesh() not drawing with the correct rotation?

Discussion in 'General Graphics' started by PhilSA, Jan 14, 2021.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Unity 2020.2.1, URP 10.2.2

    I am drawing meshes with Graphics.DrawMesh() like this, but the drawn meshes are always shown with a "quaternion.identity" rotation no matter what rotation I give them:
    Code (CSharp):
    1.  
    2.     void Update()
    3.     {
    4.         for (int i = _lazers.Count - 1; i >= 0; i--)
    5.         {
    6.             TestLazer lazer = _lazers[i];
    7.             _materialPropertyBlock.SetColor(_shadedColorPropertyId, lazer.Color);
    8.             Graphics.DrawMesh(LazerMesh, lazer.pos, lazer.rot, LazerMaterial, 0, null, 0, _materialPropertyBlock);
    9.  
    10.             // Debug
    11.             Debug.DrawRay(lazer.pos, lazer.rot * Vector3.forward * 5f, lazer.Color);
    12.         }
    13.     }
    14.  
    I know for sure that my "lazer.rot" is correct because my "Debug.DrawRay" at the end of the code block displays the correctly-rotated lazer.

    Any ideas why my rotation isn't working with DrawMesh here?
     
    Last edited: Jan 14, 2021
  2. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    My bad everyone, DrawMesh() works as intended. Was just a dumb mistake on my part
     
  3. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    353
    Is it ok that mesh rotates around it's left down corner? (i work in 2D) How to calculate proper matrix if i want to rotate mesh around center?

    UPD: the problem was: i was constract my mesh vertices from 0,0,0 point
     
    Last edited: Jul 9, 2021