texture support in model entities

This commit is contained in:
ZappoMan 2014-10-30 11:04:19 -07:00
parent c650cabb5d
commit 95c5b417c9
6 changed files with 43 additions and 50 deletions

View file

@ -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 }
]);
}
});

View file

@ -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;

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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());
}

View file

@ -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<int> _jointMapping;
static Animation* getAnimation(const QString& url);
static QMap<QString, AnimationPointer> _loadedAnimations;
static AnimationCache _animationCache;