From 6657026a120d9bfe51602a3be8eb3140572c3538 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 23 Jul 2015 08:34:44 -0700 Subject: [PATCH] remove cruft: legacy shapes for skeleton bones --- interface/src/avatar/Hand.cpp | 59 -------- interface/src/avatar/Hand.h | 4 - interface/src/avatar/SkeletonModel.cpp | 140 +------------------ interface/src/avatar/SkeletonModel.h | 6 - libraries/fbx/src/FBXReader.cpp | 46 ++---- libraries/fbx/src/FBXReader.h | 4 - libraries/fbx/src/OBJReader.cpp | 5 - libraries/render-utils/src/GeometryCache.cpp | 2 +- 8 files changed, 13 insertions(+), 253 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 63604d710d..017f11a610 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -40,65 +40,6 @@ void Hand::simulate(float deltaTime, bool isMine) { } } -// We create a static CollisionList that is recycled for each collision test. -const float MAX_COLLISIONS_PER_AVATAR = 32; -static CollisionList handCollisions(MAX_COLLISIONS_PER_AVATAR); - -void Hand::collideAgainstAvatar(Avatar* avatar, bool isMyHand) { - if (!avatar || avatar == _owningAvatar) { - // don't collide hands against ourself (that is done elsewhere) - return; - } - - const SkeletonModel& skeletonModel = _owningAvatar->getSkeletonModel(); - int jointIndices[2]; - jointIndices[0] = skeletonModel.getLeftHandJointIndex(); - jointIndices[1] = skeletonModel.getRightHandJointIndex(); - - for (size_t i = 0; i < 2; i++) { - int jointIndex = jointIndices[i]; - if (jointIndex < 0) { - continue; - } - - handCollisions.clear(); - QVector shapes; - skeletonModel.getHandShapes(jointIndex, shapes); - - if (avatar->findCollisions(shapes, handCollisions)) { - glm::vec3 totalPenetration(0.0f); - glm::vec3 averageContactPoint; - for (int j = 0; j < handCollisions.size(); ++j) { - CollisionInfo* collision = handCollisions.getCollision(j); - totalPenetration += collision->_penetration; - averageContactPoint += collision->_contactPoint; - } - if (isMyHand) { - // our hand against other avatar - // TODO: resolve this penetration when we don't think the other avatar will yield - //palm.addToPenetration(averagePenetration); - } else { - // someone else's hand against MyAvatar - // TODO: submit collision info to MyAvatar which should lean accordingly - averageContactPoint /= (float)handCollisions.size(); - avatar->applyCollision(averageContactPoint, totalPenetration); - - CollisionInfo collision; - collision._penetration = totalPenetration; - collision._contactPoint = averageContactPoint; - emit avatar->collisionWithAvatar(avatar->getSessionUUID(), _owningAvatar->getSessionUUID(), collision); - } - } - } -} - -void Hand::resolvePenetrations() { - for (size_t i = 0; i < getNumPalms(); ++i) { - PalmData& palm = getPalms()[i]; - palm.resolvePenetrations(); - } -} - void Hand::render(RenderArgs* renderArgs, bool isMine) { gpu::Batch& batch = *renderArgs->_batch; if (renderArgs->_renderMode != RenderArgs::SHADOW_RENDER_MODE && diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index ddc9d13489..750633959a 100644 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -40,10 +40,6 @@ public: void simulate(float deltaTime, bool isMine); void render(RenderArgs* renderArgs, bool isMine); - void collideAgainstAvatar(Avatar* avatar, bool isMyHand); - - void resolvePenetrations(); - private: // disallow copies of the Hand, copy of owning Avatar is disallowed too Hand(const Hand&); diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index d92481494a..318db274a9 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -159,41 +159,6 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { _boundingShape.setRotation(_rotation); } -void SkeletonModel::getHandShapes(int jointIndex, QVector& shapes) const { - if (jointIndex < 0 || jointIndex >= int(_shapes.size())) { - return; - } - if (jointIndex == getLeftHandJointIndex() - || jointIndex == getRightHandJointIndex()) { - // get all shapes that have this hand as an ancestor in the skeleton heirarchy - const FBXGeometry& geometry = _geometry->getFBXGeometry(); - for (int i = 0; i < _jointStates.size(); i++) { - const FBXJoint& joint = geometry.joints[i]; - int parentIndex = joint.parentIndex; - Shape* shape = _shapes[i]; - if (i == jointIndex) { - // this shape is the hand - if (shape) { - shapes.push_back(shape); - } - if (parentIndex != -1 && _shapes[parentIndex]) { - // also add the forearm - shapes.push_back(_shapes[parentIndex]); - } - } else if (shape) { - while (parentIndex != -1) { - if (parentIndex == jointIndex) { - // this shape is a child of the hand - shapes.push_back(shape); - break; - } - parentIndex = geometry.joints[parentIndex].parentIndex; - } - } - } - } -} - void SkeletonModel::renderIKConstraints(gpu::Batch& batch) { renderJointConstraints(batch, getRightHandJointIndex()); renderJointConstraints(batch, getLeftHandJointIndex()); @@ -644,46 +609,12 @@ void SkeletonModel::buildShapes() { // rootJointIndex == -1 if the avatar model has no skeleton return; } - - float uniformScale = extractUniformScale(_scale); - const int numStates = _jointStates.size(); - for (int i = 0; i < numStates; i++) { - JointState& state = _jointStates[i]; - const FBXJoint& joint = state.getFBXJoint(); - float radius = uniformScale * joint.boneRadius; - float halfHeight = 0.5f * uniformScale * joint.distanceToParent; - Shape::Type type = joint.shapeType; - int parentIndex = joint.parentIndex; - if (parentIndex == -1 || radius < EPSILON) { - type = INVALID_SHAPE; - } else if (type == CAPSULE_SHAPE && halfHeight < EPSILON) { - // this shape is forced to be a sphere - type = SPHERE_SHAPE; - } - Shape* shape = NULL; - if (type == SPHERE_SHAPE) { - shape = new SphereShape(radius); - shape->setEntity(this); - } else if (type == CAPSULE_SHAPE) { - assert(parentIndex != -1); - shape = new CapsuleShape(radius, halfHeight); - shape->setEntity(this); - } - if (shape && parentIndex != -1) { - // always disable collisions between joint and its parent - disableCollisions(i, parentIndex); - } - _shapes.push_back(shape); - } - - // This method moves the shapes to their default positions in Model frame. computeBoundingShape(geometry); } void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { // compute default joint transforms int numStates = _jointStates.size(); - assert(numStates == _shapes.size()); QVector transforms; transforms.fill(glm::mat4(), numStates); @@ -704,39 +635,11 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { * joint.preTransform * glm::mat4_cast(modifiedRotation) * joint.postTransform; } - // Each joint contributes its point to the bounding box + // Each joint contributes a sphere at its position + glm::vec3 axis(joint.boneRadius); glm::vec3 jointPosition = extractTranslation(transforms[i]); - totalExtents.addPoint(jointPosition); - - Shape* shape = _shapes[i]; - if (!shape) { - continue; - } - - // Each joint with a shape contributes to the totalExtents: a box - // that contains the sphere centered at the end of the joint with radius of the bone. - - // TODO: skip hand and arm shapes for bounding box calculation - int type = shape->getType(); - if (type == CAPSULE_SHAPE) { - // add the two furthest surface points of the capsule - CapsuleShape* capsule = static_cast(shape); - float radius = capsule->getRadius(); - glm::vec3 axis(radius); - Extents shapeExtents; - shapeExtents.reset(); - shapeExtents.addPoint(jointPosition + axis); - shapeExtents.addPoint(jointPosition - axis); - totalExtents.addExtents(shapeExtents); - } else if (type == SPHERE_SHAPE) { - float radius = shape->getBoundingRadius(); - glm::vec3 axis(radius); - Extents shapeExtents; - shapeExtents.reset(); - shapeExtents.addPoint(jointPosition + axis); - shapeExtents.addPoint(jointPosition - axis); - totalExtents.addExtents(shapeExtents); - } + totalExtents.addPoint(jointPosition + axis); + totalExtents.addPoint(jointPosition - axis); } // compute bounding shape parameters @@ -752,43 +655,8 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { _boundingRadius = 0.5f * glm::length(diagonal); } -void SkeletonModel::resetShapePositionsToDefaultPose() { - // DEBUG method. - // Moves shapes to the joint default locations for debug visibility into - // how the bounding shape is computed. - - if (!_geometry || _shapes.isEmpty()) { - // geometry or joints have not yet been created - return; - } - - const FBXGeometry& geometry = _geometry->getFBXGeometry(); - if (geometry.joints.isEmpty()) { - return; - } - - // The shapes are moved to their default positions in computeBoundingShape(). - computeBoundingShape(geometry); - - // Then we move them into world frame for rendering at the Model's location. - for (int i = 0; i < _shapes.size(); i++) { - Shape* shape = _shapes[i]; - if (shape) { - shape->setTranslation(_translation + _rotation * shape->getTranslation()); - shape->setRotation(_rotation * shape->getRotation()); - } - } - _boundingShape.setTranslation(_translation + _rotation * _boundingShapeLocalOffset); - _boundingShape.setRotation(_rotation); -} - void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha) { const int BALL_SUBDIVISIONS = 10; - if (_shapes.isEmpty()) { - // the bounding shape has not been propery computed - // so no need to render it - return; - } // draw a blue sphere at the capsule endpoint glm::vec3 endPoint; diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index 3d63238cf2..9d0c51e521 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -32,10 +32,6 @@ public: void simulate(float deltaTime, bool fullUpdate = true); - /// \param jointIndex index of hand joint - /// \param shapes[out] list in which is stored pointers to hand shapes - void getHandShapes(int jointIndex, QVector& shapes) const; - void renderIKConstraints(gpu::Batch& batch); /// Returns the index of the left hand joint, or -1 if not found. @@ -106,8 +102,6 @@ public: const CapsuleShape& getBoundingShape() const { return _boundingShape; } const glm::vec3 getBoundingShapeOffset() const { return _boundingShapeLocalOffset; } - void resetShapePositionsToDefaultPose(); // DEBUG method - bool hasSkeleton(); float getHeadClipDistance() const { return _headClipDistance; } diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 4d7bff4df0..f67fe133f2 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -1198,7 +1198,7 @@ class JointShapeInfo { public: JointShapeInfo() : numVertices(0), sumVertexWeights(0.0f), sumWeightedRadii(0.0f), numVertexWeights(0), - averageVertex(0.0f), boneBegin(0.0f), averageRadius(0.0f) { + boneBegin(0.0f), averageRadius(0.0f) { } // NOTE: the points here are in the "joint frame" which has the "jointEnd" at the origin @@ -1206,9 +1206,8 @@ public: float sumVertexWeights; // sum of all vertex weights float sumWeightedRadii; // sum of weighted vertices int numVertexWeights; // num vertices that contributed to sums - glm::vec3 averageVertex;// average of all mesh vertices (in joint frame) glm::vec3 boneBegin; // parent joint location (in joint frame) - float averageRadius; // average distance from mesh points to averageVertex + float averageRadius; }; class AnimationCurve { @@ -2219,8 +2218,6 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping, joint.boneRadius = 0.0f; joint.inverseBindRotation = joint.inverseDefaultRotation; joint.name = model.name; - joint.shapePosition = glm::vec3(0.0f); - joint.shapeType = INVALID_SHAPE; foreach (const QString& childID, childMap.values(modelID)) { QString type = typeFlags.value(childID); @@ -2490,7 +2487,6 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping, int jointIndex = fbxCluster.jointIndex; FBXJoint& joint = geometry.joints[jointIndex]; glm::mat4 transformJointToMesh = inverseModelTransform * joint.bindTransform; - glm::quat rotateMeshToJoint = glm::inverse(extractRotation(transformJointToMesh)); glm::vec3 boneEnd = extractTranslation(transformJointToMesh); glm::vec3 boneBegin = boneEnd; glm::vec3 boneDirection; @@ -2524,8 +2520,6 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping, jointShapeInfo.sumWeightedRadii += radiusWeight * radiusScale * glm::distance(vertex, boneEnd - boneDirection * proj); ++jointShapeInfo.numVertexWeights; - glm::vec3 vertexInJointFrame = rotateMeshToJoint * (radiusScale * (vertex - boneEnd)); - jointShapeInfo.averageVertex += vertexInJointFrame; ++jointShapeInfo.numVertices; } @@ -2571,7 +2565,6 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping, JointShapeInfo& jointShapeInfo = jointShapeInfos[jointIndex]; glm::mat4 transformJointToMesh = inverseModelTransform * joint.bindTransform; - glm::quat rotateMeshToJoint = glm::inverse(extractRotation(transformJointToMesh)); glm::vec3 boneEnd = extractTranslation(transformJointToMesh); glm::vec3 boneBegin = boneEnd; @@ -2594,9 +2587,6 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping, jointShapeInfo.sumVertexWeights += radiusWeight; jointShapeInfo.sumWeightedRadii += radiusWeight * radiusScale * glm::distance(vertex, boneEnd - boneDirection * proj); ++jointShapeInfo.numVertexWeights; - - glm::vec3 vertexInJointFrame = rotateMeshToJoint * (radiusScale * (vertex - boneEnd)); - jointShapeInfo.averageVertex += vertexInJointFrame; averageVertex += vertex; } int numVertices = extracted.mesh.vertices.size(); @@ -2622,7 +2612,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping, } - // now that all joints have been scanned, compute a collision shape for each joint + // now that all joints have been scanned, compute a radius for each bone glm::vec3 defaultCapsuleAxis(0.0f, 1.0f, 0.0f); for (int i = 0; i < geometry.joints.size(); ++i) { FBXJoint& joint = geometry.joints[i]; @@ -2640,40 +2630,20 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping, joint.boneRadius = jointShapeInfo.sumWeightedRadii / jointShapeInfo.sumVertexWeights; } - // we use a capsule if the joint had ANY mesh vertices successfully projected onto the bone + // the joint is "capsule-like" if it had ANY mesh vertices successfully projected onto the bone // AND its boneRadius is not too close to zero bool collideLikeCapsule = jointShapeInfo.numVertexWeights > 0 && glm::length(jointShapeInfo.boneBegin) > EPSILON; - if (collideLikeCapsule) { - joint.shapeRotation = rotationBetween(defaultCapsuleAxis, jointShapeInfo.boneBegin); - joint.shapePosition = 0.5f * jointShapeInfo.boneBegin; - joint.shapeType = CAPSULE_SHAPE; - } else { - // collide the joint like a sphere - joint.shapeType = SPHERE_SHAPE; - if (jointShapeInfo.numVertices > 0) { - jointShapeInfo.averageVertex /= (float)jointShapeInfo.numVertices; - joint.shapePosition = jointShapeInfo.averageVertex; - } else { - joint.shapePosition = glm::vec3(0.0f); - } + if (!collideLikeCapsule) { + // this joint's mesh did not successfully project onto the bone axis + // so it isn't "capsule-like" and we need to estimate its radius a different way: + // the average radius to the average point. if (jointShapeInfo.numVertexWeights == 0 && jointShapeInfo.numVertices > 0) { - // the bone projection algorithm was not able to compute the joint radius - // so we use an alternative measure jointShapeInfo.averageRadius /= (float)jointShapeInfo.numVertices; joint.boneRadius = jointShapeInfo.averageRadius; } - - float distanceFromEnd = glm::length(joint.shapePosition); - float distanceFromBegin = glm::distance(joint.shapePosition, jointShapeInfo.boneBegin); - if (distanceFromEnd > joint.distanceToParent && distanceFromBegin > joint.distanceToParent) { - // The shape is further from both joint endpoints than the endpoints are from each other - // which probably means the model has a bad transform somewhere. We disable this shape - // by setting its type to INVALID_SHAPE. - joint.shapeType = INVALID_SHAPE; - } } } geometry.palmDirection = parseVec3(mapping.value("palmDirection", "0, -1, 0").toString()); diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index 200cd4a121..fbb303a93b 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -78,9 +77,6 @@ public: glm::quat inverseBindRotation; glm::mat4 bindTransform; QString name; - glm::vec3 shapePosition; // in joint frame - glm::quat shapeRotation; // in joint frame - quint8 shapeType; bool isSkeletonJoint; }; diff --git a/libraries/fbx/src/OBJReader.cpp b/libraries/fbx/src/OBJReader.cpp index 2ec80e3d85..35ba437745 100644 --- a/libraries/fbx/src/OBJReader.cpp +++ b/libraries/fbx/src/OBJReader.cpp @@ -427,8 +427,6 @@ FBXGeometry OBJReader::readOBJ(QIODevice* device, const QVariantHash& mapping, Q geometry.joints[0].rotationMin = glm::vec3(0, 0, 0); geometry.joints[0].rotationMax = glm::vec3(0, 0, 0); geometry.joints[0].name = "OBJ"; - geometry.joints[0].shapePosition = glm::vec3(0, 0, 0); - geometry.joints[0].shapeType = SPHERE_SHAPE; geometry.joints[0].isSkeletonJoint = true; geometry.jointIndices["x"] = 1; @@ -604,9 +602,6 @@ void fbxDebugDump(const FBXGeometry& fbxgeo) { qCDebug(modelformat) << " inverseBindRotation" << joint.inverseBindRotation; qCDebug(modelformat) << " bindTransform" << joint.bindTransform; qCDebug(modelformat) << " name" << joint.name; - qCDebug(modelformat) << " shapePosition" << joint.shapePosition; - qCDebug(modelformat) << " shapeRotation" << joint.shapeRotation; - qCDebug(modelformat) << " shapeType" << joint.shapeType; qCDebug(modelformat) << " isSkeletonJoint" << joint.isSkeletonJoint; } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 6c03d57de3..cd63f7303a 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1780,7 +1780,7 @@ NetworkGeometry::NetworkGeometry(const QUrl& url, const QSharedPointer(), -1, 0.0f, 0.0f, glm::vec3(), glm::mat4(), glm::quat(), glm::quat(), glm::quat(), glm::mat4(), glm::mat4(), glm::vec3(), glm::vec3(), glm::quat(), glm::quat(), - glm::mat4(), QString(""), glm::vec3(), glm::quat(), SHAPE_TYPE_NONE, false}; + glm::mat4(), QString(""), false}; _geometry.joints.append(joint); _geometry.leftEyeJointIndex = -1; _geometry.rightEyeJointIndex = -1;