mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Fix error on exit and jointsToFilter param removed
This commit is contained in:
parent
f54f9e5bfd
commit
49659f0039
3 changed files with 25 additions and 36 deletions
|
@ -397,31 +397,37 @@ void AvatarManager::buildPhysicsTransaction(PhysicsEngine::Transaction& transact
|
||||||
if (isInPhysics) {
|
if (isInPhysics) {
|
||||||
transaction.objectsToRemove.push_back(avatar->_motionState);
|
transaction.objectsToRemove.push_back(avatar->_motionState);
|
||||||
avatar->_motionState = nullptr;
|
avatar->_motionState = nullptr;
|
||||||
|
|
||||||
auto& detailedMotionStates = avatar->getDetailedMotionStates();
|
auto& detailedMotionStates = avatar->getDetailedMotionStates();
|
||||||
|
qDebug() << "Deleting " << detailedMotionStates.size() << "Motion states";
|
||||||
for (auto& mState : detailedMotionStates) {
|
for (auto& mState : detailedMotionStates) {
|
||||||
transaction.objectsToRemove.push_back(mState);
|
transaction.objectsToRemove.push_back(mState);
|
||||||
}
|
}
|
||||||
avatar->resetDetailedMotionStates();
|
avatar->resetDetailedMotionStates();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ShapeInfo shapeInfo;
|
|
||||||
avatar->computeShapeInfo(shapeInfo);
|
|
||||||
btCollisionShape* shape = const_cast<btCollisionShape*>(ObjectMotionState::getShapeManager()->getShape(shapeInfo));
|
|
||||||
if (shape) {
|
|
||||||
AvatarMotionState* motionState = new AvatarMotionState(avatar, shape);
|
|
||||||
motionState->setMass(avatar->computeMass());
|
|
||||||
avatar->_motionState = motionState;
|
|
||||||
transaction.objectsToAdd.push_back(motionState);
|
|
||||||
} else {
|
|
||||||
failedShapeBuilds.insert(avatar);
|
|
||||||
}
|
|
||||||
if (avatar->getDetailedMotionStates().size() == 0) {
|
if (avatar->getDetailedMotionStates().size() == 0) {
|
||||||
avatar->createDetailedMotionStates(avatar);
|
avatar->createDetailedMotionStates(avatar);
|
||||||
for (auto dMotionState : avatar->getDetailedMotionStates()) {
|
for (auto dMotionState : avatar->getDetailedMotionStates()) {
|
||||||
transaction.objectsToAdd.push_back(dMotionState);
|
transaction.objectsToAdd.push_back(dMotionState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (avatar->getDetailedMotionStates().size() > 0) {
|
||||||
|
ShapeInfo shapeInfo;
|
||||||
|
avatar->computeShapeInfo(shapeInfo);
|
||||||
|
btCollisionShape* shape = const_cast<btCollisionShape*>(ObjectMotionState::getShapeManager()->getShape(shapeInfo));
|
||||||
|
if (shape) {
|
||||||
|
AvatarMotionState* motionState = new AvatarMotionState(avatar, shape);
|
||||||
|
motionState->setMass(avatar->computeMass());
|
||||||
|
avatar->_motionState = motionState;
|
||||||
|
transaction.objectsToAdd.push_back(motionState);
|
||||||
|
} else {
|
||||||
|
failedShapeBuilds.insert(avatar);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
failedShapeBuilds.insert(avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Adding " << avatar->getDetailedMotionStates().size() << " Motion states";
|
||||||
}
|
}
|
||||||
} else if (isInPhysics) {
|
} else if (isInPhysics) {
|
||||||
transaction.objectsToChange.push_back(avatar->_motionState);
|
transaction.objectsToChange.push_back(avatar->_motionState);
|
||||||
|
@ -625,17 +631,15 @@ AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID)
|
||||||
RayToAvatarIntersectionResult AvatarManager::findRayIntersection(const PickRay& ray,
|
RayToAvatarIntersectionResult AvatarManager::findRayIntersection(const PickRay& ray,
|
||||||
const QScriptValue& avatarIdsToInclude,
|
const QScriptValue& avatarIdsToInclude,
|
||||||
const QScriptValue& avatarIdsToDiscard,
|
const QScriptValue& avatarIdsToDiscard,
|
||||||
const QStringList& jointNamesToFilter,
|
|
||||||
bool pickAgainstMesh) {
|
bool pickAgainstMesh) {
|
||||||
QVector<EntityItemID> avatarsToInclude = qVectorEntityItemIDFromScriptValue(avatarIdsToInclude);
|
QVector<EntityItemID> avatarsToInclude = qVectorEntityItemIDFromScriptValue(avatarIdsToInclude);
|
||||||
QVector<EntityItemID> avatarsToDiscard = qVectorEntityItemIDFromScriptValue(avatarIdsToDiscard);
|
QVector<EntityItemID> avatarsToDiscard = qVectorEntityItemIDFromScriptValue(avatarIdsToDiscard);
|
||||||
return findRayIntersectionVector(ray, avatarsToInclude, avatarsToDiscard, jointNamesToFilter, pickAgainstMesh);
|
return findRayIntersectionVector(ray, avatarsToInclude, avatarsToDiscard, pickAgainstMesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const PickRay& ray,
|
RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const PickRay& ray,
|
||||||
const QVector<EntityItemID>& avatarsToInclude,
|
const QVector<EntityItemID>& avatarsToInclude,
|
||||||
const QVector<EntityItemID>& avatarsToDiscard,
|
const QVector<EntityItemID>& avatarsToDiscard,
|
||||||
const QStringList& jointNamesToFilter,
|
|
||||||
bool pickAgainstMesh) {
|
bool pickAgainstMesh) {
|
||||||
RayToAvatarIntersectionResult result;
|
RayToAvatarIntersectionResult result;
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
|
@ -644,10 +648,10 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
||||||
Q_ARG(const PickRay&, ray),
|
Q_ARG(const PickRay&, ray),
|
||||||
Q_ARG(const QVector<EntityItemID>&, avatarsToInclude),
|
Q_ARG(const QVector<EntityItemID>&, avatarsToInclude),
|
||||||
Q_ARG(const QVector<EntityItemID>&, avatarsToDiscard),
|
Q_ARG(const QVector<EntityItemID>&, avatarsToDiscard),
|
||||||
Q_ARG(const QStringList&, jointNamesToFilter),
|
|
||||||
Q_ARG(bool, pickAgainstMesh));
|
Q_ARG(bool, pickAgainstMesh));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
PROFILE_RANGE(simulation_physics, __FUNCTION__);
|
PROFILE_RANGE(simulation_physics, __FUNCTION__);
|
||||||
|
|
||||||
float distance = (float)INT_MAX; // with FLT_MAX bullet rayTest does not return results
|
float distance = (float)INT_MAX; // with FLT_MAX bullet rayTest does not return results
|
||||||
|
@ -668,9 +672,8 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
||||||
|
|
||||||
for (auto &hit : physicsResults) {
|
for (auto &hit : physicsResults) {
|
||||||
auto avatarID = hit._intersectWithAvatar;
|
auto avatarID = hit._intersectWithAvatar;
|
||||||
bool avatarIsIncluded = avatarsToInclude.contains(avatarID);
|
if ((avatarsToInclude.size() > 0 && !avatarsToInclude.contains(avatarID)) ||
|
||||||
bool avatarIsDiscarded = avatarsToDiscard.contains(avatarID);
|
(avatarsToDiscard.size() > 0 && avatarsToDiscard.contains(avatarID))) {
|
||||||
if (avatarIsDiscarded || (jointNamesToFilter.size() == 0 && avatarsToInclude.size() > 0 && !avatarIsIncluded)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,19 +686,8 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
||||||
} else {
|
} else {
|
||||||
avatar = _myAvatar;
|
avatar = _myAvatar;
|
||||||
}
|
}
|
||||||
QVector<int> jointIndicesToDiscard;
|
|
||||||
if (avatar && jointNamesToFilter.size() > 0 && avatarIsIncluded) {
|
|
||||||
auto names = avatar->getJointNames();
|
|
||||||
for (int i = 0; i < names.size(); i++) {
|
|
||||||
if (!jointNamesToFilter.contains(names[i])) {
|
|
||||||
jointIndicesToDiscard.push_back(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hit._isBound) {
|
if (!hit._isBound) {
|
||||||
if (!jointIndicesToDiscard.contains(hit._intersectWithJoint)) {
|
rayAvatarResult = hit;
|
||||||
rayAvatarResult = hit;
|
|
||||||
}
|
|
||||||
} else if (avatar) {
|
} else if (avatar) {
|
||||||
auto &multiSpheres = avatar->getMultiSphereShapes();
|
auto &multiSpheres = avatar->getMultiSphereShapes();
|
||||||
if (multiSpheres.size() > 0) {
|
if (multiSpheres.size() > 0) {
|
||||||
|
@ -703,7 +695,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
||||||
for (size_t i = 0; i < hit._boundJoints.size(); i++) {
|
for (size_t i = 0; i < hit._boundJoints.size(); i++) {
|
||||||
assert(hit._boundJoints[i] < multiSpheres.size());
|
assert(hit._boundJoints[i] < multiSpheres.size());
|
||||||
auto &mSphere = multiSpheres[hit._boundJoints[i]];
|
auto &mSphere = multiSpheres[hit._boundJoints[i]];
|
||||||
if (mSphere.isValid() && jointIndicesToDiscard.contains(hit._boundJoints[i])) {
|
if (mSphere.isValid()) {
|
||||||
float boundDistance = FLT_MAX;
|
float boundDistance = FLT_MAX;
|
||||||
BoxFace face;
|
BoxFace face;
|
||||||
glm::vec3 surfaceNormal;
|
glm::vec3 surfaceNormal;
|
||||||
|
@ -757,7 +749,6 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rayAvatarResult._intersect) {
|
if (rayAvatarResult._intersect) {
|
||||||
result.intersects = true;
|
result.intersects = true;
|
||||||
result.avatarID = rayAvatarResult._intersectWithAvatar;
|
result.avatarID = rayAvatarResult._intersectWithAvatar;
|
||||||
|
|
|
@ -143,7 +143,6 @@ public:
|
||||||
Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersection(const PickRay& ray,
|
Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersection(const PickRay& ray,
|
||||||
const QScriptValue& avatarIdsToInclude = QScriptValue(),
|
const QScriptValue& avatarIdsToInclude = QScriptValue(),
|
||||||
const QScriptValue& avatarIdsToDiscard = QScriptValue(),
|
const QScriptValue& avatarIdsToDiscard = QScriptValue(),
|
||||||
const QStringList& jointNamesToFilter = QStringList(),
|
|
||||||
bool pickAgainstMesh = true);
|
bool pickAgainstMesh = true);
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @function AvatarManager.findRayIntersectionVector
|
* @function AvatarManager.findRayIntersectionVector
|
||||||
|
@ -156,7 +155,6 @@ public:
|
||||||
Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersectionVector(const PickRay& ray,
|
Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersectionVector(const PickRay& ray,
|
||||||
const QVector<EntityItemID>& avatarsToInclude,
|
const QVector<EntityItemID>& avatarsToInclude,
|
||||||
const QVector<EntityItemID>& avatarsToDiscard,
|
const QVector<EntityItemID>& avatarsToDiscard,
|
||||||
const QStringList& jointNamesToFilter,
|
|
||||||
bool pickAgainstMesh);
|
bool pickAgainstMesh);
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
|
|
|
@ -56,7 +56,7 @@ PickResultPointer RayPick::getOverlayIntersection(const PickRay& pick) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PickResultPointer RayPick::getAvatarIntersection(const PickRay& pick) {
|
PickResultPointer RayPick::getAvatarIntersection(const PickRay& pick) {
|
||||||
RayToAvatarIntersectionResult avatarRes = DependencyManager::get<AvatarManager>()->findRayIntersectionVector(pick, getIncludeItemsAs<EntityItemID>(), getIgnoreItemsAs<EntityItemID>(), QStringList(), true);
|
RayToAvatarIntersectionResult avatarRes = DependencyManager::get<AvatarManager>()->findRayIntersectionVector(pick, getIncludeItemsAs<EntityItemID>(), getIgnoreItemsAs<EntityItemID>(), true);
|
||||||
if (avatarRes.intersects) {
|
if (avatarRes.intersects) {
|
||||||
return std::make_shared<RayPickResult>(IntersectionType::AVATAR, avatarRes.avatarID, avatarRes.distance, avatarRes.intersection, pick, avatarRes.surfaceNormal, avatarRes.extraInfo);
|
return std::make_shared<RayPickResult>(IntersectionType::AVATAR, avatarRes.avatarID, avatarRes.distance, avatarRes.intersection, pick, avatarRes.surfaceNormal, avatarRes.extraInfo);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue