From 8b6e89a5c464aa78d9eb4761e38b6d47ac5ba314 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 18 Jan 2016 11:13:33 -0800 Subject: [PATCH 1/4] fix stopFarTrigger entity method call. re-add code to keep more than one distance grab per object from happening --- examples/controllers/handControllerGrab.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 7721366bab..3b46a51960 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -42,7 +42,7 @@ var PICK_WITH_HAND_RAY = true; var DISTANCE_HOLDING_RADIUS_FACTOR = 3.5; // multiplied by distance between hand and object var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did -var MOVE_WITH_HEAD = true; // experimental head-controll of distantly held objects +var MOVE_WITH_HEAD = true; // experimental head-control of distantly held objects var FAR_TO_NEAR_GRAB_PADDING_FACTOR = 1.2; var NO_INTERSECT_COLOR = { @@ -917,6 +917,10 @@ function MyController(hand) { } // far grab or equip with action if (isPhysical && !near) { + if (entityIsGrabbedByOther(intersection.entityID)) { + // don't distance grab something that is already grabbed. + return; + } this.temporaryPositionOffset = null; if (typeof grabbableData.spatialKey === 'undefined') { // We want to give a temporary position offset to this object so it is pulled close to hand @@ -1143,7 +1147,6 @@ function MyController(hand) { y: this.currentObjectPosition.y, z: this.currentObjectPosition.z } - } @@ -1489,7 +1492,7 @@ function MyController(hand) { this.continueFarTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - Entities.callEntityMethod(this.grabbedEntity, "stopNearTrigger"); + Entities.callEntityMethod(this.grabbedEntity, "stopFarTrigger"); return; } From 4232e400ccc7b3682d0865e58d49191d46ab784c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 18 Jan 2016 11:15:03 -0800 Subject: [PATCH 2/4] add getJointIndex call --- .../src/RenderableModelEntityItem.cpp | 14 ++++++++++++++ .../src/RenderableModelEntityItem.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 58c06fccfb..57a29de596 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -763,3 +763,17 @@ void RenderableModelEntityItem::locationChanged() { _model->setTranslation(getPosition()); } } + +int RenderableModelEntityItem::getJointIndex(const QString& name) const { + if (_model && _model->isActive()) { + RigPointer rig = _model->getRig(); + return rig->indexOfJoint(name); + } + return -1; +} + + +// TODO -- expose a way to list joint names +// RenderableModelEntityItem::QStringList getJointNames() const { +// rig->nameOfJoint(i); +// } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 99e5ecb097..834513ecf7 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -79,6 +79,8 @@ public: virtual void resizeJointArrays(int newSize = -1) override; + virtual int getJointIndex(const QString& name) const override; + private: QVariantMap parseTexturesToMap(QString textures); void remapTextures(); From d6e3b85237ea96e66634f037bf00691456b7b352 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 18 Jan 2016 11:15:32 -0800 Subject: [PATCH 3/4] fix javascript access via localPosition and localRotation --- libraries/entities/src/EntityItem.cpp | 2 ++ libraries/entities/src/EntityItem.h | 2 ++ .../entities/src/EntityItemProperties.cpp | 13 +++++++++++-- .../entities/src/EntityScriptingInterface.cpp | 18 +++++++++++++++++- .../entities/src/EntityScriptingInterface.h | 2 ++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 0a7a30f098..a6835dff41 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1057,6 +1057,8 @@ EntityItemProperties EntityItem::getProperties(EntityPropertyFlags desiredProper COPY_ENTITY_PROPERTY_TO_PROPERTIES(parentID, getParentID); COPY_ENTITY_PROPERTY_TO_PROPERTIES(parentJointIndex, getParentJointIndex); COPY_ENTITY_PROPERTY_TO_PROPERTIES(queryAACube, getQueryAACube); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(localPosition, getLocalPosition); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(localRotation, getLocalOrientation); properties._defaultSettings = false; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index d0b79723d1..7507893b3d 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -395,6 +395,8 @@ public: virtual bool setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) override { return false; } virtual bool setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) override { return false; } + virtual int getJointIndex(const QString& name) const { return -1; } + virtual void loader() {} // called indirectly when urls for geometry are updated protected: diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index f8dcb6ee56..d1a5b8d9ee 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -321,6 +321,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_JOINT_TRANSLATIONS_SET, jointTranslationsSet); CHECK_PROPERTY_CHANGE(PROP_JOINT_TRANSLATIONS, jointTranslations); CHECK_PROPERTY_CHANGE(PROP_QUERY_AA_CUBE, queryAACube); + CHECK_PROPERTY_CHANGE(PROP_LOCAL_POSITION, localPosition); + CHECK_PROPERTY_CHANGE(PROP_LOCAL_ROTATION, localRotation); changedProperties += _animation.getChangedProperties(); changedProperties += _keyLight.getChangedProperties(); @@ -415,8 +417,6 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_ALPHA_START, alphaStart); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_ALPHA_FINISH, alphaFinish); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_EMITTER_SHOULD_TRAIL, emitterShouldTrail); - COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_POSITION, localPosition); - COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_ROTATION, localRotation); } // Models only @@ -432,6 +432,12 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool if (_type == EntityTypes::Model || _type == EntityTypes::Zone || _type == EntityTypes::ParticleEffect) { COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_SHAPE_TYPE, shapeType, getShapeTypeAsString()); } + if (_type == EntityTypes::Box) { + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_SHAPE_TYPE, shapeType, QString("Box")); + } + if (_type == EntityTypes::Sphere) { + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_SHAPE_TYPE, shapeType, QString("Sphere")); + } // FIXME - it seems like ParticleEffect should also support this if (_type == EntityTypes::Model || _type == EntityTypes::Zone) { @@ -822,6 +828,9 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_PARENT_ID, ParentID, parentID, QUuid); ADD_PROPERTY_TO_MAP(PROP_PARENT_JOINT_INDEX, ParentJointIndex, parentJointIndex, uint16_t); + ADD_PROPERTY_TO_MAP(PROP_LOCAL_POSITION, LocalPosition, localPosition, glm::vec3); + ADD_PROPERTY_TO_MAP(PROP_LOCAL_ROTATION, LocalRotation, localRotation, glm::quat); + ADD_PROPERTY_TO_MAP(PROP_JOINT_ROTATIONS_SET, JointRotationsSet, jointRotationsSet, QVector); ADD_PROPERTY_TO_MAP(PROP_JOINT_ROTATIONS, JointRotations, jointRotations, QVector); ADD_PROPERTY_TO_MAP(PROP_JOINT_TRANSLATIONS_SET, JointTranslationsSet, jointTranslationsSet, QVector); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 4e2052c283..f78cd4fd8c 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -178,6 +178,15 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit desiredProperties.setHasProperty(PROP_PARENT_JOINT_INDEX); } + if (desiredProperties.isEmpty()) { + // these are left out of EntityItem::getEntityProperties so that localPosition and localRotation + // don't end up in json saves, etc. We still want them here, though. + EncodeBitstreamParams params; // unknown + desiredProperties = entity->getEntityProperties(params); + desiredProperties.setHasProperty(PROP_LOCAL_POSITION); + desiredProperties.setHasProperty(PROP_LOCAL_ROTATION); + } + results = entity->getProperties(desiredProperties); // TODO: improve sitting points and naturalDimensions in the future, @@ -956,7 +965,6 @@ bool EntityScriptingInterface::setAbsoluteJointTranslationsInObjectFrame(const Q return false; } - bool EntityScriptingInterface::setAbsoluteJointsDataInObjectFrame(const QUuid& entityID, const QVector& rotations, const QVector& translations) { @@ -964,3 +972,11 @@ bool EntityScriptingInterface::setAbsoluteJointsDataInObjectFrame(const QUuid& e return setAbsoluteJointRotationsInObjectFrame(entityID, rotations) || setAbsoluteJointTranslationsInObjectFrame(entityID, translations); } + +int EntityScriptingInterface::getJointIndex(const QUuid& entityID, const QString& name) { + if (!_entityTree) { + return -1; + } + EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); + return entity->getJointIndex(name); +} diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 5c22d7f6b8..e7a4c0e071 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -161,6 +161,8 @@ public slots: const QVector& rotations, const QVector& translations); + Q_INVOKABLE int getJointIndex(const QUuid& entityID, const QString& name); + signals: void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); From 3b3720781f11c168f01e418110a8bd58ab3d7aba Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 18 Jan 2016 11:15:53 -0800 Subject: [PATCH 4/4] fix a place where parent's scale wasn't properly squashed --- libraries/shared/src/SpatiallyNestable.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 02b1c0c0ae..2fea6b7db4 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -371,6 +371,7 @@ const Transform SpatiallyNestable::getTransform(int jointIndex, bool& success) c Transform jointInWorldFrame; Transform worldTransform = getTransform(success); + worldTransform.setScale(1.0f); // TODO -- scale; if (!success) { return jointInWorldFrame; }