From 95c5b417c9244f943aeceb222a8a86bb98149835 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 30 Oct 2014 11:04:19 -0700 Subject: [PATCH] texture support in model entities --- examples/editModels.js | 33 ------------------- examples/libraries/entityPropertyDialogBox.js | 3 ++ .../entities/RenderableModelEntityItem.cpp | 19 +++++++++-- .../entities/src/EntityItemProperties.cpp | 2 ++ libraries/entities/src/ModelEntityItem.cpp | 27 ++++++++------- libraries/entities/src/ModelEntityItem.h | 9 ++++- 6 files changed, 43 insertions(+), 50 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index dde12d47b3..d0e69807aa 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -2988,36 +2988,3 @@ Controller.keyReleaseEvent.connect(function (event) { } }); -Window.inlineButtonClicked.connect(function (name) { - if (name == "resetDimensions") { - var decimals = 3; - Window.reloadNonBlockingForm([ - { value: propertiesForEditedEntity.naturalDimensions.x.toFixed(decimals), oldIndex: dimensionX }, - { value: propertiesForEditedEntity.naturalDimensions.y.toFixed(decimals), oldIndex: dimensionY }, - { value: propertiesForEditedEntity.naturalDimensions.z.toFixed(decimals), oldIndex: dimensionZ } - ]); - } - - if (name == "rescaleDimensions") { - var decimals = 3; - var peekValues = editEntityFormArray; - Window.peekNonBlockingFormResult(peekValues); - var peekX = peekValues[dimensionX].value; - var peekY = peekValues[dimensionY].value; - var peekZ = peekValues[dimensionZ].value; - var peekRescale = peekValues[rescalePercentage].value; - var rescaledX = peekX * peekRescale / 100.0; - var rescaledY = peekY * peekRescale / 100.0; - var rescaledZ = peekZ * peekRescale / 100.0; - - Window.reloadNonBlockingForm([ - { value: rescaledX.toFixed(decimals), oldIndex: dimensionX }, - { value: rescaledY.toFixed(decimals), oldIndex: dimensionY }, - { value: rescaledZ.toFixed(decimals), oldIndex: dimensionZ }, - { value: 100, oldIndex: rescalePercentage } - ]); - } - -}); - - diff --git a/examples/libraries/entityPropertyDialogBox.js b/examples/libraries/entityPropertyDialogBox.js index 0246e9e800..2c4bf5329e 100644 --- a/examples/libraries/entityPropertyDialogBox.js +++ b/examples/libraries/entityPropertyDialogBox.js @@ -52,6 +52,8 @@ EntityPropertyDialogBox = (function () { index++; array.push({ label: "Animation Frame:", value: properties.animationFrameIndex }); index++; + array.push({ label: "Textures:", value: properties.textures }); + index++; } array.push({ label: "Position:", type: "header" }); index++; @@ -233,6 +235,7 @@ EntityPropertyDialogBox = (function () { properties.animationIsPlaying = array[index++].value; properties.animationFPS = array[index++].value; properties.animationFrameIndex = array[index++].value; + properties.textures = array[index++].value; } index++; // skip header properties.position.x = array[index++].value; diff --git a/interface/src/entities/RenderableModelEntityItem.cpp b/interface/src/entities/RenderableModelEntityItem.cpp index 50bf947955..5a3ee61bbe 100644 --- a/interface/src/entities/RenderableModelEntityItem.cpp +++ b/interface/src/entities/RenderableModelEntityItem.cpp @@ -38,9 +38,12 @@ RenderableModelEntityItem::~RenderableModelEntityItem() { bool RenderableModelEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { QString oldModelURL = getModelURL(); + QString oldTextures = getTextures(); bool somethingChanged = ModelEntityItem::setProperties(properties, forceCopy); - if (somethingChanged && oldModelURL != getModelURL()) { - _needsModelReload = true; + if (somethingChanged) { + if ((oldModelURL != getModelURL()) || (oldTextures != getTextures())) { + _needsModelReload = true; + } } return somethingChanged; } @@ -180,6 +183,18 @@ Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) { } } + // here's where we remap any textures if needed... + if (!_textures.isEmpty() && _model) { + QJsonDocument texturesAsJson = QJsonDocument::fromJson(_textures.toUtf8()); + QJsonObject texturesAsJsonObject = texturesAsJson.object(); + QVariantMap textureMap = texturesAsJsonObject.toVariantMap(); + foreach(const QString& key, textureMap.keys()) { + QUrl newTextureURL = textureMap[key].toUrl(); + qDebug() << "Updating texture named" << key << "to texture at URL" << newTextureURL; + _model->setTextureWithNameToURL(key, newTextureURL); + } + } + return result; } diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 11661b02f4..ced5090ab6 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -288,6 +288,8 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(cutoff, setCutoff); COPY_PROPERTY_FROM_QSCRIPTVALUE_BOOL(locked, setLocked); COPY_PROPERTY_FROM_QSCRIPTVALUE_STRING(textures, setTextures); + +qDebug() << "COPY_PROPERTY_FROM_QSCRIPTVALUE_STRING.... textures: " << getTextures(); _lastEdited = usecTimestampNow(); } diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 83958c329b..827f4f7e39 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -41,20 +41,15 @@ ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityI EntityItemProperties ModelEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - properties._color = getXColor(); - properties._modelURL = getModelURL(); - properties._animationURL = getAnimationURL(); - properties._animationIsPlaying = getAnimationIsPlaying(); - properties._animationFrameIndex = getAnimationFrameIndex(); - properties._animationFPS = getAnimationFPS(); - properties._colorChanged = false; - properties._modelURLChanged = false; - properties._animationURLChanged = false; - properties._animationIsPlayingChanged = false; - properties._animationFrameIndexChanged = false; - properties._animationFPSChanged = false; - properties._glowLevel = getGlowLevel(); - properties._glowLevelChanged = false; + + COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(modelURL, getModelURL); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(animationURL, getAnimationURL); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(animationIsPlaying, getAnimationIsPlaying); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(animationFrameIndex, getAnimationFrameIndex); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(animationFPS, getAnimationFPS); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(glowLevel, getGlowLevel); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(textures, getTextures); return properties; } @@ -68,6 +63,7 @@ bool ModelEntityItem::setProperties(const EntityItemProperties& properties, bool SET_ENTITY_PROPERTY_FROM_PROPERTIES(animationIsPlaying, setAnimationIsPlaying); SET_ENTITY_PROPERTY_FROM_PROPERTIES(animationFrameIndex, setAnimationFrameIndex); SET_ENTITY_PROPERTY_FROM_PROPERTIES(animationFPS, setAnimationFPS); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(textures, setTextures); if (somethingChanged) { bool wantDebug = false; @@ -107,6 +103,7 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float, _animationFPS); READ_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float, _animationFrameIndex); READ_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool, _animationIsPlaying); + READ_ENTITY_PROPERTY_STRING(PROP_TEXTURES, setTextures); return bytesRead; } @@ -230,6 +227,7 @@ EntityPropertyFlags ModelEntityItem::getEntityProperties(EncodeBitstreamParams& requestedProperties += PROP_ANIMATION_FPS; requestedProperties += PROP_ANIMATION_FRAME_INDEX; requestedProperties += PROP_ANIMATION_PLAYING; + requestedProperties += PROP_TEXTURES; return requestedProperties; } @@ -250,6 +248,7 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FPS, appendValue, getAnimationFPS()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, appendValue, getAnimationFrameIndex()); APPEND_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, appendValue, getAnimationIsPlaying()); + APPEND_ENTITY_PROPERTY(PROP_TEXTURES, appendValue, getTextures()); } diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 4ed47d4894..4c79a46c5e 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -88,6 +88,10 @@ public: bool getAnimationIsPlaying() const { return _animationIsPlaying; } float getAnimationFrameIndex() const { return _animationFrameIndex; } float getAnimationFPS() const { return _animationFPS; } + + static const QString DEFAULT_TEXTURES; + const QString& getTextures() const { return _textures; } + void setTextures(const QString& textures) { _textures = textures; } static void cleanupLoadedAnimations(); @@ -105,9 +109,12 @@ protected: float _animationFrameIndex; // we keep this as a float and round to int only when we need the exact index bool _animationIsPlaying; float _animationFPS; + QString _textures; + + // used on client side bool _jointMappingCompleted; QVector _jointMapping; - + static Animation* getAnimation(const QString& url); static QMap _loadedAnimations; static AnimationCache _animationCache;