Skip to content

Commit 86af85d

Browse files
committed
deep copy for DMesh3
1 parent 36d4e76 commit 86af85d

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

core/DVector.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ public DVector() {
2020
Blocks.Add(new T[nBlockSize]);
2121
}
2222

23+
public DVector(DVector<T> copy)
24+
{
25+
nBlockSize = copy.nBlockSize;
26+
iCurBlock = copy.iCurBlock;
27+
iCurBlockUsed = copy.iCurBlockUsed;
28+
Blocks = new List<T[]>();
29+
for ( int i = 0; i < copy.Blocks.Count; ++i ) {
30+
Blocks.Add(new T[nBlockSize]);
31+
Array.Copy(copy.Blocks[i], Blocks[i], copy.Blocks[i].Length);
32+
}
33+
}
34+
2335
public DVector(IEnumerable<T> init)
2436
{
2537
nBlockSize = 2048;

core/RefCountVector.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public RefCountVector()
2525
used_count = 0;
2626
}
2727

28+
public RefCountVector(RefCountVector copy)
29+
{
30+
ref_counts = new DVector<short>(copy.ref_counts);
31+
free_indices = new DVector<int>(copy.free_indices);
32+
used_count = copy.used_count;
33+
}
2834

2935
public bool empty {
3036
get { return used_count == 0; }

mesh/DMesh3.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,39 @@ public DMesh3(bool bWantNormals = true, bool bWantColors = false, bool bWantUVs
120120
}
121121

122122

123+
public DMesh3(DMesh3 copy)
124+
{
125+
vertices = new DVector<double>(copy.vertices);
126+
if (copy.normals != null)
127+
normals = new DVector<float>(copy.normals);
128+
if (copy.colors != null)
129+
colors = new DVector<float>(copy.colors);
130+
if (copy.uv != null)
131+
uv = new DVector<float>(copy.uv);
132+
133+
vertices_refcount = new RefCountVector(copy.vertices_refcount);
134+
vertex_edges = new DVector<List<int>>(copy.vertex_edges);
135+
int N = vertex_edges.Length;
136+
for ( int i = 0; i < N; ++i ) {
137+
if (vertices_refcount.isValid(i))
138+
vertex_edges[i] = new List<int>(copy.vertex_edges[i]);
139+
else
140+
vertex_edges[i] = null;
141+
}
142+
143+
triangles = new DVector<int>(copy.triangles);
144+
triangle_edges = new DVector<int>(copy.triangle_edges);
145+
triangles_refcount = new RefCountVector(copy.triangles_refcount);
146+
if (copy.triangle_groups != null)
147+
triangle_groups = new DVector<int>(copy.triangle_groups);
148+
149+
edges = new DVector<int>(copy.edges);
150+
edges_refcount = new RefCountVector(copy.edges_refcount);
151+
}
152+
153+
154+
155+
123156
void updateTimeStamp() {
124157
timestamp++;
125158
}

0 commit comments

Comments
 (0)