Model has a Rig rather than a RigPointer

This commit is contained in:
Andrew Meadows 2017-05-19 13:24:16 -07:00
parent 17b6cf29df
commit 7b879a7964
24 changed files with 177 additions and 205 deletions

View file

@ -52,7 +52,7 @@ const QUuid MY_AVATAR_KEY; // NULL key
AvatarManager::AvatarManager(QObject* parent) :
_avatarsToFade(),
_myAvatar(std::make_shared<MyAvatar>(qApp->thread(), std::make_shared<Rig>()))
_myAvatar(std::make_shared<MyAvatar>(qApp->thread()))
{
// register a meta type for the weak pointer we'll use for the owning avatar mixer for each avatar
qRegisterMetaType<QWeakPointer<Node> >("NodeWeakPointer");
@ -300,7 +300,7 @@ void AvatarManager::simulateAvatarFades(float deltaTime) {
}
AvatarSharedPointer AvatarManager::newSharedAvatar() {
return std::make_shared<OtherAvatar>(qApp->thread(), std::make_shared<Rig>());
return std::make_shared<OtherAvatar>(qApp->thread());
}
void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason) {

View file

@ -98,8 +98,8 @@ static const glm::quat DEFAULT_AVATAR_LEFTFOOT_ROT { -0.40167322754859924f, 0.91
static const glm::vec3 DEFAULT_AVATAR_RIGHTFOOT_POS { 0.08f, -0.96f, 0.029f };
static const glm::quat DEFAULT_AVATAR_RIGHTFOOT_ROT { -0.4016716778278351f, 0.9154615998268127f, 0.0053307069465518f, 0.023696165531873703f };
MyAvatar::MyAvatar(QThread* thread, RigPointer rig) :
Avatar(thread, rig),
MyAvatar::MyAvatar(QThread* thread) :
Avatar(thread),
_yawSpeed(YAW_SPEED_DEFAULT),
_pitchSpeed(PITCH_SPEED_DEFAULT),
_scriptedMotorTimescale(DEFAULT_SCRIPTED_MOTOR_TIMESCALE),
@ -120,7 +120,6 @@ MyAvatar::MyAvatar(QThread* thread, RigPointer rig) :
_goToPending(false),
_goToPosition(),
_goToOrientation(),
_rig(rig),
_prevShouldDrawHead(true),
_audioListenerMode(FROM_HEAD),
_hmdAtRestDetector(glm::vec3(0), glm::quat())
@ -129,7 +128,7 @@ MyAvatar::MyAvatar(QThread* thread, RigPointer rig) :
// give the pointer to our head to inherited _headData variable from AvatarData
_headData = new MyHead(this);
_skeletonModel = std::make_shared<MySkeletonModel>(this, nullptr, rig);
_skeletonModel = std::make_shared<MySkeletonModel>(this, nullptr);
connect(_skeletonModel.get(), &Model::setURLFinished, this, &Avatar::setModelURLFinished);
@ -180,9 +179,7 @@ MyAvatar::MyAvatar(QThread* thread, RigPointer rig) :
auto audioIO = DependencyManager::get<AudioClient>();
audioIO->setIsPlayingBackRecording(isPlaying);
if (_rig) {
_rig->setEnableAnimations(!isPlaying);
}
_skeletonModel->getRig().setEnableAnimations(!isPlaying);
});
connect(recorder.data(), &Recorder::recordingStateChanged, [=] {
@ -233,12 +230,12 @@ MyAvatar::MyAvatar(QThread* thread, RigPointer rig) :
}
auto jointData = dummyAvatar.getRawJointData();
if (jointData.length() > 0 && _rig) {
_rig->copyJointsFromJointData(jointData);
if (jointData.length() > 0) {
_skeletonModel->getRig().copyJointsFromJointData(jointData);
}
});
connect(rig.get(), SIGNAL(onLoadComplete()), this, SIGNAL(onLoadComplete()));
connect(&(_skeletonModel->getRig()), SIGNAL(onLoadComplete()), this, SIGNAL(onLoadComplete()));
_characterController.setDensity(_density);
}
@ -355,9 +352,7 @@ void MyAvatar::clearIKJointLimitHistory() {
return;
}
if (_rig) {
_rig->clearIKJointLimitHistory();
}
_skeletonModel->getRig().clearIKJointLimitHistory();
}
void MyAvatar::reset(bool andRecenter, bool andReload, bool andHead) {
@ -528,10 +523,8 @@ void MyAvatar::simulate(float deltaTime) {
{
PerformanceTimer perfTimer("skeleton");
if (_rig) {
_rig->setEnableDebugDrawIKTargets(_enableDebugDrawIKTargets);
_rig->setEnableDebugDrawIKConstraints(_enableDebugDrawIKConstraints);
}
_skeletonModel->getRig().setEnableDebugDrawIKTargets(_enableDebugDrawIKTargets);
_skeletonModel->getRig().setEnableDebugDrawIKConstraints(_enableDebugDrawIKConstraints);
_skeletonModel->simulate(deltaTime);
}
@ -550,7 +543,7 @@ void MyAvatar::simulate(float deltaTime) {
PerformanceTimer perfTimer("joints");
// copy out the skeleton joints from the model
if (_rigEnabled) {
_rig->copyJointsIntoJointData(_jointData);
_skeletonModel->getRig().copyJointsIntoJointData(_jointData);
}
}
@ -795,7 +788,7 @@ void MyAvatar::overrideAnimation(const QString& url, float fps, bool loop, float
Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame));
return;
}
_rig->overrideAnimation(url, fps, loop, firstFrame, lastFrame);
_skeletonModel->getRig().overrideAnimation(url, fps, loop, firstFrame, lastFrame);
}
void MyAvatar::restoreAnimation() {
@ -803,7 +796,7 @@ void MyAvatar::restoreAnimation() {
QMetaObject::invokeMethod(this, "restoreAnimation");
return;
}
_rig->restoreAnimation();
_skeletonModel->getRig().restoreAnimation();
}
QStringList MyAvatar::getAnimationRoles() {
@ -812,7 +805,7 @@ QStringList MyAvatar::getAnimationRoles() {
QMetaObject::invokeMethod(this, "getAnimationRoles", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QStringList, result));
return result;
}
return _rig->getAnimationRoles();
return _skeletonModel->getRig().getAnimationRoles();
}
void MyAvatar::overrideRoleAnimation(const QString& role, const QString& url, float fps, bool loop,
@ -822,7 +815,7 @@ void MyAvatar::overrideRoleAnimation(const QString& role, const QString& url, fl
Q_ARG(float, fps), Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame));
return;
}
_rig->overrideRoleAnimation(role, url, fps, loop, firstFrame, lastFrame);
_skeletonModel->getRig().overrideRoleAnimation(role, url, fps, loop, firstFrame, lastFrame);
}
void MyAvatar::restoreRoleAnimation(const QString& role) {
@ -830,7 +823,7 @@ void MyAvatar::restoreRoleAnimation(const QString& role) {
QMetaObject::invokeMethod(this, "restoreRoleAnimation", Q_ARG(const QString&, role));
return;
}
_rig->restoreRoleAnimation(role);
_skeletonModel->getRig().restoreRoleAnimation(role);
}
void MyAvatar::saveData() {
@ -968,7 +961,7 @@ void MyAvatar::setUseAnimPreAndPostRotations(bool isEnabled) {
}
void MyAvatar::setEnableInverseKinematics(bool isEnabled) {
_rig->setEnableInverseKinematics(isEnabled);
_skeletonModel->getRig().setEnableInverseKinematics(isEnabled);
}
void MyAvatar::loadData() {
@ -1217,7 +1210,7 @@ void MyAvatar::setJointData(int index, const glm::quat& rotation, const glm::vec
return;
}
// HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority
_rig->setJointState(index, true, rotation, translation, SCRIPT_PRIORITY);
_skeletonModel->getRig().setJointState(index, true, rotation, translation, SCRIPT_PRIORITY);
}
void MyAvatar::setJointRotation(int index, const glm::quat& rotation) {
@ -1226,7 +1219,7 @@ void MyAvatar::setJointRotation(int index, const glm::quat& rotation) {
return;
}
// HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority
_rig->setJointRotation(index, true, rotation, SCRIPT_PRIORITY);
_skeletonModel->getRig().setJointRotation(index, true, rotation, SCRIPT_PRIORITY);
}
void MyAvatar::setJointTranslation(int index, const glm::vec3& translation) {
@ -1235,7 +1228,7 @@ void MyAvatar::setJointTranslation(int index, const glm::vec3& translation) {
return;
}
// HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority
_rig->setJointTranslation(index, true, translation, SCRIPT_PRIORITY);
_skeletonModel->getRig().setJointTranslation(index, true, translation, SCRIPT_PRIORITY);
}
void MyAvatar::clearJointData(int index) {
@ -1243,7 +1236,7 @@ void MyAvatar::clearJointData(int index) {
QMetaObject::invokeMethod(this, "clearJointData", Q_ARG(int, index));
return;
}
_rig->clearJointAnimationPriority(index);
_skeletonModel->getRig().clearJointAnimationPriority(index);
}
void MyAvatar::clearJointsData() {
@ -1251,7 +1244,7 @@ void MyAvatar::clearJointsData() {
QMetaObject::invokeMethod(this, "clearJointsData");
return;
}
_rig->clearJointStates();
_skeletonModel->getRig().clearJointStates();
}
void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
@ -1694,7 +1687,7 @@ void MyAvatar::setAnimGraphUrl(const QUrl& url) {
_skeletonModel->reset(); // Why is this necessary? Without this, we crash in the next render.
_currentAnimGraphUrl.set(url);
_rig->initAnimGraph(url);
_skeletonModel->getRig().initAnimGraph(url);
_bodySensorMatrix = deriveBodyFromHMDSensor(); // Based on current cached HMD position/rotation..
updateSensorToWorldMatrix(); // Uses updated position/orientation and _bodySensorMatrix changes
@ -1710,7 +1703,7 @@ void MyAvatar::initAnimGraph() {
graphUrl = QUrl::fromLocalFile(PathUtils::resourcesPath() + "avatar/avatar-animation.json");
}
_rig->initAnimGraph(graphUrl);
_skeletonModel->getRig().initAnimGraph(graphUrl);
_currentAnimGraphUrl.set(graphUrl);
_bodySensorMatrix = deriveBodyFromHMDSensor(); // Based on current cached HMD position/rotation..
@ -1718,7 +1711,7 @@ void MyAvatar::initAnimGraph() {
}
void MyAvatar::destroyAnimGraph() {
_rig->destroyAnimGraph();
_skeletonModel->getRig().destroyAnimGraph();
}
void MyAvatar::postUpdate(float deltaTime) {
@ -1734,22 +1727,23 @@ void MyAvatar::postUpdate(float deltaTime) {
if (_enableDebugDrawDefaultPose || _enableDebugDrawAnimPose) {
auto animSkeleton = _rig->getAnimSkeleton();
auto animSkeleton = _skeletonModel->getRig().getAnimSkeleton();
// the rig is in the skeletonModel frame
AnimPose xform(glm::vec3(1), _skeletonModel->getRotation(), _skeletonModel->getTranslation());
if (_enableDebugDrawDefaultPose && animSkeleton) {
glm::vec4 gray(0.2f, 0.2f, 0.2f, 0.2f);
AnimDebugDraw::getInstance().addAbsolutePoses("myAvatarDefaultPoses", animSkeleton, _rig->getAbsoluteDefaultPoses(), xform, gray);
AnimDebugDraw::getInstance().addAbsolutePoses("myAvatarDefaultPoses", animSkeleton, _skeletonModel->getRig().getAbsoluteDefaultPoses(), xform, gray);
}
if (_enableDebugDrawAnimPose && animSkeleton) {
// build absolute AnimPoseVec from rig
AnimPoseVec absPoses;
absPoses.reserve(_rig->getJointStateCount());
for (int i = 0; i < _rig->getJointStateCount(); i++) {
absPoses.push_back(AnimPose(_rig->getJointTransform(i)));
const Rig& rig = _skeletonModel->getRig();
absPoses.reserve(rig.getJointStateCount());
for (int i = 0; i < rig.getJointStateCount(); i++) {
absPoses.push_back(AnimPose(rig.getJointTransform(i)));
}
glm::vec4 cyan(0.1f, 0.6f, 0.6f, 1.0f);
AnimDebugDraw::getInstance().addAbsolutePoses("myAvatarAnimPoses", animSkeleton, absPoses, xform, cyan);
@ -2338,17 +2332,18 @@ glm::mat4 MyAvatar::deriveBodyFromHMDSensor() const {
const glm::quat hmdOrientation = getHMDSensorOrientation();
const glm::quat hmdOrientationYawOnly = cancelOutRollAndPitch(hmdOrientation);
int rightEyeIndex = _rig->indexOfJoint("RightEye");
int leftEyeIndex = _rig->indexOfJoint("LeftEye");
int neckIndex = _rig->indexOfJoint("Neck");
int hipsIndex = _rig->indexOfJoint("Hips");
const Rig& rig = _skeletonModel->getRig();
int rightEyeIndex = rig.indexOfJoint("RightEye");
int leftEyeIndex = rig.indexOfJoint("LeftEye");
int neckIndex = rig.indexOfJoint("Neck");
int hipsIndex = rig.indexOfJoint("Hips");
glm::vec3 rigMiddleEyePos = DEFAULT_AVATAR_MIDDLE_EYE_POS;
if (leftEyeIndex >= 0 && rightEyeIndex >= 0) {
rigMiddleEyePos = (_rig->getAbsoluteDefaultPose(leftEyeIndex).trans() + _rig->getAbsoluteDefaultPose(rightEyeIndex).trans()) / 2.0f;
rigMiddleEyePos = (rig.getAbsoluteDefaultPose(leftEyeIndex).trans() + rig.getAbsoluteDefaultPose(rightEyeIndex).trans()) / 2.0f;
}
glm::vec3 rigNeckPos = neckIndex != -1 ? _rig->getAbsoluteDefaultPose(neckIndex).trans() : DEFAULT_AVATAR_NECK_POS;
glm::vec3 rigHipsPos = hipsIndex != -1 ? _rig->getAbsoluteDefaultPose(hipsIndex).trans() : DEFAULT_AVATAR_HIPS_POS;
glm::vec3 rigNeckPos = neckIndex != -1 ? rig.getAbsoluteDefaultPose(neckIndex).trans() : DEFAULT_AVATAR_NECK_POS;
glm::vec3 rigHipsPos = hipsIndex != -1 ? rig.getAbsoluteDefaultPose(hipsIndex).trans() : DEFAULT_AVATAR_HIPS_POS;
glm::vec3 localEyes = (rigMiddleEyePos - rigHipsPos);
glm::vec3 localNeck = (rigNeckPos - rigHipsPos);
@ -2714,8 +2709,8 @@ glm::vec3 MyAvatar::getAbsoluteJointTranslationInObjectFrame(int index) const {
glm::mat4 MyAvatar::getCenterEyeCalibrationMat() const {
// TODO: as an optimization cache this computation, then invalidate the cache when the avatar model is changed.
int rightEyeIndex = _rig->indexOfJoint("RightEye");
int leftEyeIndex = _rig->indexOfJoint("LeftEye");
int rightEyeIndex = _skeletonModel->getRig().indexOfJoint("RightEye");
int leftEyeIndex = _skeletonModel->getRig().indexOfJoint("LeftEye");
if (rightEyeIndex >= 0 && leftEyeIndex >= 0) {
auto centerEyePos = (getAbsoluteDefaultJointTranslationInObjectFrame(rightEyeIndex) + getAbsoluteDefaultJointTranslationInObjectFrame(leftEyeIndex)) * 0.5f;
auto centerEyeRot = Quaternions::Y_180;
@ -2727,7 +2722,7 @@ glm::mat4 MyAvatar::getCenterEyeCalibrationMat() const {
glm::mat4 MyAvatar::getHeadCalibrationMat() const {
// TODO: as an optimization cache this computation, then invalidate the cache when the avatar model is changed.
int headIndex = _rig->indexOfJoint("Head");
int headIndex = _skeletonModel->getRig().indexOfJoint("Head");
if (headIndex >= 0) {
auto headPos = getAbsoluteDefaultJointTranslationInObjectFrame(headIndex);
auto headRot = getAbsoluteDefaultJointRotationInObjectFrame(headIndex);
@ -2739,7 +2734,7 @@ glm::mat4 MyAvatar::getHeadCalibrationMat() const {
glm::mat4 MyAvatar::getSpine2CalibrationMat() const {
// TODO: as an optimization cache this computation, then invalidate the cache when the avatar model is changed.
int spine2Index = _rig->indexOfJoint("Spine2");
int spine2Index = _skeletonModel->getRig().indexOfJoint("Spine2");
if (spine2Index >= 0) {
auto spine2Pos = getAbsoluteDefaultJointTranslationInObjectFrame(spine2Index);
auto spine2Rot = getAbsoluteDefaultJointRotationInObjectFrame(spine2Index);
@ -2751,7 +2746,7 @@ glm::mat4 MyAvatar::getSpine2CalibrationMat() const {
glm::mat4 MyAvatar::getHipsCalibrationMat() const {
// TODO: as an optimization cache this computation, then invalidate the cache when the avatar model is changed.
int hipsIndex = _rig->indexOfJoint("Hips");
int hipsIndex = _skeletonModel->getRig().indexOfJoint("Hips");
if (hipsIndex >= 0) {
auto hipsPos = getAbsoluteDefaultJointTranslationInObjectFrame(hipsIndex);
auto hipsRot = getAbsoluteDefaultJointRotationInObjectFrame(hipsIndex);
@ -2763,7 +2758,7 @@ glm::mat4 MyAvatar::getHipsCalibrationMat() const {
glm::mat4 MyAvatar::getLeftFootCalibrationMat() const {
// TODO: as an optimization cache this computation, then invalidate the cache when the avatar model is changed.
int leftFootIndex = _rig->indexOfJoint("LeftFoot");
int leftFootIndex = _skeletonModel->getRig().indexOfJoint("LeftFoot");
if (leftFootIndex >= 0) {
auto leftFootPos = getAbsoluteDefaultJointTranslationInObjectFrame(leftFootIndex);
auto leftFootRot = getAbsoluteDefaultJointRotationInObjectFrame(leftFootIndex);
@ -2775,7 +2770,7 @@ glm::mat4 MyAvatar::getLeftFootCalibrationMat() const {
glm::mat4 MyAvatar::getRightFootCalibrationMat() const {
// TODO: as an optimization cache this computation, then invalidate the cache when the avatar model is changed.
int rightFootIndex = _rig->indexOfJoint("RightFoot");
int rightFootIndex = _skeletonModel->getRig().indexOfJoint("RightFoot");
if (rightFootIndex >= 0) {
auto rightFootPos = getAbsoluteDefaultJointTranslationInObjectFrame(rightFootIndex);
auto rightFootRot = getAbsoluteDefaultJointRotationInObjectFrame(rightFootIndex);
@ -2795,7 +2790,7 @@ bool MyAvatar::pinJoint(int index, const glm::vec3& position, const glm::quat& o
slamPosition(position);
setOrientation(orientation);
_rig->setMaxHipsOffsetLength(0.05f);
_skeletonModel->getRig().setMaxHipsOffsetLength(0.05f);
auto it = std::find(_pinnedJoints.begin(), _pinnedJoints.end(), index);
if (it == _pinnedJoints.end()) {
@ -2812,7 +2807,7 @@ bool MyAvatar::clearPinOnJoint(int index) {
auto hipsIndex = getJointIndex("Hips");
if (index == hipsIndex) {
_rig->setMaxHipsOffsetLength(FLT_MAX);
_skeletonModel->getRig().setMaxHipsOffsetLength(FLT_MAX);
}
return true;
@ -2821,7 +2816,7 @@ bool MyAvatar::clearPinOnJoint(int index) {
}
float MyAvatar::getIKErrorOnLastSolve() const {
return _rig->getIKErrorOnLastSolve();
return _skeletonModel->getRig().getIKErrorOnLastSolve();
}
// thread-safe

View file

@ -148,7 +148,7 @@ public:
};
Q_ENUM(DriveKeys)
explicit MyAvatar(QThread* thread, RigPointer rig);
explicit MyAvatar(QThread* thread);
~MyAvatar();
void instantiableAvatar() override {};
@ -322,9 +322,9 @@ public:
// adding one of the other handlers. While any handler may change a value in animStateDictionaryIn (or supply different values in animStateDictionaryOut)
// a handler must not remove properties from animStateDictionaryIn, nor change property values that it does not intend to change.
// It is not specified in what order multiple handlers are called.
Q_INVOKABLE QScriptValue addAnimationStateHandler(QScriptValue handler, QScriptValue propertiesList) { return _rig->addAnimationStateHandler(handler, propertiesList); }
Q_INVOKABLE QScriptValue addAnimationStateHandler(QScriptValue handler, QScriptValue propertiesList) { return _skeletonModel->getRig().addAnimationStateHandler(handler, propertiesList); }
// Removes a handler previously added by addAnimationStateHandler.
Q_INVOKABLE void removeAnimationStateHandler(QScriptValue handler) { _rig->removeAnimationStateHandler(handler); }
Q_INVOKABLE void removeAnimationStateHandler(QScriptValue handler) { _skeletonModel->getRig().removeAnimationStateHandler(handler); }
Q_INVOKABLE bool getSnapTurn() const { return _useSnapTurn; }
Q_INVOKABLE void setSnapTurn(bool on) { _useSnapTurn = on; }
@ -708,7 +708,6 @@ private:
glm::quat _goToOrientation;
std::unordered_set<int> _headBoneSet;
RigPointer _rig;
bool _prevShouldDrawHead;
bool _rigEnabled { true };

View file

@ -13,7 +13,7 @@
#include "Application.h"
#include "InterfaceLogging.h"
MySkeletonModel::MySkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer rig) : SkeletonModel(owningAvatar, parent, rig) {
MySkeletonModel::MySkeletonModel(Avatar* owningAvatar, QObject* parent) : SkeletonModel(owningAvatar, parent) {
}
Rig::CharacterControllerState convertCharacterControllerState(CharacterController::State state) {
@ -63,7 +63,7 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
glm::mat4 rigToWorld = createMatFromQuatAndPos(getRotation(), getTranslation());
glm::mat4 worldToRig = glm::inverse(rigToWorld);
glm::mat4 rigHMDMat = worldToRig * worldHMDMat;
_rig->computeHeadFromHMD(AnimPose(rigHMDMat), headParams.rigHeadPosition, headParams.rigHeadOrientation);
_rig.computeHeadFromHMD(AnimPose(rigHMDMat), headParams.rigHeadPosition, headParams.rigHeadOrientation);
headParams.headEnabled = true;
} else {
// even though full head IK is disabled, the rig still needs the head orientation to rotate the head up and down in desktop mode.
@ -94,7 +94,7 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
headParams.isTalking = head->getTimeWithoutTalking() <= 1.5f;
_rig->updateFromHeadParameters(headParams, deltaTime);
_rig.updateFromHeadParameters(headParams, deltaTime);
Rig::HandAndFeetParameters handAndFeetParams;
@ -138,14 +138,14 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
handAndFeetParams.bodyCapsuleHalfHeight = myAvatar->getCharacterController()->getCapsuleHalfHeight();
handAndFeetParams.bodyCapsuleLocalOffset = myAvatar->getCharacterController()->getCapsuleLocalOffset();
_rig->updateFromHandAndFeetParameters(handAndFeetParams, deltaTime);
_rig.updateFromHandAndFeetParameters(handAndFeetParams, deltaTime);
Rig::CharacterControllerState ccState = convertCharacterControllerState(myAvatar->getCharacterController()->getState());
auto velocity = myAvatar->getLocalVelocity();
auto position = myAvatar->getLocalPosition();
auto orientation = myAvatar->getLocalOrientation();
_rig->computeMotionAnimationState(deltaTime, position, velocity, orientation, ccState);
_rig.computeMotionAnimationState(deltaTime, position, velocity, orientation, ccState);
// evaluate AnimGraph animation and update jointStates.
Model::updateRig(deltaTime, parentTransform);
@ -158,6 +158,6 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
eyeParams.leftEyeJointIndex = geometry.leftEyeJointIndex;
eyeParams.rightEyeJointIndex = geometry.rightEyeJointIndex;
_rig->updateFromEyeParameters(eyeParams);
_rig.updateFromEyeParameters(eyeParams);
}

View file

@ -19,7 +19,7 @@ private:
using Parent = SkeletonModel;
public:
MySkeletonModel(Avatar* owningAvatar, QObject* parent = nullptr, RigPointer rig = nullptr);
MySkeletonModel(Avatar* owningAvatar, QObject* parent = nullptr);
void updateRig(float deltaTime, glm::mat4 parentTransform) override;
};

View file

@ -18,7 +18,7 @@
QString const ModelOverlay::TYPE = "model";
ModelOverlay::ModelOverlay()
: _model(std::make_shared<Model>(std::make_shared<Rig>(), nullptr, this)),
: _model(std::make_shared<Model>(nullptr, this)),
_modelTextures(QVariantMap())
{
_model->init();
@ -28,7 +28,7 @@ ModelOverlay::ModelOverlay()
ModelOverlay::ModelOverlay(const ModelOverlay* modelOverlay) :
Volume3DOverlay(modelOverlay),
_model(std::make_shared<Model>(std::make_shared<Rig>(), nullptr, this)),
_model(std::make_shared<Model>(nullptr, this)),
_modelTextures(QVariantMap()),
_url(modelOverlay->_url),
_updateModel(false),
@ -211,12 +211,10 @@ QVariant ModelOverlay::getProperty(const QString& property) {
if (property == "jointNames") {
if (_model && _model->isActive()) {
// note: going through Rig because Model::getJointNames() (which proxies to FBXGeometry) was always empty
const RigPointer rig = _model->getRig();
if (rig) {
return mapJoints<QStringList, QString>([rig](int jointIndex) -> QString {
return rig->nameOfJoint(jointIndex);
});
}
const Rig* rig = &(_model->getRig());
return mapJoints<QStringList, QString>([rig](int jointIndex) -> QString {
return rig->nameOfJoint(jointIndex);
});
}
}

View file

@ -27,7 +27,6 @@
class Rig;
class AnimInverseKinematics;
typedef std::shared_ptr<Rig> RigPointer;
// Rig instances are reentrant.
// However only specific methods thread-safe. Noted below.

View file

@ -98,7 +98,7 @@ void Avatar::setShowNamesAboveHeads(bool show) {
showNamesAboveHeads = show;
}
Avatar::Avatar(QThread* thread, RigPointer rig) :
Avatar::Avatar(QThread* thread) :
_voiceSphereID(GeometryCache::UNKNOWN_ID)
{
// we may have been created in the network thread, but we live in the main thread
@ -344,9 +344,9 @@ void Avatar::simulate(float deltaTime, bool inView) {
if (inView) {
Head* head = getHead();
if (_hasNewJointData) {
_skeletonModel->getRig()->copyJointsFromJointData(_jointData);
_skeletonModel->getRig().copyJointsFromJointData(_jointData);
glm::mat4 rootTransform = glm::scale(_skeletonModel->getScale()) * glm::translate(_skeletonModel->getOffset());
_skeletonModel->getRig()->computeExternalPoses(rootTransform);
_skeletonModel->getRig().computeExternalPoses(rootTransform);
_jointDataSimulationRate.increment();
_skeletonModel->simulate(deltaTime, true);
@ -907,17 +907,16 @@ glm::vec3 Avatar::getDefaultJointTranslation(int index) const {
glm::quat Avatar::getAbsoluteDefaultJointRotationInObjectFrame(int index) const {
glm::quat rotation;
auto rig = _skeletonModel->getRig();
glm::quat rot = rig->getAnimSkeleton()->getAbsoluteDefaultPose(index).rot();
glm::quat rot = _skeletonModel->getRig().getAnimSkeleton()->getAbsoluteDefaultPose(index).rot();
return Quaternions::Y_180 * rot;
}
glm::vec3 Avatar::getAbsoluteDefaultJointTranslationInObjectFrame(int index) const {
glm::vec3 translation;
auto rig = _skeletonModel->getRig();
glm::vec3 trans = rig->getAnimSkeleton()->getAbsoluteDefaultPose(index).trans();
const Rig& rig = _skeletonModel->getRig();
glm::vec3 trans = rig.getAnimSkeleton()->getAbsoluteDefaultPose(index).trans();
glm::mat4 y180Mat = createMatFromQuatAndPos(Quaternions::Y_180, glm::vec3());
return transformPoint(y180Mat * rig->getGeometryToRigTransform(), trans);
return transformPoint(y180Mat * rig.getGeometryToRigTransform(), trans);
}
glm::quat Avatar::getAbsoluteJointRotationInObjectFrame(int index) const {
@ -1083,16 +1082,16 @@ void Avatar::setModelURLFinished(bool success) {
// create new model, can return an instance of a SoftAttachmentModel rather then Model
static std::shared_ptr<Model> allocateAttachmentModel(bool isSoft, RigPointer rigOverride, bool isCauterized) {
static std::shared_ptr<Model> allocateAttachmentModel(bool isSoft, const Rig& rigOverride, bool isCauterized) {
if (isSoft) {
// cast to std::shared_ptr<Model>
std::shared_ptr<SoftAttachmentModel> softModel = std::make_shared<SoftAttachmentModel>(std::make_shared<Rig>(), nullptr, rigOverride);
std::shared_ptr<SoftAttachmentModel> softModel = std::make_shared<SoftAttachmentModel>(nullptr, rigOverride);
if (isCauterized) {
softModel->flagAsCauterized();
}
return std::dynamic_pointer_cast<Model>(softModel);
} else {
return std::make_shared<Model>(std::make_shared<Rig>());
return std::make_shared<Model>();
}
}
@ -1409,21 +1408,19 @@ void Avatar::setParentJointIndex(quint16 parentJointIndex) {
QList<QVariant> Avatar::getSkeleton() {
SkeletonModelPointer skeletonModel = _skeletonModel;
if (skeletonModel) {
RigPointer rig = skeletonModel->getRig();
if (rig) {
AnimSkeleton::ConstPointer skeleton = rig->getAnimSkeleton();
if (skeleton) {
QList<QVariant> list;
list.reserve(skeleton->getNumJoints());
for (int i = 0; i < skeleton->getNumJoints(); i++) {
QVariantMap obj;
obj["name"] = skeleton->getJointName(i);
obj["index"] = i;
obj["parentIndex"] = skeleton->getParentIndex(i);
list.push_back(obj);
}
return list;
const Rig& rig = skeletonModel->getRig();
AnimSkeleton::ConstPointer skeleton = rig.getAnimSkeleton();
if (skeleton) {
QList<QVariant> list;
list.reserve(skeleton->getNumJoints());
for (int i = 0; i < skeleton->getNumJoints(); i++) {
QVariantMap obj;
obj["name"] = skeleton->getJointName(i);
obj["index"] = i;
obj["parentIndex"] = skeleton->getParentIndex(i);
list.push_back(obj);
}
return list;
}
}

View file

@ -75,7 +75,7 @@ public:
static void setShowCollisionShapes(bool render);
static void setShowNamesAboveHeads(bool show);
explicit Avatar(QThread* thread, RigPointer rig = nullptr);
explicit Avatar(QThread* thread);
~Avatar();
virtual void instantiableAvatar() = 0;

View file

@ -8,9 +8,9 @@
#include "OtherAvatar.h"
OtherAvatar::OtherAvatar(QThread* thread, RigPointer rig) : Avatar(thread, rig) {
OtherAvatar::OtherAvatar(QThread* thread) : Avatar(thread) {
// give the pointer to our head to inherited _headData variable from AvatarData
_headData = new Head(this);
_skeletonModel = std::make_shared<SkeletonModel>(this, nullptr, rig);
_skeletonModel = std::make_shared<SkeletonModel>(this, nullptr);
connect(_skeletonModel.get(), &Model::setURLFinished, this, &Avatar::setModelURLFinished);
}

View file

@ -13,7 +13,7 @@
class OtherAvatar : public Avatar {
public:
explicit OtherAvatar(QThread* thread, RigPointer rig = nullptr);
explicit OtherAvatar(QThread* thread);
virtual void instantiableAvatar() override {};
};

View file

@ -22,8 +22,8 @@
#include "Avatar.h"
#include "Logging.h"
SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer rig) :
CauterizedModel(rig, parent),
SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) :
CauterizedModel(parent),
_owningAvatar(owningAvatar),
_boundingCapsuleLocalOffset(0.0f),
_boundingCapsuleRadius(0.0f),
@ -31,7 +31,6 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer r
_defaultEyeModelPosition(glm::vec3(0.0f, 0.0f, 0.0f)),
_headClipDistance(DEFAULT_NEAR_CLIP)
{
assert(_rig);
assert(_owningAvatar);
}
@ -41,12 +40,12 @@ SkeletonModel::~SkeletonModel() {
void SkeletonModel::initJointStates() {
const FBXGeometry& geometry = getFBXGeometry();
glm::mat4 modelOffset = glm::scale(_scale) * glm::translate(_offset);
_rig->initJointStates(geometry, modelOffset);
_rig.initJointStates(geometry, modelOffset);
// Determine the default eye position for avatar scale = 1.0
int headJointIndex = geometry.headJointIndex;
if (0 > headJointIndex || headJointIndex >= _rig->getJointStateCount()) {
qCWarning(avatars_renderer) << "Bad head joint! Got:" << headJointIndex << "jointCount:" << _rig->getJointStateCount();
if (0 > headJointIndex || headJointIndex >= _rig.getJointStateCount()) {
qCWarning(avatars_renderer) << "Bad head joint! Got:" << headJointIndex << "jointCount:" << _rig.getJointStateCount();
}
glm::vec3 leftEyePosition, rightEyePosition;
getEyeModelPositions(leftEyePosition, rightEyePosition);
@ -102,7 +101,7 @@ void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
// If the head is not positioned, updateEyeJoints won't get the math right
glm::quat headOrientation;
_rig->getJointRotation(geometry.headJointIndex, headOrientation);
_rig.getJointRotation(geometry.headJointIndex, headOrientation);
glm::vec3 eulers = safeEulerAngles(headOrientation);
head->setBasePitch(glm::degrees(-eulers.x));
head->setBaseYaw(glm::degrees(eulers.y));
@ -116,7 +115,7 @@ void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
eyeParams.leftEyeJointIndex = geometry.leftEyeJointIndex;
eyeParams.rightEyeJointIndex = geometry.rightEyeJointIndex;
_rig->updateFromEyeParameters(eyeParams);
_rig.updateFromEyeParameters(eyeParams);
}
void SkeletonModel::updateAttitude() {
@ -136,7 +135,7 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
// let rig compute the model offset
glm::vec3 registrationPoint;
if (_rig->getModelRegistrationPoint(registrationPoint)) {
if (_rig.getModelRegistrationPoint(registrationPoint)) {
setOffset(registrationPoint);
}
} else {
@ -164,8 +163,8 @@ bool operator<(const IndexValue& firstIndex, const IndexValue& secondIndex) {
}
bool SkeletonModel::getLeftGrabPosition(glm::vec3& position) const {
int knuckleIndex = _rig->indexOfJoint("LeftHandMiddle1");
int handIndex = _rig->indexOfJoint("LeftHand");
int knuckleIndex = _rig.indexOfJoint("LeftHandMiddle1");
int handIndex = _rig.indexOfJoint("LeftHand");
if (knuckleIndex >= 0 && handIndex >= 0) {
glm::quat handRotation;
glm::vec3 knucklePosition;
@ -189,8 +188,8 @@ bool SkeletonModel::getLeftGrabPosition(glm::vec3& position) const {
}
bool SkeletonModel::getRightGrabPosition(glm::vec3& position) const {
int knuckleIndex = _rig->indexOfJoint("RightHandMiddle1");
int handIndex = _rig->indexOfJoint("RightHand");
int knuckleIndex = _rig.indexOfJoint("RightHandMiddle1");
int handIndex = _rig.indexOfJoint("RightHand");
if (knuckleIndex >= 0 && handIndex >= 0) {
glm::quat handRotation;
glm::vec3 knucklePosition;
@ -304,7 +303,7 @@ float VERY_BIG_MASS = 1.0e6f;
// virtual
void SkeletonModel::computeBoundingShape() {
if (!isLoaded() || _rig->jointStatesEmpty()) {
if (!isLoaded() || _rig.jointStatesEmpty()) {
return;
}
@ -316,7 +315,7 @@ void SkeletonModel::computeBoundingShape() {
float radius, height;
glm::vec3 offset;
_rig->computeAvatarBoundingCapsule(geometry, radius, height, offset);
_rig.computeAvatarBoundingCapsule(geometry, radius, height, offset);
float invScale = 1.0f / _owningAvatar->getUniformScale();
_boundingCapsuleRadius = invScale * radius;
_boundingCapsuleHeight = invScale * height;

View file

@ -28,7 +28,7 @@ class SkeletonModel : public CauterizedModel {
public:
SkeletonModel(Avatar* owningAvatar, QObject* parent = nullptr, RigPointer rig = nullptr);
SkeletonModel(Avatar* owningAvatar, QObject* parent = nullptr);
~SkeletonModel();
void initJointStates() override;

View file

@ -582,7 +582,7 @@ ModelPointer EntityTreeRenderer::allocateModel(const QString& url, float loading
return model;
}
model = std::make_shared<Model>(std::make_shared<Rig>(), nullptr, spatiallyNestableOverride);
model = std::make_shared<Model>(nullptr, spatiallyNestableOverride);
model->setLoadingPriority(loadingPriority);
model->init();
model->setURL(QUrl(url));

View file

@ -807,7 +807,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
const FBXMesh& mesh = fbxGeometry.meshes.at(i);
if (mesh.clusters.size() > 0) {
const FBXCluster& cluster = mesh.clusters.at(0);
auto jointMatrix = _model->getRig()->getJointTransform(cluster.jointIndex);
auto jointMatrix = _model->getRig().getJointTransform(cluster.jointIndex);
// we backtranslate by the registration offset so we can apply that offset to the shapeInfo later
localTransforms.push_back(invRegistraionOffset * jointMatrix * cluster.inverseBindMatrix);
} else {
@ -1080,26 +1080,22 @@ bool RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame(int index,
if (!_model) {
return false;
}
RigPointer rig = _model->getRig();
if (!rig) {
return false;
}
int jointParentIndex = rig->getJointParentIndex(index);
const Rig& rig = _model->getRig();
int jointParentIndex = rig.getJointParentIndex(index);
if (jointParentIndex == -1) {
return setLocalJointRotation(index, rotation);
}
bool success;
AnimPose jointParentPose;
success = rig->getAbsoluteJointPoseInRigFrame(jointParentIndex, jointParentPose);
success = rig.getAbsoluteJointPoseInRigFrame(jointParentIndex, jointParentPose);
if (!success) {
return false;
}
AnimPose jointParentInversePose = jointParentPose.inverse();
AnimPose jointAbsolutePose; // in rig frame
success = rig->getAbsoluteJointPoseInRigFrame(index, jointAbsolutePose);
success = rig.getAbsoluteJointPoseInRigFrame(index, jointAbsolutePose);
if (!success) {
return false;
}
@ -1113,26 +1109,23 @@ bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int ind
if (!_model) {
return false;
}
RigPointer rig = _model->getRig();
if (!rig) {
return false;
}
const Rig& rig = _model->getRig();
int jointParentIndex = rig->getJointParentIndex(index);
int jointParentIndex = rig.getJointParentIndex(index);
if (jointParentIndex == -1) {
return setLocalJointTranslation(index, translation);
}
bool success;
AnimPose jointParentPose;
success = rig->getAbsoluteJointPoseInRigFrame(jointParentIndex, jointParentPose);
success = rig.getAbsoluteJointPoseInRigFrame(jointParentIndex, jointParentPose);
if (!success) {
return false;
}
AnimPose jointParentInversePose = jointParentPose.inverse();
AnimPose jointAbsolutePose; // in rig frame
success = rig->getAbsoluteJointPoseInRigFrame(index, jointAbsolutePose);
success = rig.getAbsoluteJointPoseInRigFrame(index, jointAbsolutePose);
if (!success) {
return false;
}
@ -1248,20 +1241,16 @@ void RenderableModelEntityItem::locationChanged(bool tellPhysics) {
}
int RenderableModelEntityItem::getJointIndex(const QString& name) const {
if (_model && _model->isActive()) {
RigPointer rig = _model->getRig();
return rig->indexOfJoint(name);
}
return -1;
return (_model && _model->isActive()) ? _model->getRig().indexOfJoint(name) : -1;
}
QStringList RenderableModelEntityItem::getJointNames() const {
QStringList result;
if (_model && _model->isActive()) {
RigPointer rig = _model->getRig();
int jointCount = rig->getJointStateCount();
const Rig& rig = _model->getRig();
int jointCount = rig.getJointStateCount();
for (int jointIndex = 0; jointIndex < jointCount; jointIndex++) {
result << rig->nameOfJoint(jointIndex);
result << rig.nameOfJoint(jointIndex);
}
}
return result;

View file

@ -81,7 +81,7 @@ int RenderableZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned ch
}
Model* RenderableZoneEntityItem::getModel() {
Model* model = new Model(nullptr);
Model* model = new Model();
model->setIsWireframe(true);
model->init();
return model;

View file

@ -16,8 +16,8 @@
#include "RenderUtilsLogging.h"
CauterizedModel::CauterizedModel(RigPointer rig, QObject* parent) :
Model(rig, parent) {
CauterizedModel::CauterizedModel(QObject* parent) :
Model(parent) {
}
CauterizedModel::~CauterizedModel() {
@ -107,7 +107,7 @@ void CauterizedModel::updateClusterMatrices() {
const FBXMesh& mesh = geometry.meshes.at(i);
for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j);
auto jointMatrix = _rig->getJointTransform(cluster.jointIndex);
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
}
@ -130,14 +130,14 @@ void CauterizedModel::updateClusterMatrices() {
glm::vec4(0.0f, 0.0f, 0.0f, 0.0f),
glm::vec4(0.0f, 0.0f, 0.0f, 0.0f),
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
auto cauterizeMatrix = _rig->getJointTransform(geometry.neckJointIndex) * zeroScale;
auto cauterizeMatrix = _rig.getJointTransform(geometry.neckJointIndex) * zeroScale;
for (int i = 0; i < _cauterizeMeshStates.size(); i++) {
Model::MeshState& state = _cauterizeMeshStates[i];
const FBXMesh& mesh = geometry.meshes.at(i);
for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j);
auto jointMatrix = _rig->getJointTransform(cluster.jointIndex);
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
if (_cauterizeBoneSet.find(cluster.jointIndex) != _cauterizeBoneSet.end()) {
jointMatrix = cauterizeMatrix;
}

View file

@ -16,7 +16,7 @@ class CauterizedModel : public Model {
Q_OBJECT
public:
CauterizedModel(RigPointer rig, QObject* parent);
CauterizedModel(QObject* parent);
virtual ~CauterizedModel();
void flagAsCauterized() { _isCauterized = true; }

View file

@ -78,7 +78,7 @@ void initCollisionMaterials() {
}
}
Model::Model(RigPointer rig, QObject* parent, SpatiallyNestable* spatiallyNestableOverride) :
Model::Model(QObject* parent, SpatiallyNestable* spatiallyNestableOverride) :
QObject(parent),
_renderGeometry(),
_collisionGeometry(),
@ -96,8 +96,7 @@ Model::Model(RigPointer rig, QObject* parent, SpatiallyNestable* spatiallyNestab
_isVisible(true),
_blendNumber(0),
_appliedBlendNumber(0),
_isWireframe(false),
_rig(rig)
_isWireframe(false)
{
// we may have been created in the network thread, but we live in the main thread
if (_viewState) {
@ -271,7 +270,7 @@ void Model::updateRenderItems() {
void Model::initJointTransforms() {
if (isLoaded()) {
glm::mat4 modelOffset = glm::scale(_scale) * glm::translate(_offset);
_rig->setModelOffset(modelOffset);
_rig.setModelOffset(modelOffset);
}
}
@ -281,7 +280,7 @@ void Model::init() {
void Model::reset() {
if (isLoaded()) {
const FBXGeometry& geometry = getFBXGeometry();
_rig->reset(geometry);
_rig.reset(geometry);
}
}
@ -294,7 +293,8 @@ bool Model::updateGeometry() {
_needsReload = false;
if (_rig->jointStatesEmpty() && getFBXGeometry().joints.size() > 0) {
// TODO: should all Models have a valid _rig?
if (_rig.jointStatesEmpty() && getFBXGeometry().joints.size() > 0) {
initJointStates();
assert(_meshStates.empty());
@ -326,7 +326,7 @@ void Model::initJointStates() {
const FBXGeometry& geometry = getFBXGeometry();
glm::mat4 modelOffset = glm::scale(_scale) * glm::translate(_offset);
_rig->initJointStates(geometry, modelOffset);
_rig.initJointStates(geometry, modelOffset);
}
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance,
@ -746,19 +746,19 @@ Extents Model::getUnscaledMeshExtents() const {
}
void Model::clearJointState(int index) {
_rig->clearJointState(index);
_rig.clearJointState(index);
}
void Model::setJointState(int index, bool valid, const glm::quat& rotation, const glm::vec3& translation, float priority) {
_rig->setJointState(index, valid, rotation, translation, priority);
_rig.setJointState(index, valid, rotation, translation, priority);
}
void Model::setJointRotation(int index, bool valid, const glm::quat& rotation, float priority) {
_rig->setJointRotation(index, valid, rotation, priority);
_rig.setJointRotation(index, valid, rotation, priority);
}
void Model::setJointTranslation(int index, bool valid, const glm::vec3& translation, float priority) {
_rig->setJointTranslation(index, valid, translation, priority);
_rig.setJointTranslation(index, valid, translation, priority);
}
int Model::getParentJointIndex(int jointIndex) const {
@ -825,43 +825,43 @@ void Model::loadURLFinished(bool success) {
}
bool Model::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position) const {
return _rig->getJointPositionInWorldFrame(jointIndex, position, _translation, _rotation);
return _rig.getJointPositionInWorldFrame(jointIndex, position, _translation, _rotation);
}
bool Model::getJointPosition(int jointIndex, glm::vec3& position) const {
return _rig->getJointPosition(jointIndex, position);
return _rig.getJointPosition(jointIndex, position);
}
bool Model::getJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) const {
return _rig->getJointRotationInWorldFrame(jointIndex, rotation, _rotation);
return _rig.getJointRotationInWorldFrame(jointIndex, rotation, _rotation);
}
bool Model::getJointRotation(int jointIndex, glm::quat& rotation) const {
return _rig->getJointRotation(jointIndex, rotation);
return _rig.getJointRotation(jointIndex, rotation);
}
bool Model::getJointTranslation(int jointIndex, glm::vec3& translation) const {
return _rig->getJointTranslation(jointIndex, translation);
return _rig.getJointTranslation(jointIndex, translation);
}
bool Model::getAbsoluteJointRotationInRigFrame(int jointIndex, glm::quat& rotationOut) const {
return _rig->getAbsoluteJointRotationInRigFrame(jointIndex, rotationOut);
return _rig.getAbsoluteJointRotationInRigFrame(jointIndex, rotationOut);
}
bool Model::getAbsoluteJointTranslationInRigFrame(int jointIndex, glm::vec3& translationOut) const {
return _rig->getAbsoluteJointTranslationInRigFrame(jointIndex, translationOut);
return _rig.getAbsoluteJointTranslationInRigFrame(jointIndex, translationOut);
}
bool Model::getRelativeDefaultJointRotation(int jointIndex, glm::quat& rotationOut) const {
return _rig->getRelativeDefaultJointRotation(jointIndex, rotationOut);
return _rig.getRelativeDefaultJointRotation(jointIndex, rotationOut);
}
bool Model::getRelativeDefaultJointTranslation(int jointIndex, glm::vec3& translationOut) const {
return _rig->getRelativeDefaultJointTranslation(jointIndex, translationOut);
return _rig.getRelativeDefaultJointTranslation(jointIndex, translationOut);
}
bool Model::getJointCombinedRotation(int jointIndex, glm::quat& rotation) const {
return _rig->getJointCombinedRotation(jointIndex, rotation, _rotation);
return _rig.getJointCombinedRotation(jointIndex, rotation, _rotation);
}
QStringList Model::getJointNames() const {
@ -1049,7 +1049,7 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
void Model::updateRig(float deltaTime, glm::mat4 parentTransform) {
_needsUpdateClusterMatrices = true;
glm::mat4 rigToWorldTransform = createMatFromQuatAndPos(getRotation(), getTranslation());
_rig->updateAnimations(deltaTime, parentTransform, rigToWorldTransform);
_rig.updateAnimations(deltaTime, parentTransform, rigToWorldTransform);
}
void Model::computeMeshPartLocalBounds() {
@ -1073,7 +1073,7 @@ void Model::updateClusterMatrices() {
const FBXMesh& mesh = geometry.meshes.at(i);
for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j);
auto jointMatrix = _rig->getJointTransform(cluster.jointIndex);
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
}
@ -1100,19 +1100,19 @@ void Model::inverseKinematics(int endIndex, glm::vec3 targetPosition, const glm:
const FBXGeometry& geometry = getFBXGeometry();
const QVector<int>& freeLineage = geometry.joints.at(endIndex).freeLineage;
glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset);
_rig->inverseKinematics(endIndex, targetPosition, targetRotation, priority, freeLineage, parentTransform);
_rig.inverseKinematics(endIndex, targetPosition, targetRotation, priority, freeLineage, parentTransform);
}
bool Model::restoreJointPosition(int jointIndex, float fraction, float priority) {
const FBXGeometry& geometry = getFBXGeometry();
const QVector<int>& freeLineage = geometry.joints.at(jointIndex).freeLineage;
return _rig->restoreJointPosition(jointIndex, fraction, priority, freeLineage);
return _rig.restoreJointPosition(jointIndex, fraction, priority, freeLineage);
}
float Model::getLimbLength(int jointIndex) const {
const FBXGeometry& geometry = getFBXGeometry();
const QVector<int>& freeLineage = geometry.joints.at(jointIndex).freeLineage;
return _rig->getLimbLength(jointIndex, freeLineage, _scale, geometry.joints);
return _rig.getLimbLength(jointIndex, freeLineage, _scale, geometry.joints);
}
bool Model::maybeStartBlender() {
@ -1155,9 +1155,7 @@ void Model::deleteGeometry() {
_deleteGeometryCounter++;
_blendedVertexBuffers.clear();
_meshStates.clear();
if (_rig) {
_rig->destroyAnimGraph();
}
_rig.destroyAnimGraph();
_blendedBlendshapeCoefficients.clear();
_renderGeometry.reset();
_collisionGeometry.reset();

View file

@ -68,7 +68,7 @@ public:
static void setAbstractViewStateInterface(AbstractViewStateInterface* viewState) { _viewState = viewState; }
Model(RigPointer rig, QObject* parent = nullptr, SpatiallyNestable* spatiallyNestableOverride = nullptr);
Model(QObject* parent = nullptr, SpatiallyNestable* spatiallyNestableOverride = nullptr);
virtual ~Model();
inline ModelPointer getThisPointer() const {
@ -174,7 +174,7 @@ public:
}
/// Returns the number of joint states in the model.
int getJointStateCount() const { return (int)_rig->getJointStateCount(); }
int getJointStateCount() const { return (int)_rig.getJointStateCount(); }
bool getJointPositionInWorldFrame(int jointIndex, glm::vec3& position) const;
bool getJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) const;
bool getJointCombinedRotation(int jointIndex, glm::quat& rotation) const;
@ -223,7 +223,8 @@ public:
return ((index < 0) && (index >= _blendshapeCoefficients.size())) ? 0.0f : _blendshapeCoefficients.at(index);
}
virtual RigPointer getRig() const { return _rig; }
Rig& getRig() { return _rig; }
const Rig& getRig() const { return _rig; }
const glm::vec3& getRegistrationPoint() const { return _registrationPoint; }
@ -390,7 +391,7 @@ protected:
mutable bool _needsUpdateTextures { true };
friend class ModelMeshPartPayload;
RigPointer _rig;
Rig _rig;
uint32_t _deleteGeometryCounter { 0 };

View file

@ -8,11 +8,9 @@
#include "SoftAttachmentModel.h"
SoftAttachmentModel::SoftAttachmentModel(RigPointer rig, QObject* parent, RigPointer rigOverride) :
CauterizedModel(rig, parent),
SoftAttachmentModel::SoftAttachmentModel(QObject* parent, const Rig& rigOverride) :
CauterizedModel(parent),
_rigOverride(rigOverride) {
assert(_rig);
assert(_rigOverride);
}
SoftAttachmentModel::~SoftAttachmentModel() {
@ -24,11 +22,11 @@ void SoftAttachmentModel::updateRig(float deltaTime, glm::mat4 parentTransform)
}
int SoftAttachmentModel::getJointIndexOverride(int i) const {
QString name = _rig->nameOfJoint(i);
QString name = _rig.nameOfJoint(i);
if (name.isEmpty()) {
return -1;
}
return _rigOverride->indexOfJoint(name);
return _rigOverride.indexOfJoint(name);
}
// virtual
@ -51,10 +49,10 @@ void SoftAttachmentModel::updateClusterMatrices() {
// TODO: cache these look-ups as an optimization
int jointIndexOverride = getJointIndexOverride(cluster.jointIndex);
glm::mat4 jointMatrix;
if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride->getJointStateCount()) {
jointMatrix = _rigOverride->getJointTransform(jointIndexOverride);
if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride.getJointStateCount()) {
jointMatrix = _rigOverride.getJointTransform(jointIndexOverride);
} else {
jointMatrix = _rig->getJointTransform(cluster.jointIndex);
jointMatrix = _rig.getJointTransform(cluster.jointIndex);
}
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
}

View file

@ -23,7 +23,7 @@ class SoftAttachmentModel : public CauterizedModel {
Q_OBJECT
public:
SoftAttachmentModel(RigPointer rig, QObject* parent, RigPointer rigOverride);
SoftAttachmentModel(QObject* parent, const Rig& rigOverride);
~SoftAttachmentModel();
void updateRig(float deltaTime, glm::mat4 parentTransform) override;
@ -32,7 +32,7 @@ public:
protected:
int getJointIndexOverride(int i) const;
RigPointer _rigOverride;
const Rig& _rigOverride;
};
#endif // hifi_SoftAttachmentModel_h

View file

@ -47,7 +47,7 @@
#include <Rig.h>
#include "RigTests.h"
static void reportJoint(RigPointer rig, int index) { // Handy for debugging
static void reportJoint(const Rig& rig, int index) { // Handy for debugging
std::cout << "\n";
std::cout << index << " " << rig->getAnimSkeleton()->getJointName(index).toUtf8().data() << "\n";
glm::vec3 pos;
@ -58,16 +58,16 @@ static void reportJoint(RigPointer rig, int index) { // Handy for debugging
std::cout << " rot:" << safeEulerAngles(rot) << "\n";
std::cout << "\n";
}
static void reportByName(RigPointer rig, const QString& name) {
static void reportByName(const Rig& rig, const QString& name) {
int jointIndex = rig->indexOfJoint(name);
reportJoint(rig, jointIndex);
}
static void reportAll(RigPointer rig) {
static void reportAll(const Rig& rig) {
for (int i = 0; i < rig->getJointStateCount(); i++) {
reportJoint(rig, i);
}
}
static void reportSome(RigPointer rig) {
static void reportSome(const Rig& rig) {
QString names[] = {"Head", "Neck", "RightShoulder", "RightArm", "RightForeArm", "RightHand", "Spine2", "Spine1", "Spine", "Hips", "RightUpLeg", "RightLeg", "RightFoot", "RightToeBase", "RightToe_End"};
for (auto name : names) {
reportByName(rig, name);
@ -91,8 +91,7 @@ void RigTests::initTestCase() {
#endif
QVERIFY((bool)geometry);
_rig = std::make_shared<Rig>();
_rig->initJointStates(*geometry, glm::mat4());
_rig.initJointStates(*geometry, glm::mat4());
std::cout << "Rig is ready " << geometry->joints.count() << " joints " << std::endl;
reportAll(_rig);
}

View file

@ -43,13 +43,13 @@
class RigTests : public QObject {
Q_OBJECT
private slots:
void initTestCase();
void initialPoseArmsDown();
private:
RigPointer _rig;
Rig _rig;
};
#endif // hifi_RigTests_h