mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 13:24:02 +02:00
Merge pull request #15141 from luiscuenca/flowAPIExtra
add getFlowData method to MyAvatar
This commit is contained in:
commit
c36d752b6b
4 changed files with 129 additions and 1 deletions
|
@ -5333,10 +5333,22 @@ void MyAvatar::addAvatarHandsToFlow(const std::shared_ptr<Avatar>& otherAvatar)
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::useFlow(bool isActive, bool isCollidable, const QVariantMap& physicsConfig, const QVariantMap& collisionsConfig) {
|
void MyAvatar::useFlow(bool isActive, bool isCollidable, const QVariantMap& physicsConfig, const QVariantMap& collisionsConfig) {
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
QMetaObject::invokeMethod(this, "useFlow",
|
||||||
|
Q_ARG(bool, isActive),
|
||||||
|
Q_ARG(bool, isCollidable),
|
||||||
|
Q_ARG(const QVariantMap&, physicsConfig),
|
||||||
|
Q_ARG(const QVariantMap&, collisionsConfig));
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (_skeletonModel->isLoaded()) {
|
if (_skeletonModel->isLoaded()) {
|
||||||
_skeletonModel->getRig().initFlow(isActive);
|
|
||||||
auto &flow = _skeletonModel->getRig().getFlow();
|
auto &flow = _skeletonModel->getRig().getFlow();
|
||||||
auto &collisionSystem = flow.getCollisionSystem();
|
auto &collisionSystem = flow.getCollisionSystem();
|
||||||
|
if (!flow.isInitialized() && isActive) {
|
||||||
|
_skeletonModel->getRig().initFlow(true);
|
||||||
|
} else {
|
||||||
|
flow.setActive(isActive);
|
||||||
|
}
|
||||||
collisionSystem.setActive(isCollidable);
|
collisionSystem.setActive(isCollidable);
|
||||||
auto physicsGroups = physicsConfig.keys();
|
auto physicsGroups = physicsConfig.keys();
|
||||||
if (physicsGroups.size() > 0) {
|
if (physicsGroups.size() > 0) {
|
||||||
|
@ -5387,6 +5399,93 @@ void MyAvatar::useFlow(bool isActive, bool isCollidable, const QVariantMap& phys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariantMap MyAvatar::getFlowData() {
|
||||||
|
QVariantMap result;
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
BLOCKING_INVOKE_METHOD(this, "getFlowData",
|
||||||
|
Q_RETURN_ARG(QVariantMap, result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (_skeletonModel->isLoaded()) {
|
||||||
|
auto jointNames = getJointNames();
|
||||||
|
auto &flow = _skeletonModel->getRig().getFlow();
|
||||||
|
auto &collisionSystem = flow.getCollisionSystem();
|
||||||
|
bool initialized = flow.isInitialized();
|
||||||
|
result.insert("initialized", initialized);
|
||||||
|
result.insert("active", flow.getActive());
|
||||||
|
result.insert("colliding", collisionSystem.getActive());
|
||||||
|
QVariantMap physicsData;
|
||||||
|
QVariantMap collisionsData;
|
||||||
|
QVariantMap threadData;
|
||||||
|
std::map<QString, QVariantList> groupJointsMap;
|
||||||
|
QVariantList jointCollisionData;
|
||||||
|
auto &groups = flow.getGroupSettings();
|
||||||
|
for (auto &joint : flow.getJoints()) {
|
||||||
|
auto &groupName = joint.second.getGroup();
|
||||||
|
if (groups.find(groupName) != groups.end()) {
|
||||||
|
if (groupJointsMap.find(groupName) == groupJointsMap.end()) {
|
||||||
|
groupJointsMap.insert(std::pair<QString, QVariantList>(groupName, QVariantList()));
|
||||||
|
}
|
||||||
|
groupJointsMap[groupName].push_back(joint.second.getIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto &group : groups) {
|
||||||
|
QVariantMap settingsObject;
|
||||||
|
QString groupName = group.first;
|
||||||
|
FlowPhysicsSettings groupSettings = group.second;
|
||||||
|
settingsObject.insert("active", groupSettings._active);
|
||||||
|
settingsObject.insert("damping", groupSettings._damping);
|
||||||
|
settingsObject.insert("delta", groupSettings._delta);
|
||||||
|
settingsObject.insert("gravity", groupSettings._gravity);
|
||||||
|
settingsObject.insert("inertia", groupSettings._inertia);
|
||||||
|
settingsObject.insert("radius", groupSettings._radius);
|
||||||
|
settingsObject.insert("stiffness", groupSettings._stiffness);
|
||||||
|
settingsObject.insert("jointIndices", groupJointsMap[groupName]);
|
||||||
|
physicsData.insert(groupName, settingsObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &collisions = collisionSystem.getCollisions();
|
||||||
|
for (auto &collision : collisions) {
|
||||||
|
QVariantMap collisionObject;
|
||||||
|
collisionObject.insert("offset", vec3toVariant(collision._offset));
|
||||||
|
collisionObject.insert("radius", collision._radius);
|
||||||
|
collisionObject.insert("jointIndex", collision._jointIndex);
|
||||||
|
QString jointName = jointNames.size() > collision._jointIndex ? jointNames[collision._jointIndex] : "unknown";
|
||||||
|
collisionsData.insert(jointName, collisionObject);
|
||||||
|
}
|
||||||
|
for (auto &thread : flow.getThreads()) {
|
||||||
|
QVariantList indices;
|
||||||
|
for (int index : thread._joints) {
|
||||||
|
indices.append(index);
|
||||||
|
}
|
||||||
|
threadData.insert(thread._jointsPointer->at(thread._joints[0]).getName(), indices);
|
||||||
|
}
|
||||||
|
result.insert("physics", physicsData);
|
||||||
|
result.insert("collisions", collisionsData);
|
||||||
|
result.insert("threads", threadData);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantList MyAvatar::getCollidingFlowJoints() {
|
||||||
|
QVariantList result;
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
BLOCKING_INVOKE_METHOD(this, "getCollidingFlowJoints",
|
||||||
|
Q_RETURN_ARG(QVariantList, result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_skeletonModel->isLoaded()) {
|
||||||
|
auto& flow = _skeletonModel->getRig().getFlow();
|
||||||
|
for (auto &joint : flow.getJoints()) {
|
||||||
|
if (joint.second.isColliding()) {
|
||||||
|
result.append(joint.second.getIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void MyAvatar::initFlowFromFST() {
|
void MyAvatar::initFlowFromFST() {
|
||||||
if (_skeletonModel->isLoaded()) {
|
if (_skeletonModel->isLoaded()) {
|
||||||
auto &flowData = _skeletonModel->getHFMModel().flowData;
|
auto &flowData = _skeletonModel->getHFMModel().flowData;
|
||||||
|
|
|
@ -1198,6 +1198,19 @@ public:
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void useFlow(bool isActive, bool isCollidable, const QVariantMap& physicsConfig = QVariantMap(), const QVariantMap& collisionsConfig = QVariantMap());
|
Q_INVOKABLE void useFlow(bool isActive, bool isCollidable, const QVariantMap& physicsConfig = QVariantMap(), const QVariantMap& collisionsConfig = QVariantMap());
|
||||||
|
|
||||||
|
/**jsdoc
|
||||||
|
* @function MyAvatar.getFlowData
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE QVariantMap getFlowData();
|
||||||
|
|
||||||
|
/**jsdoc
|
||||||
|
* returns the indices of every colliding flow joint
|
||||||
|
* @function MyAvatar.getCollidingFlowJoints
|
||||||
|
* @returns {int[]}
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE QVariantList getCollidingFlowJoints();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
|
|
|
@ -463,6 +463,7 @@ void Flow::calculateConstraints(const std::shared_ptr<AnimSkeleton>& skeleton,
|
||||||
auto flowPrefix = FLOW_JOINT_PREFIX.toUpper();
|
auto flowPrefix = FLOW_JOINT_PREFIX.toUpper();
|
||||||
auto simPrefix = SIM_JOINT_PREFIX.toUpper();
|
auto simPrefix = SIM_JOINT_PREFIX.toUpper();
|
||||||
std::vector<int> handsIndices;
|
std::vector<int> handsIndices;
|
||||||
|
_groupSettings.clear();
|
||||||
|
|
||||||
for (int i = 0; i < skeleton->getNumJoints(); i++) {
|
for (int i = 0; i < skeleton->getNumJoints(); i++) {
|
||||||
auto name = skeleton->getJointName(i);
|
auto name = skeleton->getJointName(i);
|
||||||
|
@ -509,6 +510,7 @@ void Flow::calculateConstraints(const std::shared_ptr<AnimSkeleton>& skeleton,
|
||||||
auto flowJoint = FlowJoint(i, parentIndex, -1, name, group, jointSettings);
|
auto flowJoint = FlowJoint(i, parentIndex, -1, name, group, jointSettings);
|
||||||
_flowJointData.insert(std::pair<int, FlowJoint>(i, flowJoint));
|
_flowJointData.insert(std::pair<int, FlowJoint>(i, flowJoint));
|
||||||
}
|
}
|
||||||
|
updateGroupSettings(group, jointSettings);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (PRESET_COLLISION_DATA.find(name) != PRESET_COLLISION_DATA.end()) {
|
if (PRESET_COLLISION_DATA.find(name) != PRESET_COLLISION_DATA.end()) {
|
||||||
|
@ -727,6 +729,7 @@ void Flow::setPhysicsSettingsForGroup(const QString& group, const FlowPhysicsSet
|
||||||
joint.second.setSettings(settings);
|
joint.second.setSettings(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateGroupSettings(group, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Flow::getJointPositionInWorldFrame(const AnimPoseVec& absolutePoses, int jointIndex, glm::vec3& position, glm::vec3 translation, glm::quat rotation) const {
|
bool Flow::getJointPositionInWorldFrame(const AnimPoseVec& absolutePoses, int jointIndex, glm::vec3& position, glm::vec3 translation, glm::quat rotation) const {
|
||||||
|
@ -780,4 +783,12 @@ Flow& Flow::operator=(const Flow& otherFlow) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Flow::updateGroupSettings(const QString& group, const FlowPhysicsSettings& settings) {
|
||||||
|
if (_groupSettings.find(group) == _groupSettings.end()) {
|
||||||
|
_groupSettings.insert(std::pair<QString, FlowPhysicsSettings>(group, settings));
|
||||||
|
} else {
|
||||||
|
_groupSettings[group] = settings;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -149,6 +149,7 @@ public:
|
||||||
void setCollisionSettingsByJoint(int jointIndex, const FlowCollisionSettings& settings);
|
void setCollisionSettingsByJoint(int jointIndex, const FlowCollisionSettings& settings);
|
||||||
void setActive(bool active) { _active = active; }
|
void setActive(bool active) { _active = active; }
|
||||||
bool getActive() const { return _active; }
|
bool getActive() const { return _active; }
|
||||||
|
const std::vector<FlowCollisionSphere>& getCollisions() const { return _selfCollisions; }
|
||||||
protected:
|
protected:
|
||||||
std::vector<FlowCollisionSphere> _selfCollisions;
|
std::vector<FlowCollisionSphere> _selfCollisions;
|
||||||
std::vector<FlowCollisionSphere> _othersCollisions;
|
std::vector<FlowCollisionSphere> _othersCollisions;
|
||||||
|
@ -221,6 +222,7 @@ public:
|
||||||
const glm::quat& getCurrentRotation() const { return _currentRotation; }
|
const glm::quat& getCurrentRotation() const { return _currentRotation; }
|
||||||
const glm::vec3& getCurrentTranslation() const { return _initialTranslation; }
|
const glm::vec3& getCurrentTranslation() const { return _initialTranslation; }
|
||||||
const glm::vec3& getInitialPosition() const { return _initialPosition; }
|
const glm::vec3& getInitialPosition() const { return _initialPosition; }
|
||||||
|
bool isColliding() const { return _colliding; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -293,6 +295,7 @@ public:
|
||||||
void setOthersCollision(const QUuid& otherId, int jointIndex, const glm::vec3& position);
|
void setOthersCollision(const QUuid& otherId, int jointIndex, const glm::vec3& position);
|
||||||
FlowCollisionSystem& getCollisionSystem() { return _collisionSystem; }
|
FlowCollisionSystem& getCollisionSystem() { return _collisionSystem; }
|
||||||
void setPhysicsSettingsForGroup(const QString& group, const FlowPhysicsSettings& settings);
|
void setPhysicsSettingsForGroup(const QString& group, const FlowPhysicsSettings& settings);
|
||||||
|
const std::map<QString, FlowPhysicsSettings>& getGroupSettings() const { return _groupSettings; }
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -309,6 +312,7 @@ private:
|
||||||
void setJoints(AnimPoseVec& relativePoses, const std::vector<bool>& overrideFlags);
|
void setJoints(AnimPoseVec& relativePoses, const std::vector<bool>& overrideFlags);
|
||||||
void updateJoints(AnimPoseVec& relativePoses, AnimPoseVec& absolutePoses);
|
void updateJoints(AnimPoseVec& relativePoses, AnimPoseVec& absolutePoses);
|
||||||
bool updateRootFramePositions(const AnimPoseVec& absolutePoses, size_t threadIndex);
|
bool updateRootFramePositions(const AnimPoseVec& absolutePoses, size_t threadIndex);
|
||||||
|
void updateGroupSettings(const QString& group, const FlowPhysicsSettings& settings);
|
||||||
void setScale(float scale);
|
void setScale(float scale);
|
||||||
|
|
||||||
float _scale { 1.0f };
|
float _scale { 1.0f };
|
||||||
|
@ -316,6 +320,7 @@ private:
|
||||||
glm::vec3 _entityPosition;
|
glm::vec3 _entityPosition;
|
||||||
glm::quat _entityRotation;
|
glm::quat _entityRotation;
|
||||||
std::map<int, FlowJoint> _flowJointData;
|
std::map<int, FlowJoint> _flowJointData;
|
||||||
|
std::map<QString, FlowPhysicsSettings> _groupSettings;
|
||||||
std::vector<FlowThread> _jointThreads;
|
std::vector<FlowThread> _jointThreads;
|
||||||
std::vector<QString> _flowJointKeywords;
|
std::vector<QString> _flowJointKeywords;
|
||||||
FlowCollisionSystem _collisionSystem;
|
FlowCollisionSystem _collisionSystem;
|
||||||
|
|
Loading…
Reference in a new issue