mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
Don't recompute unchaged transform
This commit is contained in:
parent
03031c4c04
commit
fb670275c2
4 changed files with 35 additions and 10 deletions
|
@ -52,7 +52,8 @@ const float PALM_PRIORITY = 3.0f;
|
|||
|
||||
void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
|
||||
setTranslation(_owningAvatar->getPosition());
|
||||
setRotation(_owningAvatar->getOrientation() * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
static const glm::quat refOrientation = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
setRotation(_owningAvatar->getOrientation() * refOrientation);
|
||||
const float MODEL_SCALE = 0.0006f;
|
||||
setScale(glm::vec3(1.0f, 1.0f, 1.0f) * _owningAvatar->getScale() * MODEL_SCALE);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
JointState::JointState() :
|
||||
_animationPriority(0.0f),
|
||||
_transformChanged(true),
|
||||
_positionInParentFrame(0.0f),
|
||||
_distanceToParent(0.0f),
|
||||
_fbxJoint(NULL),
|
||||
|
@ -26,6 +27,7 @@ JointState::JointState() :
|
|||
}
|
||||
|
||||
JointState::JointState(const JointState& other) : _constraint(NULL) {
|
||||
_transformChanged = true;
|
||||
_transform = other._transform;
|
||||
_rotation = other._rotation;
|
||||
_rotationInConstrainedFrame = other._rotationInConstrainedFrame;
|
||||
|
@ -47,7 +49,10 @@ JointState::~JointState() {
|
|||
|
||||
void JointState::setFBXJoint(const FBXJoint* joint) {
|
||||
assert(joint != NULL);
|
||||
_rotationInConstrainedFrame = joint->rotation;
|
||||
if (joint->rotation != _rotationInConstrainedFrame) {
|
||||
_rotationInConstrainedFrame = joint->rotation;
|
||||
_transformChanged = true;
|
||||
}
|
||||
// NOTE: JointState does not own the FBXJoint to which it points.
|
||||
_fbxJoint = joint;
|
||||
if (_constraint) {
|
||||
|
@ -71,6 +76,7 @@ void JointState::updateConstraint() {
|
|||
void JointState::copyState(const JointState& state) {
|
||||
_animationPriority = state._animationPriority;
|
||||
_transform = state._transform;
|
||||
_transformChanged = true;
|
||||
_rotation = extractRotation(_transform);
|
||||
_rotationInConstrainedFrame = state._rotationInConstrainedFrame;
|
||||
_positionInParentFrame = state._positionInParentFrame;
|
||||
|
@ -88,11 +94,20 @@ void JointState::initTransform(const glm::mat4& parentTransform) {
|
|||
_distanceToParent = glm::length(_positionInParentFrame);
|
||||
}
|
||||
|
||||
void JointState::computeTransform(const glm::mat4& parentTransform) {
|
||||
void JointState::computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged) {
|
||||
if (!parentTransformChanged && !_transformChanged) {
|
||||
return;
|
||||
}
|
||||
|
||||
glm::quat rotationInParentFrame = _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation;
|
||||
glm::mat4 transformInParentFrame = _fbxJoint->preTransform * glm::mat4_cast(rotationInParentFrame) * _fbxJoint->postTransform;
|
||||
_transform = parentTransform * glm::translate(_fbxJoint->translation) * transformInParentFrame;
|
||||
_rotation = extractRotation(_transform);
|
||||
glm::mat4 newTransform = parentTransform * glm::translate(_fbxJoint->translation) * transformInParentFrame;
|
||||
_transformChanged = true;
|
||||
|
||||
if (newTransform != _transform) {
|
||||
_transform = newTransform;
|
||||
_rotation = extractRotation(_transform);
|
||||
}
|
||||
}
|
||||
|
||||
void JointState::computeVisibleTransform(const glm::mat4& parentTransform) {
|
||||
|
@ -139,6 +154,7 @@ void JointState::clearTransformTranslation() {
|
|||
_transform[3][0] = 0.0f;
|
||||
_transform[3][1] = 0.0f;
|
||||
_transform[3][2] = 0.0f;
|
||||
_transformChanged = true;
|
||||
_visibleTransform[3][0] = 0.0f;
|
||||
_visibleTransform[3][1] = 0.0f;
|
||||
_visibleTransform[3][2] = 0.0f;
|
||||
|
@ -151,13 +167,15 @@ void JointState::setRotation(const glm::quat& rotation, bool constrain, float pr
|
|||
void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, float priority) {
|
||||
// NOTE: delta is in model-frame
|
||||
assert(_fbxJoint != NULL);
|
||||
if (priority < _animationPriority) {
|
||||
if (priority < _animationPriority || delta.null) {
|
||||
return;
|
||||
}
|
||||
_animationPriority = priority;
|
||||
if (!constrain || _constraint == NULL) {
|
||||
// no constraints
|
||||
_rotationInConstrainedFrame = _rotationInConstrainedFrame * glm::inverse(_rotation) * delta * _rotation;
|
||||
_transformChanged = true;
|
||||
|
||||
_rotation = delta * _rotation;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
void copyState(const JointState& state);
|
||||
|
||||
void initTransform(const glm::mat4& parentTransform);
|
||||
void computeTransform(const glm::mat4& parentTransform);
|
||||
void computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged = true);
|
||||
|
||||
void computeVisibleTransform(const glm::mat4& parentTransform);
|
||||
const glm::mat4& getVisibleTransform() const { return _visibleTransform; }
|
||||
|
@ -41,6 +41,8 @@ public:
|
|||
glm::vec3 getVisiblePosition() const { return extractTranslation(_visibleTransform); }
|
||||
|
||||
const glm::mat4& getTransform() const { return _transform; }
|
||||
void resetTransformChanged() { _transformChanged = false; }
|
||||
bool getTransformChanged() const { return _transformChanged; }
|
||||
|
||||
glm::quat getRotation() const { return _rotation; }
|
||||
glm::vec3 getPosition() const { return extractTranslation(_transform); }
|
||||
|
@ -104,6 +106,7 @@ private:
|
|||
/// debug helper function
|
||||
void loadBindRotation();
|
||||
|
||||
bool _transformChanged;
|
||||
glm::mat4 _transform; // joint- to model-frame
|
||||
glm::quat _rotation; // joint- to model-frame
|
||||
glm::quat _rotationInConstrainedFrame; // rotation in frame where angular constraints would be applied
|
||||
|
|
|
@ -922,7 +922,7 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
|
|||
void Model::simulateInternal(float deltaTime) {
|
||||
// NOTE: this is a recursive call that walks all attachments, and their attachments
|
||||
// update the world space transforms for all joints
|
||||
|
||||
|
||||
// update animations
|
||||
foreach (const AnimationHandlePointer& handle, _runningAnimations) {
|
||||
handle->simulate(deltaTime);
|
||||
|
@ -931,8 +931,11 @@ void Model::simulateInternal(float deltaTime) {
|
|||
for (int i = 0; i < _jointStates.size(); i++) {
|
||||
updateJointState(i);
|
||||
}
|
||||
for (int i = 0; i < _jointStates.size(); i++) {
|
||||
_jointStates[i].resetTransformChanged();
|
||||
}
|
||||
|
||||
_shapesAreDirty = ! _shapes.isEmpty();
|
||||
_shapesAreDirty = !_shapes.isEmpty();
|
||||
|
||||
// update the attachment transforms and simulate them
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
|
@ -994,7 +997,7 @@ void Model::updateJointState(int index) {
|
|||
state.computeTransform(parentTransform);
|
||||
} else {
|
||||
const JointState& parentState = _jointStates.at(parentIndex);
|
||||
state.computeTransform(parentState.getTransform());
|
||||
state.computeTransform(parentState.getTransform(), parentState.getTransformChanged());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue