modelToWorld rotation not in cluster matrices

This commit is contained in:
Andrew Meadows 2017-01-10 16:21:13 -08:00
parent 0b574e170a
commit 44699fc661
3 changed files with 17 additions and 26 deletions

View file

@ -63,8 +63,7 @@ void MeshPartPayload::updateMeshPart(const std::shared_ptr<const model::Mesh>& d
void MeshPartPayload::updateTransform(const Transform& transform, const Transform& offsetTransform) { void MeshPartPayload::updateTransform(const Transform& transform, const Transform& offsetTransform) {
_transform = transform; _transform = transform;
_offsetTransform = offsetTransform; Transform::mult(_drawTransform, _transform, offsetTransform);
Transform::mult(_drawTransform, _transform, _offsetTransform);
_worldBound = _localBound; _worldBound = _localBound;
_worldBound.transform(_drawTransform); _worldBound.transform(_drawTransform);
} }
@ -360,8 +359,8 @@ void ModelMeshPartPayload::notifyLocationChanged() {
} }
void ModelMeshPartPayload::updateTransformForSkinnedMesh(const Transform& transform, const Transform& offsetTransform, const QVector<glm::mat4>& clusterMatrices) { void ModelMeshPartPayload::updateTransformForSkinnedMesh(const Transform& transform, const QVector<glm::mat4>& clusterMatrices) {
ModelMeshPartPayload::updateTransform(transform, offsetTransform); _transform = transform;
if (clusterMatrices.size() > 0) { if (clusterMatrices.size() > 0) {
_worldBound = AABox(); _worldBound = AABox();
@ -371,8 +370,10 @@ void ModelMeshPartPayload::updateTransformForSkinnedMesh(const Transform& transf
_worldBound += clusterBound; _worldBound += clusterBound;
} }
// clusterMatrix has world rotation but not world translation. _worldBound.transform(transform);
_worldBound.translate(transform.getTranslation()); if (clusterMatrices.size() == 1) {
_transform.worldTransform(Transform(clusterMatrices[0]));
}
} }
} }
@ -520,23 +521,15 @@ void ModelMeshPartPayload::bindTransform(gpu::Batch& batch, const ShapePipeline:
// Still relying on the raw data from the model // Still relying on the raw data from the model
const Model::MeshState& state = _model->_meshStates.at(_meshIndex); const Model::MeshState& state = _model->_meshStates.at(_meshIndex);
Transform transform;
if (state.clusterBuffer) { if (state.clusterBuffer) {
if (canCauterize && _model->getCauterizeBones()) { if (canCauterize && _model->getCauterizeBones()) {
batch.setUniformBuffer(ShapePipeline::Slot::BUFFER::SKINNING, state.cauterizedClusterBuffer); batch.setUniformBuffer(ShapePipeline::Slot::BUFFER::SKINNING, state.cauterizedClusterBuffer);
} else { } else {
batch.setUniformBuffer(ShapePipeline::Slot::BUFFER::SKINNING, state.clusterBuffer); batch.setUniformBuffer(ShapePipeline::Slot::BUFFER::SKINNING, state.clusterBuffer);
} }
} else {
if (canCauterize && _model->getCauterizeBones()) {
transform = Transform(state.cauterizedClusterMatrices[0]);
} else {
transform = Transform(state.clusterMatrices[0]);
}
} }
transform.preTranslate(_transform.getTranslation()); batch.setModelTransform(_transform);
batch.setModelTransform(transform);
} }
void ModelMeshPartPayload::startFade() { void ModelMeshPartPayload::startFade() {
@ -570,7 +563,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) const {
} }
// When an individual mesh parts like this finishes its fade, we will mark the Model as // When an individual mesh parts like this finishes its fade, we will mark the Model as
// having render items that need updating // having render items that need updating
bool nextIsFading = _isFading ? isStillFading() : false; bool nextIsFading = _isFading ? isStillFading() : false;
bool startFading = !_isFading && !_hasFinishedFade && _hasStartedFade; bool startFading = !_isFading && !_hasFinishedFade && _hasStartedFade;
@ -592,6 +585,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) const {
// Bind the model transform and the skinCLusterMatrices if needed // Bind the model transform and the skinCLusterMatrices if needed
bool canCauterize = args->_renderMode != RenderArgs::SHADOW_RENDER_MODE; bool canCauterize = args->_renderMode != RenderArgs::SHADOW_RENDER_MODE;
// TODO: maybe get rid of this call?
_model->updateClusterMatrices(_transform.getTranslation(), _transform.getRotation()); _model->updateClusterMatrices(_transform.getTranslation(), _transform.getRotation());
bindTransform(batch, locations, canCauterize); bindTransform(batch, locations, canCauterize);

View file

@ -56,13 +56,12 @@ public:
model::Mesh::Part _drawPart; model::Mesh::Part _drawPart;
std::shared_ptr<const model::Material> _drawMaterial; std::shared_ptr<const model::Material> _drawMaterial;
model::Box _localBound; model::Box _localBound;
Transform _drawTransform; Transform _drawTransform;
Transform _transform; Transform _transform;
Transform _offsetTransform;
mutable model::Box _worldBound; mutable model::Box _worldBound;
bool _hasColorAttrib = false; bool _hasColorAttrib = false;
size_t getVerticesCount() const { return _drawMesh ? _drawMesh->getNumVertices() : 0; } size_t getVerticesCount() const { return _drawMesh ? _drawMesh->getNumVertices() : 0; }
@ -86,7 +85,7 @@ public:
typedef Payload::DataPointer Pointer; typedef Payload::DataPointer Pointer;
void notifyLocationChanged() override; void notifyLocationChanged() override;
void updateTransformForSkinnedMesh(const Transform& transform, const Transform& offsetTransform, const QVector<glm::mat4>& clusterMatrices); void updateTransformForSkinnedMesh(const Transform& transform, const QVector<glm::mat4>& clusterMatrices);
// Entity fade in // Entity fade in
void startFade(); void startFade();

View file

@ -245,7 +245,7 @@ void Model::updateRenderItems() {
// update the model transform and bounding box for this render item. // update the model transform and bounding box for this render item.
const Model::MeshState& state = data._model->_meshStates.at(data._meshIndex); const Model::MeshState& state = data._model->_meshStates.at(data._meshIndex);
data.updateTransformForSkinnedMesh(modelTransform, modelMeshOffset, state.clusterMatrices); data.updateTransformForSkinnedMesh(modelTransform, state.clusterMatrices);
} }
} }
}); });
@ -1167,7 +1167,6 @@ void Model::updateClusterMatrices(glm::vec3 modelPosition, glm::quat modelOrient
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
auto cauterizeMatrix = _rig->getJointTransform(geometry.neckJointIndex) * zeroScale; auto cauterizeMatrix = _rig->getJointTransform(geometry.neckJointIndex) * zeroScale;
glm::mat4 modelToWorld = glm::mat4_cast(modelOrientation);
for (int i = 0; i < _meshStates.size(); i++) { for (int i = 0; i < _meshStates.size(); i++) {
MeshState& state = _meshStates[i]; MeshState& state = _meshStates[i];
const FBXMesh& mesh = geometry.meshes.at(i); const FBXMesh& mesh = geometry.meshes.at(i);
@ -1176,11 +1175,10 @@ void Model::updateClusterMatrices(glm::vec3 modelPosition, glm::quat modelOrient
auto jointMatrix = _rig->getJointTransform(cluster.jointIndex); auto jointMatrix = _rig->getJointTransform(cluster.jointIndex);
#if GLM_ARCH & GLM_ARCH_SSE2 #if GLM_ARCH & GLM_ARCH_SSE2
glm::mat4 temp, out, inverseBindMatrix = cluster.inverseBindMatrix; glm::mat4 temp, out, inverseBindMatrix = cluster.inverseBindMatrix;
glm_mat4_mul((glm_vec4*)&modelToWorld, (glm_vec4*)&jointMatrix, (glm_vec4*)&temp);
glm_mat4_mul((glm_vec4*)&temp, (glm_vec4*)&inverseBindMatrix, (glm_vec4*)&out); glm_mat4_mul((glm_vec4*)&temp, (glm_vec4*)&inverseBindMatrix, (glm_vec4*)&out);
state.clusterMatrices[j] = out; state.clusterMatrices[j] = out;
#else #else
state.clusterMatrices[j] = modelToWorld * jointMatrix * cluster.inverseBindMatrix; state.clusterMatrices[j] = jointMatrix * cluster.inverseBindMatrix;
#endif #endif
// as an optimization, don't build cautrizedClusterMatrices if the boneSet is empty. // as an optimization, don't build cautrizedClusterMatrices if the boneSet is empty.
@ -1188,7 +1186,7 @@ void Model::updateClusterMatrices(glm::vec3 modelPosition, glm::quat modelOrient
if (_cauterizeBoneSet.find(cluster.jointIndex) != _cauterizeBoneSet.end()) { if (_cauterizeBoneSet.find(cluster.jointIndex) != _cauterizeBoneSet.end()) {
jointMatrix = cauterizeMatrix; jointMatrix = cauterizeMatrix;
} }
state.cauterizedClusterMatrices[j] = modelToWorld * jointMatrix * cluster.inverseBindMatrix; state.cauterizedClusterMatrices[j] = jointMatrix * cluster.inverseBindMatrix;
} }
} }