I’ve done a lot of research and even used to dabble in ECS back in 2015 but the implementation of ECS in Unity is a little bit different.
I’d like to store mesh triangles on a component attached to an entity. This means three points as well as some other info that comes out the other end. As I understand it, you can’t store arrays so my options are.
1: Attach hundreds of triangles as components to a single entity. The triangle points must be updated ever frame to world space. So a system would do that
2: Have a system that holds the parent mesh and then applies based on the entity it is associated with. I don’t like this because it detaches the data (which is a bunch of triangles) from the entity that it is associated with. Each entity will probably have a different mesh so they can’t be shared.
The idea is that you take a triangle. Calculate a bunch of info on it and then return that info and combine it to output some forces.
Any help would be appreciated!
You can store array in the form of DynamicBuffers. Dynamic Buffers | Package Manager UI website
[InternalBufferCapacity(0)]
public struct VertexElement : IBufferElementData {
public static implicit operator float3(VertexElement e) { return e.Value; }
public static implicit operator VertexElement(float3 e) { return new VertexElement { Value = e }; }
public float3 Value;
}
[InternalBufferCapacity(0)]
public struct NormalElement : IBufferElementData {
public static implicit operator float3(NormalElement e) { return e.Value; }
public static implicit operator NormalElement(float3 e) { return new NormalElement { Value = e }; }
public float3 Value;
}
[InternalBufferCapacity(0)]
public struct TriangleElement : IBufferElementData {
public static implicit operator int(TriangleElement e) { return e.Value; }
public static implicit operator TriangleElement(int e) { return new TriangleElement { Value = e }; }
public int Value;
}
1 Like
Awesome, thanks for pointing me towards that!