using Unity.Burst; using Unity.Collections; using Unity.Entities; using Unity.Mathematics; using Unity.Transforms; namespace Graphical.PrefabInitializer { [BurstCompile] public partial struct WireframeInitSystem : ISystem { [BurstCompile] public void OnCreate(ref SystemState state) { state.RequireForUpdate(); } [BurstCompile] public void OnUpdate(ref SystemState state) { var uninitializedQuery = SystemAPI.QueryBuilder() .WithAll() .WithNone().Build(); var entities = uninitializedQuery.ToEntityArray(Allocator.Temp); state.EntityManager.AddComponent(uninitializedQuery); var worldSpaceShellLookup = SystemAPI.GetBufferLookup(); var localTransformLookup = SystemAPI.GetComponentLookup(true); var parentLookup = SystemAPI.GetComponentLookup(true); var postTransformMatrixLookup = SystemAPI.GetComponentLookup(true); foreach (var entity in entities) { var localSpace = SystemAPI.GetComponent(entity); ref var input = ref localSpace.Blob.Value.Vertices; var worldSpace = worldSpaceShellLookup[entity]; worldSpace.Resize(input.Length, NativeArrayOptions.UninitializedMemory); var output = worldSpace.Reinterpret(); TransformHelpers.ComputeWorldTransformMatrix(entity, out var matrix, ref localTransformLookup, ref parentLookup, ref postTransformMatrixLookup); for (int i = 0; i < input.Length; i++) { output[i] = math.mul(matrix, new float4(input[i], 1)).xyz; } } } } }