diff --git a/examples/stick.js b/examples/stick.js new file mode 100644 index 0000000000..02101f59e1 --- /dev/null +++ b/examples/stick.js @@ -0,0 +1,18 @@ +var stickID = null; +// sometimes if this is run immediately the stick doesn't get created? use a timer. +Script.setTimeout(function() { + var stickID = Entities.addEntity({ + type: "Model", + modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/stick.fbx", + compoundShapeURL: "https://hifi-public.s3.amazonaws.com/eric/models/stick.obj", + dimensions: {x: .11, y: .11, z: .59}, + position: MyAvatar.getRightPalmPosition(), + rotation: MyAvatar.orientation, + damping: .1, + collisionsWillMove: true + }); + Entities.addAction("hold", stickID, {relativePosition: {x: 0.0, y: 0.0, z: -0.9}, timeScale: 0.15}); +}, 3000); + +function cleanup() { Entities.deleteEntity(stickID); } +Script.scriptEnding.connect(cleanup); diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index 50f862c535..457db8f5c3 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -36,8 +36,6 @@ public: virtual const EntityItemPointer& getOwnerEntity() const = 0; virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0; virtual bool updateArguments(QVariantMap arguments) = 0; - // virtual QByteArray serialize() = 0; - // static EntityActionPointer deserialize(EntityItemPointer ownerEntity, QByteArray data); static EntityActionType actionTypeFromString(QString actionTypeString); static QString actionTypeToString(EntityActionType actionType); @@ -52,6 +50,9 @@ protected: virtual glm::vec3 getAngularVelocity() = 0; virtual void setAngularVelocity(glm::vec3 angularVelocity) = 0; + // these look in the arguments map for a named argument. if it's not found or isn't well formed, + // ok will be set to false (note that it's never set to true -- set it to true before calling these). + // if required is true, failure to extract an argument will cause a warning to be printed. static glm::vec3 extractVec3Argument (QString objectName, QVariantMap arguments, QString argumentName, bool& ok, bool required = true); static glm::quat extractQuatArgument (QString objectName, QVariantMap arguments, diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 6f6633ce0f..a091c786b7 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -495,6 +495,12 @@ QUuid EntityScriptingInterface::addAction(const QString& actionTypeString, QUuid actionID = QUuid::createUuid(); auto actionFactory = DependencyManager::get(); bool success = actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) { + // create this action even if the entity doesn't have physics info. it will often be the + // case that a script adds an action immediately after an object is created, and the physicsInfo + // is computed asynchronously. + // if (!entity->getPhysicsInfo()) { + // return false; + // } EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString); if (actionType == ACTION_TYPE_NONE) { return false; diff --git a/libraries/physics/src/ObjectActionSpring.cpp b/libraries/physics/src/ObjectActionSpring.cpp index 6883e73766..8eb4f7f652 100644 --- a/libraries/physics/src/ObjectActionSpring.cpp +++ b/libraries/physics/src/ObjectActionSpring.cpp @@ -34,7 +34,6 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { void* physicsInfo = _ownerEntity->getPhysicsInfo(); if (!physicsInfo) { unlock(); - qDebug() << "ObjectActionSpring::updateActionWorker no physicsInfo"; return; } ObjectMotionState* motionState = static_cast(physicsInfo); @@ -65,7 +64,7 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { glm::quat bodyRotation = bulletToGLM(rigidBody->getOrientation()); // if qZero and qOne are too close to each other, we can get NaN for angle. auto alignmentDot = glm::dot(bodyRotation, _rotationalTarget); - const float almostOne = 0.99999; + const float almostOne = 0.99999f; if (glm::abs(alignmentDot) < almostOne) { glm::quat target = _rotationalTarget; if (alignmentDot < 0) { @@ -75,12 +74,6 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { glm::quat deltaQ = target * qZeroInverse; glm::vec3 axis = glm::axis(deltaQ); float angle = glm::angle(deltaQ); - if (isNaN(angle)) { - qDebug() << "ObjectActionSpring::updateAction angle =" << angle - << "body-rotation =" << bodyRotation.x << bodyRotation.y << bodyRotation.z << bodyRotation.w - << "target-rotation =" - << target.x << target.y << target.z<< target.w; - } assert(!isNaN(angle)); glm::vec3 newAngularVelocity = (angle / _angularTimeScale) * glm::normalize(axis); rigidBody->setAngularVelocity(glmToBullet(newAngularVelocity)); @@ -130,7 +123,7 @@ bool ObjectActionSpring::updateArguments(QVariantMap arguments) { if (pscOk) { _linearTimeScale = linearTimeScale; } else { - _linearTimeScale = 0.1; + _linearTimeScale = 0.1f; } } @@ -141,7 +134,7 @@ bool ObjectActionSpring::updateArguments(QVariantMap arguments) { if (rscOk) { _angularTimeScale = angularTimeScale; } else { - _angularTimeScale = 0.1; + _angularTimeScale = 0.1f; } } diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 8cb29609ba..b9481d367e 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -245,7 +245,7 @@ public: void update(const UpdateFunctorPointer& updateFunctor) { _payload->update(updateFunctor); } // Shape Type Interface - const model::MaterialKey& getMaterialKey() const { return _payload->getMaterialKey(); } + const model::MaterialKey getMaterialKey() const { return _payload->getMaterialKey(); } protected: PayloadPointer _payload;