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,38 +228,34 @@ using Alembic::AbcGeom::IC4fGeomParam;
|
||||||
using Alembic::AbcGeom::IV2fGeomParam;
|
using Alembic::AbcGeom::IV2fGeomParam;
|
||||||
|
|
||||||
static void read_mcols(const CDStreamConfig &config, void *data,
|
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);
|
MCol *cfaces = static_cast<MCol *>(data);
|
||||||
MPoly *polys = config.mpoly;
|
MPoly *polys = config.mpoly;
|
||||||
MLoop *mloops = config.mloop;
|
MLoop *mloops = config.mloop;
|
||||||
|
|
||||||
if (c3f_ptr) {
|
/* Either one or the other should be given. */
|
||||||
for (int i = 0; i < config.totpoly; ++i) {
|
BLI_assert(c3f_ptr || c4f_ptr);
|
||||||
MPoly *p = &polys[i];
|
const bool use_c3f_ptr = (c3f_ptr.get() != nullptr);
|
||||||
MCol *cface = &cfaces[p->loopstart + p->totloop];
|
|
||||||
MLoop *mloop = &mloops[p->loopstart + p->totloop];
|
|
||||||
|
|
||||||
for (int j = 0; j < p->totloop; ++j) {
|
for (int i = 0; i < config.totpoly; ++i) {
|
||||||
cface--;
|
MPoly *p = &polys[i];
|
||||||
mloop--;
|
MCol *cface = &cfaces[p->loopstart + p->totloop];
|
||||||
|
MLoop *mloop = &mloops[p->loopstart + p->totloop];
|
||||||
|
|
||||||
|
for (int j = 0; j < p->totloop; ++j) {
|
||||||
|
cface--;
|
||||||
|
mloop--;
|
||||||
|
|
||||||
|
if (use_c3f_ptr) {
|
||||||
const Imath::C3f &color = (*c3f_ptr)[mloop->v];
|
const Imath::C3f &color = (*c3f_ptr)[mloop->v];
|
||||||
cface->a = FTOCHAR(color[0]);
|
cface->a = FTOCHAR(color[0]);
|
||||||
cface->r = FTOCHAR(color[1]);
|
cface->r = FTOCHAR(color[1]);
|
||||||
cface->g = FTOCHAR(color[2]);
|
cface->g = FTOCHAR(color[2]);
|
||||||
cface->b = 255;
|
cface->b = 255;
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
}
|
|
||||||
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--;
|
|
||||||
const Imath::C4f &color = (*c4f_ptr)[mloop->v];
|
const Imath::C4f &color = (*c4f_ptr)[mloop->v];
|
||||||
cface->a = FTOCHAR(color[0]);
|
cface->a = FTOCHAR(color[0]);
|
||||||
cface->r = FTOCHAR(color[1]);
|
cface->r = FTOCHAR(color[1]);
|
||||||
|
|
Loading…
Reference in New Issue