Skip to content

Commit 52ae69a

Browse files
committed
Fix regression in ExtTriangleMesh::Copy (not copying optional data...)
1 parent d77dfd3 commit 52ae69a

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

src/luxrays/core/exttrianglemesh.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,30 +347,39 @@ ExtTriangleMeshUPtr ExtTriangleMesh::CopyExt(
347347
Point *vs = meshVertices;
348348
if (!vs) {
349349
vs = AllocVerticesBuffer(vertCount);
350-
copy(vertices, vertices + vertCount, vs);
350+
std::copy(vertices, vertices + vertCount, vs);
351351
}
352352

353353
Triangle *ts = meshTris;
354354
if (!ts) {
355355
ts = AllocTrianglesBuffer(triCount);
356-
copy(tris, tris + triCount, ts);
356+
std::copy(tris, tris + triCount, ts);
357357
}
358358

359359
Normal *ns = meshNormals;
360360
if (!ns && HasNormals()) {
361361
ns = new Normal[vertCount];
362-
copy(normals, normals + vertCount, ns);
362+
std::copy(normals, normals + vertCount, ns);
363363
}
364364

365365

366-
ExtMeshProp<UV> us;
367-
ExtMeshProp<Spectrum> cs;
368-
ExtMeshProp<float> as;
366+
// Optionals: UV, colors, alphas. Initialize from source
367+
ExtMeshProp<UV> us = uvs;
368+
ExtMeshProp<Spectrum> cs = cols;
369+
ExtMeshProp<float> as = alphas;
369370

371+
372+
// Copy overwriting values
370373
for (u_int i = 0; i < EXTMESH_MAX_DATA_COUNT; ++i) {
371-
us.SetLayer(i, uvs.CopyLayer(i, meshUVs));
372-
cs.SetLayer(i, cols.CopyLayer(i, meshCols));
373-
as.SetLayer(i, alphas.CopyLayer(i, meshAlphas));
374+
if (meshUVs) {
375+
us.SetLayer(i, uvs.CopyLayer(i, meshUVs));
376+
}
377+
if (meshCols) {
378+
cs.SetLayer(i, cols.CopyLayer(i, meshCols));
379+
}
380+
if (meshAlphas) {
381+
as.SetLayer(i, alphas.CopyLayer(i, meshAlphas));
382+
}
374383
}
375384

376385
auto m = std::make_unique<ExtTriangleMesh>(vertCount, triCount,
@@ -409,9 +418,9 @@ ExtTriangleMeshUPtr ExtTriangleMesh::Copy(
409418
meshVertices,
410419
meshTris,
411420
meshNormals,
412-
meshUVs,
413-
meshCols,
414-
meshAlphas,
421+
mUVs ? std::optional(meshUVs) : std::nullopt,
422+
mCols ? std::optional(meshCols) : std::nullopt,
423+
mAlphas ? std::optional(meshAlphas) : std::nullopt,
415424
bRadius
416425
);
417426
}

0 commit comments

Comments
 (0)