I made a small package to render a line with pure ECS. One Entity per one line segment. I recently got a container arrangement visualization job for use in logistics which I decided to use ECS to tackle it. In the picture each straight line is one Entity with LineSegment containing float3 indicating from-to position and a line width. And LineStyle : ISharedComponentData indicating what material to use. Both components on one Entity will cause the system to attach the remaning things to be able to render a line, like MIR and LocalToWorld. https://github.com/5argon/ECSLineRenderer Idea Generate a thin rectangle mesh that goes 1 unit in the Z axis. Using MeshInstanceRenderer component and the TransformSystem, we could use z scale as line length, x scale as line width, position as line from, and rotation as line to. Assuming that this is only one segment of a line. To construct complex lines, we create more LineSegment entity. They should be render instanced as they are using the same mesh. What's left is to wait for MeshInstanceRendererSystem to support material property block so we could change line color without a new material. Rounded caps not suported yet, but surely that will break instancing because of different mesh. All lines are always rotated to face the main camera in billboard rendering style.
Fine I'm also waits official ecs renderer with layers, MPB and other (of course we can use our own version). In my case I use simple quad mesh with my billboard shader for game indicators, and use global vector for scale. But every indicator view use different material (with same texture but different offset), but wih MPB I'll can change atlas offsets without generation new instances and drawcalls (old video)
works great, though i get a boxing error at line 69. it's not obvious to me why the boxing happens, and why this resolves it: Code (CSharp): if (seg.from.Equals(seg.to) || seg.from.Equals(cameraPosition)) { continue; }
Just in time! I needed something exactly like this. Did you do any benchmarks on large amounts of lines drawn on a screen?
No time to do it yet.. but essentially it should be equivalent of any ECS showcase which draws a ton of boxes or spheres since each line is essentially just a tiny plane with same mesh + different matrix calculation. Something might be inefficient there that I have to look at later. I would like to make a benchmark scene like that Kingdom Hearts 2 boss who shoots million of lasers from around you to the center, but I would like to add rounded caps support first. Is the error only when using Burst? I might forgot to turn it on the whole time. Will look at it later. Thanks!
Your issue is there is no explicit implementation of float3.Equals() so it's using the default Object.Equals(object, object) method which causes the boxing.