diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 8c07091b53..c95ec7cc2d 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -70,7 +70,6 @@ EntityItemProperties::EntityItemProperties() : _localRenderAlpha(1.0f), _isSpotlight(false), - _naturalDimensions(1.0f, 1.0f, 1.0f), _colorChanged(false), _modelURLChanged(false), _animationURLChanged(false), @@ -97,10 +96,28 @@ EntityItemProperties::EntityItemProperties() : _exponentChanged(false), _cutoffChanged(false), - _defaultSettings(true) + _defaultSettings(true), + _sittingPoints(NULL), + _naturalDimensions(1.0f, 1.0f, 1.0f) { + if (_sittingPoints) { + delete _sittingPoints; + _sittingPoints = NULL; + } } +void EntityItemProperties::setSittingPoints(const QVector& sittingPoints) { + if (!_sittingPoints) { + _sittingPoints = new QVector; + } + _sittingPoints->clear(); + + foreach (SittingPoint sitPoint, sittingPoints) { + _sittingPoints->append(sitPoint); + } +} + + void EntityItemProperties::debugDump() const { qDebug() << "EntityItemProperties..."; qDebug() << " _type=" << EntityTypes::getEntityTypeName(_type); @@ -201,14 +218,18 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons // Sitting properties support QScriptValue sittingPoints = engine->newObject(); - for (int i = 0; i < _sittingPoints.size(); ++i) { - QScriptValue sittingPoint = engine->newObject(); - sittingPoint.setProperty("name", _sittingPoints[i].name); - sittingPoint.setProperty("position", vec3toScriptValue(engine, _sittingPoints[i].position)); - sittingPoint.setProperty("rotation", quatToScriptValue(engine, _sittingPoints[i].rotation)); - sittingPoints.setProperty(i, sittingPoint); + if (_sittingPoints) { + for (int i = 0; i < _sittingPoints->size(); ++i) { + QScriptValue sittingPoint = engine->newObject(); + sittingPoint.setProperty("name", _sittingPoints->at(i).name); + sittingPoint.setProperty("position", vec3toScriptValue(engine, _sittingPoints->at(i).position)); + sittingPoint.setProperty("rotation", quatToScriptValue(engine, _sittingPoints->at(i).rotation)); + sittingPoints.setProperty(i, sittingPoint); + } + sittingPoints.setProperty("length", _sittingPoints->size()); + } else { + sittingPoints.setProperty("length", 0); } - sittingPoints.setProperty("length", _sittingPoints.size()); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(sittingPoints, sittingPoints); // gettable, but not settable AABox aaBox = getAABoxInMeters(); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 1867c2e900..3b72ee8111 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -220,8 +220,7 @@ public: void clearID() { _id = UNKNOWN_ENTITY_ID; _idSet = false; } void markAllChanged(); - QVector getSittingPoints() const { return _sittingPoints; } - void setSittingPoints(QVector sittingPoints) { _sittingPoints = sittingPoints; } + void setSittingPoints(const QVector& sittingPoints); const glm::vec3& getNaturalDimensions() const { return _naturalDimensions; } void setNaturalDimensions(const glm::vec3& value) { _naturalDimensions = value; } @@ -336,11 +335,6 @@ private: 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; bool _animationURLChanged; @@ -368,6 +362,11 @@ private: bool _cutoffChanged; bool _defaultSettings; + + // NOTE: The following are pseudo client only properties. They are only used in clients which can access + // properties of model geometry. But these properties are not serialized like other properties. + QVector* _sittingPoints; + glm::vec3 _naturalDimensions; }; Q_DECLARE_METATYPE(EntityItemProperties); QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties); diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index 1dc25494d8..3b58ec01cd 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -50,10 +50,15 @@ LightEntityItem::LightEntityItem(const EntityItemID& entityItemID, const EntityI EntityItemProperties LightEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - properties.setDiffuseColor(getDiffuseXColor()); - properties.setAmbientColor(getAmbientXColor()); - properties.setSpecularColor(getSpecularXColor()); - properties.setIsSpotlight(getIsSpotlight()); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(isSpotlight, getIsSpotlight); + properties.setDiffuseColor(getDiffuseXColor()); // special case + COPY_ENTITY_PROPERTY_TO_PROPERTIES(ambientColor, getAmbientXColor); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(specularColor, getSpecularXColor); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(constantAttenuation, getConstantAttenuation); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(linearAttenuation, getLinearAttenuation); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(quadraticAttenuation, getQuadraticAttenuation); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(exponent, getExponent); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(cutoff, getCutoff); return properties; } @@ -61,11 +66,18 @@ EntityItemProperties LightEntityItem::getProperties() const { bool LightEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { bool somethingChanged = EntityItem::setProperties(properties, forceCopy); // set the properties in our base class + SET_ENTITY_PROPERTY_FROM_PROPERTIES(isSpotlight, setIsSpotlight); SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setDiffuseColor); //SET_ENTITY_PROPERTY_FROM_PROPERTIES(diffuseColor, setDiffuseColor); - //SET_ENTITY_PROPERTY_FROM_PROPERTIES(ambientColor, setAmbientColor); - //SET_ENTITY_PROPERTY_FROM_PROPERTIES(specularColor, setSpecularColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(ambientColor, setAmbientColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(specularColor, setSpecularColor); SET_ENTITY_PROPERTY_FROM_PROPERTIES(isSpotlight, setIsSpotlight); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(constantAttenuation, setConstantAttenuation); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(linearAttenuation, setLinearAttenuation); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(quadraticAttenuation, setQuadraticAttenuation); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(exponent, setExponent); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(cutoff, setCutoff); + if (somethingChanged) { bool wantDebug = false;