mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 16:14:35 +02:00
Changed recording file format
This commit is contained in:
parent
e485b278ef
commit
11e60c864a
1 changed files with 36 additions and 25 deletions
|
@ -32,7 +32,7 @@
|
||||||
static const int MAGIC_NUMBER_SIZE = 8;
|
static const int MAGIC_NUMBER_SIZE = 8;
|
||||||
static const char MAGIC_NUMBER[MAGIC_NUMBER_SIZE] = {17, 72, 70, 82, 13, 10, 26, 10};
|
static const char MAGIC_NUMBER[MAGIC_NUMBER_SIZE] = {17, 72, 70, 82, 13, 10, 26, 10};
|
||||||
// Version (Major, Minor)
|
// Version (Major, Minor)
|
||||||
static const QPair<quint8, quint8> VERSION(0, 1);
|
static const QPair<quint8, quint8> VERSION(0, 2);
|
||||||
|
|
||||||
int SCALE_RADIX = 10;
|
int SCALE_RADIX = 10;
|
||||||
int BLENDSHAPE_RADIX = 15;
|
int BLENDSHAPE_RADIX = 15;
|
||||||
|
@ -118,12 +118,6 @@ bool readQuat(QDataStream& stream, glm::quat& value) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeFloat(QDataStream& stream, float value, int radix) {
|
|
||||||
unsigned char buffer[256];
|
|
||||||
int writtenToBuffer = packFloatScalarToSignedTwoByteFixed(buffer, value, radix);
|
|
||||||
stream.writeRawData(reinterpret_cast<char*>(buffer), writtenToBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool readFloat(QDataStream& stream, float& value, int radix) {
|
bool readFloat(QDataStream& stream, float& value, int radix) {
|
||||||
int floatByteSize = 2; // 1 floats * 2 bytes
|
int floatByteSize = 2; // 1 floats * 2 bytes
|
||||||
int16_t buffer[256];
|
int16_t buffer[256];
|
||||||
|
@ -185,7 +179,7 @@ void writeRecordingToFile(RecordingPointer recording, const QString& filename) {
|
||||||
// Orientation
|
// Orientation
|
||||||
writeQuat(fileStream, context.orientation);
|
writeQuat(fileStream, context.orientation);
|
||||||
// Scale
|
// Scale
|
||||||
writeFloat(fileStream, context.scale, SCALE_RADIX);
|
fileStream << context.scale;
|
||||||
// Head model
|
// Head model
|
||||||
fileStream << context.headModel;
|
fileStream << context.headModel;
|
||||||
// Skeleton model
|
// Skeleton model
|
||||||
|
@ -204,7 +198,7 @@ void writeRecordingToFile(RecordingPointer recording, const QString& filename) {
|
||||||
// Orientation
|
// Orientation
|
||||||
writeQuat(fileStream, data.rotation);
|
writeQuat(fileStream, data.rotation);
|
||||||
// Scale
|
// Scale
|
||||||
writeFloat(fileStream, data.scale, SCALE_RADIX);
|
fileStream << data.scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RECORDING
|
// RECORDING
|
||||||
|
@ -231,7 +225,7 @@ void writeRecordingToFile(RecordingPointer recording, const QString& filename) {
|
||||||
for (quint32 j = 0; j < numBlendshapes; ++j) {
|
for (quint32 j = 0; j < numBlendshapes; ++j) {
|
||||||
if (i == 0 ||
|
if (i == 0 ||
|
||||||
frame._blendshapeCoefficients[j] != previousFrame._blendshapeCoefficients[j]) {
|
frame._blendshapeCoefficients[j] != previousFrame._blendshapeCoefficients[j]) {
|
||||||
writeFloat(stream, frame.getBlendshapeCoefficients()[j], BLENDSHAPE_RADIX);
|
stream << frame.getBlendshapeCoefficients()[j];
|
||||||
mask.setBit(maskIndex);
|
mask.setBit(maskIndex);
|
||||||
}
|
}
|
||||||
++maskIndex;
|
++maskIndex;
|
||||||
|
@ -277,7 +271,7 @@ void writeRecordingToFile(RecordingPointer recording, const QString& filename) {
|
||||||
mask.resize(mask.size() + 1);
|
mask.resize(mask.size() + 1);
|
||||||
}
|
}
|
||||||
if (i == 0 || frame._scale != previousFrame._scale) {
|
if (i == 0 || frame._scale != previousFrame._scale) {
|
||||||
writeFloat(stream, frame._scale, SCALE_RADIX);
|
stream << frame._scale;
|
||||||
mask.setBit(maskIndex);
|
mask.setBit(maskIndex);
|
||||||
}
|
}
|
||||||
maskIndex++;
|
maskIndex++;
|
||||||
|
@ -297,7 +291,7 @@ void writeRecordingToFile(RecordingPointer recording, const QString& filename) {
|
||||||
mask.resize(mask.size() + 1);
|
mask.resize(mask.size() + 1);
|
||||||
}
|
}
|
||||||
if (i == 0 || frame._leanSideways != previousFrame._leanSideways) {
|
if (i == 0 || frame._leanSideways != previousFrame._leanSideways) {
|
||||||
writeFloat(stream, frame._leanSideways, LEAN_RADIX);
|
stream << frame._leanSideways;
|
||||||
mask.setBit(maskIndex);
|
mask.setBit(maskIndex);
|
||||||
}
|
}
|
||||||
maskIndex++;
|
maskIndex++;
|
||||||
|
@ -307,7 +301,7 @@ void writeRecordingToFile(RecordingPointer recording, const QString& filename) {
|
||||||
mask.resize(mask.size() + 1);
|
mask.resize(mask.size() + 1);
|
||||||
}
|
}
|
||||||
if (i == 0 || frame._leanForward != previousFrame._leanForward) {
|
if (i == 0 || frame._leanForward != previousFrame._leanForward) {
|
||||||
writeFloat(stream, frame._leanForward, LEAN_RADIX);
|
stream << frame._leanForward;
|
||||||
mask.setBit(maskIndex);
|
mask.setBit(maskIndex);
|
||||||
}
|
}
|
||||||
maskIndex++;
|
maskIndex++;
|
||||||
|
@ -438,7 +432,7 @@ RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString
|
||||||
|
|
||||||
QPair<quint8, quint8> version;
|
QPair<quint8, quint8> version;
|
||||||
fileStream >> version; // File format version
|
fileStream >> version; // File format version
|
||||||
if (version != VERSION) {
|
if (version != VERSION && version != QPair<quint8, quint8>(0,1)) {
|
||||||
qDebug() << "ERROR: This file format version is not supported.";
|
qDebug() << "ERROR: This file format version is not supported.";
|
||||||
return recording;
|
return recording;
|
||||||
}
|
}
|
||||||
|
@ -484,10 +478,10 @@ RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale
|
// Scale
|
||||||
if (!readFloat(fileStream, context.scale, SCALE_RADIX)) {
|
if (version == QPair<quint8, quint8>(0,1)) {
|
||||||
qDebug() << "Couldn't read file correctly. (Invalid float)";
|
readFloat(fileStream, context.scale, SCALE_RADIX);
|
||||||
recording.clear();
|
} else {
|
||||||
return recording;
|
fileStream >> context.scale;
|
||||||
}
|
}
|
||||||
// Head model
|
// Head model
|
||||||
fileStream >> context.headModel;
|
fileStream >> context.headModel;
|
||||||
|
@ -519,9 +513,10 @@ RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale
|
// Scale
|
||||||
if (!readFloat(fileStream, data.scale, SCALE_RADIX)) {
|
if (version == QPair<quint8, quint8>(0,1)) {
|
||||||
qDebug() << "Couldn't read attachment correctly. (Invalid float)";
|
readFloat(fileStream, data.scale, SCALE_RADIX);
|
||||||
continue;
|
} else {
|
||||||
|
fileStream >> data.scale;
|
||||||
}
|
}
|
||||||
context.attachments << data;
|
context.attachments << data;
|
||||||
}
|
}
|
||||||
|
@ -548,8 +543,12 @@ RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString
|
||||||
}
|
}
|
||||||
frame._blendshapeCoefficients.resize(numBlendshapes);
|
frame._blendshapeCoefficients.resize(numBlendshapes);
|
||||||
for (quint32 j = 0; j < numBlendshapes; ++j) {
|
for (quint32 j = 0; j < numBlendshapes; ++j) {
|
||||||
if (!mask[maskIndex++] || !readFloat(stream, frame._blendshapeCoefficients[j], BLENDSHAPE_RADIX)) {
|
if (!mask[maskIndex++]) {
|
||||||
frame._blendshapeCoefficients[j] = previousFrame._blendshapeCoefficients[j];
|
frame._blendshapeCoefficients[j] = previousFrame._blendshapeCoefficients[j];
|
||||||
|
} else if (version == QPair<quint8, quint8>(0,1)) {
|
||||||
|
readFloat(stream, frame._blendshapeCoefficients[j], BLENDSHAPE_RADIX);
|
||||||
|
} else {
|
||||||
|
stream >> frame._blendshapeCoefficients[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Joint Rotations
|
// Joint Rotations
|
||||||
|
@ -571,20 +570,32 @@ RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString
|
||||||
frame._rotation = previousFrame._rotation;
|
frame._rotation = previousFrame._rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mask[maskIndex++] || !readFloat(stream, frame._scale, SCALE_RADIX)) {
|
if (!mask[maskIndex++]) {
|
||||||
frame._scale = previousFrame._scale;
|
frame._scale = previousFrame._scale;
|
||||||
|
} else if (version == QPair<quint8, quint8>(0,1)) {
|
||||||
|
readFloat(stream, frame._scale, SCALE_RADIX);
|
||||||
|
} else {
|
||||||
|
stream >> frame._scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mask[maskIndex++] || !readQuat(stream, frame._headRotation)) {
|
if (!mask[maskIndex++] || !readQuat(stream, frame._headRotation)) {
|
||||||
frame._headRotation = previousFrame._headRotation;
|
frame._headRotation = previousFrame._headRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mask[maskIndex++] || !readFloat(stream, frame._leanSideways, LEAN_RADIX)) {
|
if (!mask[maskIndex++]) {
|
||||||
frame._leanSideways = previousFrame._leanSideways;
|
frame._leanSideways = previousFrame._leanSideways;
|
||||||
|
} else if (version == QPair<quint8, quint8>(0,1)) {
|
||||||
|
readFloat(stream, frame._leanSideways, LEAN_RADIX);
|
||||||
|
} else {
|
||||||
|
stream >> frame._leanSideways;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mask[maskIndex++] || !readFloat(stream, frame._leanForward, LEAN_RADIX)) {
|
if (!mask[maskIndex++]) {
|
||||||
frame._leanForward = previousFrame._leanForward;
|
frame._leanForward = previousFrame._leanForward;
|
||||||
|
} else if (version == QPair<quint8, quint8>(0,1)) {
|
||||||
|
readFloat(stream, frame._leanForward, LEAN_RADIX);
|
||||||
|
} else {
|
||||||
|
stream >> frame._leanForward;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mask[maskIndex++] || !readVec3(stream, frame._lookAtPosition)) {
|
if (!mask[maskIndex++] || !readVec3(stream, frame._lookAtPosition)) {
|
||||||
|
|
Loading…
Reference in a new issue