forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWireframeInitSystem.cs
More file actions
51 lines (44 loc) · 1.94 KB
/
Copy pathWireframeInitSystem.cs
File metadata and controls
51 lines (44 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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<ExecuteWireframeBlob>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var uninitializedQuery = SystemAPI.QueryBuilder()
.WithAll<WireframeLocalSpace>()
.WithNone<WireframeWorldSpace>().Build();
var entities = uninitializedQuery.ToEntityArray(Allocator.Temp);
state.EntityManager.AddComponent<WireframeWorldSpace>(uninitializedQuery);
var worldSpaceShellLookup = SystemAPI.GetBufferLookup<WireframeWorldSpace>();
var localTransformLookup = SystemAPI.GetComponentLookup<LocalTransform>(true);
var parentLookup = SystemAPI.GetComponentLookup<Parent>(true);
var postTransformMatrixLookup = SystemAPI.GetComponentLookup<PostTransformMatrix>(true);
foreach (var entity in entities)
{
var localSpace = SystemAPI.GetComponent<WireframeLocalSpace>(entity);
ref var input = ref localSpace.Blob.Value.Vertices;
var worldSpace = worldSpaceShellLookup[entity];
worldSpace.Resize(input.Length, NativeArrayOptions.UninitializedMemory);
var output = worldSpace.Reinterpret<float3>();
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;
}
}
}
}
}