Showing the changes to libraries/render-utils/src/Model.cpp (1 of 4 files). Show all
Unified · Split
| @@ -121,15 +121,17 @@ Model::~Model() { · 120 unmodified lines | ||
| 121 | 121 | AbstractViewStateInterface* Model::_viewState = NULL; |
| 122 | 122 | |
| 123 | 123 | void Model::setShowCollisionMesh(bool value) { |
| 124 | − if (_showCollisionGeometry != value) { | |
| 125 | − _showCollisionGeometry = value; | |
| 126 | − _needsFixupInScene = true; | |
| 124 | + if (_readyToShowCollisionGeometry) { | |
| 125 | + if (_showCollisionGeometry != value) { | |
| 126 | + _showCollisionGeometry = value; | |
| 127 | + _needsFixupInScene = true; | |
| 128 | + } | |
| 127 | 129 | } |
| 128 | 130 | } |
| 129 | 131 | |
| 130 | 132 | bool Model::needsFixupInScene() const { |
| 131 | 133 | if ((_needsFixupInScene || !_addedToScene) && !_needsReload && isLoaded()) { |
| 132 | − if (_showCollisionGeometry && _collisionGeometry) { | |
| 134 | + if (_showCollisionGeometry && _readyToShowCollisionGeometry && _collisionGeometry) { | |
| 133 | 135 | return true; |
| 134 | 136 | } |
| 135 | 137 | if (!_meshStates.isEmpty() || (_renderGeometry && _renderGeometry->getMeshes().empty())) { |
| @@ -241,8 +243,6 @@ void Model::updateRenderItems() { · 105 unmodified lines | ||
| 241 | 243 | |
| 242 | 244 | // collision mesh does not share the same unit scale as the FBX file's mesh: only apply offset |
| 243 | 245 | Transform collisionMeshOffset; |
| 244 | − // adebug FIXME: recover correct behavior for collisionURL shapes | |
| 245 | − //collisionMeshOffset.postTranslate(self->_offset); | |
| 246 | 246 | collisionMeshOffset.setIdentity(); |
| 247 | 247 | foreach (auto itemID, self->_collisionRenderItems.keys()) { |
| 248 | 248 | pendingChanges.updateItem<MeshPartPayload>(itemID, [modelTransform, collisionMeshOffset](MeshPartPayload& data) { |
| @@ -614,13 +614,13 @@ void Model::setVisibleInScene(bool newValue, std::shared_ptr<render::Scene> scen · 365 unmodified lines | ||
| 614 | 614 | bool Model::addToScene(std::shared_ptr<render::Scene> scene, |
| 615 | 615 | render::PendingChanges& pendingChanges, |
| 616 | 616 | render::Item::Status::Getters& statusGetters) { |
| 617 | − bool readyToRender = (_showCollisionGeometry && _collisionGeometry) || isLoaded(); | |
| 617 | + bool readyToRender = (_showCollisionGeometry && _readyToShowCollisionGeometry && _collisionGeometry) || isLoaded(); | |
| 618 | 618 | if (!_addedToScene && readyToRender) { |
| 619 | 619 | createRenderItemSet(); |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | bool somethingAdded = false; |
| 623 | − if (_showCollisionGeometry && _collisionGeometry) { | |
| 623 | + if (_showCollisionGeometry && _readyToShowCollisionGeometry && _collisionGeometry) { | |
| 624 | 624 | if (_collisionRenderItems.empty()) { |
| 625 | 625 | foreach (auto renderItem, _collisionRenderItemsSet) { |
| 626 | 626 | auto item = scene->allocateID(); |
| @@ -1258,7 +1258,7 @@ AABox Model::getRenderableMeshBound() const { · 631 unmodified lines | ||
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | void Model::createRenderItemSet() { |
| 1261 | − if (_showCollisionGeometry && _collisionGeometry) { | |
| 1261 | + if (_showCollisionGeometry && _readyToShowCollisionGeometry && _collisionGeometry) { | |
| 1262 | 1262 | if (_collisionRenderItemsSet.empty()) { |
| 1263 | 1263 | createCollisionRenderItemSet(); |
| 1264 | 1264 | } |
| @@ -1321,18 +1321,6 @@ void Model::createCollisionRenderItemSet() { · 56 unmodified lines | ||
| 1321 | 1321 | // We should not have any existing renderItems if we enter this section of code |
| 1322 | 1322 | Q_ASSERT(_collisionRenderItemsSet.isEmpty()); |
| 1323 | 1323 | |
| 1324 | − Transform transform; | |
| 1325 | − transform.setIdentity(); | |
| 1326 | − // adebug FIXME: recover correct behavior for collisionURL | |
| 1327 | − //transform.setTranslation(_translation); | |
| 1328 | − //transform.setRotation(_rotation); | |
| 1329 | − | |
| 1330 | − Transform offset; | |
| 1331 | − // adebug FIXME: recover correct behavior for collisionURL | |
| 1332 | − offset.setIdentity(); | |
| 1333 | − //offset.setScale(_scale); | |
| 1334 | − //offset.postTranslate(_offset); | |
| 1335 | − | |
| 1336 | 1324 | // Run through all of the meshes, and place them into their segregated, but unsorted buckets |
| 1337 | 1325 | uint32_t numMeshes = (uint32_t)meshes.size(); |
| 1338 | 1326 | for (uint32_t i = 0; i < numMeshes; i++) { |
| @@ -1345,7 +1333,7 @@ void Model::createCollisionRenderItemSet() { · 6 unmodified lines | ||
| 1345 | 1333 | int numParts = (int)mesh->getNumParts(); |
| 1346 | 1334 | for (int partIndex = 0; partIndex < numParts; partIndex++) { |
| 1347 | 1335 | model::MaterialPointer& material = _collisionMaterials[partIndex % NUM_COLLISION_HULL_COLORS]; |
| 1348 | − _collisionRenderItemsSet << std::make_shared<MeshPartPayload>(mesh, partIndex, material, transform, offset); | |
| 1336 | + _collisionRenderItemsSet << std::make_shared<MeshPartPayload>(mesh, partIndex, material); | |
| 1349 | 1337 | } |
| 1350 | 1338 | } |
| 1351 | 1339 | } |
| @@ -1365,7 +1353,7 @@ bool Model::initWhenReady(render::ScenePointer scene) { · 13 unmodified lines | ||
| 1365 | 1353 | render::PendingChanges pendingChanges; |
| 1366 | 1354 | |
| 1367 | 1355 | bool addedPendingChanges = false; |
| 1368 | − if (_showCollisionGeometry && _collisionGeometry) { | |
| 1356 | + if (_showCollisionGeometry && _readyToShowCollisionGeometry && _collisionGeometry) { | |
| 1369 | 1357 | foreach (auto renderItem, _collisionRenderItemsSet) { |
| 1370 | 1358 | auto item = scene->allocateID(); |
| 1371 | 1359 | auto renderPayload = std::make_shared<MeshPartPayload::Payload>(renderItem); |
| @@ -1387,7 +1375,7 @@ bool Model::initWhenReady(render::ScenePointer scene) { · 15 unmodified lines | ||
| 1387 | 1375 | scene->enqueuePendingChanges(pendingChanges); |
| 1388 | 1376 | // NOTE: updateRender items enqueues identical pendingChanges (using a lambda) |
| 1389 | 1377 | // so it looks like we're doing double work here, but I don't want to remove the call |
| 1390 | − // for fear there is some sideeffect we'll miss. -- Andrew 2016.07.21 | |
| 1378 | + // for fear there is some side effect we'll miss. -- Andrew 2016.07.21 | |
| 1391 | 1379 | // TODO: figure out if we really need this call to updateRenderItems() or not. |
| 1392 | 1380 | updateRenderItems(); |
| 1393 | 1381 | } |
| @@ -1410,11 +1398,15 @@ void Model::setCollisionMesh(model::MeshPointer mesh) { · 16 unmodified lines | ||
| 1410 | 1398 | _collisionWatcher.stopWatching(); |
| 1411 | 1399 | _collisionGeometry = std::make_shared<CollisionRenderGeometry>(mesh); |
| 1412 | 1400 | |
| 1401 | + // HACK: we don't want to show the _collisionGeometry until we're ready (e.g. it has been created) | |
| 1402 | + // hence we track whether it has been created using _readyToShowCollisionGeoemtry, because there | |
| 1403 | + // is an ambiguous case where _collisionGeometry is valid (from CompoundURL) but has not yet been | |
| 1404 | + // properly computed (zeroed offset transform) using the CollisionRenderMeshCache. | |
| 1405 | + // | |
| 1406 | + // TODO: At the moment we create the collision mesh for every model that has a collision shape | |
| 1407 | + // as soon as we know the shape, but we SHOULD only ever create the render mesh when we need it. | |
| 1413 | 1408 | if (_showCollisionGeometry) { |
| 1414 | 1409 | _needsFixupInScene = true; |
| 1415 | − // TODO: need to trigger: | |
| 1416 | − // (a) reconstruction of RenderItems | |
| 1417 | − // (b) and reinsertion into scene if we are showing collision geometry | |
| 1418 | 1410 | } |
| 1419 | 1411 | } |
| 1420 | 1412 | |