generated from vrchat-community/template-package
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathComputeMergesJob.cs
More file actions
79 lines (73 loc) · 2.58 KB
/
ComputeMergesJob.cs
File metadata and controls
79 lines (73 loc) · 2.58 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
namespace Meshia.MeshSimplification
{
[BurstCompile]
struct ComputeMergesJob : IJobParallelForDefer
{
[ReadOnly]
public NativeArray<float3> VertexPositionBuffer;
[ReadOnly]
public NativeArray<ErrorQuadric> VertexErrorQuadrics;
[ReadOnly]
public NativeArray<float3> TriangleNormals;
[ReadOnly]
public NativeParallelMultiHashMap<int, int> VertexContainingTriangles;
[ReadOnly]
public NativeBitArray VertexIsBorderEdgeBits;
[ReadOnly]
public NativeArray<int2> Edges;
[ReadOnly]
public NativeArray<uint> VertexBlendIndicesBuffer;
[ReadOnly]
public NativeBitArray PreserveBorderEdgesBoneIndices;
[WriteOnly]
public NativeArray<VertexMerge> UnorderedDirtyVertexMerges;
public bool PreserveBorderEdges;
public bool PreserveSurfaceCurvature;
public void Execute(int index)
{
var mergeFactory = new MergeFactory
{
VertexPositionBuffer = VertexPositionBuffer,
VertexErrorQuadrics = VertexErrorQuadrics,
VertexContainingTriangles = VertexContainingTriangles,
VertexIsBorderEdgeBits = VertexIsBorderEdgeBits,
TriangleNormals = TriangleNormals,
PreserveBorderEdges = PreserveBorderEdges,
PreserveSurfaceCurvature = PreserveSurfaceCurvature,
PreserveBorderEdgesBoneIndices = PreserveBorderEdgesBoneIndices,
VertexBlendIndicesBuffer = VertexBlendIndicesBuffer,
};
var edge = Edges[index];
VertexMerge merge;
if (mergeFactory.TryComputeMerge(edge, out var position, out var cost))
{
merge = new()
{
VertexAIndex = edge.x,
VertexBIndex = edge.y,
VertexAVersion = 0,
VertexBVersion = 0,
Position = position,
Cost = cost,
};
}
else
{
merge = new()
{
VertexAIndex = edge.x,
VertexBIndex = edge.y,
VertexAVersion = 0,
VertexBVersion = 0,
Position = float.NaN,
Cost = float.PositiveInfinity,
};
}
UnorderedDirtyVertexMerges[index] = merge;
}
}
}