fix model bounds

This commit is contained in:
SamGondelman 2019-04-30 13:38:11 -07:00
parent 9261df5c24
commit 5a184bd584
5 changed files with 11 additions and 21 deletions

View file

@ -164,7 +164,7 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
Parent::simulate(deltaTime, fullUpdate); Parent::simulate(deltaTime, fullUpdate);
} }
// FIXME: This texture loading logic should probably live in Avatar, to mirror RenderableModelEntityItem and ModelOverlay, // FIXME: This texture loading logic should probably live in Avatar, to mirror RenderableModelEntityItem,
// but Avatars don't get updates in the same way // but Avatars don't get updates in the same way
if (!_texturesLoaded && getGeometry() && getGeometry()->areTexturesLoaded()) { if (!_texturesLoaded && getGeometry() && getGeometry()->areTexturesLoaded()) {
_texturesLoaded = true; _texturesLoaded = true;

View file

@ -237,9 +237,11 @@ void CauterizedModel::updateRenderItems() {
if (useDualQuaternionSkinning) { if (useDualQuaternionSkinning) {
data.updateClusterBuffer(meshState.clusterDualQuaternions, data.updateClusterBuffer(meshState.clusterDualQuaternions,
cauterizedMeshState.clusterDualQuaternions); cauterizedMeshState.clusterDualQuaternions);
data.computeAdjustedLocalBound(meshState.clusterDualQuaternions);
} else { } else {
data.updateClusterBuffer(meshState.clusterMatrices, data.updateClusterBuffer(meshState.clusterMatrices,
cauterizedMeshState.clusterMatrices); cauterizedMeshState.clusterMatrices);
data.computeAdjustedLocalBound(meshState.clusterMatrices);
} }
Transform renderTransform = modelTransform; Transform renderTransform = modelTransform;

View file

@ -450,9 +450,9 @@ void ModelMeshPartPayload::render(RenderArgs* args) {
void ModelMeshPartPayload::computeAdjustedLocalBound(const std::vector<glm::mat4>& clusterMatrices) { void ModelMeshPartPayload::computeAdjustedLocalBound(const std::vector<glm::mat4>& clusterMatrices) {
_adjustedLocalBound = _localBound; _adjustedLocalBound = _localBound;
if (clusterMatrices.size() > 0) { if (clusterMatrices.size() > 0) {
_adjustedLocalBound.transform(clusterMatrices[0]); _adjustedLocalBound.transform(clusterMatrices.back());
for (int i = 1; i < (int)clusterMatrices.size(); ++i) { for (int i = 0; i < (int)clusterMatrices.size() - 1; ++i) {
AABox clusterBound = _localBound; AABox clusterBound = _localBound;
clusterBound.transform(clusterMatrices[i]); clusterBound.transform(clusterMatrices[i]);
_adjustedLocalBound += clusterBound; _adjustedLocalBound += clusterBound;
@ -463,12 +463,12 @@ void ModelMeshPartPayload::computeAdjustedLocalBound(const std::vector<glm::mat4
void ModelMeshPartPayload::computeAdjustedLocalBound(const std::vector<Model::TransformDualQuaternion>& clusterDualQuaternions) { void ModelMeshPartPayload::computeAdjustedLocalBound(const std::vector<Model::TransformDualQuaternion>& clusterDualQuaternions) {
_adjustedLocalBound = _localBound; _adjustedLocalBound = _localBound;
if (clusterDualQuaternions.size() > 0) { if (clusterDualQuaternions.size() > 0) {
Transform rootTransform(clusterDualQuaternions[0].getRotation(), Transform rootTransform(clusterDualQuaternions.back().getRotation(),
clusterDualQuaternions[0].getScale(), clusterDualQuaternions.back().getScale(),
clusterDualQuaternions[0].getTranslation()); clusterDualQuaternions.back().getTranslation());
_adjustedLocalBound.transform(rootTransform); _adjustedLocalBound.transform(rootTransform);
for (int i = 1; i < (int)clusterDualQuaternions.size(); ++i) { for (int i = 0; i < (int)clusterDualQuaternions.size() - 1; ++i) {
AABox clusterBound = _localBound; AABox clusterBound = _localBound;
Transform transform(clusterDualQuaternions[i].getRotation(), Transform transform(clusterDualQuaternions[i].getRotation(),
clusterDualQuaternions[i].getScale(), clusterDualQuaternions[i].getScale(),

View file

@ -241,8 +241,10 @@ void Model::updateRenderItems() {
invalidatePayloadShapeKey, primitiveMode, renderItemKeyGlobalFlags, cauterized](ModelMeshPartPayload& data) { invalidatePayloadShapeKey, primitiveMode, renderItemKeyGlobalFlags, cauterized](ModelMeshPartPayload& data) {
if (useDualQuaternionSkinning) { if (useDualQuaternionSkinning) {
data.updateClusterBuffer(meshState.clusterDualQuaternions); data.updateClusterBuffer(meshState.clusterDualQuaternions);
data.computeAdjustedLocalBound(meshState.clusterDualQuaternions);
} else { } else {
data.updateClusterBuffer(meshState.clusterMatrices); data.updateClusterBuffer(meshState.clusterMatrices);
data.computeAdjustedLocalBound(meshState.clusterMatrices);
} }
Transform renderTransform = modelTransform; Transform renderTransform = modelTransform;
@ -1367,8 +1369,6 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
// update the world space transforms for all joints // update the world space transforms for all joints
glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset); glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset);
updateRig(deltaTime, parentTransform); updateRig(deltaTime, parentTransform);
computeMeshPartLocalBounds();
} }
} }
@ -1379,17 +1379,6 @@ void Model::updateRig(float deltaTime, glm::mat4 parentTransform) {
_rig.updateAnimations(deltaTime, parentTransform, rigToWorldTransform); _rig.updateAnimations(deltaTime, parentTransform, rigToWorldTransform);
} }
void Model::computeMeshPartLocalBounds() {
for (auto& part : _modelMeshRenderItems) {
const Model::MeshState& state = _meshStates.at(part->_meshIndex);
if (_useDualQuaternionSkinning) {
part->computeAdjustedLocalBound(state.clusterDualQuaternions);
} else {
part->computeAdjustedLocalBound(state.clusterMatrices);
}
}
}
// virtual // virtual
void Model::updateClusterMatrices() { void Model::updateClusterMatrices() {
DETAILED_PERFORMANCE_TIMER("Model::updateClusterMatrices"); DETAILED_PERFORMANCE_TIMER("Model::updateClusterMatrices");

View file

@ -427,7 +427,6 @@ protected:
void setScaleInternal(const glm::vec3& scale); void setScaleInternal(const glm::vec3& scale);
void snapToRegistrationPoint(); void snapToRegistrationPoint();
void computeMeshPartLocalBounds();
virtual void updateRig(float deltaTime, glm::mat4 parentTransform); virtual void updateRig(float deltaTime, glm::mat4 parentTransform);
/// Allow sub classes to force invalidating the bboxes /// Allow sub classes to force invalidating the bboxes