History

Merge remote-tracking branch 'samuel/scriptableMaterials' into Leopoly_Phase1_010_graphics-scripting-merge

humbletim committed 8 years ago

Commit 72fca7e2 parents be8d79f 4c6169e498 files · +18323 −41125Browse files

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

Unified · Split

libraries/render-utils/src/Model.cpp+107−17
@@ -273,8 +273,10 @@ void Model::updateRenderItems() { · 272 unmodified lines
273273
274274 bool isWireframe = self->isWireframe();
275275 bool isVisible = self->isVisible();
276+ uint8_t viewTagBits = self->getViewTagBits();
276277 bool isLayeredInFront = self->isLayeredInFront();
277278 bool isLayeredInHUD = self->isLayeredInHUD();
279+ bool isGroupCulled = self->isGroupCulled();
278280
279281 render::Transaction transaction;
280282 for (int i = 0; i < (int) self->_modelMeshRenderItemIDs.size(); i++) {
@@ -285,8 +287,10 @@ void Model::updateRenderItems() { · 4 unmodified lines
285287
286288 bool invalidatePayloadShapeKey = self->shouldInvalidatePayloadShapeKey(meshIndex);
287289
288− transaction.updateItem<ModelMeshPartPayload>(itemID, [modelTransform, clusterTransforms, invalidatePayloadShapeKey,
289− isWireframe, isVisible, isLayeredInFront, isLayeredInHUD](ModelMeshPartPayload& data) {
290+ transaction.updateItem<ModelMeshPartPayload>(itemID, [modelTransform, clusterTransforms,
291+ invalidatePayloadShapeKey, isWireframe, isVisible,
292+ viewTagBits, isLayeredInFront,
293+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
290294 data.updateClusterBuffer(clusterTransforms);
291295
292296 Transform renderTransform = modelTransform;
@@ -302,7 +306,7 @@ void Model::updateRenderItems() { · 9 unmodified lines
302306 }
303307 data.updateTransformForSkinnedMesh(renderTransform, modelTransform);
304308
305− data.setKey(isVisible, isLayeredInFront || isLayeredInHUD);
309+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
306310 data.setLayer(isLayeredInFront, isLayeredInHUD);
307311 data.setShapeKey(invalidatePayloadShapeKey, isWireframe);
308312 });
@@ -694,22 +698,26 @@ void Model::calculateTriangleSets() { · 385 unmodified lines
694698 }
695699 }
696700
697−void Model::setVisibleInScene(bool isVisible, const render::ScenePointer& scene) {
698− if (_isVisible != isVisible) {
701+void Model::setVisibleInScene(bool isVisible, const render::ScenePointer& scene, uint8_t viewTagBits, bool isGroupCulled) {
702+ if (_isVisible != isVisible || _viewTagBits != viewTagBits || _isGroupCulled != isGroupCulled) {
699703 _isVisible = isVisible;
704+ _viewTagBits = viewTagBits;
705+ _isGroupCulled = isGroupCulled;
700706
701707 bool isLayeredInFront = _isLayeredInFront;
702708 bool isLayeredInHUD = _isLayeredInHUD;
703709
704710 render::Transaction transaction;
705711 foreach (auto item, _modelMeshRenderItemsMap.keys()) {
706− transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, isLayeredInFront, isLayeredInHUD](ModelMeshPartPayload& data) {
707− data.setKey(isVisible, isLayeredInFront || isLayeredInHUD);
712+ transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
713+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
714+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
708715 });
709716 }
710717 foreach(auto item, _collisionRenderItemsMap.keys()) {
711− transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, isLayeredInFront, isLayeredInHUD](ModelMeshPartPayload& data) {
712− data.setKey(isVisible, isLayeredInFront || isLayeredInHUD);
718+ transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
719+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
720+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
713721 });
714722 }
715723 scene->enqueueTransaction(transaction);
@@ -722,18 +730,22 @@ void Model::setLayeredInFront(bool isLayeredInFront, const render::ScenePointer& · 6 unmodified lines
722730 _isLayeredInFront = isLayeredInFront;
723731
724732 bool isVisible = _isVisible;
733+ uint8_t viewTagBits = _viewTagBits;
725734 bool isLayeredInHUD = _isLayeredInHUD;
735+ bool isGroupCulled = _isGroupCulled;
726736
727737 render::Transaction transaction;
728738 foreach(auto item, _modelMeshRenderItemsMap.keys()) {
729− transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, isLayeredInFront, isLayeredInHUD](ModelMeshPartPayload& data) {
730− data.setKey(isVisible, isLayeredInFront || isLayeredInHUD);
739+ transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
740+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
741+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
731742 data.setLayer(isLayeredInFront, isLayeredInHUD);
732743 });
733744 }
734745 foreach(auto item, _collisionRenderItemsMap.keys()) {
735− transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, isLayeredInFront, isLayeredInHUD](ModelMeshPartPayload& data) {
736− data.setKey(isVisible, isLayeredInFront || isLayeredInHUD);
746+ transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
747+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
748+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
737749 data.setLayer(isLayeredInFront, isLayeredInHUD);
738750 });
739751 }
@@ -746,18 +758,22 @@ void Model::setLayeredInHUD(bool isLayeredInHUD, const render::ScenePointer& sce · 6 unmodified lines
746758 _isLayeredInHUD = isLayeredInHUD;
747759
748760 bool isVisible = _isVisible;
761+ uint8_t viewTagBits = _viewTagBits;
749762 bool isLayeredInFront = _isLayeredInFront;
763+ bool isGroupCulled = _isGroupCulled;
750764
751765 render::Transaction transaction;
752766 foreach(auto item, _modelMeshRenderItemsMap.keys()) {
753− transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, isLayeredInFront, isLayeredInHUD](ModelMeshPartPayload& data) {
754− data.setKey(isVisible, isLayeredInFront || isLayeredInHUD);
767+ transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
768+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
769+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
755770 data.setLayer(isLayeredInFront, isLayeredInHUD);
756771 });
757772 }
758773 foreach(auto item, _collisionRenderItemsMap.keys()) {
759− transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, isLayeredInFront, isLayeredInHUD](ModelMeshPartPayload& data) {
760− data.setKey(isVisible, isLayeredInFront || isLayeredInHUD);
774+ transaction.updateItem<ModelMeshPartPayload>(item, [isVisible, viewTagBits, isLayeredInFront,
775+ isLayeredInHUD, isGroupCulled](ModelMeshPartPayload& data) {
776+ data.updateKey(isVisible, isLayeredInFront || isLayeredInHUD, viewTagBits, isGroupCulled);
761777 data.setLayer(isLayeredInFront, isLayeredInHUD);
762778 });
763779 }
@@ -829,6 +845,7 @@ void Model::removeFromScene(const render::ScenePointer& scene, render::Transacti · 65 unmodified lines
829845 _modelMeshRenderItemIDs.clear();
830846 _modelMeshRenderItemsMap.clear();
831847 _modelMeshRenderItems.clear();
848+ _modelMeshMaterialNames.clear();
832849 _modelMeshRenderItemShapes.clear();
833850
834851 foreach(auto item, _collisionRenderItemsMap.keys()) {
@@ -1457,6 +1474,7 @@ void Model::createVisibleRenderItemSet() { · 622 unmodified lines
14571474 Q_ASSERT(_modelMeshRenderItems.isEmpty());
14581475
14591476 _modelMeshRenderItems.clear();
1477+ _modelMeshMaterialNames.clear();
14601478 _modelMeshRenderItemShapes.clear();
14611479
14621480 Transform transform;
@@ -1480,6 +1498,7 @@ void Model::createVisibleRenderItemSet() { · 17 unmodified lines
14801498 int numParts = (int)mesh->getNumParts();
14811499 for (int partIndex = 0; partIndex < numParts; partIndex++) {
14821500 _modelMeshRenderItems << std::make_shared<ModelMeshPartPayload>(shared_from_this(), i, partIndex, shapeID, transform, offset);
1501+ _modelMeshMaterialNames.push_back(getGeometry()->getShapeMaterial(shapeID)->getName());
14831502 _modelMeshRenderItemShapes.emplace_back(ShapeInfo{ (int)i });
14841503 shapeID++;
14851504 }
@@ -1525,6 +1544,77 @@ bool Model::isRenderable() const { · 39 unmodified lines
15251544 return !_meshStates.empty() || (isLoaded() && _renderGeometry->getMeshes().empty());
15261545 }
15271546
1547+std::vector<unsigned int> Model::getMeshIDsFromMaterialID(QString parentMaterialName) {
1548+ // try to find all meshes with materials that match parentMaterialName as a string
1549+ // if none, return parentMaterialName as a uint
1550+ std::vector<unsigned int> toReturn;
1551+ const QString MATERIAL_NAME_PREFIX = "mat::";
1552+ if (parentMaterialName.startsWith(MATERIAL_NAME_PREFIX)) {
1553+ parentMaterialName.replace(0, MATERIAL_NAME_PREFIX.size(), QString(""));
1554+ for (unsigned int i = 0; i < (unsigned int)_modelMeshMaterialNames.size(); i++) {
1555+ if (_modelMeshMaterialNames[i] == parentMaterialName.toStdString()) {
1556+ toReturn.push_back(i);
1557+ }
1558+ }
1559+ }
1560+
1561+ if (toReturn.empty()) {
1562+ toReturn.push_back(parentMaterialName.toUInt());
1563+ }
1564+
1565+ return toReturn;
1566+}
1567+
1568+void Model::addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName) {
1569+ std::vector<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str()));
1570+ render::Transaction transaction;
1571+ for (auto shapeID : shapeIDs) {
1572+ if (shapeID < _modelMeshRenderItemIDs.size()) {
1573+ auto itemID = _modelMeshRenderItemIDs[shapeID];
1574+ bool visible = isVisible();
1575+ uint8_t viewTagBits = getViewTagBits();
1576+ bool layeredInFront = isLayeredInFront();
1577+ bool layeredInHUD = isLayeredInHUD();
1578+ bool wireframe = isWireframe();
1579+ auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex;
1580+ bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
1581+ transaction.updateItem<ModelMeshPartPayload>(itemID, [material, visible, layeredInFront, layeredInHUD, viewTagBits,
1582+ invalidatePayloadShapeKey, wireframe](ModelMeshPartPayload& data) {
1583+ data.addMaterial(material);
1584+ // if the material changed, we might need to update our item key or shape key
1585+ data.updateKey(visible, layeredInFront || layeredInHUD, viewTagBits);
1586+ data.setShapeKey(invalidatePayloadShapeKey, wireframe);
1587+ });
1588+ }
1589+ }
1590+ AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction);
1591+}
1592+
1593+void Model::removeMaterial(graphics::MaterialPointer material, const std::string& parentMaterialName) {
1594+ std::vector<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str()));
1595+ render::Transaction transaction;
1596+ for (auto shapeID : shapeIDs) {
1597+ if (shapeID < _modelMeshRenderItemIDs.size()) {
1598+ auto itemID = _modelMeshRenderItemIDs[shapeID];
1599+ bool visible = isVisible();
1600+ uint8_t viewTagBits = getViewTagBits();
1601+ bool layeredInFront = isLayeredInFront();
1602+ bool layeredInHUD = isLayeredInHUD();
1603+ bool wireframe = isWireframe();
1604+ auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex;
1605+ bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
1606+ transaction.updateItem<ModelMeshPartPayload>(itemID, [material, visible, layeredInFront, layeredInHUD, viewTagBits,
1607+ invalidatePayloadShapeKey, wireframe](ModelMeshPartPayload& data) {
1608+ data.removeMaterial(material);
1609+ // if the material changed, we might need to update our item key or shape key
1610+ data.updateKey(visible, layeredInFront || layeredInHUD, viewTagBits);
1611+ data.setShapeKey(invalidatePayloadShapeKey, wireframe);
1612+ });
1613+ }
1614+ }
1615+ AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction);
1616+}
1617+
15281618 class CollisionRenderGeometry : public Geometry {
15291619 public:
15301620 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