Skip to content

Commit 81d2629

Browse files
committed
Update the projects to entities 1.0.0-exp.8 packages
1 parent 0af8dc7 commit 81d2629

File tree

2,026 files changed

+5846423
-755711
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,026 files changed

+5846423
-755711
lines changed

ECSSamples/Assets/Advanced.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System.Collections.Generic;
2+
using Unity.Burst;
3+
using Unity.Collections;
4+
using Unity.Entities;
5+
using Unity.Jobs;
6+
using Unity.Mathematics;
7+
using Unity.Transforms;
8+
using UnityEngine;
9+
using UnityEngine.Profiling;
10+
using Hash128 = Unity.Entities.Hash128;
11+
12+
public struct MeshBBFactorySettings
13+
{
14+
public Hash128 Hash;
15+
public float MeshScale;
16+
public int PointStartIndex;
17+
public int PointCount;
18+
public float3 MinBoundingBox;
19+
public float3 MaxBoundingBox;
20+
}
21+
22+
[BurstCompile]
23+
public struct ComputeMeshBBAssetJob : IJobParallelFor
24+
{
25+
[ReadOnly] public NativeArray<MeshBBFactorySettings> Settings;
26+
[ReadOnly] public NativeArray<float3> Vertices;
27+
28+
public NativeArray<BlobAssetReference<MeshBBBlobAsset>> BlobAssets;
29+
30+
public ComputeMeshBBAssetJob(NativeArray<MeshBBFactorySettings> settings, NativeArray<float3> vertices)
31+
{
32+
Settings = settings;
33+
Vertices = vertices;
34+
BlobAssets = new NativeArray<BlobAssetReference<MeshBBBlobAsset>>(settings.Length, Allocator.TempJob);
35+
}
36+
37+
public void Execute(int index)
38+
{
39+
var builder = new BlobBuilder(Allocator.Temp);
40+
var settings = Settings[index];
41+
ref var root = ref builder.ConstructRoot<MeshBBBlobAsset>();
42+
var array = builder.Allocate(ref root.Vertices, settings.PointCount);
43+
44+
var s = settings.MeshScale;
45+
root.MeshScale = s;
46+
root.MinBoundingBox = settings.MinBoundingBox * s;
47+
root.MaxBoundingBox = settings.MaxBoundingBox * s;
48+
49+
for (int i = 0; i < array.Length; i++)
50+
{
51+
var v1 = Vertices[settings.PointStartIndex + i];
52+
array[i] = new float3(v1.x * s, v1.y * s, v1.z * s);
53+
}
54+
55+
BlobAssets[index] = builder.CreateBlobAssetReference<MeshBBBlobAsset>(Allocator.Persistent);
56+
builder.Dispose();
57+
}
58+
}
59+
60+
public class MeshBBBaker : Baker<MeshToBoundingBoxAuthoring>
61+
{
62+
public override void Bake(MeshToBoundingBoxAuthoring authoring)
63+
{
64+
// new
65+
var blobFactoryPoints = new NativeList<float3>(Allocator.TempJob);
66+
var vertices = new List<Vector3>(4096);
67+
Profiler.BeginSample("Bake_BuildHashAndPush");
68+
69+
// Compute the blob asset hash based on Authoring properties
70+
var mesh = authoring.Mesh;
71+
var hasMesh = mesh != null;
72+
var meshHashCode = hasMesh ? mesh.GetHashCode() : 0;
73+
var hash = new Hash128((uint) meshHashCode, (uint) authoring.MeshScale.GetHashCode(), 0, 0);
74+
75+
// Query the context to determine if we need to build the BlobAsset
76+
if (!TryGetBlobAssetReference(hash, out BlobAssetReference<MeshBBBlobAsset> blobAssetReference))
77+
{
78+
Profiler.BeginSample("CopyVertices");
79+
float xp = float.MinValue, yp = float.MinValue, zp = float.MinValue;
80+
float xn = float.MaxValue, yn = float.MaxValue, zn = float.MaxValue;
81+
82+
// Copy the mesh vertices into the point array
83+
if (hasMesh)
84+
{
85+
mesh.GetVertices(vertices);
86+
for (int i = 0; i < vertices.Count; i++)
87+
{
88+
var p = vertices[i];
89+
xp = math.max(p.x, xp);
90+
yp = math.max(p.y, yp);
91+
zp = math.max(p.z, zp);
92+
xn = math.min(p.x, xn);
93+
yn = math.min(p.y, yn);
94+
zn = math.min(p.z, zn);
95+
blobFactoryPoints.Add(new float3(p.x, p.y, p.z));
96+
}
97+
}
98+
else
99+
{
100+
xp = yp = zp = xn = yn = zn = 0;
101+
}
102+
103+
Profiler.EndSample();
104+
105+
// Record this blob asset for computation
106+
var vertexCount = hasMesh ? mesh.vertexCount : 0;
107+
var setting = new MeshBBFactorySettings
108+
{
109+
Hash = hash, MeshScale = authoring.MeshScale, PointStartIndex = 0,
110+
PointCount = vertexCount, MinBoundingBox = new float3(xn, yn, zn),
111+
MaxBoundingBox = new float3(xp, yp, zp)
112+
};
113+
114+
Profiler.EndSample();
115+
Profiler.BeginSample("Bake_CreateBlobAssets");
116+
117+
// Step two, compute BlobAssets
118+
var job = new ComputeMeshBBAssetJob(new NativeArray<MeshBBFactorySettings>(1, Allocator.TempJob){[0] = setting}, blobFactoryPoints.AsArray());
119+
job.Schedule(1,1).Complete();
120+
blobAssetReference = job.BlobAssets[0];
121+
AddBlobAssetWithCustomHash(ref blobAssetReference, setting.Hash);
122+
}
123+
124+
Profiler.EndSample();
125+
Profiler.BeginSample("Bake_CreateECS");
126+
127+
// Create the ECS component for the given GameObject
128+
var entity = GetEntity(authoring);
129+
AddComponent(entity, new MeshBBComponent(blobAssetReference));
130+
#if !ENABLE_TRANSFORM_V1
131+
AddComponent(entity, new LocalToWorldTransform {Value = UniformScaleTransform.FromPosition(authoring.transform.position)});
132+
#else
133+
AddComponent(entity, new Translation {Value = authoring.transform.position});
134+
#endif
135+
Profiler.EndSample();
136+
blobFactoryPoints.Dispose();
137+
}
138+
}
139+

ECSSamples/Assets/Advanced/BlobAssetScalable/MeshBBBakingSystem.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ECSSamples/Assets/Advanced/BlobAssetScalable/MeshBBConversionSystem.cs

-169
This file was deleted.

ECSSamples/Assets/Advanced/BlobAssetScalable/MeshBBConversionSystem.cs.meta

-3
This file was deleted.

ECSSamples/Assets/Advanced/BlobAssetScalable/MeshBBRenderSystem.cs

+29-15
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,45 @@
44
using Unity.Transforms;
55
using UnityEngine;
66

7-
[ExecuteAlways]
8-
public class MeshBBRenderSystem : ComponentSystem
7+
[WorldSystemFilter(WorldSystemFilterFlags.Default | WorldSystemFilterFlags.Editor)]
8+
public partial class MeshBBRenderSystem : SystemBase
99
{
10+
protected override void OnCreate()
11+
{
12+
RequireForUpdate<MeshBBComponent>();
13+
}
14+
1015
protected override void OnUpdate()
1116
{
17+
#if !ENABLE_TRANSFORM_V1
18+
Entities.ForEach((Entity e, ref MeshBBComponent dmc, ref LocalToWorldTransform t) =>
19+
#else
1220
Entities.ForEach((Entity e, ref MeshBBComponent dmc, ref Translation t) =>
21+
#endif
1322
{
1423
var min = dmc.BlobData.Value.MinBoundingBox;
1524
var max = dmc.BlobData.Value.MaxBoundingBox;
1625

26+
#if !ENABLE_TRANSFORM_V1
27+
var pos = t.Value.Position;
28+
#else
29+
var pos = t.Value;
30+
#endif
1731
// Draw a bounding box
18-
Debug.DrawLine(t.Value + new float3(min.x, min.y, min.z), t.Value + new float3(max.x, min.y, min.z));
19-
Debug.DrawLine(t.Value + new float3(min.x, max.y, min.z), t.Value + new float3(max.x, max.y, min.z));
20-
Debug.DrawLine(t.Value + new float3(min.x, min.y, min.z), t.Value + new float3(min.x, max.y, min.z));
21-
Debug.DrawLine(t.Value + new float3(max.x, min.y, min.z), t.Value + new float3(max.x, max.y, min.z));
32+
Debug.DrawLine(pos + new float3(min.x, min.y, min.z), pos + new float3(max.x, min.y, min.z));
33+
Debug.DrawLine(pos + new float3(min.x, max.y, min.z), pos + new float3(max.x, max.y, min.z));
34+
Debug.DrawLine(pos + new float3(min.x, min.y, min.z), pos + new float3(min.x, max.y, min.z));
35+
Debug.DrawLine(pos + new float3(max.x, min.y, min.z), pos + new float3(max.x, max.y, min.z));
2236

23-
Debug.DrawLine(t.Value + new float3(min.x, min.y, max.z), t.Value + new float3(max.x, min.y, max.z));
24-
Debug.DrawLine(t.Value + new float3(min.x, max.y, max.z), t.Value + new float3(max.x, max.y, max.z));
25-
Debug.DrawLine(t.Value + new float3(min.x, min.y, max.z), t.Value + new float3(min.x, max.y, max.z));
26-
Debug.DrawLine(t.Value + new float3(max.x, min.y, max.z), t.Value + new float3(max.x, max.y, max.z));
37+
Debug.DrawLine(pos + new float3(min.x, min.y, max.z), pos + new float3(max.x, min.y, max.z));
38+
Debug.DrawLine(pos + new float3(min.x, max.y, max.z), pos + new float3(max.x, max.y, max.z));
39+
Debug.DrawLine(pos + new float3(min.x, min.y, max.z), pos + new float3(min.x, max.y, max.z));
40+
Debug.DrawLine(pos + new float3(max.x, min.y, max.z), pos + new float3(max.x, max.y, max.z));
2741

28-
Debug.DrawLine(t.Value + new float3(min.x, min.y, min.z), t.Value + new float3(min.x, min.y, max.z));
29-
Debug.DrawLine(t.Value + new float3(max.x, min.y, min.z), t.Value + new float3(max.x, min.y, max.z));
30-
Debug.DrawLine(t.Value + new float3(min.x, max.y, min.z), t.Value + new float3(min.x, max.y, max.z));
31-
Debug.DrawLine(t.Value + new float3(max.x, max.y, min.z), t.Value + new float3(max.x, max.y, max.z));
32-
});
42+
Debug.DrawLine(pos + new float3(min.x, min.y, min.z), pos + new float3(min.x, min.y, max.z));
43+
Debug.DrawLine(pos + new float3(max.x, min.y, min.z), pos + new float3(max.x, min.y, max.z));
44+
Debug.DrawLine(pos + new float3(min.x, max.y, min.z), pos + new float3(min.x, max.y, max.z));
45+
Debug.DrawLine(pos + new float3(max.x, max.y, min.z), pos + new float3(max.x, max.y, max.z));
46+
}).ScheduleParallel();
3347
}
3448
}

ECSSamples/Assets/Advanced/BlobAssetSimple/SimpleAnimationBlob.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public float Evaluate(float t)
3535
return math.lerp(Keys[index], Keys[index+1], interp);
3636
}
3737

38-
public static BlobAssetReference<SimpleAnimationBlob> CreateBlob(AnimationCurve curve, Allocator allocator)
38+
public static BlobAssetReference<SimpleAnimationBlob> CreateBlob(AnimationCurve curve, Allocator allocator, Allocator allocatorForTemp = Allocator.TempJob)
3939
{
40-
using (var blob = new BlobBuilder(Allocator.TempJob))
40+
using (var blob = new BlobBuilder(allocatorForTemp))
4141
{
4242
ref var anim = ref blob.ConstructRoot<SimpleAnimationBlob>();
4343
int keyCount = 12;

0 commit comments

Comments
 (0)