mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 01:23:38 +02:00
hook up a way for scripts to set model-entity joint state
This commit is contained in:
parent
88d36487f8
commit
84bcfb7d71
11 changed files with 89 additions and 4 deletions
|
@ -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 {
|
bool Rig::getJointTranslation(int jointIndex, glm::vec3& translation) const {
|
||||||
QReadLocker readLock(&_externalPoseSetLock);
|
QReadLocker readLock(&_externalPoseSetLock);
|
||||||
if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._relativePoses.size()) {
|
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 {
|
bool Rig::getJointCombinedRotation(int jointIndex, glm::quat& result, const glm::quat& rotation) const {
|
||||||
// AJT: TODO: used by attachments
|
// AJT: TODO: used by attachments
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
|
|
|
@ -134,6 +134,8 @@ public:
|
||||||
// rig space (thread-safe)
|
// rig space (thread-safe)
|
||||||
bool getAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation) const;
|
bool getAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation) const;
|
||||||
bool getAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translation) const;
|
bool getAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translation) const;
|
||||||
|
bool setAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotation);
|
||||||
|
bool setAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translation);
|
||||||
|
|
||||||
// legacy
|
// legacy
|
||||||
bool getJointCombinedRotation(int jointIndex, glm::quat& result, const glm::quat& rotation) const;
|
bool getJointCombinedRotation(int jointIndex, glm::quat& result, const glm::quat& rotation) const;
|
||||||
|
|
|
@ -292,7 +292,21 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_model) {
|
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 (hasAnimation()) {
|
||||||
if (!jointsMapped()) {
|
if (!jointsMapped()) {
|
||||||
QStringList modelJointNames = _model->getJointNames();
|
QStringList modelJointNames = _model->getJointNames();
|
||||||
|
@ -600,7 +614,7 @@ bool RenderableModelEntityItem::contains(const glm::vec3& point) const {
|
||||||
const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry();
|
const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry();
|
||||||
return collisionGeometry.convexHullContains(worldToEntity(point));
|
return collisionGeometry.convexHullContains(worldToEntity(point));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,6 +638,22 @@ glm::vec3 RenderableModelEntityItem::getAbsoluteJointTranslationInObjectFrame(in
|
||||||
return glm::vec3(0.0f);
|
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() {
|
void RenderableModelEntityItem::locationChanged() {
|
||||||
EntityItem::locationChanged();
|
EntityItem::locationChanged();
|
||||||
if (_model && _model->isActive()) {
|
if (_model && _model->isActive()) {
|
||||||
|
|
|
@ -71,6 +71,8 @@ public:
|
||||||
// these are in the frame of this object (model space)
|
// these are in the frame of this object (model space)
|
||||||
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override;
|
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override;
|
||||||
virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(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 loader() override;
|
||||||
virtual void locationChanged() override;
|
virtual void locationChanged() override;
|
||||||
|
@ -91,6 +93,13 @@ private:
|
||||||
render::ItemID _myMetaItem;
|
render::ItemID _myMetaItem;
|
||||||
|
|
||||||
bool _showCollisionHull = false;
|
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
|
#endif // hifi_RenderableModelEntityItem_h
|
||||||
|
|
|
@ -381,6 +381,8 @@ public:
|
||||||
// these are in the frame of this object
|
// these are in the frame of this object
|
||||||
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override { return glm::quat(); }
|
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 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
|
virtual void loader() {} // called indirectly when urls for geometry are updated
|
||||||
|
|
||||||
|
|
|
@ -826,3 +826,23 @@ glm::quat EntityScriptingInterface::getAbsoluteJointRotationInObjectFrame(const
|
||||||
return glm::quat();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -151,6 +151,8 @@ public slots:
|
||||||
|
|
||||||
Q_INVOKABLE glm::vec3 getAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex);
|
Q_INVOKABLE glm::vec3 getAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex);
|
||||||
Q_INVOKABLE glm::quat getAbsoluteJointRotationInObjectFrame(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:
|
signals:
|
||||||
void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||||
|
|
|
@ -129,7 +129,6 @@ protected:
|
||||||
QVector<glm::vec3> _lastKnownFrameDataTranslations;
|
QVector<glm::vec3> _lastKnownFrameDataTranslations;
|
||||||
int _lastKnownCurrentFrame;
|
int _lastKnownCurrentFrame;
|
||||||
|
|
||||||
|
|
||||||
bool isAnimatingSomething() const;
|
bool isAnimatingSomething() const;
|
||||||
|
|
||||||
rgbColor _color;
|
rgbColor _color;
|
||||||
|
|
|
@ -699,6 +699,14 @@ void Model::setJointTranslation(int index, bool valid, const glm::vec3& translat
|
||||||
_rig->setJointTranslation(index, valid, translation, priority);
|
_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 {
|
int Model::getParentJointIndex(int jointIndex) const {
|
||||||
return (isActive() && jointIndex != -1) ? _geometry->getFBXGeometry().joints.at(jointIndex).parentIndex : -1;
|
return (isActive() && jointIndex != -1) ? _geometry->getFBXGeometry().joints.at(jointIndex).parentIndex : -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,6 +170,9 @@ public:
|
||||||
bool getAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotationOut) const;
|
bool getAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotationOut) const;
|
||||||
bool getAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translationOut) 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 getRelativeDefaultJointRotation(int jointIndex, glm::quat& rotationOut) const;
|
||||||
bool getRelativeDefaultJointTranslation(int jointIndex, glm::vec3& translationOut) const;
|
bool getRelativeDefaultJointTranslation(int jointIndex, glm::vec3& translationOut) const;
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,9 @@ public:
|
||||||
virtual const Transform getAbsoluteJointTransformInObjectFrame(int jointIndex) const;
|
virtual const Transform getAbsoluteJointTransformInObjectFrame(int jointIndex) const;
|
||||||
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const { assert(false); return glm::quat(); }
|
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 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;
|
SpatiallyNestablePointer getThisPointer() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue