From 1de618ed3eb9cbd13a38324557956b78b91e52bf Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 27 Oct 2014 16:25:26 -0700 Subject: [PATCH] added new light related properties --- .../entities/src/EntityItemProperties.cpp | 65 +++++++++++++++++++ libraries/entities/src/EntityItemProperties.h | 51 +++++++++++++-- 2 files changed, 112 insertions(+), 4 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 3c3729e436..8c07091b53 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -79,6 +79,24 @@ EntityItemProperties::EntityItemProperties() : _animationFPSChanged(false), _glowLevelChanged(false), _localRenderAlphaChanged(false), + _isSpotlightChanged(false), + + _ambientColor(), + _specularColor(), + _constantAttenuation(1.0f), + _linearAttenuation(0.0f), + _quadraticAttenuation(0.0f), + _exponent(0.0f), + _cutoff(PI), + + _ambientColorChanged(false), + _specularColorChanged(false), + _constantAttenuationChanged(false), + _linearAttenuationChanged(false), + _quadraticAttenuationChanged(false), + _exponentChanged(false), + _cutoffChanged(false), + _defaultSettings(true) { } @@ -121,6 +139,13 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_IGNORE_FOR_COLLISIONS, ignoreForCollisions); CHECK_PROPERTY_CHANGE(PROP_COLLISIONS_WILL_MOVE, collisionsWillMove); CHECK_PROPERTY_CHANGE(PROP_IS_SPOTLIGHT, isSpotlight); + CHECK_PROPERTY_CHANGE(PROP_AMBIENT_COLOR, ambientColor); + CHECK_PROPERTY_CHANGE(PROP_SPECULAR_COLOR, specularColor); + CHECK_PROPERTY_CHANGE(PROP_CONSTANT_ATTENUATION, constantAttenuation); + CHECK_PROPERTY_CHANGE(PROP_LINEAR_ATTENUATION, linearAttenuation); + CHECK_PROPERTY_CHANGE(PROP_QUADRATIC_ATTENUATION, quadraticAttenuation); + CHECK_PROPERTY_CHANGE(PROP_EXPONENT, exponent); + CHECK_PROPERTY_CHANGE(PROP_CUTOFF, cutoff); return changedProperties; } @@ -164,6 +189,16 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons COPY_PROPERTY_TO_QSCRIPTVALUE(collisionsWillMove); COPY_PROPERTY_TO_QSCRIPTVALUE(isSpotlight); + // NOTE: we do want this, so we will read both aliases diffuseColor and color + COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(diffuseColor, getDiffuseColor()); + COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(ambientColor, getAmbientColor()); + COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(specularColor, getSpecularColor()); + COPY_PROPERTY_TO_QSCRIPTVALUE(constantAttenuation); + COPY_PROPERTY_TO_QSCRIPTVALUE(linearAttenuation); + COPY_PROPERTY_TO_QSCRIPTVALUE(quadraticAttenuation); + COPY_PROPERTY_TO_QSCRIPTVALUE(exponent); + COPY_PROPERTY_TO_QSCRIPTVALUE(cutoff); + // Sitting properties support QScriptValue sittingPoints = engine->newObject(); for (int i = 0; i < _sittingPoints.size(); ++i) { @@ -223,6 +258,14 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE_BOOL(ignoreForCollisions, setIgnoreForCollisions); COPY_PROPERTY_FROM_QSCRIPTVALUE_BOOL(collisionsWillMove, setCollisionsWillMove); COPY_PROPERTY_FROM_QSCRIPTVALUE_BOOL(isSpotlight, setIsSpotlight); + COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(diffuseColor, setDiffuseColor); + COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(ambientColor, setAmbientColor); + COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(specularColor, setSpecularColor); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(constantAttenuation, setConstantAttenuation); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(linearAttenuation, setLinearAttenuation); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(quadraticAttenuation, setQuadraticAttenuation); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(exponent, setExponent); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(cutoff, setCutoff); _lastEdited = usecTimestampNow(); } @@ -374,6 +417,13 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_IGNORE_FOR_COLLISIONS, appendValue, properties.getIgnoreForCollisions()); APPEND_ENTITY_PROPERTY(PROP_COLLISIONS_WILL_MOVE, appendValue, properties.getCollisionsWillMove()); APPEND_ENTITY_PROPERTY(PROP_IS_SPOTLIGHT, appendValue, properties.getIsSpotlight()); + APPEND_ENTITY_PROPERTY(PROP_AMBIENT_COLOR, appendColor, properties.getAmbientColor()); + APPEND_ENTITY_PROPERTY(PROP_SPECULAR_COLOR, appendColor, properties.getSpecularColor()); + APPEND_ENTITY_PROPERTY(PROP_CONSTANT_ATTENUATION, appendValue, properties.getConstantAttenuation()); + APPEND_ENTITY_PROPERTY(PROP_LINEAR_ATTENUATION, appendValue, properties.getLinearAttenuation()); + APPEND_ENTITY_PROPERTY(PROP_QUADRATIC_ATTENUATION, appendValue, properties.getQuadraticAttenuation()); + APPEND_ENTITY_PROPERTY(PROP_EXPONENT, appendValue, properties.getExponent()); + APPEND_ENTITY_PROPERTY(PROP_CUTOFF, appendValue, properties.getCutoff()); } if (propertyCount > 0) { int endOfEntityItemData = packetData->getUncompressedByteOffset(); @@ -573,6 +623,13 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_IGNORE_FOR_COLLISIONS, bool, setIgnoreForCollisions); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLLISIONS_WILL_MOVE, bool, setCollisionsWillMove); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_IS_SPOTLIGHT, bool, setIsSpotlight); + READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_AMBIENT_COLOR, setAmbientColor); + READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_SPECULAR_COLOR, setSpecularColor); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_CONSTANT_ATTENUATION, float, setConstantAttenuation); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINEAR_ATTENUATION, float, setLinearAttenuation); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_QUADRATIC_ATTENUATION, float, setQuadraticAttenuation); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EXPONENT, float, setExponent); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_CUTOFF, float, setCutoff); return valid; } @@ -628,6 +685,14 @@ void EntityItemProperties::markAllChanged() { _glowLevelChanged = true; _localRenderAlphaChanged = true; _isSpotlightChanged = true; + + _ambientColorChanged = true; + _specularColorChanged = true; + _constantAttenuationChanged = true; + _linearAttenuationChanged = true; + _quadraticAttenuationChanged = true; + _exponentChanged = true; + _cutoffChanged = true; } AACube EntityItemProperties::getMaximumAACubeInTreeUnits() const { diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 699aa5a612..1867c2e900 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -248,9 +248,36 @@ public: void setIsSpotlight(bool value) { _isSpotlight = value; _isSpotlightChanged = true; } // total hack for now - void setDiffuseColor(const xColor& value) { setColor(value); } - void setAmbientColor(const xColor& value) { setColor(value); } - void setSpecularColor(const xColor& value) { setColor(value); } + //void setDiffuseColor(const xColor& value) { setColor(value); } + //void setAmbientColor(const xColor& value) { setColor(value); } + //void setSpecularColor(const xColor& value) { setColor(value); } + + xColor getDiffuseColor() const { return _color; } // diffuseColor is an alias for color + xColor getAmbientColor() const { return _ambientColor; } + xColor getSpecularColor() const { return _specularColor; } + + void setDiffuseColor(const xColor& value) { _color = value; _colorChanged = true; } + void setAmbientColor(const xColor& value) { _ambientColor = value; _ambientColorChanged = true; } + void setSpecularColor(const xColor& value) { _specularColor = value; _specularColorChanged = true; } + + bool diffuseColorChanged() const { return _colorChanged; } + bool ambientColorChanged() const { return _ambientColorChanged; } + bool specularColorChanged() const { return _specularColorChanged; } + + bool getConstantAttenuation() const { return _constantAttenuation; } + void setConstantAttenuation(float value) { _constantAttenuation = value; _constantAttenuationChanged = true; } + + bool getLinearAttenuation() const { return _linearAttenuation; } + void setLinearAttenuation(float value) { _linearAttenuation = value; _linearAttenuationChanged = true; } + + bool getQuadraticAttenuation() const { return _quadraticAttenuation; } + void setQuadraticAttenuation(float value) { _quadraticAttenuation = value; _quadraticAttenuationChanged = true; } + + bool getExponent() const { return _exponent; } + void setExponent(bool value) { _exponent = value; _exponentChanged = true; } + + bool getCutoff() const { return _cutoff; } + void setCutoff(bool value) { _cutoff = value; _cutoffChanged = true; } void setLastEdited(quint64 usecTime) { _lastEdited = usecTime; } @@ -308,9 +335,11 @@ private: float _glowLevel; float _localRenderAlpha; bool _isSpotlight; + + // TODO: for some reason if you add anything before _sittingPoints in this class, you'll get crashes + // it's not clear to me why this is, but we should research it and fix whatever the underlying problem is QVector _sittingPoints; glm::vec3 _naturalDimensions; - bool _colorChanged; bool _modelURLChanged; @@ -321,8 +350,22 @@ private: bool _glowLevelChanged; bool _localRenderAlphaChanged; bool _isSpotlightChanged; + + xColor _ambientColor; + xColor _specularColor; + float _constantAttenuation; + float _linearAttenuation; + float _quadraticAttenuation; + float _exponent; + float _cutoff; + bool _ambientColorChanged; bool _specularColorChanged; + bool _constantAttenuationChanged; + bool _linearAttenuationChanged; + bool _quadraticAttenuationChanged; + bool _exponentChanged; + bool _cutoffChanged; bool _defaultSettings; };