mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 15:49:33 +02:00
Allow threads with only one joint, remove dummy joints and unused constants
This commit is contained in:
parent
bea7680864
commit
ec4d069011
3 changed files with 54 additions and 83 deletions
|
@ -252,6 +252,7 @@ void FlowJoint::setInitialData(const glm::vec3& initialPosition, const glm::vec3
|
||||||
_previousPosition = initialPosition;
|
_previousPosition = initialPosition;
|
||||||
_currentPosition = initialPosition;
|
_currentPosition = initialPosition;
|
||||||
_initialTranslation = initialTranslation;
|
_initialTranslation = initialTranslation;
|
||||||
|
_currentRotation = initialRotation;
|
||||||
_initialRotation = initialRotation;
|
_initialRotation = initialRotation;
|
||||||
_translationDirection = glm::normalize(_initialTranslation);
|
_translationDirection = glm::normalize(_initialTranslation);
|
||||||
_parentPosition = parentPosition;
|
_parentPosition = parentPosition;
|
||||||
|
@ -280,7 +281,7 @@ void FlowJoint::update(float deltaTime) {
|
||||||
}
|
}
|
||||||
FlowNode::update(deltaTime, accelerationOffset);
|
FlowNode::update(deltaTime, accelerationOffset);
|
||||||
if (_anchored) {
|
if (_anchored) {
|
||||||
if (!_isDummy) {
|
if (!_isHelper) {
|
||||||
_currentPosition = _updatedPosition;
|
_currentPosition = _updatedPosition;
|
||||||
} else {
|
} else {
|
||||||
_currentPosition = _parentPosition;
|
_currentPosition = _parentPosition;
|
||||||
|
@ -301,19 +302,10 @@ void FlowJoint::solve(const FlowCollisionResult& collision) {
|
||||||
FlowNode::solve(_parentPosition, _length, collision);
|
FlowNode::solve(_parentPosition, _length, collision);
|
||||||
};
|
};
|
||||||
|
|
||||||
FlowDummyJoint::FlowDummyJoint(const glm::vec3& initialPosition, int index, int parentIndex, int childIndex, FlowPhysicsSettings settings) :
|
void FlowJoint::toHelperJoint(const glm::vec3& initialPosition, float length) {
|
||||||
FlowJoint(index, parentIndex, childIndex, DUMMY_KEYWORD + "_" + index, DUMMY_KEYWORD, settings) {
|
|
||||||
_isDummy = true;
|
|
||||||
_initialPosition = initialPosition;
|
_initialPosition = initialPosition;
|
||||||
_length = DUMMY_JOINT_DISTANCE;
|
_isHelper = true;
|
||||||
}
|
|
||||||
|
|
||||||
void FlowDummyJoint::toIsolatedJoint(float length, int childIndex, const QString& group) {
|
|
||||||
_isDummy = false;
|
|
||||||
_length = length;
|
_length = length;
|
||||||
_childIndex = childIndex;
|
|
||||||
_group = group;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FlowThread::FlowThread(int rootIndex, std::map<int, FlowJoint>* joints) {
|
FlowThread::FlowThread(int rootIndex, std::map<int, FlowJoint>* joints) {
|
||||||
|
@ -344,6 +336,7 @@ void FlowThread::computeFlowThread(int rootIndex) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_length = 0.0f;
|
||||||
for (size_t i = 0; i < indexes.size(); i++) {
|
for (size_t i = 0; i < indexes.size(); i++) {
|
||||||
int index = indexes[i];
|
int index = indexes[i];
|
||||||
_joints.push_back(index);
|
_joints.push_back(index);
|
||||||
|
@ -456,6 +449,7 @@ FlowThread& FlowThread::operator=(const FlowThread& otherFlowThread) {
|
||||||
myJoint._updatedPosition = joint._updatedPosition;
|
myJoint._updatedPosition = joint._updatedPosition;
|
||||||
myJoint._updatedRotation = joint._updatedRotation;
|
myJoint._updatedRotation = joint._updatedRotation;
|
||||||
myJoint._updatedTranslation = joint._updatedTranslation;
|
myJoint._updatedTranslation = joint._updatedTranslation;
|
||||||
|
myJoint._isHelper = joint._isHelper;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -532,9 +526,9 @@ void Flow::calculateConstraints(const std::shared_ptr<AnimSkeleton>& skeleton,
|
||||||
glm::vec3 jointPosition, parentPosition, jointTranslation;
|
glm::vec3 jointPosition, parentPosition, jointTranslation;
|
||||||
glm::quat jointRotation;
|
glm::quat jointRotation;
|
||||||
getJointPositionInWorldFrame(absolutePoses, jointIndex, jointPosition, _entityPosition, _entityRotation);
|
getJointPositionInWorldFrame(absolutePoses, jointIndex, jointPosition, _entityPosition, _entityRotation);
|
||||||
getJointPositionInWorldFrame(absolutePoses, jointData.second.getParentIndex(), parentPosition, _entityPosition, _entityRotation);
|
|
||||||
getJointTranslation(relativePoses, jointIndex, jointTranslation);
|
getJointTranslation(relativePoses, jointIndex, jointTranslation);
|
||||||
getJointRotation(relativePoses, jointIndex, jointRotation);
|
getJointRotation(relativePoses, jointIndex, jointRotation);
|
||||||
|
getJointPositionInWorldFrame(absolutePoses, jointData.second.getParentIndex(), parentPosition, _entityPosition, _entityRotation);
|
||||||
|
|
||||||
jointData.second.setInitialData(jointPosition, jointTranslation, jointRotation, parentPosition);
|
jointData.second.setInitialData(jointPosition, jointTranslation, jointRotation, parentPosition);
|
||||||
}
|
}
|
||||||
|
@ -549,47 +543,36 @@ void Flow::calculateConstraints(const std::shared_ptr<AnimSkeleton>& skeleton,
|
||||||
_flowJointData[joint.second.getParentIndex()].setChildIndex(joint.first);
|
_flowJointData[joint.second.getParentIndex()].setChildIndex(joint.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int extraIndex = -1;
|
||||||
for (size_t i = 0; i < roots.size(); i++) {
|
for (size_t i = 0; i < roots.size(); i++) {
|
||||||
FlowThread thread = FlowThread(roots[i], &_flowJointData);
|
FlowThread thread = FlowThread(roots[i], &_flowJointData);
|
||||||
// add threads with at least 2 joints
|
// add threads with at least 2 joints
|
||||||
if (thread._joints.size() > 0) {
|
if (thread._joints.size() > 0) {
|
||||||
if (thread._joints.size() == 1) {
|
if (thread._joints.size() == 1) {
|
||||||
int jointIndex = roots[i];
|
int jointIndex = roots[i];
|
||||||
auto joint = _flowJointData[jointIndex];
|
auto &joint = _flowJointData[jointIndex];
|
||||||
auto jointPosition = joint.getUpdatedPosition();
|
auto &jointPosition = joint.getUpdatedPosition();
|
||||||
auto newSettings = FlowPhysicsSettings(joint.getSettings());
|
auto newSettings = joint.getSettings();
|
||||||
newSettings._stiffness = ISOLATED_JOINT_STIFFNESS;
|
extraIndex = extraIndex > -1 ? extraIndex + 1 : skeleton->getNumJoints();
|
||||||
int extraIndex = (int)_flowJointData.size();
|
joint.setChildIndex(extraIndex);
|
||||||
auto newJoint = FlowDummyJoint(jointPosition, extraIndex, jointIndex, -1, newSettings);
|
auto newJoint = FlowJoint(extraIndex, jointIndex, -1, joint.getName(), joint.getGroup(), newSettings);
|
||||||
newJoint.toIsolatedJoint(ISOLATED_JOINT_LENGTH, extraIndex, _flowJointData[jointIndex].getGroup());
|
newJoint.toHelperJoint(jointPosition, HELPER_JOINT_LENGTH);
|
||||||
thread = FlowThread(jointIndex, &_flowJointData);
|
glm::vec3 translation = glm::vec3(0.0f, HELPER_JOINT_LENGTH, 0.0f);
|
||||||
|
newJoint.setInitialData(jointPosition + translation, 100.0f * translation , Quaternions::IDENTITY, jointPosition);
|
||||||
|
_flowJointData.insert(std::pair<int, FlowJoint>(extraIndex, newJoint));
|
||||||
|
FlowThread newThread = FlowThread(jointIndex, &_flowJointData);
|
||||||
|
if (newThread._joints.size() > 1) {
|
||||||
|
_jointThreads.push_back(newThread);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_jointThreads.push_back(thread);
|
||||||
}
|
}
|
||||||
_jointThreads.push_back(thread);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_jointThreads.size() == 0) {
|
if (_jointThreads.size() == 0) {
|
||||||
onCleanup();
|
onCleanup();
|
||||||
}
|
}
|
||||||
if (SHOW_DUMMY_JOINTS && rightHandIndex > -1) {
|
|
||||||
int jointCount = (int)_flowJointData.size();
|
|
||||||
int extraIndex = (int)_flowJointData.size();
|
|
||||||
glm::vec3 rightHandPosition;
|
|
||||||
getJointPositionInWorldFrame(absolutePoses, rightHandIndex, rightHandPosition, _entityPosition, _entityRotation);
|
|
||||||
int parentIndex = rightHandIndex;
|
|
||||||
for (int i = 0; i < DUMMY_JOINT_COUNT; i++) {
|
|
||||||
int childIndex = (i == (DUMMY_JOINT_COUNT - 1)) ? -1 : extraIndex + 1;
|
|
||||||
auto newJoint = FlowDummyJoint(rightHandPosition, extraIndex, parentIndex, childIndex, DEFAULT_JOINT_SETTINGS);
|
|
||||||
_flowJointData.insert(std::pair<int, FlowJoint>(extraIndex, newJoint));
|
|
||||||
parentIndex = extraIndex;
|
|
||||||
extraIndex++;
|
|
||||||
}
|
|
||||||
_flowJointData[jointCount].setAnchored(true);
|
|
||||||
|
|
||||||
auto extraThread = FlowThread(jointCount, &_flowJointData);
|
|
||||||
_jointThreads.push_back(extraThread);
|
|
||||||
}
|
|
||||||
if (handsIndices.size() > 0) {
|
if (handsIndices.size() > 0) {
|
||||||
FlowCollisionSettings handSettings;
|
FlowCollisionSettings handSettings;
|
||||||
handSettings._radius = HAND_COLLISION_RADIUS;
|
handSettings._radius = HAND_COLLISION_RADIUS;
|
||||||
|
@ -699,10 +682,16 @@ void Flow::updateJoints(AnimPoseVec& relativePoses, AnimPoseVec& absolutePoses)
|
||||||
int jointIndex = jointData.first;
|
int jointIndex = jointData.first;
|
||||||
glm::vec3 jointPosition, parentPosition, jointTranslation;
|
glm::vec3 jointPosition, parentPosition, jointTranslation;
|
||||||
glm::quat jointRotation, parentWorldRotation;
|
glm::quat jointRotation, parentWorldRotation;
|
||||||
getJointPositionInWorldFrame(absolutePoses, jointIndex, jointPosition, _entityPosition, _entityRotation);
|
if (!jointData.second.isHelper()) {
|
||||||
|
getJointPositionInWorldFrame(absolutePoses, jointIndex, jointPosition, _entityPosition, _entityRotation);
|
||||||
|
getJointTranslation(relativePoses, jointIndex, jointTranslation);
|
||||||
|
getJointRotation(relativePoses, jointIndex, jointRotation);
|
||||||
|
} else {
|
||||||
|
jointPosition = jointData.second.getCurrentPosition();
|
||||||
|
jointTranslation = jointData.second.getCurrentTranslation();
|
||||||
|
jointRotation = jointData.second.getCurrentRotation();
|
||||||
|
}
|
||||||
getJointPositionInWorldFrame(absolutePoses, jointData.second.getParentIndex(), parentPosition, _entityPosition, _entityRotation);
|
getJointPositionInWorldFrame(absolutePoses, jointData.second.getParentIndex(), parentPosition, _entityPosition, _entityRotation);
|
||||||
getJointTranslation(relativePoses, jointIndex, jointTranslation);
|
|
||||||
getJointRotation(relativePoses, jointIndex, jointRotation);
|
|
||||||
getJointRotationInWorldFrame(absolutePoses, jointData.second.getParentIndex(), parentWorldRotation, _entityRotation);
|
getJointRotationInWorldFrame(absolutePoses, jointData.second.getParentIndex(), parentWorldRotation, _entityRotation);
|
||||||
jointData.second.setUpdatedData(jointPosition, jointTranslation, jointRotation, parentPosition, parentWorldRotation);
|
jointData.second.setUpdatedData(jointPosition, jointTranslation, jointRotation, parentPosition, parentWorldRotation);
|
||||||
}
|
}
|
||||||
|
@ -753,7 +742,7 @@ bool Flow::getJointPositionInWorldFrame(const AnimPoseVec& absolutePoses, int jo
|
||||||
} else {
|
} else {
|
||||||
position = glm::vec3(0.0f);
|
position = glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,6 @@
|
||||||
class Rig;
|
class Rig;
|
||||||
class AnimSkeleton;
|
class AnimSkeleton;
|
||||||
|
|
||||||
const bool SHOW_DUMMY_JOINTS = false;
|
|
||||||
|
|
||||||
const int LEFT_HAND = 0;
|
|
||||||
const int RIGHT_HAND = 1;
|
|
||||||
|
|
||||||
const float HAPTIC_TOUCH_STRENGTH = 0.25f;
|
const float HAPTIC_TOUCH_STRENGTH = 0.25f;
|
||||||
const float HAPTIC_TOUCH_DURATION = 10.0f;
|
const float HAPTIC_TOUCH_DURATION = 10.0f;
|
||||||
const float HAPTIC_SLOPE = 0.18f;
|
const float HAPTIC_SLOPE = 0.18f;
|
||||||
|
@ -38,19 +33,8 @@ const QString SIM_JOINT_PREFIX = "sim";
|
||||||
|
|
||||||
const std::vector<QString> HAND_COLLISION_JOINTS = { "RightHandMiddle1", "RightHandThumb3", "LeftHandMiddle1", "LeftHandThumb3", "RightHandMiddle3", "LeftHandMiddle3" };
|
const std::vector<QString> HAND_COLLISION_JOINTS = { "RightHandMiddle1", "RightHandThumb3", "LeftHandMiddle1", "LeftHandThumb3", "RightHandMiddle3", "LeftHandMiddle3" };
|
||||||
|
|
||||||
const QString JOINT_COLLISION_PREFIX = "joint_";
|
|
||||||
const QString HAND_COLLISION_PREFIX = "hand_";
|
|
||||||
const float HAND_COLLISION_RADIUS = 0.03f;
|
const float HAND_COLLISION_RADIUS = 0.03f;
|
||||||
const float HAND_TOUCHING_DISTANCE = 2.0f;
|
const float HELPER_JOINT_LENGTH = 0.05f;
|
||||||
|
|
||||||
const int COLLISION_SHAPES_LIMIT = 4;
|
|
||||||
|
|
||||||
const QString DUMMY_KEYWORD = "Extra";
|
|
||||||
const int DUMMY_JOINT_COUNT = 8;
|
|
||||||
const float DUMMY_JOINT_DISTANCE = 0.05f;
|
|
||||||
|
|
||||||
const float ISOLATED_JOINT_STIFFNESS = 0.0f;
|
|
||||||
const float ISOLATED_JOINT_LENGTH = 0.05f;
|
|
||||||
|
|
||||||
const float DEFAULT_STIFFNESS = 0.0f;
|
const float DEFAULT_STIFFNESS = 0.0f;
|
||||||
const float DEFAULT_GRAVITY = -0.0096f;
|
const float DEFAULT_GRAVITY = -0.0096f;
|
||||||
|
@ -212,6 +196,7 @@ public:
|
||||||
|
|
||||||
FlowJoint(): FlowNode() {};
|
FlowJoint(): FlowNode() {};
|
||||||
FlowJoint(int jointIndex, int parentIndex, int childIndex, const QString& name, const QString& group, const FlowPhysicsSettings& settings);
|
FlowJoint(int jointIndex, int parentIndex, int childIndex, const QString& name, const QString& group, const FlowPhysicsSettings& settings);
|
||||||
|
void toHelperJoint(const glm::vec3& initialPosition, float length);
|
||||||
void setInitialData(const glm::vec3& initialPosition, const glm::vec3& initialTranslation, const glm::quat& initialRotation, const glm::vec3& parentPosition);
|
void setInitialData(const glm::vec3& initialPosition, const glm::vec3& initialTranslation, const glm::quat& initialRotation, const glm::vec3& parentPosition);
|
||||||
void setUpdatedData(const glm::vec3& updatedPosition, const glm::vec3& updatedTranslation, const glm::quat& updatedRotation, const glm::vec3& parentPosition, const glm::quat& parentWorldRotation);
|
void setUpdatedData(const glm::vec3& updatedPosition, const glm::vec3& updatedTranslation, const glm::quat& updatedRotation, const glm::vec3& parentPosition, const glm::quat& parentWorldRotation);
|
||||||
void setRecoveryPosition(const glm::vec3& recoveryPosition);
|
void setRecoveryPosition(const glm::vec3& recoveryPosition);
|
||||||
|
@ -219,19 +204,23 @@ public:
|
||||||
void solve(const FlowCollisionResult& collision);
|
void solve(const FlowCollisionResult& collision);
|
||||||
|
|
||||||
void setScale(float scale, bool initScale);
|
void setScale(float scale, bool initScale);
|
||||||
bool isAnchored() { return _anchored; }
|
bool isAnchored() const { return _anchored; }
|
||||||
void setAnchored(bool anchored) { _anchored = anchored; }
|
void setAnchored(bool anchored) { _anchored = anchored; }
|
||||||
|
bool isHelper() const { return _isHelper; }
|
||||||
|
|
||||||
const FlowPhysicsSettings& getSettings() { return _settings; }
|
const FlowPhysicsSettings& getSettings() { return _settings; }
|
||||||
void setSettings(const FlowPhysicsSettings& settings) { _settings = settings; }
|
void setSettings(const FlowPhysicsSettings& settings) { _settings = settings; }
|
||||||
|
|
||||||
const glm::vec3& getCurrentPosition() { return _currentPosition; }
|
const glm::vec3& getCurrentPosition() const { return _currentPosition; }
|
||||||
int getIndex() { return _index; }
|
int getIndex() const { return _index; }
|
||||||
int getParentIndex() { return _parentIndex; }
|
int getParentIndex() const { return _parentIndex; }
|
||||||
void setChildIndex(int index) { _childIndex = index; }
|
void setChildIndex(int index) { _childIndex = index; }
|
||||||
const glm::vec3& getUpdatedPosition() { return _updatedPosition; }
|
const glm::vec3& getUpdatedPosition() const { return _updatedPosition; }
|
||||||
const QString& getGroup() { return _group; }
|
const QString& getGroup() const { return _group; }
|
||||||
const glm::quat& getCurrentRotation() { return _currentRotation; }
|
const QString& getName() const { return _name; }
|
||||||
|
const glm::quat& getCurrentRotation() const { return _currentRotation; }
|
||||||
|
const glm::vec3& getCurrentTranslation() const { return _initialTranslation; }
|
||||||
|
const glm::vec3& getInitialPosition() const { return _initialPosition; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -240,7 +229,8 @@ protected:
|
||||||
int _childIndex{ -1 };
|
int _childIndex{ -1 };
|
||||||
QString _name;
|
QString _name;
|
||||||
QString _group;
|
QString _group;
|
||||||
bool _isDummy{ false };
|
|
||||||
|
bool _isHelper{ false };
|
||||||
|
|
||||||
glm::vec3 _initialTranslation;
|
glm::vec3 _initialTranslation;
|
||||||
glm::quat _initialRotation;
|
glm::quat _initialRotation;
|
||||||
|
@ -262,13 +252,6 @@ protected:
|
||||||
bool _applyRecovery { false };
|
bool _applyRecovery { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class FlowDummyJoint : public FlowJoint {
|
|
||||||
public:
|
|
||||||
FlowDummyJoint(const glm::vec3& initialPosition, int index, int parentIndex, int childIndex, FlowPhysicsSettings settings);
|
|
||||||
void toIsolatedJoint(float length, int childIndex, const QString& group);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class FlowThread {
|
class FlowThread {
|
||||||
public:
|
public:
|
||||||
FlowThread() {};
|
FlowThread() {};
|
||||||
|
|
|
@ -1911,14 +1911,12 @@ void Rig::initAnimGraph(const QUrl& url) {
|
||||||
qCritical(animation) << "Error loading: code = " << error << "str =" << str;
|
qCritical(animation) << "Error loading: code = " << error << "str =" << str;
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
connect(this, &Rig::onLoadComplete, [&]() {
|
connect(this, &Rig::onLoadComplete, [&]() {
|
||||||
if (_internalFlow.getActive()) {
|
_internalFlow.setActive(false);
|
||||||
_internalFlow.calculateConstraints(_animSkeleton, _internalPoseSet._relativePoses, _internalPoseSet._absolutePoses);
|
_internalFlow.cleanUp();
|
||||||
_networkFlow.calculateConstraints(_animSkeleton, _internalPoseSet._relativePoses, _internalPoseSet._absolutePoses);
|
_networkFlow.setActive(false);
|
||||||
}
|
_networkFlow.cleanUp();
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2136,5 +2134,6 @@ void Rig::initFlow(bool isActive) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_internalFlow.cleanUp();
|
_internalFlow.cleanUp();
|
||||||
|
_networkFlow.cleanUp();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue