History

JointStates are owned by Rig objects. Model, FaceModel, SkeletonModel call into their Rig pointer to access JointStates.

Seth Alves committed 11 years ago

Commit ee334ff1 parent 47965bc19 files · +549 −622Browse files

Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 19 files). Show all

Unified · Split

interface/src/avatar/SkeletonModel.cpp+66−65
@@ -30,7 +30,7 @@ enum StandingFootState { · 29 unmodified lines
3030 };
3131
3232 SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer rig) :
33− Model(parent, rig),
33+ Model(rig, parent),
3434 _triangleFanID(DependencyManager::get<GeometryCache>()->allocateID()),
3535 _owningAvatar(owningAvatar),
3636 _boundingShape(),
@@ -51,11 +51,13 @@ SkeletonModel::~SkeletonModel() { · 14 unmodified lines
5151 }
5252
5353 void SkeletonModel::initJointStates(QVector<JointState> states) {
54− Model::initJointStates(states);
54+ const FBXGeometry& geometry = _geometry->getFBXGeometry();
55+ glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
56+ _boundingRadius = _rig->initJointStates(states, parentTransform);
5557
5658 // Determine the default eye position for avatar scale = 1.0
5759 int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
58− if (0 <= headJointIndex && headJointIndex < _jointStates.size()) {
60+ if (0 <= headJointIndex && headJointIndex < _rig->getJointStateCount()) {
5961
6062 glm::vec3 leftEyePosition, rightEyePosition;
6163 getEyeModelPositions(leftEyePosition, rightEyePosition);
@@ -75,8 +77,8 @@ void SkeletonModel::initJointStates(QVector<JointState> states) { · 13 unmodified lines
7577 // the SkeletonModel override of updateJointState() will clear the translation part
7678 // of its root joint and we need that done before we try to build shapes hence we
7779 // recompute all joint transforms at this time.
78− for (int i = 0; i < _jointStates.size(); i++) {
79− updateJointState(i);
80+ for (int i = 0; i < _rig->getJointStateCount(); i++) {
81+ _rig->updateJointState(i, parentTransform);
8082 }
8183
8284 clearShapes();
@@ -168,7 +170,7 @@ void SkeletonModel::getHandShapes(int jointIndex, QVector<const Shape*>& shapes) · 85 unmodified lines
168170 || jointIndex == getRightHandJointIndex()) {
169171 // get all shapes that have this hand as an ancestor in the skeleton heirarchy
170172 const FBXGeometry& geometry = _geometry->getFBXGeometry();
171− for (int i = 0; i < _jointStates.size(); i++) {
173+ for (int i = 0; i < _rig->getJointStateCount(); i++) {
172174 const FBXJoint& joint = geometry.joints[i];
173175 int parentIndex = joint.parentIndex;
174176 Shape* shape = _shapes[i];
@@ -211,7 +213,7 @@ bool operator<(const IndexValue& firstIndex, const IndexValue& secondIndex) { · 36 unmodified lines
211213 }
212214
213215 void SkeletonModel::applyHandPosition(int jointIndex, const glm::vec3& position) {
214− if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
216+ if (jointIndex == -1 || jointIndex >= _rig->getJointStateCount()) {
215217 return;
216218 }
217219 // NOTE: 'position' is in model-frame
@@ -226,16 +228,20 @@ void SkeletonModel::applyHandPosition(int jointIndex, const glm::vec3& position) · 8 unmodified lines
226228 if (forearmLength < EPSILON) {
227229 return;
228230 }
229− JointState& state = _jointStates[jointIndex];
230− glm::quat handRotation = state.getRotation();
231+ glm::quat handRotation;
232+ if (!_rig->getJointStateRotation(jointIndex, handRotation)) {
233+ return;
234+ }
231235
232236 // align hand with forearm
233237 float sign = (jointIndex == geometry.rightHandJointIndex) ? 1.0f : -1.0f;
234− state.applyRotationDelta(rotationBetween(handRotation * glm::vec3(-sign, 0.0f, 0.0f), forearmVector), true, PALM_PRIORITY);
238+ _rig->applyJointRotationDelta(jointIndex,
239+ rotationBetween(handRotation * glm::vec3(-sign, 0.0f, 0.0f), forearmVector),
240+ true, PALM_PRIORITY);
235241 }
236242
237243 void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) {
238− if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
244+ if (jointIndex == -1 || jointIndex >= _rig->getJointStateCount()) {
239245 return;
240246 }
241247 const FBXGeometry& geometry = _geometry->getFBXGeometry();
@@ -261,43 +267,40 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) { · 19 unmodified lines
261267 glm::vec3 forearm = palmRotation * glm::vec3(sign * forearmLength, 0.0f, 0.0f);
262268 setJointPosition(parentJointIndex, palmPosition + forearm,
263269 glm::quat(), false, -1, false, glm::vec3(0.0f, -1.0f, 0.0f), PALM_PRIORITY);
264− JointState& parentState = _jointStates[parentJointIndex];
265− parentState.setRotationInBindFrame(palmRotation, PALM_PRIORITY);
270+ _rig->setJointRotationInBindFrame(parentJointIndex, palmRotation, PALM_PRIORITY);
266271 // lock hand to forearm by slamming its rotation (in parent-frame) to identity
267− _jointStates[jointIndex].setRotationInConstrainedFrame(glm::quat(), PALM_PRIORITY);
272+ _rig->setJointRotationInConstrainedFrame(jointIndex, glm::quat(), PALM_PRIORITY);
268273 } else {
269274 inverseKinematics(jointIndex, palmPosition, palmRotation, PALM_PRIORITY);
270275 }
271276 }
272277
273278 void SkeletonModel::updateJointState(int index) {
274− if (index < 0 && index >= _jointStates.size()) {
275− return; // bail
276− }
277− JointState& state = _jointStates[index];
278− const FBXJoint& joint = state.getFBXJoint();
279− if (joint.parentIndex >= 0 && joint.parentIndex < _jointStates.size()) {
280− const JointState& parentState = _jointStates.at(joint.parentIndex);
281− const FBXGeometry& geometry = _geometry->getFBXGeometry();
279+ const FBXGeometry& geometry = _geometry->getFBXGeometry();
280+ glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
281+
282+ const JointState joint = _rig->getJointState(index);
283+ if (joint.getParentIndex() >= 0 && joint.getParentIndex() < _rig->getJointStateCount()) {
284+ const JointState parentState = _rig->getJointState(joint.getParentIndex());
282285 if (index == geometry.leanJointIndex) {
283− maybeUpdateLeanRotation(parentState, state);
284−
286+ maybeUpdateLeanRotation(parentState, index);
287+
285288 } else if (index == geometry.neckJointIndex) {
286− maybeUpdateNeckRotation(parentState, joint, state);
287−
289+ maybeUpdateNeckRotation(parentState, joint.getFBXJoint(), index);
290+
288291 } else if (index == geometry.leftEyeJointIndex || index == geometry.rightEyeJointIndex) {
289− maybeUpdateEyeRotation(parentState, joint, state);
292+ maybeUpdateEyeRotation(parentState, joint.getFBXJoint(), index);
290293 }
291294 }
292295
293− Model::updateJointState(index);
296+ _rig->updateJointState(index, parentTransform);
294297
295298 if (index == _geometry->getFBXGeometry().rootJointIndex) {
296− state.clearTransformTranslation();
299+ _rig->clearJointTransformTranslation(index);
297300 }
298301 }
299302
300−void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, JointState& state) {
303+void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, int index) {
301304 if (!_owningAvatar->isMyAvatar()) {
302305 return;
303306 }
@@ -305,24 +308,24 @@ void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, Joint · 1 unmodified line
305308 glm::vec3 xAxis(1.0f, 0.0f, 0.0f);
306309 glm::vec3 yAxis(0.0f, 1.0f, 0.0f);
307310 glm::vec3 zAxis(0.0f, 0.0f, 1.0f);
308− glm::quat inverse = glm::inverse(parentState.getRotation() * state.getDefaultRotationInParentFrame());
309− state.setRotationInConstrainedFrame(
310− glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanSideways(), inverse * zAxis)
311− * glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanForward(), inverse * xAxis)
312− * glm::angleAxis(RADIANS_PER_DEGREE * _owningAvatar->getHead()->getTorsoTwist(), inverse * yAxis)
313− * state.getFBXJoint().rotation, LEAN_PRIORITY);
311+ glm::quat inverse = glm::inverse(parentState.getRotation() * _rig->getJointDefaultRotationInParentFrame(index));
312+ _rig->setJointRotationInConstrainedFrame(index,
313+ glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanSideways(), inverse * zAxis)
314+ * glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanForward(), inverse * xAxis)
315+ * glm::angleAxis(RADIANS_PER_DEGREE * _owningAvatar->getHead()->getTorsoTwist(), inverse * yAxis)
316+ * _rig->getJointState(index).getFBXJoint().rotation, LEAN_PRIORITY);
314317 }
315318
316−void SkeletonModel::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
317− _owningAvatar->getHead()->getFaceModel().maybeUpdateNeckRotation(parentState, joint, state);
319+void SkeletonModel::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, int index) {
320+ _owningAvatar->getHead()->getFaceModel().maybeUpdateNeckRotation(parentState, joint, index);
318321 }
319322
320−void SkeletonModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
321− _owningAvatar->getHead()->getFaceModel().maybeUpdateEyeRotation(this, parentState, joint, state);
323+void SkeletonModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, int index) {
324+ _owningAvatar->getHead()->getFaceModel().maybeUpdateEyeRotation(this, parentState, joint, index);
322325 }
323326
324327 void SkeletonModel::renderJointConstraints(gpu::Batch& batch, int jointIndex) {
325− if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
328+ if (jointIndex == -1 || jointIndex >= _rig->getJointStateCount()) {
326329 return;
327330 }
328331 const FBXGeometry& geometry = _geometry->getFBXGeometry();
@@ -331,9 +334,11 @@ void SkeletonModel::renderJointConstraints(gpu::Batch& batch, int jointIndex) { · 2 unmodified lines
331334 batch._glLineWidth(3.0f);
332335 do {
333336 const FBXJoint& joint = geometry.joints.at(jointIndex);
334− const JointState& jointState = _jointStates.at(jointIndex);
337+ const JointState& jointState = _rig->getJointState(jointIndex);
335338 glm::vec3 position = _rotation * jointState.getPosition() + _translation;
336− glm::quat parentRotation = (joint.parentIndex == -1) ? _rotation : _rotation * _jointStates.at(joint.parentIndex).getRotation();
339+ glm::quat parentRotation = (joint.parentIndex == -1) ?
340+ _rotation :
341+ _rotation * _rig->getJointState(joint.parentIndex).getRotation();
337342 float fanScale = directionSize * 0.75f;
338343
339344 Transform transform = Transform();
@@ -464,14 +469,11 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c · 124 unmodified lines
464469 glm::vec3 forwardVector(rightHand ? -1.0f : 1.0f, 0.0f, 0.0f);
465470 glm::quat shoulderRotation = rotationBetween(forwardVector, elbowPosition - shoulderPosition);
466471
467− JointState& shoulderState = _jointStates[shoulderJointIndex];
468− shoulderState.setRotationInBindFrame(shoulderRotation, PALM_PRIORITY);
469−
470− JointState& elbowState = _jointStates[elbowJointIndex];
471− elbowState.setRotationInBindFrame(rotationBetween(shoulderRotation * forwardVector, wristPosition - elbowPosition) * shoulderRotation, PALM_PRIORITY);
472−
473− JointState& handState = _jointStates[jointIndex];
474− handState.setRotationInBindFrame(rotation, PALM_PRIORITY);
472+ _rig->setJointRotationInBindFrame(shoulderJointIndex, shoulderRotation, PALM_PRIORITY);
473+ _rig->setJointRotationInBindFrame(elbowJointIndex,
474+ rotationBetween(shoulderRotation * forwardVector, wristPosition - elbowPosition) *
475+ shoulderRotation, PALM_PRIORITY);
476+ _rig->setJointRotationInBindFrame(jointIndex, rotation, PALM_PRIORITY);
475477 }
476478
477479 bool SkeletonModel::getLeftHandPosition(glm::vec3& position) const {
@@ -526,7 +528,7 @@ bool SkeletonModel::getNeckParentRotationFromDefaultOrientation(glm::quat& neckP · 48 unmodified lines
526528 glm::quat worldFrameRotation;
527529 bool success = getJointRotationInWorldFrame(parentIndex, worldFrameRotation);
528530 if (success) {
529− neckParentRotation = worldFrameRotation * _jointStates[parentIndex].getFBXJoint().inverseDefaultRotation;
531+ neckParentRotation = worldFrameRotation * _rig->getJointState(parentIndex).getFBXJoint().inverseDefaultRotation;
530532 }
531533 return success;
532534 }
@@ -636,7 +638,7 @@ float VERY_BIG_MASS = 1.0e6f; · 103 unmodified lines
636638
637639 // virtual
638640 void SkeletonModel::buildShapes() {
639− if (_geometry == NULL || _jointStates.isEmpty()) {
641+ if (_geometry == NULL || _rig->jointStatesEmpty()) {
640642 return;
641643 }
642644
@@ -647,9 +649,8 @@ void SkeletonModel::buildShapes() { · 4 unmodified lines
647649 }
648650
649651 float uniformScale = extractUniformScale(_scale);
650− const int numStates = _jointStates.size();
651− for (int i = 0; i < numStates; i++) {
652− JointState& state = _jointStates[i];
652+ for (int i = 0; i < _rig->getJointStateCount(); i++) {
653+ const JointState& state = _rig->getJointState(i);
653654 const FBXJoint& joint = state.getFBXJoint();
654655 float radius = uniformScale * joint.boneRadius;
655656 float halfHeight = 0.5f * uniformScale * joint.distanceToParent;
@@ -683,7 +684,7 @@ void SkeletonModel::buildShapes() { · 27 unmodified lines
683684
684685 void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) {
685686 // compute default joint transforms
686− int numStates = _jointStates.size();
687+ int numStates = _rig->getJointStateCount();
687688 assert(numStates == _shapes.size());
688689 QVector<glm::mat4> transforms;
689690 transforms.fill(glm::mat4(), numStates);
@@ -694,11 +695,11 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { · 4 unmodified lines
694695 totalExtents.addPoint(glm::vec3(0.0f));
695696 for (int i = 0; i < numStates; i++) {
696697 // compute the default transform of this joint
697− JointState& state = _jointStates[i];
698+ const JointState& state = _rig->getJointState(i);
698699 const FBXJoint& joint = state.getFBXJoint();
699700 int parentIndex = joint.parentIndex;
700701 if (parentIndex == -1) {
701− transforms[i] = _jointStates[i].getTransform();
702+ transforms[i] = _rig->getJointTransform(i);
702703 } else {
703704 glm::quat modifiedRotation = joint.preRotation * joint.rotation * joint.postRotation;
704705 transforms[i] = transforms[parentIndex] * glm::translate(joint.translation)
@@ -748,7 +749,7 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { · 43 unmodified lines
748749 _boundingShape.setRadius(capsuleRadius);
749750 _boundingShape.setHalfHeight(0.5f * diagonal.y - capsuleRadius);
750751
751− glm::vec3 rootPosition = _jointStates[geometry.rootJointIndex].getPosition();
752+ glm::vec3 rootPosition = _rig->getJointState(geometry.rootJointIndex).getPosition();
752753 _boundingShapeLocalOffset = 0.5f * (totalExtents.maximum + totalExtents.minimum) - rootPosition;
753754 _boundingRadius = 0.5f * glm::length(diagonal);
754755 }
@@ -853,7 +854,7 @@ void SkeletonModel::cauterizeHead() { · 98 unmodified lines
853854 if (isActive()) {
854855 const FBXGeometry& geometry = _geometry->getFBXGeometry();
855856 const int neckJointIndex = geometry.neckJointIndex;
856− if (neckJointIndex > 0 && neckJointIndex < _jointStates.size()) {
857+ if (neckJointIndex > 0 && neckJointIndex < _rig->getJointStateCount()) {
857858
858859 // lazy init of headBones
859860 if (_headBones.size() == 0) {
@@ -861,13 +862,13 @@ void SkeletonModel::cauterizeHead() { · 1 unmodified line
861862 }
862863
863864 // preserve the translation for the neck
864− glm::vec4 trans = _jointStates[neckJointIndex].getTransform()[3];
865+ // glm::vec4 trans = _jointStates[neckJointIndex].getTransform()[3];
866+ glm::vec4 trans = _rig->getJointTransform(neckJointIndex)[3];
865867 glm::vec4 zero(0, 0, 0, 0);
866868 for (const int &i : _headBones) {
867− JointState& joint = _jointStates[i];
868869 glm::mat4 newXform(zero, zero, zero, trans);
869− joint.setTransform(newXform);
870− joint.setVisibleTransform(newXform);
870+ _rig->setJointTransform(i, newXform);
871+ _rig->setJointVisibleTransform(i, newXform);
871872 }
872873 }
873874 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t