hook up a way for scripts to set model-entity joint state

This commit is contained in:
Seth Alves 2015-12-22 17:43:01 -08:00
parent 88d36487f8
commit 84bcfb7d71
11 changed files with 89 additions and 4 deletions

View file

@ -386,6 +386,10 @@ bool Rig::getAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation
}
}
bool Rig::setAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation) {
return false;
}
bool Rig::getJointTranslation(int jointIndex, glm::vec3& translation) const {
QReadLocker readLock(&_externalPoseSetLock);
if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._relativePoses.size()) {
@ -406,6 +410,10 @@ bool Rig::getAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& trans
}
}
bool Rig::setAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translation) {
return false;
}
bool Rig::getJointCombinedRotation(int jointIndex, glm::quat& result, const glm::quat& rotation) const {
// AJT: TODO: used by attachments
ASSERT(false);

View file

@ -134,6 +134,8 @@ public:
// rig space (thread-safe)
bool getAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation) const;
bool getAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translation) const;
bool setAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation);
bool setAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translation);
// legacy
bool getJointCombinedRotation(int jointIndex, glm::quat& result, const glm::quat& rotation) const;

View file

@ -292,7 +292,21 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
}
if (_model) {
// handle animations..
// handle script updates...
_scriptSetFrameDataLock.withWriteLock([&] {
while (!_scriptSetFrameDataRotationsIndexes.empty()) {
int index = _scriptSetFrameDataRotationsIndexes.dequeue();
glm::quat rotation = _scriptSetFrameDataRotations.dequeue();
_model->setJointRotation(index, true, rotation, 1.0f);
}
while (!_scriptSetFrameDataTranslationsIndexes.empty()) {
int index = _scriptSetFrameDataTranslationsIndexes.dequeue();
glm::vec3 translation = _scriptSetFrameDataTranslations.dequeue();
_model->setJointTranslation(index, true, translation, 1.0f);
}
});
// handle animations...
if (hasAnimation()) {
if (!jointsMapped()) {
QStringList modelJointNames = _model->getJointNames();
@ -600,7 +614,7 @@ bool RenderableModelEntityItem::contains(const glm::vec3& point) const {
const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry();
return collisionGeometry.convexHullContains(worldToEntity(point));
}
return false;
}
@ -624,6 +638,22 @@ glm::vec3 RenderableModelEntityItem::getAbsoluteJointTranslationInObjectFrame(in
return glm::vec3(0.0f);
}
bool RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame(int index, glm::quat& rotation) {
_scriptSetFrameDataLock.withWriteLock([&] {
_scriptSetFrameDataRotationsIndexes.enqueue(index);
_scriptSetFrameDataRotations.enqueue(rotation);
});
return true;
}
bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int index, glm::vec3& translation) {
_scriptSetFrameDataLock.withWriteLock([&] {
_scriptSetFrameDataTranslationsIndexes.enqueue(index);
_scriptSetFrameDataTranslations.enqueue(translation);
});
return true;
}
void RenderableModelEntityItem::locationChanged() {
EntityItem::locationChanged();
if (_model && _model->isActive()) {

View file

@ -71,6 +71,8 @@ public:
// these are in the frame of this object (model space)
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override;
virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const override;
virtual bool setAbsoluteJointRotationInObjectFrame(int index, glm::quat& rotation) override;
virtual bool setAbsoluteJointTranslationInObjectFrame(int index, glm::vec3& translation) override;
virtual void loader() override;
virtual void locationChanged() override;
@ -91,6 +93,13 @@ private:
render::ItemID _myMetaItem;
bool _showCollisionHull = false;
// these are used to let scripts set ModelEntityItem joint data
ReadWriteLockable _scriptSetFrameDataLock;
QQueue<glm::quat> _scriptSetFrameDataRotations;
QQueue<int> _scriptSetFrameDataRotationsIndexes;
QQueue<glm::vec3> _scriptSetFrameDataTranslations;
QQueue<int> _scriptSetFrameDataTranslationsIndexes;
};
#endif // hifi_RenderableModelEntityItem_h

View file

@ -381,6 +381,8 @@ public:
// these are in the frame of this object
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override { return glm::quat(); }
virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const override { return glm::vec3(0.0f); }
virtual bool setAbsoluteJointRotationInObjectFrame(int index, glm::quat& rotation) override { return false; }
virtual bool setAbsoluteJointTranslationInObjectFrame(int index, glm::vec3& translation) override { return false; }
virtual void loader() {} // called indirectly when urls for geometry are updated

View file

@ -826,3 +826,23 @@ glm::quat EntityScriptingInterface::getAbsoluteJointRotationInObjectFrame(const
return glm::quat();
}
}
bool EntityScriptingInterface::setAbsoluteJointTranslationInObjectFrame(const QUuid& entityID,
int jointIndex, glm::vec3 translation) {
if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) {
auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity);
return modelEntity->setAbsoluteJointTranslationInObjectFrame(jointIndex, translation);
} else {
return false;
}
}
bool EntityScriptingInterface::setAbsoluteJointRotationInObjectFrame(const QUuid& entityID,
int jointIndex, glm::quat rotation) {
if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) {
auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity);
return modelEntity->setAbsoluteJointRotationInObjectFrame(jointIndex, rotation);
} else {
return false;
}
}

View file

@ -151,6 +151,8 @@ public slots:
Q_INVOKABLE glm::vec3 getAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex);
Q_INVOKABLE glm::quat getAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex);
Q_INVOKABLE bool setAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex, glm::vec3 translation);
Q_INVOKABLE bool setAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex, glm::quat rotation);
signals:
void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);

View file

@ -129,7 +129,6 @@ protected:
QVector<glm::vec3> _lastKnownFrameDataTranslations;
int _lastKnownCurrentFrame;
bool isAnimatingSomething() const;
rgbColor _color;

View file

@ -699,6 +699,14 @@ void Model::setJointTranslation(int index, bool valid, const glm::vec3& translat
_rig->setJointTranslation(index, valid, translation, priority);
}
bool Model::setAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation) {
return _rig->setAbsoluteJointRotationInRigFrame(jointIndex, rotation);
}
bool Model::setAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translation) {
return _rig->setAbsoluteJointTranslationInRigFrame(jointIndex, translation);
}
int Model::getParentJointIndex(int jointIndex) const {
return (isActive() && jointIndex != -1) ? _geometry->getFBXGeometry().joints.at(jointIndex).parentIndex : -1;
}

View file

@ -170,6 +170,9 @@ public:
bool getAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotationOut) const;
bool getAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translationOut) const;
bool setAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation);
bool setAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translation);
bool getRelativeDefaultJointRotation(int jointIndex, glm::quat& rotationOut) const;
bool getRelativeDefaultJointTranslation(int jointIndex, glm::vec3& translationOut) const;

View file

@ -91,7 +91,9 @@ public:
virtual const Transform getAbsoluteJointTransformInObjectFrame(int jointIndex) const;
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const { assert(false); return glm::quat(); }
virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const { assert(false); return glm::vec3(); }
virtual bool setAbsoluteJointRotationInObjectFrame(int index, glm::quat& rotation) { assert(false); return false; }
virtual bool setAbsoluteJointTranslationInObjectFrame(int index, glm::vec3& translation) { assert(false); return false; }
SpatiallyNestablePointer getThisPointer() const;
protected: