ANIM cooking bug fixes

This commit is contained in:
Jack Andersen 2016-08-28 14:28:53 -10:00
parent 969e2a86de
commit bf992f2d16
3 changed files with 45 additions and 54 deletions

View File

@ -370,6 +370,8 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
scaleMultOut = maxScaleDiff / quantRangeF; scaleMultOut = maxScaleDiff / quantRangeF;
/* Output channel inits */ /* Output channel inits */
std::vector<QuantizedValue> initVals;
initVals.reserve(channels.size());
kit = chanKeys.begin(); kit = chanKeys.begin();
for (Channel& chan : channels) for (Channel& chan : channels)
{ {
@ -382,6 +384,7 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
{ {
QuantizedRot qr = QuantizeRotation((*kit)[0], rotDivOut); QuantizedRot qr = QuantizeRotation((*kit)[0], rotDivOut);
chan.i = qr.v; chan.i = qr.v;
initVals.push_back(chan.i);
break; break;
} }
case Channel::Type::Translation: case Channel::Type::Translation:
@ -389,6 +392,7 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
chan.i = {atInt32((*kit)[0].v3.vec[0] / transMultOut), chan.i = {atInt32((*kit)[0].v3.vec[0] / transMultOut),
atInt32((*kit)[0].v3.vec[1] / transMultOut), atInt32((*kit)[0].v3.vec[1] / transMultOut),
atInt32((*kit)[0].v3.vec[2] / transMultOut)}; atInt32((*kit)[0].v3.vec[2] / transMultOut)};
initVals.push_back(chan.i);
break; break;
} }
case Channel::Type::Scale: case Channel::Type::Scale:
@ -396,6 +400,7 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
chan.i = {atInt32((*kit)[0].v3.vec[0] / scaleMultOut), chan.i = {atInt32((*kit)[0].v3.vec[0] / scaleMultOut),
atInt32((*kit)[0].v3.vec[1] / scaleMultOut), atInt32((*kit)[0].v3.vec[1] / scaleMultOut),
atInt32((*kit)[0].v3.vec[2] / scaleMultOut)}; atInt32((*kit)[0].v3.vec[2] / scaleMultOut)};
initVals.push_back(chan.i);
break; break;
} }
default: break; default: break;
@ -404,31 +409,30 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
} }
/* Pre-pass to analyze quantization factors for channels */ /* Pre-pass to analyze quantization factors for channels */
std::vector<QuantizedValue> lastVals = initVals;
kit = chanKeys.begin(); kit = chanKeys.begin();
auto vit = lastVals.begin();
for (Channel& chan : channels) for (Channel& chan : channels)
{ {
QuantizedValue& last = *vit++;
switch (chan.type) switch (chan.type)
{ {
case Channel::Type::Rotation: case Channel::Type::Rotation:
{ {
QuantizedRot qrLast = QuantizeRotation((*kit)[0], rotDivOut);
for (auto it=kit->begin() + 1; for (auto it=kit->begin() + 1;
it != kit->end(); it != kit->end();
++it) ++it)
{ {
QuantizedRot qrCur = QuantizeRotation(*it, rotDivOut); QuantizedRot qrCur = QuantizeRotation(*it, rotDivOut);
chan.q[0] = std::max(chan.q[0], atUint8(ceilf(log2f(qrCur.v[0] - qrLast.v[0])))); chan.q[0] = std::max(chan.q[0], atUint8(ceilf(log2f(qrCur.v[0] - last.v[0]))));
chan.q[1] = std::max(chan.q[1], atUint8(ceilf(log2f(qrCur.v[1] - qrLast.v[1])))); chan.q[1] = std::max(chan.q[1], atUint8(ceilf(log2f(qrCur.v[1] - last.v[1]))));
chan.q[2] = std::max(chan.q[2], atUint8(ceilf(log2f(qrCur.v[2] - qrLast.v[2])))); chan.q[2] = std::max(chan.q[2], atUint8(ceilf(log2f(qrCur.v[2] - last.v[2]))));
qrLast = qrCur; last = qrCur.v;
} }
break; break;
} }
case Channel::Type::Translation: case Channel::Type::Translation:
{ {
QuantizedValue last = {atInt32((*kit)[0].v3.vec[0] / transMultOut),
atInt32((*kit)[0].v3.vec[1] / transMultOut),
atInt32((*kit)[0].v3.vec[2] / transMultOut)};
for (auto it=kit->begin() + 1; for (auto it=kit->begin() + 1;
it != kit->end(); it != kit->end();
++it) ++it)
@ -445,9 +449,6 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
} }
case Channel::Type::Scale: case Channel::Type::Scale:
{ {
QuantizedValue last = {atInt32((*kit)[0].v3.vec[0] / scaleMultOut),
atInt32((*kit)[0].v3.vec[1] / scaleMultOut),
atInt32((*kit)[0].v3.vec[2] / scaleMultOut)};
for (auto it=kit->begin() + 1; for (auto it=kit->begin() + 1;
it != kit->end(); it != kit->end();
++it) ++it)
@ -470,71 +471,56 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
/* Generate Bitstream */ /* Generate Bitstream */
sizeOut = ComputeBitstreamSize(keyFrameCount, channels); sizeOut = ComputeBitstreamSize(keyFrameCount, channels);
std::unique_ptr<atUint8[]> newData(new atUint8[sizeOut]); std::unique_ptr<atUint8[]> newData(new atUint8[sizeOut]);
printf("TOTAL: %zu\n", sizeOut * 8);
lastVals = initVals;
for (size_t f=0 ; f<keyFrameCount ; ++f) for (size_t f=0 ; f<keyFrameCount ; ++f)
{ {
kit = chanKeys.begin(); kit = chanKeys.begin();
vit = lastVals.begin();
for (const Channel& chan : channels) for (const Channel& chan : channels)
{ {
const Value& val = (*kit)[f];
QuantizedValue& last = *vit++;
switch (chan.type) switch (chan.type)
{ {
case Channel::Type::Rotation: case Channel::Type::Rotation:
{ {
QuantizedRot qrLast = QuantizeRotation((*kit)[0], rotDivOut); QuantizedRot qrCur = QuantizeRotation(val, rotDivOut);
for (auto it=kit->begin() + 1; quantizeBit(newData.get(), qrCur.w);
it != kit->end(); quantize(newData.get(), chan.q[0], qrCur.v[0] - last.v[0]);
++it) quantize(newData.get(), chan.q[1], qrCur.v[1] - last.v[1]);
{ quantize(newData.get(), chan.q[2], qrCur.v[2] - last.v[2]);
QuantizedRot qrCur = QuantizeRotation(*it, rotDivOut); last = qrCur.v;
quantizeBit(newData.get(), qrCur.w);
quantize(newData.get(), chan.q[0], qrCur.v[0] - qrLast.v[0]);
quantize(newData.get(), chan.q[1], qrCur.v[1] - qrLast.v[1]);
quantize(newData.get(), chan.q[2], qrCur.v[2] - qrLast.v[2]);
qrLast = qrCur;
}
break; break;
} }
case Channel::Type::Translation: case Channel::Type::Translation:
{ {
QuantizedValue last = {atInt32((*kit)[0].v3.vec[0] / transMultOut), QuantizedValue cur = {atInt32(val.v3.vec[0] / transMultOut),
atInt32((*kit)[0].v3.vec[1] / transMultOut), atInt32(val.v3.vec[1] / transMultOut),
atInt32((*kit)[0].v3.vec[2] / transMultOut)}; atInt32(val.v3.vec[2] / transMultOut)};
for (auto it=kit->begin() + 1; quantize(newData.get(), chan.q[0], cur[0] - last[0]);
it != kit->end(); quantize(newData.get(), chan.q[1], cur[1] - last[1]);
++it) quantize(newData.get(), chan.q[2], cur[2] - last[2]);
{ last = cur;
QuantizedValue cur = {atInt32(it->v3.vec[0] / transMultOut),
atInt32(it->v3.vec[1] / transMultOut),
atInt32(it->v3.vec[2] / transMultOut)};
quantize(newData.get(), chan.q[0], cur[0] - last[0]);
quantize(newData.get(), chan.q[1], cur[1] - last[1]);
quantize(newData.get(), chan.q[2], cur[2] - last[2]);
last = cur;
}
break; break;
} }
case Channel::Type::Scale: case Channel::Type::Scale:
{ {
QuantizedValue last = {atInt32((*kit)[0].v3.vec[0] / scaleMultOut), QuantizedValue cur = {atInt32(val.v3.vec[0] / scaleMultOut),
atInt32((*kit)[0].v3.vec[1] / scaleMultOut), atInt32(val.v3.vec[1] / scaleMultOut),
atInt32((*kit)[0].v3.vec[2] / scaleMultOut)}; atInt32(val.v3.vec[2] / scaleMultOut)};
for (auto it=kit->begin() + 1; quantize(newData.get(), chan.q[0], cur[0] - last[0]);
it != kit->end(); quantize(newData.get(), chan.q[1], cur[1] - last[1]);
++it) quantize(newData.get(), chan.q[2], cur[2] - last[2]);
{ last = cur;
QuantizedValue cur = {atInt32(it->v3.vec[0] / scaleMultOut),
atInt32(it->v3.vec[1] / scaleMultOut),
atInt32(it->v3.vec[2] / scaleMultOut)};
quantize(newData.get(), chan.q[0], cur[0] - last[0]);
quantize(newData.get(), chan.q[1], cur[1] - last[1]);
quantize(newData.get(), chan.q[2], cur[2] - last[2]);
last = cur;
}
break; break;
} }
default: break; default: break;
} }
++kit; ++kit;
} }
printf("LASTCUR: %zu\n", m_bitCur);
} }
return newData; return newData;
} }

View File

@ -514,6 +514,8 @@ ANIM::ANIM(const BlenderAction& act,
newAnim.bones.reserve(act.channels.size()); newAnim.bones.reserve(act.channels.size());
size_t extChanCount = 0; size_t extChanCount = 0;
std::unordered_set<atInt32> addedBones;
addedBones.reserve(act.channels.size());
for (const BlenderAction::Channel& chan : act.channels) for (const BlenderAction::Channel& chan : act.channels)
{ {
auto search = idMap.find(chan.boneName); auto search = idMap.find(chan.boneName);
@ -522,6 +524,9 @@ ANIM::ANIM(const BlenderAction& act,
Log.report(logvisor::Warning, "unable to find id for bone '%s'", chan.boneName.c_str()); Log.report(logvisor::Warning, "unable to find id for bone '%s'", chan.boneName.c_str());
continue; continue;
} }
if (addedBones.find(search->second) != addedBones.cend())
continue;
addedBones.insert(search->second);
extChanCount += std::max(zeus::PopCount(chan.attrMask), 2); extChanCount += std::max(zeus::PopCount(chan.attrMask), 2);
newAnim.bones.emplace_back(search->second, (chan.attrMask & 0x2) != 0); newAnim.bones.emplace_back(search->second, (chan.attrMask & 0x2) != 0);

2
hecl

@ -1 +1 @@
Subproject commit 676894fa01f966d1661ed32810ffbcac168c2db2 Subproject commit 2a4b0cd21c56c6a4b558f68bbb91c5e2b9c41bc5