Fixed rotation polarity and weights are now 16 bit.

This commit is contained in:
Anthony J. Thibault 2017-12-22 10:54:48 -08:00
parent 5bb0b06061
commit b69edceb4f
5 changed files with 12 additions and 66 deletions

View file

@ -224,7 +224,7 @@ public:
QVector<glm::vec2> texCoords;
QVector<glm::vec2> texCoords1;
QVector<uint16_t> clusterIndices;
QVector<uint8_t> clusterWeights;
QVector<uint16_t> clusterWeights;
QVector<int32_t> originalIndices;
QVector<FBXCluster> clusters;

View file

@ -1727,9 +1727,9 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
}
if (totalWeight > 0.0f) {
const float ALMOST_HALF = 0.499f;
float weightScalingFactor = (float)(UINT8_MAX) / totalWeight;
float weightScalingFactor = (float)(UINT16_MAX) / totalWeight;
for (int k = j; k < j + WEIGHTS_PER_VERTEX; ++k) {
extracted.mesh.clusterWeights[k] = (uint8_t)(weightScalingFactor * weightAccumulators[k] + ALMOST_HALF);
extracted.mesh.clusterWeights[k] = (uint16_t)(weightScalingFactor * weightAccumulators[k] + ALMOST_HALF);
}
}
}

View file

@ -583,7 +583,7 @@ void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QString& url) {
// we need 16 bits instead of just 8 for clusterIndices
clusterIndicesSize *= 2;
}
int clusterWeightsSize = fbxMesh.clusterWeights.size() * sizeof(uint8_t);
int clusterWeightsSize = fbxMesh.clusterWeights.size() * sizeof(uint16_t);
int normalsOffset = 0;
int tangentsOffset = normalsOffset + normalsSize;
@ -662,7 +662,7 @@ void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QString& url) {
if (clusterWeightsSize) {
mesh->addAttribute(gpu::Stream::SKIN_CLUSTER_WEIGHT,
model::BufferView(attribBuffer, clusterWeightsOffset, clusterWeightsSize,
gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::XYZW)));
gpu::Element(gpu::VEC4, gpu::NUINT16, gpu::XYZW)));
}

View file

@ -113,12 +113,7 @@ void CauterizedModel::updateClusterMatrices() {
for (int i = 0; i < (int)_meshStates.size(); i++) {
Model::MeshState& state = _meshStates[i];
const FBXMesh& mesh = geometry.meshes.at(i);
#if defined(SKIN_DQ)
// HACK: FOR DQ go thru reverse order!
for (int j = mesh.clusters.size() - 1; j >= 0; j--) {
#else
for (int j = 0; j < mesh.clusters.size(); j++) {
#endif
const FBXCluster& cluster = mesh.clusters.at(j);
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
@ -132,25 +127,6 @@ void CauterizedModel::updateClusterMatrices() {
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, m);
AnimPose p(m);
state.clusterTransforms[j] = Model::TransformDualQuaternion(m);
// AJT: HACK n^2!!!! fix me, find parent clusterTransform.
int parentIndex = _rig.getJointParentIndex(cluster.jointIndex);
int parentClusterIndex = -1;
// scan for parent!
for (int ii = mesh.clusters.size() - 1; ii > j; ii--) {
if (mesh.clusters[ii].jointIndex == parentIndex) {
parentClusterIndex = ii;
break;
}
}
// ensure that we have the same polarity as our parent!
if (parentClusterIndex >= 0) {
//if (state.clusterTransforms[parentClusterIndex]._dq.dot(state.clusterTransforms[j]._dq) < 0.0f) {
if (glm::dot(state.clusterTransforms[parentClusterIndex]._dq.real(), state.clusterTransforms[j]._dq.real()) < 0.0f) {
state.clusterTransforms[j]._dq = -state.clusterTransforms[j]._dq;
}
}
#else
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterTransforms[j]);
#endif
@ -171,12 +147,7 @@ void CauterizedModel::updateClusterMatrices() {
Model::MeshState& state = _cauterizeMeshStates[i];
const FBXMesh& mesh = geometry.meshes.at(i);
#if defined(SKIN_DQ)
// HACK: FOR DQ go thru reverse order!
for (int j = mesh.clusters.size() - 1; j >= 0; j--) {
#else
for (int j = 0; j < mesh.clusters.size(); j++) {
#endif
for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j);
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
@ -194,25 +165,6 @@ void CauterizedModel::updateClusterMatrices() {
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, m);
AnimPose p(m);
state.clusterTransforms[j] = Model::TransformDualQuaternion(m);
// AJT: HACK n^2!!!! fix me, find parent clusterTransform.
int parentIndex = _rig.getJointParentIndex(cluster.jointIndex);
int parentClusterIndex = -1;
// scan for parent!
for (int ii = mesh.clusters.size() - 1; ii > j; ii--) {
if (mesh.clusters[ii].jointIndex == parentIndex) {
parentClusterIndex = ii;
break;
}
}
// ensure that we have the same polarity as our parent!
if (parentClusterIndex >= 0) {
//if (state.clusterTransforms[parentClusterIndex]._dq.dot(state.clusterTransforms[j]._dq) < 0.0f) {
if (glm::dot(state.clusterTransforms[parentClusterIndex]._dq.real(), state.clusterTransforms[j]._dq.real()) < 0.0f) {
state.clusterTransforms[j]._dq = -state.clusterTransforms[j]._dq;
}
}
#else
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterTransforms[j]);
#endif

View file

@ -56,10 +56,8 @@ void skinPosition(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPositio
float dqClusterWeight = clusterWeight;
if (i == 0) {
prevR = real;
} else {
if (dot(prevR, real) < 0) {
dqClusterWeight = -clusterWeight;
}
} else if (dot(prevR, real) < 0) {
dqClusterWeight = -clusterWeight;
}
sAccum += scale * clusterWeight;
@ -123,10 +121,8 @@ void skinPositionNormal(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inP
float dqClusterWeight = clusterWeight;
if (i == 0) {
prevR = real;
} else {
if (dot(prevR, real) < 0) {
dqClusterWeight = -clusterWeight;
}
} else if (dot(prevR, real) < 0) {
dqClusterWeight = -clusterWeight;
}
sAccum += scale * clusterWeight;
@ -191,10 +187,8 @@ void skinPositionNormalTangent(ivec4 skinClusterIndex, vec4 skinClusterWeight, v
float dqClusterWeight = clusterWeight;
if (i == 0) {
prevR = real;
} else {
if (dot(prevR, real) < 0) {
dqClusterWeight = -clusterWeight;
}
} else if (dot(prevR, real) < 0) {
dqClusterWeight = -clusterWeight;
}
sAccum += scale * clusterWeight;