More fixes

This commit is contained in:
luiscuenca 2019-01-25 13:42:18 -07:00
parent 7a0f3ea7ef
commit df4be641eb
8 changed files with 48 additions and 69 deletions

View file

@ -636,17 +636,17 @@ AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID)
RayToAvatarIntersectionResult AvatarManager::findRayIntersection(const PickRay& ray,
const QScriptValue& avatarIdsToInclude,
const QScriptValue& avatarIdsToDiscard,
const QStringList& jointIndicesToFilter,
const QStringList& jointNamesToFilter,
bool pickAgainstMesh) {
QVector<EntityItemID> avatarsToInclude = qVectorEntityItemIDFromScriptValue(avatarIdsToInclude);
QVector<EntityItemID> avatarsToDiscard = qVectorEntityItemIDFromScriptValue(avatarIdsToDiscard);
return findRayIntersectionVector(ray, avatarsToInclude, avatarsToDiscard, jointIndicesToFilter, pickAgainstMesh);
return findRayIntersectionVector(ray, avatarsToInclude, avatarsToDiscard, jointNamesToFilter, pickAgainstMesh);
}
RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const PickRay& ray,
const QVector<EntityItemID>& avatarsToInclude,
const QVector<EntityItemID>& avatarsToDiscard,
const QStringList& jointIndicesToFilter,
const QStringList& jointNamesToFilter,
bool pickAgainstMesh) {
RayToAvatarIntersectionResult result;
if (QThread::currentThread() != thread()) {
@ -655,35 +655,37 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
Q_ARG(const PickRay&, ray),
Q_ARG(const QVector<EntityItemID>&, avatarsToInclude),
Q_ARG(const QVector<EntityItemID>&, avatarsToDiscard),
Q_ARG(const QStringList&, jointIndicesToFilter),
Q_ARG(const QStringList&, jointNamesToFilter),
Q_ARG(bool, pickAgainstMesh));
return result;
}
PROFILE_RANGE(simulation_physics, __FUNCTION__);
float distance = (float)INT_MAX; // with FLT_MAX bullet rayTest does not return results
BoxFace face = BoxFace::UNKNOWN_FACE;
glm::vec3 surfaceNormal;
QVariantMap extraInfo;
std::vector<MyCharacterController::RayAvatarResult> physicsResults = _myAvatar->getCharacterController()->rayTest(glmToBullet(ray.origin), glmToBullet(ray.direction), distance, QVector<uint>());
glm::vec3 transformedRayPoint;
glm::vec3 transformedRayDirection;
if (physicsResults.size() > 0) {
glm::vec3 rayDirectionInv = { ray.direction.x != 0 ? 1.0f / ray.direction.x : INFINITY,
ray.direction.y != 0.0f ? 1.0f / ray.direction.y : INFINITY,
ray.direction.z != 0.0f ? 1.0f / ray.direction.z : INFINITY };
ray.direction.y != 0.0f ? 1.0f / ray.direction.y : INFINITY,
ray.direction.z != 0.0f ? 1.0f / ray.direction.z : INFINITY };
MyCharacterController::RayAvatarResult rayAvatarResult;
AvatarPointer avatar = nullptr;
BoxFace face = BoxFace::UNKNOWN_FACE;
glm::vec3 surfaceNormal;
QVariantMap extraInfo;
for (auto &hit : physicsResults) {
auto avatarID = hit._intersectWithAvatar;
bool avatarIsIncluded = avatarsToInclude.contains(avatarID);
bool avatarIsDiscarded = avatarsToDiscard.contains(avatarID);
if (jointIndicesToFilter.size() == 0 && ((avatarsToInclude.size() > 0 && !avatarIsIncluded) ||
(avatarsToDiscard.size() > 0 && avatarIsDiscarded))) {
if (avatarIsDiscarded || (jointNamesToFilter.size() == 0 && avatarsToInclude.size() > 0 && !avatarIsIncluded)) {
continue;
}
if (!(_myAvatar->getSessionUUID() == avatarID)) {
if (_myAvatar->getSessionUUID() != avatarID) {
auto avatarMap = getHashCopy();
AvatarHash::iterator itr = avatarMap.find(avatarID);
if (itr != avatarMap.end()) {
@ -692,25 +694,17 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
} else {
avatar = _myAvatar;
}
QVector<int> jointsToDiscard;
if (avatar && jointIndicesToFilter.size() > 0) {
QVector<int> jointIndicesToDiscard;
if (avatar && jointNamesToFilter.size() > 0 && avatarIsIncluded) {
auto names = avatar->getJointNames();
if (avatarIsIncluded) {
for (int i = 0; i < names.size(); i++) {
if (!jointIndicesToFilter.contains(names[i])) {
jointsToDiscard.push_back(i);
}
}
} else if (avatarIsDiscarded) {
for (int i = 0; i < names.size(); i++) {
if (jointIndicesToFilter.contains(names[i])) {
jointsToDiscard.push_back(i);
}
for (int i = 0; i < names.size(); i++) {
if (!jointNamesToFilter.contains(names[i])) {
jointIndicesToDiscard.push_back(i);
}
}
}
if (!hit._isBound) {
if (!jointsToDiscard.contains(hit._intersectWithJoint)) {
if (!jointIndicesToDiscard.contains(hit._intersectWithJoint)) {
rayAvatarResult = hit;
}
} else if (avatar) {
@ -720,7 +714,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
for (size_t i = 0; i < hit._boundJoints.size(); i++) {
assert(hit._boundJoints[i] < multiSpheres.size());
auto &mSphere = multiSpheres[hit._boundJoints[i]];
if (mSphere.isValid() && !jointsToDiscard.contains(hit._boundJoints[i])) {
if (mSphere.isValid() && jointIndicesToDiscard.contains(hit._boundJoints[i])) {
float boundDistance = FLT_MAX;
BoxFace face;
glm::vec3 surfaceNormal;
@ -770,7 +764,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
extraInfo["worldIntersectionPoint"] = vec3toVariant(rayAvatarResult._intersectionPoint);
break;
}
} else {
} else if (rayAvatarResult._intersect){
break;
}
}

View file

@ -138,26 +138,26 @@ public:
* @param {PickRay} ray
* @param {Uuid[]} [avatarsToInclude=[]]
* @param {Uuid[]} [avatarsToDiscard=[]]
* @param {string[]} [jointIndicesToFilter=[] - If included/discarded avatars are provided only this joints corresponding to those avatars would be included/discarded. ]
* @param {string[]} [jointNamesToFilter=[] - If included avatars are provided only this joints corresponding to those avatars would be included ]
* @returns {RayToAvatarIntersectionResult}
*/
Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersection(const PickRay& ray,
const QScriptValue& avatarIdsToInclude = QScriptValue(),
const QScriptValue& avatarIdsToDiscard = QScriptValue(),
const QStringList& jointIndicesToFilter = QStringList(),
const QStringList& jointNamesToFilter = QStringList(),
bool pickAgainstMesh = true);
/**jsdoc
* @function AvatarManager.findRayIntersectionVector
* @param {PickRay} ray
* @param {Uuid[]} avatarsToInclude
* @param {Uuid[]} avatarsToDiscard
* @param {string[]} [jointIndicesToFilter=[] - If included/discarded avatars are provided only this joints corresponding to those avatars would be included/discarded. ]
* @param {string[]} [jointNamesToFilter=[] - If included avatars are provided only this joints corresponding to those avatars would be included ]
* @returns {RayToAvatarIntersectionResult}
*/
Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersectionVector(const PickRay& ray,
const QVector<EntityItemID>& avatarsToInclude,
const QVector<EntityItemID>& avatarsToDiscard,
const QStringList& jointIndicesToFilter,
const QStringList& jointNamesToFilter,
bool pickAgainstMesh);
/**jsdoc

View file

@ -103,7 +103,7 @@ MyAvatar::MyAvatar(QThread* thread) :
_scriptedMotorFrame(SCRIPTED_MOTOR_CAMERA_FRAME),
_scriptedMotorMode(SCRIPTED_MOTOR_SIMPLE_MODE),
_motionBehaviors(AVATAR_MOTION_DEFAULTS),
_characterController(this),
_characterController(std::shared_ptr<MyAvatar>(this)),
_eyeContactTarget(LEFT_EYE),
_realWorldFieldOfView("realWorldFieldOfView",
DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES),
@ -2994,14 +2994,13 @@ void MyAvatar::postUpdate(float deltaTime, const render::ScenePointer& scene) {
const Rig& rig = _skeletonModel->getRig();
int jointCount = rig.getJointStateCount();
if (jointCount == (int)_multiSphereShapes.size()) {
int count = 0;
for (int i = 0; i < jointCount; i++) {
AnimPose jointPose;
rig.getAbsoluteJointPoseInRigFrame(i, jointPose);
const AnimPose pose = rigToWorldPose * jointPose;
auto &multiSphere = _multiSphereShapes[i];
auto debugLines = multiSphere.getDebugLines();
DebugDraw::getInstance().drawRays(debugLines, DEBUG_COLORS[count++ % NUM_DEBUG_COLORS], pose.trans(), pose.rot());
DebugDraw::getInstance().drawRays(debugLines, DEBUG_COLORS[i % NUM_DEBUG_COLORS], pose.trans(), pose.rot());
}
}
}
@ -5218,6 +5217,3 @@ void MyAvatar::releaseGrab(const QUuid& grabID) {
}
}
std::shared_ptr<MyAvatar> MyAvatar::getMyAvatarSharedPointer() {
return DependencyManager::get<AvatarManager>()->getMyAvatar();
}

View file

@ -1158,8 +1158,6 @@ public:
*/
Q_INVOKABLE void releaseGrab(const QUuid& grabID);
std::shared_ptr<MyAvatar> getMyAvatarSharedPointer();
AvatarEntityMap getAvatarEntityData() const override;
void setAvatarEntityData(const AvatarEntityMap& avatarEntityData) override;
void updateAvatarEntity(const QUuid& entityID, const QByteArray& entityData) override;

View file

@ -26,7 +26,7 @@ void MyCharacterController::RayShotgunResult::reset() {
walkable = true;
}
MyCharacterController::MyCharacterController(MyAvatar* avatar) {
MyCharacterController::MyCharacterController(std::shared_ptr<MyAvatar> avatar) {
assert(avatar);
_avatar = avatar;
@ -370,7 +370,7 @@ btCollisionShape* MyCharacterController::createDetailedCollisionShapeForJoint(in
DetailedMotionState* MyCharacterController::createDetailedMotionStateForJoint(int jointIndex) {
auto shape = createDetailedCollisionShapeForJoint(jointIndex);
if (shape) {
DetailedMotionState* motionState = new DetailedMotionState(_avatar->getMyAvatarSharedPointer(), shape, jointIndex);
DetailedMotionState* motionState = new DetailedMotionState(_avatar, shape, jointIndex);
motionState->setMass(_avatar->computeMass());
return motionState;
}
@ -384,9 +384,6 @@ void MyCharacterController::clearDetailedMotionStates() {
}
void MyCharacterController::resetDetailedMotionStates() {
for (size_t i = 0; i < _detailedMotionStates.size(); i++) {
_detailedMotionStates[i] = nullptr;
}
_detailedMotionStates.clear();
}
@ -398,7 +395,6 @@ void MyCharacterController::buildPhysicsTransaction(PhysicsEngine::Transaction&
_pendingFlags &= ~PENDING_FLAG_REMOVE_DETAILED_FROM_SIMULATION;
for (size_t i = 0; i < _detailedMotionStates.size(); i++) {
transaction.objectsToRemove.push_back(_detailedMotionStates[i]);
_detailedMotionStates[i] = nullptr;
}
_detailedMotionStates.clear();
}
@ -423,9 +419,9 @@ void MyCharacterController::handleProcessedPhysicsTransaction(PhysicsEngine::Tra
}
class ClosestDetailed : public btCollisionWorld::AllHitsRayResultCallback {
class DetailedRayResultCallback : public btCollisionWorld::AllHitsRayResultCallback {
public:
ClosestDetailed()
DetailedRayResultCallback()
: btCollisionWorld::AllHitsRayResultCallback(btVector3(0.0f, 0.0f, 0.0f), btVector3(0.0f, 0.0f, 0.0f)) {
// the RayResultCallback's group and mask must match MY_AVATAR
m_collisionFilterGroup = BULLET_COLLISION_GROUP_DETAILED_RAY;
@ -442,11 +438,12 @@ std::vector<MyCharacterController::RayAvatarResult> MyCharacterController::rayTe
std::vector<RayAvatarResult> foundAvatars;
if (_dynamicsWorld) {
btVector3 end = origin + length * direction;
ClosestDetailed rayCallback = ClosestDetailed();
DetailedRayResultCallback rayCallback = DetailedRayResultCallback();
rayCallback.m_flags |= btTriangleRaycastCallback::kF_KeepUnflippedNormal;
rayCallback.m_flags |= btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest;
_dynamicsWorld->rayTest(origin, end, rayCallback);
if (rayCallback.m_hitFractions.size() > 0) {
foundAvatars.reserve(rayCallback.m_hitFractions.size());
for (int i = 0; i < rayCallback.m_hitFractions.size(); i++) {
auto object = rayCallback.m_collisionObjects[i];
ObjectMotionState* motionState = static_cast<ObjectMotionState*>(object->getUserPointer());

View file

@ -23,7 +23,7 @@ class DetailedMotionState;
class MyCharacterController : public CharacterController {
public:
explicit MyCharacterController(MyAvatar* avatar);
explicit MyCharacterController(std::shared_ptr<MyAvatar> avatar);
~MyCharacterController ();
void setDynamicsWorld(btDynamicsWorld* world) override;
@ -77,7 +77,7 @@ private:
btConvexHullShape* computeShape() const;
protected:
MyAvatar* _avatar { nullptr };
std::shared_ptr<MyAvatar> _avatar { nullptr };
// shotgun scan data
btAlignedObjectArray<btVector3> _topPoints;

View file

@ -1727,6 +1727,8 @@ void Avatar::computeDetailedShapeInfo(ShapeInfo& shapeInfo, int jointIndex) {
auto& data = _multiSphereShapes[jointIndex].getSpheresData();
std::vector<glm::vec3> positions;
std::vector<btScalar> radiuses;
positions.reserve(data.size());
radiuses.reserve(data.size());
for (auto& sphere : data) {
positions.push_back(sphere._position);
radiuses.push_back(sphere._radius);

View file

@ -48,12 +48,10 @@ void SphereRegion::extractEdges(bool reverseY) {
if (vec.z == 0.0f) {
insertUnique(p1, _edgesX);
insertUnique(p2, _edgesX);
}
else if (vec.y == 0.0f && p1.y == yVal && p2.y == yVal) {
} else if (vec.y == 0.0f && p1.y == yVal && p2.y == yVal) {
insertUnique(p1, _edgesY);
insertUnique(p2, _edgesY);
}
else if (vec.x == 0.0f) {
} else if (vec.x == 0.0f) {
insertUnique(p1, _edgesZ);
insertUnique(p2, _edgesZ);
}
@ -104,8 +102,7 @@ CollisionShapeExtractionMode MultiSphereShape::getExtractionModeByName(const QSt
mode = CollisionShapeExtractionMode::SphereCollapse;
} else if (isRightHand || isLeftHand) {
mode = CollisionShapeExtractionMode::SpheresXY;
}
else if (isSim || isFlow || isEye || isToe) {
} else if (isSim || isFlow || isEye || isToe) {
mode = CollisionShapeExtractionMode::None;
}
return mode;
@ -174,17 +171,13 @@ bool MultiSphereShape::computeMultiSphereShape(int jointIndex, const QString& na
if (xyDif < 0.5f * xyEpsilon && xzDif < 0.5f * xzEpsilon && yzDif < 0.5f * yzEpsilon) {
applyMode = CollisionShapeExtractionMode::Sphere;
}
else if (xzDif < xzEpsilon) {
} else if (xzDif < xzEpsilon) {
applyMode = dimensions.y > dimensions.z ? CollisionShapeExtractionMode::SpheresY : CollisionShapeExtractionMode::SpheresXZ;
}
else if (xyDif < xyEpsilon) {
} else if (xyDif < xyEpsilon) {
applyMode = dimensions.z > dimensions.y ? CollisionShapeExtractionMode::SpheresZ : CollisionShapeExtractionMode::SpheresXY;
}
else if (yzDif < yzEpsilon) {
} else if (yzDif < yzEpsilon) {
applyMode = dimensions.x > dimensions.y ? CollisionShapeExtractionMode::SpheresX : CollisionShapeExtractionMode::SpheresYZ;
}
else {
} else {
applyMode = CollisionShapeExtractionMode::SpheresXYZ;
}
@ -473,8 +466,7 @@ void MultiSphereShape::calculateSphereLines(std::vector<std::pair<glm::vec3, glm
}
if ((vAxis.z == 0 && vAxis.x < 0) || (vAxis.x == 0 && vAxis.z < 0)) {
vAxis = -vAxis;
}
else if (vAxis.x < 0) {
} else if (vAxis.x < 0) {
vAxis = -vAxis;
}
}