From Cedric Pinson,
Add check in RigTransformSoftware if bones are null Indent TimelineAnimationManager Add check for NaN in UpdateCallback.cpp Fix TimelineAnimationManager clear target (a refactore of Timeline is require for futur) Fix Computation of bounding box for RigGeometry
This commit is contained in:
parent
f099dab160
commit
53d5b56202
@ -12,8 +12,8 @@
|
|||||||
* OpenSceneGraph Public License for more details.
|
* OpenSceneGraph Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OSGANIMATION_ANIMATION_MANAGER_BASE_H
|
#ifndef OSGANIMATION_ANIMATION_MANAGER_BASE
|
||||||
#define OSGANIMATION_ANIMATION_MANAGER_BASE_H
|
#define OSGANIMATION_ANIMATION_MANAGER_BASE 1
|
||||||
|
|
||||||
#include <osgAnimation/LinkVisitor>
|
#include <osgAnimation/LinkVisitor>
|
||||||
#include <osgAnimation/Animation>
|
#include <osgAnimation/Animation>
|
||||||
@ -55,7 +55,6 @@ namespace osgAnimation
|
|||||||
/// set a flag to define the behaviour
|
/// set a flag to define the behaviour
|
||||||
void setAutomaticLink(bool);
|
void setAutomaticLink(bool);
|
||||||
bool isAutomaticLink() const;
|
bool isAutomaticLink() const;
|
||||||
|
|
||||||
void dirty();
|
void dirty();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
* Michael Platings <mplatings@pixelpower.com>
|
* Michael Platings <mplatings@pixelpower.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OSGANIMATION_INTERPOLATOR_H
|
#ifndef OSGANIMATION_INTERPOLATOR
|
||||||
#define OSGANIMATION_INTERPOLATOR_H
|
#define OSGANIMATION_INTERPOLATOR 1
|
||||||
|
|
||||||
#include <osg/Notify>
|
#include <osg/Notify>
|
||||||
#include <osgAnimation/Keyframe>
|
#include <osgAnimation/Keyframe>
|
||||||
|
@ -86,7 +86,7 @@ namespace osgAnimation
|
|||||||
{
|
{
|
||||||
if (_bones.empty())
|
if (_bones.empty())
|
||||||
{
|
{
|
||||||
osg::notify(osg::WARN) << "RigTransformSoftware::UniqBoneSetVertexSet no bones found" << std::endl;
|
osg::notify(osg::WARN) << this << " RigTransformSoftware::UniqBoneSetVertexSet no bones found" << std::endl;
|
||||||
_result = osg::Matrix::identity();
|
_result = osg::Matrix::identity();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -96,6 +96,11 @@ namespace osgAnimation
|
|||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
const Bone* bone = _bones[i].getBone();
|
const Bone* bone = _bones[i].getBone();
|
||||||
|
if (!bone)
|
||||||
|
{
|
||||||
|
osg::notify(osg::WARN) << this << " RigTransformSoftware::computeMatrixForVertexSet Warning a bone is null, skip it" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const osg::Matrix& invBindMatrix = bone->getInvBindMatrixInSkeletonSpace();
|
const osg::Matrix& invBindMatrix = bone->getInvBindMatrixInSkeletonSpace();
|
||||||
const osg::Matrix& matrix = bone->getMatrixInSkeletonSpace();
|
const osg::Matrix& matrix = bone->getMatrixInSkeletonSpace();
|
||||||
osg::Matrix::value_type w = _bones[i].getWeight();
|
osg::Matrix::value_type w = _bones[i].getWeight();
|
||||||
|
@ -12,12 +12,13 @@
|
|||||||
* OpenSceneGraph Public License for more details.
|
* OpenSceneGraph Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OSGANIMATION_TIMELINE_H
|
#ifndef OSGANIMATION_TIMELINE
|
||||||
#define OSGANIMATION_TIMELINE_H
|
#define OSGANIMATION_TIMELINE 1
|
||||||
|
|
||||||
#include <osgAnimation/Export>
|
#include <osgAnimation/Export>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <osg/observer_ptr>
|
||||||
#include <osg/Notify>
|
#include <osg/Notify>
|
||||||
#include <osg/Stats>
|
#include <osg/Stats>
|
||||||
#include <osgAnimation/Action>
|
#include <osgAnimation/Action>
|
||||||
@ -27,7 +28,7 @@
|
|||||||
|
|
||||||
namespace osgAnimation
|
namespace osgAnimation
|
||||||
{
|
{
|
||||||
class OSGANIMATION_EXPORT Timeline : public Action //osg::Object
|
class OSGANIMATION_EXPORT Timeline : public Action
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -79,9 +80,9 @@ namespace osgAnimation
|
|||||||
const ActionLayers& getActionLayers() const { return _actions; }
|
const ActionLayers& getActionLayers() const { return _actions; }
|
||||||
|
|
||||||
void processPendingOperation();
|
void processPendingOperation();
|
||||||
|
void setAnimationManager(AnimationManagerBase*);
|
||||||
protected:
|
protected:
|
||||||
|
osg::observer_ptr<AnimationManagerBase> _animationManager;
|
||||||
ActionLayers _actions;
|
ActionLayers _actions;
|
||||||
double _lastUpdate;
|
double _lastUpdate;
|
||||||
double _speed;
|
double _speed;
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
* OpenSceneGraph Public License for more details.
|
* OpenSceneGraph Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OSGANIMATION_TIMELINE_ANIMATION_MANAGER_H
|
#ifndef OSGANIMATION_TIMELINE_ANIMATION_MANAGER
|
||||||
#define OSGANIMATION_TIMELINE_ANIMATION_MANAGER_H
|
#define OSGANIMATION_TIMELINE_ANIMATION_MANAGER 1
|
||||||
|
|
||||||
#include <osgAnimation/Export>
|
#include <osgAnimation/Export>
|
||||||
#include <osgAnimation/AnimationManagerBase>
|
#include <osgAnimation/AnimationManagerBase>
|
||||||
@ -23,12 +23,12 @@
|
|||||||
namespace osgAnimation
|
namespace osgAnimation
|
||||||
{
|
{
|
||||||
|
|
||||||
class OSGANIMATION_EXPORT TimelineAnimationManager : public AnimationManagerBase
|
class OSGANIMATION_EXPORT TimelineAnimationManager : public AnimationManagerBase
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
osg::ref_ptr<Timeline> _timeline;
|
osg::ref_ptr<Timeline> _timeline;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
META_Object(osgAnimation, TimelineAnimationManager);
|
META_Object(osgAnimation, TimelineAnimationManager);
|
||||||
TimelineAnimationManager();
|
TimelineAnimationManager();
|
||||||
TimelineAnimationManager(const AnimationManagerBase& manager);
|
TimelineAnimationManager(const AnimationManagerBase& manager);
|
||||||
@ -37,7 +37,7 @@ public:
|
|||||||
Timeline* getTimeline() { return _timeline.get(); }
|
Timeline* getTimeline() { return _timeline.get(); }
|
||||||
const Timeline* getTimeline() const { return _timeline.get(); }
|
const Timeline* getTimeline() const { return _timeline.get(); }
|
||||||
void update(double time);
|
void update(double time);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,45 @@
|
|||||||
|
|
||||||
using namespace osgAnimation;
|
using namespace osgAnimation;
|
||||||
|
|
||||||
|
// The idea is to compute a bounding box with a factor x of the first step we compute the bounding box
|
||||||
|
class RigComputeBoundingBoxCallback : public osg::Drawable::ComputeBoundingBoxCallback
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RigComputeBoundingBoxCallback(double factor = 2.0) : _computed(false), _factor(factor) {}
|
||||||
|
void reset() { _computed = false; }
|
||||||
|
virtual osg::BoundingBox computeBound(const osg::Drawable& drawable) const
|
||||||
|
{
|
||||||
|
const osgAnimation::RigGeometry& rig = dynamic_cast<const osgAnimation::RigGeometry&>(drawable);
|
||||||
|
|
||||||
|
// if a valid inital bounding box is set we use it without asking more
|
||||||
|
if (rig.getInitialBound().valid())
|
||||||
|
return rig.getInitialBound();
|
||||||
|
|
||||||
|
if (_computed)
|
||||||
|
return _boundingBox;
|
||||||
|
|
||||||
|
// if the computing of bb is invalid (like no geometry inside)
|
||||||
|
// then dont tag the bounding box as computed
|
||||||
|
osg::BoundingBox bb = rig.computeBound();
|
||||||
|
if (!bb.valid())
|
||||||
|
return bb;
|
||||||
|
|
||||||
|
|
||||||
|
_boundingBox.expandBy(bb);
|
||||||
|
osg::Vec3 center = _boundingBox.center();
|
||||||
|
osg::Vec3 vec = (_boundingBox._max-center)*_factor;
|
||||||
|
_boundingBox.expandBy(center + vec);
|
||||||
|
_boundingBox.expandBy(center - vec);
|
||||||
|
_computed = true;
|
||||||
|
// osg::notify(osg::NOTICE) << "build the bounding box for RigGeometry " << rig.getName() << " " << _boundingBox._min << " " << _boundingBox._max << std::endl;
|
||||||
|
return _boundingBox;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
mutable bool _computed;
|
||||||
|
double _factor;
|
||||||
|
mutable osg::BoundingBox _boundingBox;
|
||||||
|
};
|
||||||
|
|
||||||
RigGeometry::RigGeometry()
|
RigGeometry::RigGeometry()
|
||||||
{
|
{
|
||||||
_supportsDisplayList = false;
|
_supportsDisplayList = false;
|
||||||
@ -29,7 +68,7 @@ RigGeometry::RigGeometry()
|
|||||||
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();
|
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();
|
||||||
|
|
||||||
// disable the computation of boundingbox for the rig mesh
|
// disable the computation of boundingbox for the rig mesh
|
||||||
setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback);
|
setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
RigGeometry::RigGeometry(const osg::Geometry& b) : osg::Geometry(b, osg::CopyOp::SHALLOW_COPY)
|
RigGeometry::RigGeometry(const osg::Geometry& b) : osg::Geometry(b, osg::CopyOp::SHALLOW_COPY)
|
||||||
@ -42,7 +81,7 @@ RigGeometry::RigGeometry(const osg::Geometry& b) : osg::Geometry(b, osg::CopyOp:
|
|||||||
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();
|
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();
|
||||||
|
|
||||||
// disable the computation of boundingbox for the rig mesh
|
// disable the computation of boundingbox for the rig mesh
|
||||||
setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback);
|
setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) :
|
RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) :
|
||||||
|
@ -34,6 +34,7 @@ TimelineAnimationManager::TimelineAnimationManager(const TimelineAnimationManage
|
|||||||
|
|
||||||
void TimelineAnimationManager::update(double time)
|
void TimelineAnimationManager::update(double time)
|
||||||
{
|
{
|
||||||
clearTargets();
|
// clearTargets();
|
||||||
|
_timeline->setAnimationManager(this);
|
||||||
_timeline->update(time);
|
_timeline->update(time);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <osgAnimation/UpdateCallback>
|
#include <osgAnimation/UpdateCallback>
|
||||||
#include <osg/MatrixTransform>
|
#include <osg/MatrixTransform>
|
||||||
#include <osg/PositionAttitudeTransform>
|
#include <osg/PositionAttitudeTransform>
|
||||||
|
#include <osg/Math>
|
||||||
|
|
||||||
using namespace osgAnimation;
|
using namespace osgAnimation;
|
||||||
|
|
||||||
@ -69,10 +70,11 @@ void UpdateTransform::update(osg::MatrixTransform& mat)
|
|||||||
osg::Matrix::rotate(x,1.0,0.0,0.0) *
|
osg::Matrix::rotate(x,1.0,0.0,0.0) *
|
||||||
osg::Matrix::rotate(y,0.0,1.0,0.0) *
|
osg::Matrix::rotate(y,0.0,1.0,0.0) *
|
||||||
osg::Matrix::rotate(z,0.0,0.0,1.0);
|
osg::Matrix::rotate(z,0.0,0.0,1.0);
|
||||||
mat.setMatrix(osg::Matrix::scale(_scale->getValue()) *
|
m = osg::Matrix::scale(_scale->getValue()) * m * osg::Matrix::translate(_position->getValue());
|
||||||
m *
|
mat.setMatrix(m);
|
||||||
osg::Matrix::translate(_position->getValue()));
|
|
||||||
mat.dirtyBound();
|
if (!m.valid())
|
||||||
|
osg::notify(osg::WARN) << this << " UpdateTransform::update detected NaN" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateTransform::update(osg::PositionAttitudeTransform& pat)
|
void UpdateTransform::update(osg::PositionAttitudeTransform& pat)
|
||||||
|
Loading…
Reference in New Issue
Block a user