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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ANIMATION_MANAGER_BASE_H
|
||||
#define OSGANIMATION_ANIMATION_MANAGER_BASE_H
|
||||
#ifndef OSGANIMATION_ANIMATION_MANAGER_BASE
|
||||
#define OSGANIMATION_ANIMATION_MANAGER_BASE 1
|
||||
|
||||
#include <osgAnimation/LinkVisitor>
|
||||
#include <osgAnimation/Animation>
|
||||
@ -55,7 +55,6 @@ namespace osgAnimation
|
||||
/// set a flag to define the behaviour
|
||||
void setAutomaticLink(bool);
|
||||
bool isAutomaticLink() const;
|
||||
|
||||
void dirty();
|
||||
|
||||
protected:
|
||||
|
@ -16,8 +16,8 @@
|
||||
* Michael Platings <mplatings@pixelpower.com>
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_INTERPOLATOR_H
|
||||
#define OSGANIMATION_INTERPOLATOR_H
|
||||
#ifndef OSGANIMATION_INTERPOLATOR
|
||||
#define OSGANIMATION_INTERPOLATOR 1
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osgAnimation/Keyframe>
|
||||
|
@ -86,7 +86,7 @@ namespace osgAnimation
|
||||
{
|
||||
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();
|
||||
return;
|
||||
}
|
||||
@ -96,6 +96,11 @@ namespace osgAnimation
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
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& matrix = bone->getMatrixInSkeletonSpace();
|
||||
osg::Matrix::value_type w = _bones[i].getWeight();
|
||||
|
@ -12,12 +12,13 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_TIMELINE_H
|
||||
#define OSGANIMATION_TIMELINE_H
|
||||
#ifndef OSGANIMATION_TIMELINE
|
||||
#define OSGANIMATION_TIMELINE 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <osg/observer_ptr>
|
||||
#include <osg/Notify>
|
||||
#include <osg/Stats>
|
||||
#include <osgAnimation/Action>
|
||||
@ -27,7 +28,7 @@
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
class OSGANIMATION_EXPORT Timeline : public Action //osg::Object
|
||||
class OSGANIMATION_EXPORT Timeline : public Action
|
||||
{
|
||||
public:
|
||||
|
||||
@ -79,9 +80,9 @@ namespace osgAnimation
|
||||
const ActionLayers& getActionLayers() const { return _actions; }
|
||||
|
||||
void processPendingOperation();
|
||||
|
||||
void setAnimationManager(AnimationManagerBase*);
|
||||
protected:
|
||||
|
||||
osg::observer_ptr<AnimationManagerBase> _animationManager;
|
||||
ActionLayers _actions;
|
||||
double _lastUpdate;
|
||||
double _speed;
|
||||
@ -89,7 +90,7 @@ namespace osgAnimation
|
||||
unsigned int _previousFrameEvaluated;
|
||||
bool _initFirstFrame;
|
||||
TimelineStatus _state;
|
||||
|
||||
|
||||
bool _collectStats;
|
||||
osg::ref_ptr<osg::Stats> _stats;
|
||||
osg::ref_ptr<osgAnimation::StatsActionVisitor> _statsVisitor;
|
||||
|
@ -12,8 +12,8 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_TIMELINE_ANIMATION_MANAGER_H
|
||||
#define OSGANIMATION_TIMELINE_ANIMATION_MANAGER_H
|
||||
#ifndef OSGANIMATION_TIMELINE_ANIMATION_MANAGER
|
||||
#define OSGANIMATION_TIMELINE_ANIMATION_MANAGER 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/AnimationManagerBase>
|
||||
@ -23,21 +23,21 @@
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT TimelineAnimationManager : public AnimationManagerBase
|
||||
{
|
||||
protected:
|
||||
osg::ref_ptr<Timeline> _timeline;
|
||||
class OSGANIMATION_EXPORT TimelineAnimationManager : public AnimationManagerBase
|
||||
{
|
||||
protected:
|
||||
osg::ref_ptr<Timeline> _timeline;
|
||||
|
||||
public:
|
||||
META_Object(osgAnimation, TimelineAnimationManager);
|
||||
TimelineAnimationManager();
|
||||
TimelineAnimationManager(const AnimationManagerBase& manager);
|
||||
TimelineAnimationManager(const TimelineAnimationManager& nc,const osg::CopyOp&);
|
||||
public:
|
||||
META_Object(osgAnimation, TimelineAnimationManager);
|
||||
TimelineAnimationManager();
|
||||
TimelineAnimationManager(const AnimationManagerBase& manager);
|
||||
TimelineAnimationManager(const TimelineAnimationManager& nc,const osg::CopyOp&);
|
||||
|
||||
Timeline* getTimeline() { return _timeline.get(); }
|
||||
const Timeline* getTimeline() const { return _timeline.get(); }
|
||||
void update(double time);
|
||||
};
|
||||
Timeline* getTimeline() { return _timeline.get(); }
|
||||
const Timeline* getTimeline() const { return _timeline.get(); }
|
||||
void update(double time);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,45 @@
|
||||
|
||||
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()
|
||||
{
|
||||
_supportsDisplayList = false;
|
||||
@ -29,7 +68,7 @@ RigGeometry::RigGeometry()
|
||||
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();
|
||||
|
||||
// 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)
|
||||
@ -42,7 +81,7 @@ RigGeometry::RigGeometry(const osg::Geometry& b) : osg::Geometry(b, osg::CopyOp:
|
||||
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();
|
||||
|
||||
// disable the computation of boundingbox for the rig mesh
|
||||
setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback);
|
||||
setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback);
|
||||
}
|
||||
|
||||
RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) :
|
||||
|
@ -34,6 +34,7 @@ TimelineAnimationManager::TimelineAnimationManager(const TimelineAnimationManage
|
||||
|
||||
void TimelineAnimationManager::update(double time)
|
||||
{
|
||||
clearTargets();
|
||||
// clearTargets();
|
||||
_timeline->setAnimationManager(this);
|
||||
_timeline->update(time);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <osgAnimation/UpdateCallback>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/Math>
|
||||
|
||||
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(y,0.0,1.0,0.0) *
|
||||
osg::Matrix::rotate(z,0.0,0.0,1.0);
|
||||
mat.setMatrix(osg::Matrix::scale(_scale->getValue()) *
|
||||
m *
|
||||
osg::Matrix::translate(_position->getValue()));
|
||||
mat.dirtyBound();
|
||||
m = osg::Matrix::scale(_scale->getValue()) * m * osg::Matrix::translate(_position->getValue());
|
||||
mat.setMatrix(m);
|
||||
|
||||
if (!m.valid())
|
||||
osg::notify(osg::WARN) << this << " UpdateTransform::update detected NaN" << std::endl;
|
||||
}
|
||||
|
||||
void UpdateTransform::update(osg::PositionAttitudeTransform& pat)
|
||||
|
Loading…
Reference in New Issue
Block a user