Search Unity

hybrid style ECS to render objects ?

Discussion in 'Graphics for ECS' started by daniel-griffiths, Jun 11, 2018.

  1. daniel-griffiths

    daniel-griffiths

    Joined:
    Jun 14, 2016
    Posts:
    27
    Hello, does and one know how to use hybrid style ECS to render the object meshrenderer.

    would be very interested to find out if it possible?

    I would also like to know if ECS can take care of the physics?

    Thanks

    Daniel
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    You turn off the MeshRenderer, then you base your drawing on `Graphics.DrawMesh` or `Graphics.DrawMeshInstanced` instead. You can make a system with required data coming from ECS then loop through them to use those commands. In the future, those 2 commands would ideally accept native containers so no copy from ECS out is required. Currently the fast way to copy data out from ECS you can look in MeshInstanceRendererSystem.cs > CopyMatrices.

    `MeshInstanceRendererComponent` together with `PositionComponent` `RotationComponent` etc. uses this approach by collecting/processing the matrix required for `Graphics.DrawMeshInstanced` and finally loop through them in a system. `Mesh` can go in an `ISharedComponentData`.

    ECS does not support physics right now...
     
    andywatts likes this.
  3. daniel-griffiths

    daniel-griffiths

    Joined:
    Jun 14, 2016
    Posts:
    27
    Hi, and thanks for the reply. In context of the hybrid system i am currently doing this:

    Code (CSharp):
    1.     struct Components
    2.     {
    3.         public Rotator rotator;
    4.         public Transform transform;
    5.         public MeshRenderer renderer;
    6.      
    7.     }
    8.     protected override void OnUpdate()
    9.     {
    10.         foreach (var e in GetEntities<Components>())
    11.         {
    12.             var time = Time.deltaTime;
    13.             e.transform.Rotate(0, e.rotator._speed * time, 0);
    14.             //e.renderer.material.color = e.rotator._color;
    15.         }
    16.  
    17.     }
    How would i implement what you have suggested in this scenario?
     
  4. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    224
  5. Micz84

    Micz84

    Joined:
    Jul 21, 2012
    Posts:
    451
    Line 12 should be outside of the loop. It will not change during execution of this loop and you are unnecessarily paying a cost of method call each loop iteration.
     
  6. daniel-griffiths

    daniel-griffiths

    Joined:
    Jun 14, 2016
    Posts:
    27
    Hi Micz, thanks for that reply, yeah was on to that was just seeing if it made a difference ;)