Pure ECS approach to render a line. One
Entity per one line segment.
How to use
LineSegment : IComponentData (from-to point information and line width) and
LineStyle : ISharedComponentData, which holds reference type things like the line's material.
Entity would be attached with
LocalToWorld matrix to enable rendering by a system. That matrix is then will be also updated according to what you have in
How to include with GitHub functionality of Unity Package Manager
Add this line
"com.e7.ecs.linerenderer": "git://github.com/5argon/ECSLineRenderer.git", to your packages.json
It does not update automatically when I push fixes to this repo. You must remove the lock in your Packages folder.
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.
All lines are rotated to face the main camera in billboard rendering style.
- Line width is in Unity's standard grid unit.
- If position from and to are the same the system will not update the line. (Stays at previous position)
- It came with a bonus
LineStyleComponentso you could play with it in the scene/edit mode with hybrid ECS.
LineSegmentRegistrationSystem: The logic which you create
LineSegmententity should come before this system.
LineSegmentTransformSystem: Update your
LineSegmentfrom-to location before this system's update. It will update
LineSegmentTransformSystemBootstrap: Make the main camera give itself to
LineSegmentTrasformSystem, it need to do the billboard rotation.
It could not do fancy things that
LineRenderer can do. Currently just :
- No multiple segment (per entity).
- Line width.
- Line styling by only the material.
I would like to support material property block but I don't want to copy Unity's code and modify into my own, I would have to always check the system on every update and copy again if it changes. For now I want to leave it to a default
To support arbitrary vertices rounded end cap it will break instancing as that uses a new mesh, also we could not pre generate all the meshes at
OnCreateManager. Maybe I will just pre-generate a set of limited options to choose from instead. (e.g. 0~8 vertex rounded edge and nothing more)
You cannot change
LineStylelater, the copy to
MesnInstanceRenderercomponent is only at the creation of entity with required components.
Add changed filter mechanism that ties to the camera's position, so if the camera does not move there is no need to compute the billboard rotation.