From c48d79ad8bfd036223fdf2fe47e26346f0668663 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 7 Nov 2014 09:05:47 -0800 Subject: [PATCH] add gettable feature which lists texture names --- examples/libraries/entityPropertyDialogBox.js | 3 +++ .../entities/RenderableModelEntityItem.cpp | 11 +++++++++ .../src/entities/RenderableModelEntityItem.h | 1 + interface/src/renderer/GeometryCache.cpp | 23 +++++++++++++++++++ interface/src/renderer/GeometryCache.h | 1 + .../entities/src/EntityItemProperties.cpp | 3 +++ libraries/entities/src/EntityItemProperties.h | 4 ++++ 7 files changed, 46 insertions(+) diff --git a/examples/libraries/entityPropertyDialogBox.js b/examples/libraries/entityPropertyDialogBox.js index 01e0c76e0d..cf9cec8d24 100644 --- a/examples/libraries/entityPropertyDialogBox.js +++ b/examples/libraries/entityPropertyDialogBox.js @@ -54,6 +54,8 @@ EntityPropertyDialogBox = (function () { index++; array.push({ label: "Textures:", value: properties.textures }); index++; + array.push({ label: "Texture Names:" + properties.textureNames, type: "header" }); + index++; } array.push({ label: "Position:", type: "header" }); index++; @@ -239,6 +241,7 @@ EntityPropertyDialogBox = (function () { properties.animationFPS = array[index++].value; properties.animationFrameIndex = array[index++].value; properties.textures = array[index++].value; + index++; // skip textureNames label } index++; // skip header properties.position.x = array[index++].value; diff --git a/interface/src/entities/RenderableModelEntityItem.cpp b/interface/src/entities/RenderableModelEntityItem.cpp index ce8d497da3..1900b3facd 100644 --- a/interface/src/entities/RenderableModelEntityItem.cpp +++ b/interface/src/entities/RenderableModelEntityItem.cpp @@ -234,6 +234,17 @@ bool RenderableModelEntityItem::needsSimulation() const { return _needsInitialSimulation || simulationState == Moving || simulationState == Changing; } +EntityItemProperties RenderableModelEntityItem::getProperties() const { + EntityItemProperties properties = ModelEntityItem::getProperties(); // get the properties from our base class + if (_model) { + const QSharedPointer& networkGeometry = _model->getGeometry(); + if (networkGeometry) { + properties.setTextureNames(networkGeometry->getTextureNames()); + } + } + return properties; +} + diff --git a/interface/src/entities/RenderableModelEntityItem.h b/interface/src/entities/RenderableModelEntityItem.h index dbc77b7e48..53ad8243f8 100644 --- a/interface/src/entities/RenderableModelEntityItem.h +++ b/interface/src/entities/RenderableModelEntityItem.h @@ -41,6 +41,7 @@ public: virtual ~RenderableModelEntityItem(); + virtual EntityItemProperties getProperties() const; virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy); virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, diff --git a/interface/src/renderer/GeometryCache.cpp b/interface/src/renderer/GeometryCache.cpp index 1e53d06d7c..6d9c53f42c 100644 --- a/interface/src/renderer/GeometryCache.cpp +++ b/interface/src/renderer/GeometryCache.cpp @@ -734,6 +734,29 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u } } +QStringList NetworkGeometry::getTextureNames() const { + QStringList result; + for (int i = 0; i < _meshes.size(); i++) { + const NetworkMesh& mesh = _meshes[i]; + for (int j = 0; j < mesh.parts.size(); j++) { + const NetworkMeshPart& part = mesh.parts[j]; + + if (!part.diffuseTextureName.isEmpty()) { + result << part.diffuseTextureName; + } + + if (!part.normalTextureName.isEmpty()) { + result << part.normalTextureName; + } + + if (!part.specularTextureName.isEmpty()) { + result << part.specularTextureName; + } + } + } + return result; +} + /// Reads geometry in a worker thread. class GeometryReader : public QRunnable { public: diff --git a/interface/src/renderer/GeometryCache.h b/interface/src/renderer/GeometryCache.h index 72d283c931..28f1341b5f 100644 --- a/interface/src/renderer/GeometryCache.h +++ b/interface/src/renderer/GeometryCache.h @@ -112,6 +112,7 @@ public: virtual void clearLoadPriority(const QPointer& owner); void setTextureWithNameToURL(const QString& name, const QUrl& url); + QStringList getTextureNames() const; protected: diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 11661b02f4..451fffec80 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -243,6 +243,9 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons boundingBox.setProperty("dimensions", boundingBoxDimensions); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(boundingBox, boundingBox); // gettable, but not settable + QString textureNamesList = _textureNames.join(","); + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(textureNames, textureNamesList); // gettable, but not settable + return properties; } diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 92fa344286..3ae2aa9c7a 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -285,6 +285,9 @@ public: const QString& getTextures() const { return _textures; } void setTextures(const QString& value) { _textures = value; _texturesChanged = true; } + + const QStringList& getTextureNames() const { return _textureNames; } + void setTextureNames(const QStringList& value) { _textureNames = value; } void setLastEdited(quint64 usecTime) { _lastEdited = usecTime; } @@ -381,6 +384,7 @@ private: // properties of model geometry. But these properties are not serialized like other properties. QVector _sittingPoints; glm::vec3 _naturalDimensions; + QStringList _textureNames; }; Q_DECLARE_METATYPE(EntityItemProperties); QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties);