From c650cabb5d76e1da033f957cfdac03412097724b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 30 Oct 2014 10:05:20 -0700 Subject: [PATCH] support for locked property, some plumbing for textures property --- examples/editModels.js | 195 +----------------- examples/libraries/entityPropertyDialogBox.js | 12 +- libraries/entities/src/EntityItem.cpp | 6 + libraries/entities/src/EntityItem.h | 5 + .../entities/src/EntityItemProperties.cpp | 16 ++ libraries/entities/src/EntityItemProperties.h | 17 ++ libraries/entities/src/EntityTree.cpp | 31 ++- 7 files changed, 84 insertions(+), 198 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 0a908595a3..dde12d47b3 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -25,6 +25,9 @@ Script.include("libraries/globals.js"); Script.include("libraries/toolBars.js"); +Script.include("libraries/entityPropertyDialogBox.js"); +var entityPropertyDialogBox = EntityPropertyDialogBox; + var windowDimensions = Controller.getViewportDimensions(); var toolIconUrl = HIFI_PUBLIC_BUCKET + "images/tools/"; var toolHeight = 50; @@ -2845,126 +2848,8 @@ var dimensionY; var dimensionZ; var rescalePercentage; -function showPropertiesForm() { - propertiesForEditedEntity = Entities.getEntityProperties(editModelID); - var properties = propertiesForEditedEntity; - - var array = new Array(); - var index = 0; - var decimals = 3; - if (properties.type == "Model") { - array.push({ label: "Model URL:", value: properties.modelURL }); - index++; - array.push({ label: "Animation URL:", value: properties.animationURL }); - index++; - array.push({ label: "Animation is playing:", value: properties.animationIsPlaying }); - index++; - array.push({ label: "Animation FPS:", value: properties.animationFPS }); - index++; - array.push({ label: "Animation Frame:", value: properties.animationFrameIndex }); - index++; - } - array.push({ label: "Position:", type: "header" }); - index++; - array.push({ label: "X:", value: properties.position.x.toFixed(decimals) }); - index++; - array.push({ label: "Y:", value: properties.position.y.toFixed(decimals) }); - index++; - array.push({ label: "Z:", value: properties.position.z.toFixed(decimals) }); - index++; - - array.push({ label: "Registration X:", value: properties.registrationPoint.x.toFixed(decimals) }); - index++; - array.push({ label: "Registration Y:", value: properties.registrationPoint.y.toFixed(decimals) }); - index++; - array.push({ label: "Registration Z:", value: properties.registrationPoint.z.toFixed(decimals) }); - index++; - - array.push({ label: "Rotation:", type: "header" }); - index++; - var angles = Quat.safeEulerAngles(properties.rotation); - array.push({ label: "Pitch:", value: angles.x.toFixed(decimals) }); - index++; - array.push({ label: "Yaw:", value: angles.y.toFixed(decimals) }); - index++; - array.push({ label: "Roll:", value: angles.z.toFixed(decimals) }); - index++; - - array.push({ label: "Dimensions:", type: "header" }); - index++; - array.push({ label: "Width:", value: properties.dimensions.x.toFixed(decimals) }); - dimensionX = index; - index++; - array.push({ label: "Height:", value: properties.dimensions.y.toFixed(decimals) }); - dimensionY = index; - index++; - array.push({ label: "Depth:", value: properties.dimensions.z.toFixed(decimals) }); - dimensionZ = index; - index++; - array.push({ label: "", type: "inlineButton", buttonLabel: "Reset to Natural Dimensions", name: "resetDimensions" }); - index++; - array.push({ label: "Rescale Percentage:", value: 100 }); - rescalePercentage = index; - index++; - array.push({ label: "", type: "inlineButton", buttonLabel: "Rescale", name: "rescaleDimensions" }); - index++; - - array.push({ label: "Velocity:", type: "header" }); - index++; - array.push({ label: "Linear X:", value: properties.velocity.x.toFixed(decimals) }); - index++; - array.push({ label: "Linear Y:", value: properties.velocity.y.toFixed(decimals) }); - index++; - array.push({ label: "Linear Z:", value: properties.velocity.z.toFixed(decimals) }); - index++; - array.push({ label: "Linear Damping:", value: properties.damping.toFixed(decimals) }); - index++; - array.push({ label: "Angular Pitch:", value: properties.angularVelocity.x.toFixed(decimals) }); - index++; - array.push({ label: "Angular Yaw:", value: properties.angularVelocity.y.toFixed(decimals) }); - index++; - array.push({ label: "Angular Roll:", value: properties.angularVelocity.z.toFixed(decimals) }); - index++; - array.push({ label: "Angular Damping:", value: properties.angularDamping.toFixed(decimals) }); - index++; - - array.push({ label: "Gravity X:", value: properties.gravity.x.toFixed(decimals) }); - index++; - array.push({ label: "Gravity Y:", value: properties.gravity.y.toFixed(decimals) }); - index++; - array.push({ label: "Gravity Z:", value: properties.gravity.z.toFixed(decimals) }); - index++; - - array.push({ label: "Collisions:", type: "header" }); - index++; - array.push({ label: "Mass:", value: properties.mass.toFixed(decimals) }); - index++; - array.push({ label: "Ignore for Collisions:", value: properties.ignoreForCollisions }); - index++; - array.push({ label: "Collisions Will Move:", value: properties.collisionsWillMove }); - index++; - - array.push({ label: "Lifetime:", value: properties.lifetime.toFixed(decimals) }); - index++; - - array.push({ label: "Visible:", value: properties.visible }); - index++; - - if (properties.type == "Box" || properties.type == "Sphere") { - array.push({ label: "Color:", type: "header" }); - index++; - array.push({ label: "Red:", value: properties.color.red }); - index++; - array.push({ label: "Green:", value: properties.color.green }); - index++; - array.push({ label: "Blue:", value: properties.color.blue }); - index++; - } - array.push({ button: "Cancel" }); - index++; - - editEntityFormArray = array; - Window.nonBlockingForm("Edit Properties", array); +function showPropertiesForm(editModelID) { + entityPropertyDialogBox.openDialog(editModelID); } function handeMenuEvent(menuItem) { @@ -3018,7 +2903,7 @@ function handeMenuEvent(menuItem) { var selectedModel = form[0].value; if (form[1].value == "Properties") { editModelID = selectedModel; - showPropertiesForm(); + showPropertiesForm(editModelID); } else if (form[1].value == "Delete") { Entities.deleteEntity(selectedModel); } else if (form[1].value == "Teleport") { @@ -3134,73 +3019,5 @@ Window.inlineButtonClicked.connect(function (name) { } }); -Window.nonBlockingFormClosed.connect(function() { - array = editEntityFormArray; - if (Window.getNonBlockingFormResult(array)) { - var properties = propertiesForEditedEntity; - var index = 0; - if (properties.type == "Model") { - properties.modelURL = array[index++].value; - properties.animationURL = array[index++].value; - properties.animationIsPlaying = array[index++].value; - properties.animationFPS = array[index++].value; - properties.animationFrameIndex = array[index++].value; - } - index++; // skip header - properties.position.x = array[index++].value; - properties.position.y = array[index++].value; - properties.position.z = array[index++].value; - properties.registrationPoint.x = array[index++].value; - properties.registrationPoint.y = array[index++].value; - properties.registrationPoint.z = array[index++].value; - - index++; // skip header - var angles = Quat.safeEulerAngles(properties.rotation); - angles.x = array[index++].value; - angles.y = array[index++].value; - angles.z = array[index++].value; - properties.rotation = Quat.fromVec3Degrees(angles); - - index++; // skip header - properties.dimensions.x = array[index++].value; - properties.dimensions.y = array[index++].value; - properties.dimensions.z = array[index++].value; - index++; // skip reset button - index++; // skip rescale percentage - index++; // skip rescale button - - index++; // skip header - properties.velocity.x = array[index++].value; - properties.velocity.y = array[index++].value; - properties.velocity.z = array[index++].value; - properties.damping = array[index++].value; - - properties.angularVelocity.x = array[index++].value; - properties.angularVelocity.y = array[index++].value; - properties.angularVelocity.z = array[index++].value; - properties.angularDamping = array[index++].value; - - properties.gravity.x = array[index++].value; - properties.gravity.y = array[index++].value; - properties.gravity.z = array[index++].value; - - index++; // skip header - properties.mass = array[index++].value; - properties.ignoreForCollisions = array[index++].value; - properties.collisionsWillMove = array[index++].value; - - properties.lifetime = array[index++].value; - properties.visible = array[index++].value; - - if (properties.type == "Box" || properties.type == "Sphere") { - index++; // skip header - properties.color.red = array[index++].value; - properties.color.green = array[index++].value; - properties.color.blue = array[index++].value; - } - Entities.editEntity(editModelID, properties); - } - modelSelected = false; -}); diff --git a/examples/libraries/entityPropertyDialogBox.js b/examples/libraries/entityPropertyDialogBox.js index c23f8b0dcc..0246e9e800 100644 --- a/examples/libraries/entityPropertyDialogBox.js +++ b/examples/libraries/entityPropertyDialogBox.js @@ -35,6 +35,12 @@ EntityPropertyDialogBox = (function () { var array = new Array(); var index = 0; + + array.push({ label: "Entity Type:" + properties.type, type: "header" }); + index++; + array.push({ label: "Locked:", value: properties.locked }); + index++; + if (properties.type == "Model") { array.push({ label: "Model URL:", value: properties.modelURL }); index++; @@ -219,6 +225,8 @@ EntityPropertyDialogBox = (function () { if (Window.getNonBlockingFormResult(array)) { var properties = propertiesForEditedEntity; var index = 0; + index++; // skip type header + properties.locked = array[index++].value; if (properties.type == "Model") { properties.modelURL = array[index++].value; properties.animationURL = array[index++].value; @@ -298,7 +306,9 @@ EntityPropertyDialogBox = (function () { } Entities.editEntity(editModelID, properties); - selectionDisplay.select(editModelID, false); + if (typeof(selectionDisplay) != "undefined") { + selectionDisplay.select(editModelID, false); + } } modelSelected = false; }); diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 91231df3f5..346070c567 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -45,6 +45,7 @@ const float EntityItem::DEFAULT_ANGULAR_DAMPING = 0.5f; const bool EntityItem::DEFAULT_VISIBLE = true; const bool EntityItem::DEFAULT_IGNORE_FOR_COLLISIONS = false; const bool EntityItem::DEFAULT_COLLISIONS_WILL_MOVE = false; +const bool EntityItem::DEFAULT_LOCKED = false; void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { _id = entityItemID.id; @@ -118,6 +119,7 @@ EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& param requestedProperties += PROP_VISIBLE; requestedProperties += PROP_IGNORE_FOR_COLLISIONS; requestedProperties += PROP_COLLISIONS_WILL_MOVE; + requestedProperties += PROP_LOCKED; return requestedProperties; } @@ -233,6 +235,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_VISIBLE, appendValue, getVisible()); APPEND_ENTITY_PROPERTY(PROP_IGNORE_FOR_COLLISIONS, appendValue, getIgnoreForCollisions()); APPEND_ENTITY_PROPERTY(PROP_COLLISIONS_WILL_MOVE, appendValue, getCollisionsWillMove()); + APPEND_ENTITY_PROPERTY(PROP_LOCKED, appendValue, getLocked()); appendSubclassData(packetData, params, entityTreeElementExtraEncodeData, requestedProperties, @@ -495,6 +498,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_VISIBLE, bool, _visible); READ_ENTITY_PROPERTY(PROP_IGNORE_FOR_COLLISIONS, bool, _ignoreForCollisions); READ_ENTITY_PROPERTY(PROP_COLLISIONS_WILL_MOVE, bool, _collisionsWillMove); + READ_ENTITY_PROPERTY(PROP_LOCKED, bool, _locked); if (wantDebug) { qDebug() << " readEntityDataFromBuffer() _registrationPoint:" << _registrationPoint; @@ -750,6 +754,7 @@ EntityItemProperties EntityItem::getProperties() const { COPY_ENTITY_PROPERTY_TO_PROPERTIES(visible, getVisible); COPY_ENTITY_PROPERTY_TO_PROPERTIES(ignoreForCollisions, getIgnoreForCollisions); COPY_ENTITY_PROPERTY_TO_PROPERTIES(collisionsWillMove, getCollisionsWillMove); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(locked, getLocked); properties._defaultSettings = false; @@ -785,6 +790,7 @@ bool EntityItem::setProperties(const EntityItemProperties& properties, bool forc SET_ENTITY_PROPERTY_FROM_PROPERTIES(visible, setVisible); SET_ENTITY_PROPERTY_FROM_PROPERTIES(ignoreForCollisions, setIgnoreForCollisions); SET_ENTITY_PROPERTY_FROM_PROPERTIES(collisionsWillMove, setCollisionsWillMove); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(locked, setLocked); if (somethingChanged) { somethingChangedNotification(); // notify derived classes that something has changed diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index d41bd4a179..65da3c964a 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -243,6 +243,10 @@ public: static const bool DEFAULT_COLLISIONS_WILL_MOVE; bool getCollisionsWillMove() const { return _collisionsWillMove; } void setCollisionsWillMove(bool value) { _collisionsWillMove = value; } + + static const bool DEFAULT_LOCKED; + bool getLocked() const { return _locked; } + void setLocked(bool value) { _locked = value; } // TODO: We need to get rid of these users of getRadius()... float getRadius() const; @@ -281,6 +285,7 @@ protected: bool _visible; bool _ignoreForCollisions; bool _collisionsWillMove; + bool _locked; // NOTE: Radius support is obsolete, but these private helper functions are available for this class to // parse old data streams diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index b6184c80f7..11661b02f4 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -88,6 +88,8 @@ EntityItemProperties::EntityItemProperties() : _quadraticAttenuation(0.0f), _exponent(0.0f), _cutoff(PI), + _locked(false), + _textures(""), _diffuseColorChanged(false), _ambientColorChanged(false), @@ -97,6 +99,8 @@ EntityItemProperties::EntityItemProperties() : _quadraticAttenuationChanged(false), _exponentChanged(false), _cutoffChanged(false), + _lockedChanged(false), + _texturesChanged(false), _defaultSettings(true), _naturalDimensions(1.0f, 1.0f, 1.0f) @@ -160,6 +164,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_QUADRATIC_ATTENUATION, quadraticAttenuation); CHECK_PROPERTY_CHANGE(PROP_EXPONENT, exponent); CHECK_PROPERTY_CHANGE(PROP_CUTOFF, cutoff); + CHECK_PROPERTY_CHANGE(PROP_LOCKED, locked); + CHECK_PROPERTY_CHANGE(PROP_TEXTURES, textures); return changedProperties; } @@ -210,6 +216,8 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons COPY_PROPERTY_TO_QSCRIPTVALUE(quadraticAttenuation); COPY_PROPERTY_TO_QSCRIPTVALUE(exponent); COPY_PROPERTY_TO_QSCRIPTVALUE(cutoff); + COPY_PROPERTY_TO_QSCRIPTVALUE(locked); + COPY_PROPERTY_TO_QSCRIPTVALUE(textures); // Sitting properties support QScriptValue sittingPoints = engine->newObject(); @@ -278,6 +286,8 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(quadraticAttenuation, setQuadraticAttenuation); COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(exponent, setExponent); COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(cutoff, setCutoff); + COPY_PROPERTY_FROM_QSCRIPTVALUE_BOOL(locked, setLocked); + COPY_PROPERTY_FROM_QSCRIPTVALUE_STRING(textures, setTextures); _lastEdited = usecTimestampNow(); } @@ -437,6 +447,8 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem 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()); + APPEND_ENTITY_PROPERTY(PROP_LOCKED, appendValue, properties.getLocked()); + APPEND_ENTITY_PROPERTY(PROP_TEXTURES, appendValue, properties.getTextures()); } if (propertyCount > 0) { int endOfEntityItemData = packetData->getUncompressedByteOffset(); @@ -644,6 +656,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int 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); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LOCKED, bool, setLocked); + READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_TEXTURES, setTextures); return valid; } @@ -708,6 +722,8 @@ void EntityItemProperties::markAllChanged() { _quadraticAttenuationChanged = true; _exponentChanged = true; _cutoffChanged = true; + _lockedChanged = true; + _texturesChanged = true; } AACube EntityItemProperties::getMaximumAACubeInTreeUnits() const { diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index e03a05a1cd..92fa344286 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -75,6 +75,12 @@ enum EntityPropertyList { PROP_EXPONENT, PROP_CUTOFF, + // available to all entities + PROP_LOCKED, + + // used by Model entities + PROP_TEXTURES, + PROP_LAST_ITEM = PROP_CUTOFF }; @@ -272,6 +278,13 @@ public: float getCutoff() const { return _cutoff; } void setCutoff(float value) { _cutoff = value; _cutoffChanged = true; } + + bool getLocked() const { return _locked; } + void setLocked(bool value) { _locked = value; _lockedChanged = true; } + bool lockedChanged() const { return _lockedChanged; } + + const QString& getTextures() const { return _textures; } + void setTextures(const QString& value) { _textures = value; _texturesChanged = true; } void setLastEdited(quint64 usecTime) { _lastEdited = usecTime; } @@ -348,6 +361,8 @@ private: float _quadraticAttenuation; float _exponent; float _cutoff; + bool _locked; + QString _textures; bool _diffuseColorChanged; bool _ambientColorChanged; @@ -357,6 +372,8 @@ private: bool _quadraticAttenuationChanged; bool _exponentChanged; bool _cutoffChanged; + bool _lockedChanged; + bool _texturesChanged; bool _defaultSettings; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 58a34aeb60..61dbbda698 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -108,16 +108,31 @@ bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProp return false; } - // check to see if we need to simulate this entity... - EntityItem::SimulationState oldState = existingEntity->getSimulationState(); + // enforce support for locked entities. If an entity is currently locked, then the only + // property we allow you to change is the locked property. + if (existingEntity->getLocked()) { + if (properties.lockedChanged()) { + bool wantsLocked = properties.getLocked(); + if (!wantsLocked) { + EntityItemProperties tempProperties; + tempProperties.setLocked(wantsLocked); + UpdateEntityOperator theOperator(this, containingElement, existingEntity, tempProperties); + recurseTreeWithOperator(&theOperator); + _isDirty = true; + } + } + } else { + // check to see if we need to simulate this entity... + EntityItem::SimulationState oldState = existingEntity->getSimulationState(); - UpdateEntityOperator theOperator(this, containingElement, existingEntity, properties); - recurseTreeWithOperator(&theOperator); - _isDirty = true; - - EntityItem::SimulationState newState = existingEntity->getSimulationState(); - changeEntityState(existingEntity, oldState, newState); + UpdateEntityOperator theOperator(this, containingElement, existingEntity, properties); + recurseTreeWithOperator(&theOperator); + _isDirty = true; + EntityItem::SimulationState newState = existingEntity->getSimulationState(); + changeEntityState(existingEntity, oldState, newState); + } + containingElement = getContainingElement(entityID); if (!containingElement) { qDebug() << "UNEXPECTED!!!! after updateEntity() we no longer have a containing element??? entityID=" << entityID;