Skip to content
Pure ECS approach to render a line. One Entity per one line segment.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
DataStructures Fix the case when camera and the line direction are collinear Dec 19, 2018
Systems
.billboard.gif Repo images now hidden from import Dec 16, 2018
.ss1.png Repo images now hidden from import Dec 16, 2018
DataStructures.meta First commit on a separated repo Dec 15, 2018
E7.ECS.LineRenderer.asmdef First commit on a separated repo Dec 15, 2018
E7.ECS.LineRenderer.asmdef.meta First commit on a separated repo Dec 15, 2018
LICENSE First commit on a separated repo Dec 15, 2018
LICENSE.meta First commit on a separated repo Dec 15, 2018
README.md Repo images now hidden from import Dec 16, 2018
README.md.meta First commit on a separated repo Dec 15, 2018
Systems.meta First commit on a separated repo Dec 15, 2018
package.json First commit on a separated repo Dec 15, 2018
package.json.meta First commit on a separated repo Dec 15, 2018

README.md

ECS LineRenderer

screenshot

Pure ECS approach to render a line. One Entity per one line segment.

How to use

Create an Entity containing LineSegment : IComponentData (from-to point information and line width) and LineStyle : ISharedComponentData, which holds reference type things like the line's material.

That Entity would be attached with MeshInstanceRenderer and LocalToWorld matrix to enable rendering by a system. That matrix is then will be also updated according to what you have in LineSegment.

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.

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.

All lines are rotated to face the main camera in billboard rendering style.

billboard

Info

  • 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 LineSegmentComponent and LineStyleComponent so you could play with it in the scene/edit mode with hybrid ECS.

Systems

  • LineSegmentRegistrationSystem : The logic which you create LineSegment entity should come before this system.
  • LineSegmentTransformSystem : Update your LineSegment from-to location before this system's update. It will update LocalToWorld matrix.
  • LineSegmentTransformSystemBootstrap : Make the main camera give itself to LineSegmentTrasformSystem, it need to do the billboard rotation.

Limitations

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.

TODO

  • 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 MeshInstanceRendererSystem.

  • 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 LineStyle later, the copy to MesnInstanceRenderer component 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.

5argon

You can’t perform that action at this time.