History

Model: update renderItems when items are added to the scene.

* Renamed enqueueLocationChange to updateRenderItems * Call updateRenderItems when models are added to the scene. This will fix entity render bounds being incorrect when they are first added to the scene, then later being correct after a position update. * Renamed getMeshPartBound to getRenderableMeshBound. * Avatar now uses getRenderableMeshBound() to do boundingRadius vs frustum check. * Model::getRenderableMeshBound now returns a more accurate bound, because it is the same one used for rendering. This will fix avatar freezing, when they are in the corner of your frustum. This was due to matrices not being updated because the avatar had to a small bounding sphere.

Anthony J. Thibault committed 10 years ago

Commit bc967f01 parent 635f5863 files · +16 −53Browse files

Showing the changes to libraries/render-utils/src/Model.cpp (1 of 3 files). Show all

Unified · Split

libraries/render-utils/src/Model.cpp+14−49
@@ -94,12 +94,12 @@ bool Model::needsFixupInScene() const { · 93 unmodified lines
9494
9595 void Model::setTranslation(const glm::vec3& translation) {
9696 _translation = translation;
97− enqueueLocationChange();
97+ updateRenderItems();
9898 }
9999
100100 void Model::setRotation(const glm::quat& rotation) {
101101 _rotation = rotation;
102− enqueueLocationChange();
102+ updateRenderItems();
103103 }
104104
105105 void Model::setScale(const glm::vec3& scale) {
@@ -129,7 +129,7 @@ void Model::setOffset(const glm::vec3& offset) { · 23 unmodified lines
129129 _snappedToRegistrationPoint = false;
130130 }
131131
132−void Model::enqueueLocationChange() {
132+void Model::updateRenderItems() {
133133
134134 _needsUpdateClusterMatrices = true;
135135
@@ -560,9 +560,6 @@ bool Model::addToScene(std::shared_ptr<render::Scene> scene, render::PendingChan · 424 unmodified lines
560560 auto item = scene->allocateID();
561561 auto renderPayload = std::make_shared<ModelMeshPartPayload::Payload>(renderItem);
562562 pendingChanges.resetItem(item, renderPayload);
563− pendingChanges.updateItem<ModelMeshPartPayload>(item, [](ModelMeshPartPayload& data) {
564− data.notifyLocationChanged();
565− });
566563 _modelMeshRenderItems.insert(item, renderPayload);
567564 somethingAdded = true;
568565 }
@@ -571,13 +568,11 @@ bool Model::addToScene(std::shared_ptr<render::Scene> scene, render::PendingChan · 2 unmodified lines
571568 auto item = scene->allocateID();
572569 auto renderPayload = std::make_shared<MeshPartPayload::Payload>(renderItem);
573570 pendingChanges.resetItem(item, renderPayload);
574− pendingChanges.updateItem<MeshPartPayload>(item, [](MeshPartPayload& data) {
575− data.notifyLocationChanged();
576− });
577571 _collisionRenderItems.insert(item, renderPayload);
578572 somethingAdded = true;
579573 }
580574
575+ updateRenderItems();
581576 _readyWhenAdded = readyToAddToScene();
582577
583578 return somethingAdded;
@@ -599,9 +594,6 @@ bool Model::addToScene(std::shared_ptr<render::Scene> scene, · 15 unmodified lines
599594 auto renderPayload = std::make_shared<ModelMeshPartPayload::Payload>(renderItem);
600595 renderPayload->addStatusGetters(statusGetters);
601596 pendingChanges.resetItem(item, renderPayload);
602− pendingChanges.updateItem<ModelMeshPartPayload>(item, [](ModelMeshPartPayload& data) {
603− data.notifyLocationChanged();
604− });
605597 _modelMeshRenderItems.insert(item, renderPayload);
606598 somethingAdded = true;
607599 }
@@ -611,13 +603,12 @@ bool Model::addToScene(std::shared_ptr<render::Scene> scene, · 3 unmodified lines
611603 auto renderPayload = std::make_shared<MeshPartPayload::Payload>(renderItem);
612604 renderPayload->addStatusGetters(statusGetters);
613605 pendingChanges.resetItem(item, renderPayload);
614− pendingChanges.updateItem<MeshPartPayload>(item, [](MeshPartPayload& data) {
615− data.notifyLocationChanged();
616− });
617606 _collisionRenderItems.insert(item, renderPayload);
618607 somethingAdded = true;
619608 }
620609
610+ updateRenderItems();
611+
621612 _readyWhenAdded = readyToAddToScene();
622613
623614 return somethingAdded;
@@ -1185,38 +1176,17 @@ void Model::deleteGeometry() { · 561 unmodified lines
11851176 _blendedBlendshapeCoefficients.clear();
11861177 }
11871178
1188−AABox Model::getPartBounds(int meshIndex, int partIndex, glm::vec3 modelPosition, glm::quat modelOrientation) const {
1189−
1179+AABox Model::getRenderableMeshBound() const {
11901180 if (!isLoaded()) {
11911181 return AABox();
1192− }
1193−
1194− if (meshIndex < _meshStates.size()) {
1195− const MeshState& state = _meshStates.at(meshIndex);
1196− bool isSkinned = state.clusterMatrices.size() > 1;
1197− if (isSkinned) {
1198− // if we're skinned return the entire mesh extents because we can't know for sure our clusters don't move us
1199− return calculateScaledOffsetAABox(getFBXGeometry().meshExtents, modelPosition, modelOrientation);
1182+ } else {
1183+ // Build a bound using the last known bound from all the renderItems.
1184+ AABox totalBound;
1185+ for (auto& renderItem : _modelMeshRenderItemsSet) {
1186+ totalBound += renderItem->getBound();
12001187 }
1188+ return totalBound;
12011189 }
1202− if (getFBXGeometry().meshes.size() > meshIndex) {
1203−
1204− // FIX ME! - This is currently a hack because for some mesh parts our efforts to calculate the bounding
1205− // box of the mesh part fails. It seems to create boxes that are not consistent with where the
1206− // geometry actually renders. If instead we make all the parts share the bounds of the entire subMesh
1207− // things will render properly.
1208− //
1209− // return calculateScaledOffsetAABox(_calculatedMeshPartBoxes[QPair<int,int>(meshIndex, partIndex)]);
1210− //
1211− // NOTE: we also don't want to use the _calculatedMeshBoxes[] because they don't handle avatar moving correctly
1212− // without recalculating them...
1213− // return _calculatedMeshBoxes[meshIndex];
1214− //
1215− // If we not skinned use the bounds of the subMesh for all it's parts
1216− const FBXMesh& mesh = getFBXGeometry().meshes.at(meshIndex);
1217− return calculateScaledOffsetExtents(mesh.meshExtents, modelPosition, modelOrientation);
1218− }
1219− return AABox();
12201190 }
12211191
12221192 void Model::segregateMeshGroups() {
@@ -1308,20 +1278,15 @@ bool Model::initWhenReady(render::ScenePointer scene) { · 85 unmodified lines
13081278 auto renderPayload = std::make_shared<ModelMeshPartPayload::Payload>(renderItem);
13091279 _modelMeshRenderItems.insert(item, renderPayload);
13101280 pendingChanges.resetItem(item, renderPayload);
1311− pendingChanges.updateItem<ModelMeshPartPayload>(item, [transform, offset](MeshPartPayload& data) {
1312− data.notifyLocationChanged();
1313− });
13141281 }
13151282 foreach (auto renderItem, _collisionRenderItemsSet) {
13161283 auto item = scene->allocateID();
13171284 auto renderPayload = std::make_shared<MeshPartPayload::Payload>(renderItem);
13181285 _collisionRenderItems.insert(item, renderPayload);
13191286 pendingChanges.resetItem(item, renderPayload);
1320− pendingChanges.updateItem<MeshPartPayload>(item, [transform, offset](MeshPartPayload& data) {
1321− data.notifyLocationChanged();
1322− });
13231287 }
13241288 scene->enqueuePendingChanges(pendingChanges);
1289+ updateRenderItems();
13251290
13261291 _readyWhenAdded = true;
13271292 return true;