Search Unity

mesh rendering in wrong place, probably wrong render bounds center?

Discussion in 'Graphics for ECS' started by mailfromthewilds, May 26, 2021.

  1. mailfromthewilds

    mailfromthewilds

    Joined:
    Jan 31, 2020
    Posts:
    217
    Code (CSharp):
    1. Bounds bounds = mesh.bounds;
    2. bounds.center = entityManager.GetComponentData<Translation>(entity).Value;
    3. entityManager.AddComponentData<RenderBounds>(entity, new RenderBounds
    4. {
    5.  Value = new AABB
    6. {
    7.      Center = bounds.center,
    8.      Extents = bounds.extents
    9. }
    10.  });
    it renders it in wrong place, i think Render Bounds take local center into account
    as for extents im not sure if they take local extents or world extents

    i got this code from this forum

    btw i wanted it to render at the center of entity but supplying 0,0,0 still made it render in different place


    ok now i know, the place issue is not related to above code, but i still struggle to get proper bounds
     
    Last edited: May 26, 2021
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    RenderBounds is in the local object space of the object, it should not contain the Translation of the object. That's what WorldRenderBounds is for (which should be handled automatically).

    Typically, you would want to place the unchanged Mesh.bounds in the RenderBounds, unless you have some special case where you know you need larger bounds. The default GameObject conversion in Hybrid Renderer uses Mesh.bounds.