forked from bartvdbraak/blender
Alembic: reduced code duplication in read_mcols()
A big chunk of code was copied between the if and else bodies. By using a boolean to store whether the c3f_ptr or c4f_ptr should be used, the in-loop condition is kept as simple as possible.
This commit is contained in:
parent
96e068d3aa
commit
cc0cc880de
@ -228,13 +228,17 @@ using Alembic::AbcGeom::IC4fGeomParam;
|
||||
using Alembic::AbcGeom::IV2fGeomParam;
|
||||
|
||||
static void read_mcols(const CDStreamConfig &config, void *data,
|
||||
const C3fArraySamplePtr &c3f_ptr, const C4fArraySamplePtr &c4f_ptr)
|
||||
const C3fArraySamplePtr &c3f_ptr,
|
||||
const C4fArraySamplePtr &c4f_ptr)
|
||||
{
|
||||
MCol *cfaces = static_cast<MCol *>(data);
|
||||
MPoly *polys = config.mpoly;
|
||||
MLoop *mloops = config.mloop;
|
||||
|
||||
if (c3f_ptr) {
|
||||
/* Either one or the other should be given. */
|
||||
BLI_assert(c3f_ptr || c4f_ptr);
|
||||
const bool use_c3f_ptr = (c3f_ptr.get() != nullptr);
|
||||
|
||||
for (int i = 0; i < config.totpoly; ++i) {
|
||||
MPoly *p = &polys[i];
|
||||
MCol *cface = &cfaces[p->loopstart + p->totloop];
|
||||
@ -243,23 +247,15 @@ static void read_mcols(const CDStreamConfig &config, void *data,
|
||||
for (int j = 0; j < p->totloop; ++j) {
|
||||
cface--;
|
||||
mloop--;
|
||||
|
||||
if (use_c3f_ptr) {
|
||||
const Imath::C3f &color = (*c3f_ptr)[mloop->v];
|
||||
cface->a = FTOCHAR(color[0]);
|
||||
cface->r = FTOCHAR(color[1]);
|
||||
cface->g = FTOCHAR(color[2]);
|
||||
cface->b = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (c4f_ptr) {
|
||||
for (int i = 0; i < config.totpoly; ++i) {
|
||||
MPoly *p = &polys[i];
|
||||
MCol *cface = &cfaces[p->loopstart + p->totloop];
|
||||
MLoop *mloop = &mloops[p->loopstart + p->totloop];
|
||||
|
||||
for (int j = 0; j < p->totloop; ++j) {
|
||||
cface--;
|
||||
mloop--;
|
||||
else {
|
||||
const Imath::C4f &color = (*c4f_ptr)[mloop->v];
|
||||
cface->a = FTOCHAR(color[0]);
|
||||
cface->r = FTOCHAR(color[1]);
|
||||
|
Loading…
Reference in New Issue
Block a user