History

Merge branch 'master' into bug-fix/entity-mat-avatar-dual-quaternions

Anthony J. Thibault committed 8 years ago

Commit 86351f12 parents d2c1991 3764502268 files · +12812 −5797Browse files

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

Unified · Split

libraries/render-utils/src/Model.cpp+94−16
@@ -271,6 +271,7 @@ void Model::updateRenderItems() { · 270 unmodified lines
271271 uint8_t viewTagBits = self->getViewTagBits();
272272 bool isLayeredInFront = self->isLayeredInFront();
273273 bool isLayeredInHUD = self->isLayeredInHUD();
274+ bool isGroupCulled = self->isGroupCulled();
274275
275276 render::Transaction transaction;
276277 for (int i = 0; i < (int) self->_modelMeshRenderItemIDs.size(); i++) {
@@ -286,7 +287,7 @@ void Model::updateRenderItems() { · 9 unmodified lines
286287 transaction.updateItem<ModelMeshPartPayload>(itemID, [modelTransform, meshState, useDualQuaternionSkinning,
287288 invalidatePayloadShapeKey, isWireframe, isVisible,
288289 viewTagBits, isLayeredInFront,
289− isLayeredInHUD](ModelMeshPartPayload& data) {
290+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
290291 if (useDualQuaternionSkinning) {
291292 data.updateClusterBuffer(meshState.clusterDualQuaternions);
292293 } else {
@@ -310,7 +311,7 @@ void Model::updateRenderItems() { · 17 unmodified lines
310311 }
311312 data.updateTransformForSkinnedMesh(renderTransform, modelTransform);
312313
313− data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits);
314+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
314315 data.setLayer(isLayeredInFront, isLayeredInHUD);
315316 data.setShapeKey(invalidatePayloadShapeKey, isWireframe);
316317 });
@@ -698,10 +699,11 @@ void Model::calculateTriangleSets() { · 381 unmodified lines
698699 }
699700 }
700701
701−void Model::setVisibleInScene(bool isVisible, const render::ScenePointer& scene, uint8_t viewTagBits) {
702− if (_isVisible != isVisible || _viewTagBits != viewTagBits) {
702+void Model::setVisibleInScene(bool isVisible, const render::ScenePointer& scene, uint8_t viewTagBits, bool isGroupCulled) {
703+ if (_isVisible != isVisible || _viewTagBits != viewTagBits || _isGroupCulled != isGroupCulled) {
703704 _isVisible = isVisible;
704705 _viewTagBits = viewTagBits;
706+ _isGroupCulled = isGroupCulled;
705707
706708 bool isLayeredInFront = _isLayeredInFront;
707709 bool isLayeredInHUD = _isLayeredInHUD;
@@ -709,14 +711,14 @@ void Model::setVisibleInScene(bool isVisible, const render::ScenePointer& scene, · 1 unmodified line
709711 render::Transaction transaction;
710712 foreach (auto item, _modelMeshRenderItemsMap.keys()) {
711713 transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
712− isLayeredInHUD](ModelMeshPartPayload& data) {
713− data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits);
714+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
715+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
714716 });
715717 }
716718 foreach(auto item, _collisionRenderItemsMap.keys()) {
717719 transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
718− isLayeredInHUD](ModelMeshPartPayload& data) {
719− data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits);
720+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
721+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
720722 });
721723 }
722724 scene->enqueueTransaction(transaction);
@@ -731,19 +733,20 @@ void Model::setLayeredInFront(bool isLayeredInFront, const render::ScenePointer& · 8 unmodified lines
731733 bool isVisible = _isVisible;
732734 uint8_t viewTagBits = _viewTagBits;
733735 bool isLayeredInHUD = _isLayeredInHUD;
736+ bool isGroupCulled = _isGroupCulled;
734737
735738 render::Transaction transaction;
736739 foreach(auto item, _modelMeshRenderItemsMap.keys()) {
737740 transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
738− isLayeredInHUD](ModelMeshPartPayload& data) {
739− data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits);
741+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
742+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
740743 data.setLayer(isLayeredInFront, isLayeredInHUD);
741744 });
742745 }
743746 foreach(auto item, _collisionRenderItemsMap.keys()) {
744747 transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
745− isLayeredInHUD](ModelMeshPartPayload& data) {
746− data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits);
748+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
749+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
747750 data.setLayer(isLayeredInFront, isLayeredInHUD);
748751 });
749752 }
@@ -758,19 +761,20 @@ void Model::setLayeredInHUD(bool isLayeredInHUD, const render::ScenePointer& sce · 8 unmodified lines
758761 bool isVisible = _isVisible;
759762 uint8_t viewTagBits = _viewTagBits;
760763 bool isLayeredInFront = _isLayeredInFront;
764+ bool isGroupCulled = _isGroupCulled;
761765
762766 render::Transaction transaction;
763767 foreach(auto item, _modelMeshRenderItemsMap.keys()) {
764768 transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
765− isLayeredInHUD](ModelMeshPartPayload& data) {
766− data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits);
769+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
770+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
767771 data.setLayer(isLayeredInFront, isLayeredInHUD);
768772 });
769773 }
770774 foreach(auto item, _collisionRenderItemsMap.keys()) {
771775 transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
772− isLayeredInHUD](ModelMeshPartPayload& data) {
773− data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits);
776+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
777+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
774778 data.setLayer(isLayeredInFront, isLayeredInHUD);
775779 });
776780 }
@@ -842,6 +846,7 @@ void Model::removeFromScene(const render::ScenePointer& scene, render::Transacti · 65 unmodified lines
842846 _modelMeshRenderItemIDs.clear();
843847 _modelMeshRenderItemsMap.clear();
844848 _modelMeshRenderItems.clear();
849+ _modelMeshMaterialNames.clear();
845850 _modelMeshRenderItemShapes.clear();
846851
847852 foreach(auto item, _collisionRenderItemsMap.keys()) {
@@ -1474,6 +1479,7 @@ void Model::createVisibleRenderItemSet() { · 626 unmodified lines
14741479 Q_ASSERT(_modelMeshRenderItems.isEmpty());
14751480
14761481 _modelMeshRenderItems.clear();
1482+ _modelMeshMaterialNames.clear();
14771483 _modelMeshRenderItemShapes.clear();
14781484
14791485 Transform transform;
@@ -1497,6 +1503,7 @@ void Model::createVisibleRenderItemSet() { · 17 unmodified lines
14971503 int numParts = (int)mesh->getNumParts();
14981504 for (int partIndex = 0; partIndex < numParts; partIndex++) {
14991505 _modelMeshRenderItems << std::make_shared<ModelMeshPartPayload>(shared_from_this(), i, partIndex, shapeID, transform, offset);
1506+ _modelMeshMaterialNames.push_back(getGeometry()->getShapeMaterial(shapeID)->getName());
15001507 _modelMeshRenderItemShapes.emplace_back(ShapeInfo{ (int)i });
15011508 shapeID++;
15021509 }
@@ -1542,6 +1549,77 @@ bool Model::isRenderable() const { · 39 unmodified lines
15421549 return !_meshStates.empty() || (isLoaded() && _renderGeometry->getMeshes().empty());
15431550 }
15441551
1552+std::vector<unsigned int> Model::getMeshIDsFromMaterialID(QString parentMaterialName) {
1553+ // try to find all meshes with materials that match parentMaterialName as a string
1554+ // if none, return parentMaterialName as a uint
1555+ std::vector<unsigned int> toReturn;
1556+ const QString MATERIAL_NAME_PREFIX = "mat::";
1557+ if (parentMaterialName.startsWith(MATERIAL_NAME_PREFIX)) {
1558+ parentMaterialName.replace(0, MATERIAL_NAME_PREFIX.size(), QString(""));
1559+ for (unsigned int i = 0; i < (unsigned int)_modelMeshMaterialNames.size(); i++) {
1560+ if (_modelMeshMaterialNames[i] == parentMaterialName.toStdString()) {
1561+ toReturn.push_back(i);
1562+ }
1563+ }
1564+ }
1565+
1566+ if (toReturn.empty()) {
1567+ toReturn.push_back(parentMaterialName.toUInt());
1568+ }
1569+
1570+ return toReturn;
1571+}
1572+
1573+void Model::addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName) {
1574+ std::vector<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str()));
1575+ render::Transaction transaction;
1576+ for (auto shapeID : shapeIDs) {
1577+ if (shapeID < _modelMeshRenderItemIDs.size()) {
1578+ auto itemID = _modelMeshRenderItemIDs[shapeID];
1579+ bool visible = isVisible();
1580+ uint8_t viewTagBits = getViewTagBits();
1581+ bool layeredInFront = isLayeredInFront();
1582+ bool layeredInHUD = isLayeredInHUD();
1583+ bool wireframe = isWireframe();
1584+ auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex;
1585+ bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
1586+ transaction.updateItem<ModelMeshPartPayload>(itemID, [material, visible, layeredInFront, layeredInHUD, viewTagBits,
1587+ invalidatePayloadShapeKey, wireframe](ModelMeshPartPayload& data) {
1588+ data.addMaterial(material);
1589+ // if the material changed, we might need to update our item key or shape key
1590+ data.updateKey(visible, layeredInFront || layeredInHUD, viewTagBits);
1591+ data.setShapeKey(invalidatePayloadShapeKey, wireframe);
1592+ });
1593+ }
1594+ }
1595+ AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction);
1596+}
1597+
1598+void Model::removeMaterial(graphics::MaterialPointer material, const std::string& parentMaterialName) {
1599+ std::vector<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str()));
1600+ render::Transaction transaction;
1601+ for (auto shapeID : shapeIDs) {
1602+ if (shapeID < _modelMeshRenderItemIDs.size()) {
1603+ auto itemID = _modelMeshRenderItemIDs[shapeID];
1604+ bool visible = isVisible();
1605+ uint8_t viewTagBits = getViewTagBits();
1606+ bool layeredInFront = isLayeredInFront();
1607+ bool layeredInHUD = isLayeredInHUD();
1608+ bool wireframe = isWireframe();
1609+ auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex;
1610+ bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
1611+ transaction.updateItem<ModelMeshPartPayload>(itemID, [material, visible, layeredInFront, layeredInHUD, viewTagBits,
1612+ invalidatePayloadShapeKey, wireframe](ModelMeshPartPayload& data) {
1613+ data.removeMaterial(material);
1614+ // if the material changed, we might need to update our item key or shape key
1615+ data.updateKey(visible, layeredInFront || layeredInHUD, viewTagBits);
1616+ data.setShapeKey(invalidatePayloadShapeKey, wireframe);
1617+ });
1618+ }
1619+ }
1620+ AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction);
1621+}
1622+
15451623 class CollisionRenderGeometry : public Geometry {
15461624 public:
15471625 CollisionRenderGeometry(graphics::MeshPointer mesh) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t