blob: 939d022b0886677938b85edd7f952a26a6f355f3 (
plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
namespace NGS.MeshFusionPro;
public class MeshDataNativeArraysLW : CombinedMeshDataInternal
{
private CombinedMesh _root;
private NativeList<LightweightVertex> _vertices;
private NativeList<Bounds> _partsBounds;
private NativeArray<Bounds> _bounds;
private NativeList<LightweightVertex> _verticesLocal;
private NativeList<Bounds> _partsBoundsLocal;
private List<Vector3> _tempVertices;
private List<Vector3> _tempNormals;
private List<Vector4> _tempTangents;
private List<Vector2> _tempUV;
private List<Vector2> _tempUV2;
public NativeArray<LightweightVertex> Vertices => _vertices;
public NativeArray<Bounds> PartsBounds => _partsBounds;
public NativeArray<Bounds> Bounds => _bounds;
public NativeArray<LightweightVertex> VerticesLocal => _verticesLocal;
public NativeArray<Bounds> PartsBoundsLocal => _partsBoundsLocal;
public override Bounds GetBounds()
{
return _bounds[0];
}
public override Bounds GetBounds(CombinedMeshPart part)
{
return _partsBounds[part.Index];
}
public void ApplyDataToMesh()
{
Mesh mesh = _root.Mesh;
mesh.SetVertexBufferData(Vertices, 0, 0, _vertices.Length);
mesh.bounds = _bounds[0];
}
protected override void OnInitialized()
{
_root = base.Root;
VertexBufferUtil.ToLightweightBuffer(_root.Mesh);
_vertices = new NativeList<LightweightVertex>(Allocator.Persistent);
_partsBounds = new NativeList<Bounds>(Allocator.Persistent);
_bounds = new NativeArray<Bounds>(1, Allocator.Persistent);
_verticesLocal = new NativeList<LightweightVertex>(Allocator.Persistent);
_partsBoundsLocal = new NativeList<Bounds>(Allocator.Persistent);
_tempVertices = new List<Vector3>();
_tempNormals = new List<Vector3>();
_tempTangents = new List<Vector4>();
_tempUV = new List<Vector2>();
_tempUV2 = new List<Vector2>();
}
protected override void OnAddPart(CombinedMeshPart part, Mesh mesh, Matrix4x4 transform)
{
Bounds value = mesh.bounds;
Bounds value2 = value.Transform(transform);
_partsBounds.Add(in value2);
_partsBoundsLocal.Add(in value);
mesh.GetVertices(_tempVertices);
mesh.GetNormals(_tempNormals);
mesh.GetTangents(_tempTangents);
mesh.GetUVs(0, _tempUV);
mesh.GetUVs(1, _tempUV2);
int vertexCount = mesh.vertexCount;
for (int i = 0; i < vertexCount; i++)
{
LightweightVertex value3 = default(LightweightVertex);
value3.Position = _tempVertices[i];
value3.Normal = _tempNormals[i];
value3.Tangent = _tempTangents[i];
if (_tempUV.Count > 0)
{
value3.UV = _tempUV[i];
}
if (_tempUV2.Count > 0)
{
value3.UV2 = _tempUV2[i];
}
_verticesLocal.Add(in value3);
}
}
protected override void OnRemovePart(CombinedMeshPart part)
{
_partsBounds.RemoveAt(part.Index);
_verticesLocal.RemoveRange(part.VertexStart, part.VertexCount);
_partsBoundsLocal.RemoveAt(part.Index);
}
protected override void OnMeshUpdated()
{
Mesh mesh = _root.Mesh;
using (Mesh.MeshDataArray meshDataArray = Mesh.AcquireReadOnlyMeshData(mesh))
{
Mesh.MeshData meshData = meshDataArray[0];
_vertices.Clear();
_vertices.AddRange(meshData.GetVertexData<LightweightVertex>());
}
_bounds[0] = mesh.bounds;
}
protected override void OnDispose()
{
_vertices.Dispose();
_partsBounds.Dispose();
_bounds.Dispose();
_verticesLocal.Dispose();
_partsBoundsLocal.Dispose();
}
}
|