Merge pull request #5051 from ZappoMan/team-teaching-optimize-offset

TEAM TEACHING - improvements to avatar part clipping
This commit is contained in:
Ryan Huffman 2015-06-05 09:26:45 -07:00
commit b22ed34825
3 changed files with 34 additions and 7 deletions

View file

@ -39,7 +39,8 @@ void FaceModel::simulate(float deltaTime, bool fullUpdate) {
setPupilDilation(_owningHead->getPupilDilation());
setBlendshapeCoefficients(_owningHead->getBlendshapeCoefficients());
invalidCalculatedMeshBoxes();
// FIXME - this is very expensive, we shouldn't do it if we don't have to
//invalidCalculatedMeshBoxes();
if (isActive()) {
setOffset(-_geometry->getFBXGeometry().neckPivot);

View file

@ -93,6 +93,8 @@ Model::Model(QObject* parent) :
if (_viewState) {
moveToThread(_viewState->getMainThread());
}
setSnapModelToRegistrationPoint(true, glm::vec3(0.5f));
}
Model::~Model() {
@ -408,7 +410,7 @@ void Model::reset() {
_meshGroupsKnown = false;
_readyWhenAdded = false; // in case any of our users are using scenes
_needsReload = true;
invalidCalculatedMeshBoxes(); // if we have to reload, we need to assume our mesh boxes are all invalid
}
bool Model::updateGeometry() {
@ -460,7 +462,7 @@ bool Model::updateGeometry() {
_geometry = geometry;
_meshGroupsKnown = false;
_readyWhenAdded = false; // in case any of our users are using scenes
_needsReload = true;
invalidCalculatedMeshBoxes(); // if we have to reload, we need to assume our mesh boxes are all invalid
initJointStates(newJointStates);
needToRebuild = true;
} else if (_jointStates.isEmpty()) {
@ -1265,6 +1267,7 @@ Extents Model::calculateScaledOffsetExtents(const Extents& extents) const {
/// Returns the world space equivalent of some box in model space.
AABox Model::calculateScaledOffsetAABox(const AABox& box) const {
return AABox(calculateScaledOffsetExtents(Extents(box)));
}
@ -1602,6 +1605,7 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
|| (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint);
if (isActive() && fullUpdate) {
// NOTE: this seems problematic... need to review
_calculatedMeshBoxesValid = false; // if we have to simulate, we need to assume our mesh boxes are all invalid
_calculatedMeshTrianglesValid = false;
@ -1990,6 +1994,7 @@ void Model::applyNextGeometry() {
_meshGroupsKnown = false;
_readyWhenAdded = false; // in case any of our users are using scenes
_needsReload = false; // we are loaded now!
invalidCalculatedMeshBoxes();
_nextBaseGeometry.reset();
_nextGeometry.reset();
}
@ -2062,6 +2067,22 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran
gpu::Batch& batch = *(args->_batch);
auto mode = args->_renderMode;
// render the part bounding box
#ifdef DEBUG_BOUNDING_PARTS
{
glm::vec4 cubeColor(1.0f,0.0f,0.0f,1.0f);
AABox partBounds = getPartBounds(meshIndex, partIndex);
glm::mat4 translation = glm::translate(partBounds.calcCenter());
glm::mat4 scale = glm::scale(partBounds.getDimensions());
glm::mat4 modelToWorldMatrix = translation * scale;
batch.setModelTransform(modelToWorldMatrix);
//qDebug() << "partBounds:" << partBounds;
DependencyManager::get<DeferredLightingEffect>()->renderWireCube(batch, 1.0f, cubeColor);
}
#endif //def DEBUG_BOUNDING_PARTS
// Capture the view matrix once for the rendering of this model
if (_transforms.empty()) {
_transforms.push_back(Transform());
@ -2103,7 +2124,7 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran
if (meshIndex < 0 || meshIndex >= networkMeshes.size() || meshIndex > geometry.meshes.size()) {
_meshGroupsKnown = false; // regenerate these lists next time around.
_readyWhenAdded = false; // in case any of our users are using scenes
_needsReload = true;
invalidCalculatedMeshBoxes(); // if we have to reload, we need to assume our mesh boxes are all invalid
return; // FIXME!
}
@ -2417,7 +2438,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
if (i < 0 || i >= networkMeshes.size() || i > geometry.meshes.size()) {
_meshGroupsKnown = false; // regenerate these lists next time around.
_readyWhenAdded = false; // in case any of our users are using scenes
_needsReload = true;
invalidCalculatedMeshBoxes(); // if we have to reload, we need to assume our mesh boxes are all invalid
continue;
}

View file

@ -260,7 +260,7 @@ protected:
bool _snapModelToRegistrationPoint; /// is the model's offset automatically adjusted to a registration point in model space
bool _snappedToRegistrationPoint; /// are we currently snapped to a registration point
glm::vec3 _registrationPoint; /// the point in model space our center is snapped to
glm::vec3 _registrationPoint = glm::vec3(0.5f); /// the point in model space our center is snapped to
bool _showTrueJointTransforms;
@ -312,7 +312,12 @@ protected:
float getLimbLength(int jointIndex) const;
/// Allow sub classes to force invalidating the bboxes
void invalidCalculatedMeshBoxes() { _calculatedMeshBoxesValid = false; }
void invalidCalculatedMeshBoxes() {
qDebug() << "invalidCalculatedMeshBoxes()";
_calculatedMeshBoxesValid = false;
_calculatedMeshPartBoxesValid = false;
_calculatedMeshTrianglesValid = false;
}
private: