fix corruption in sitting points, added additional light properties

This commit is contained in:
ZappoMan 2014-10-28 09:55:13 -07:00
parent 1de618ed3e
commit a516d062a6
3 changed files with 54 additions and 22 deletions

View file

@ -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<SittingPoint>& sittingPoints) {
if (!_sittingPoints) {
_sittingPoints = new QVector<SittingPoint>;
}
_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();

View file

@ -220,8 +220,7 @@ public:
void clearID() { _id = UNKNOWN_ENTITY_ID; _idSet = false; }
void markAllChanged();
QVector<SittingPoint> getSittingPoints() const { return _sittingPoints; }
void setSittingPoints(QVector<SittingPoint> sittingPoints) { _sittingPoints = sittingPoints; }
void setSittingPoints(const QVector<SittingPoint>& 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<SittingPoint> _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<SittingPoint>* _sittingPoints;
glm::vec3 _naturalDimensions;
};
Q_DECLARE_METATYPE(EntityItemProperties);
QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties);

View file

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