Skip to content

Commit

Permalink
rollback from master merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Valentin authored and Julien Valentin committed Jun 25, 2016
1 parent ae9d50c commit 7c4218c
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/osgAnimation/Channel
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace osgAnimation
typedef TemplateKeyframeContainer<typename SamplerType::KeyframeType> KeyframeContainerType;

Object* cloneType() const { return new TemplateChannel(); }
Object* clone(const osg::CopyOp&) const { return new TemplateChannel<SamplerType>(*this); }
Object* clone(const osg::CopyOp& copyop) const { return new TemplateChannel<SamplerType>(*this); }
Channel* clone() const { return new TemplateChannel<SamplerType>(*this); }

TemplateChannel (const TemplateChannel& channel) :
Expand Down
49 changes: 45 additions & 4 deletions include/osgAnimation/MorphGeometry
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <osgAnimation/Export>
#include <osgAnimation/AnimationUpdateCallback>
#include <osg/Geometry>
#include <algorithm>

namespace osgAnimation
{
Expand Down Expand Up @@ -81,6 +82,25 @@ namespace osgAnimation
*/
virtual void addMorphTarget( osg::Geometry *morphTarget, float weight = 1.0 ) { _morphTargets.push_back(MorphTarget(morphTarget, weight)); _dirty = true; }

virtual void removeMorphTarget( osg::Geometry *morphTarget ) {
for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator) {
if(iterator->getGeometry() == morphTarget) {
_morphTargets.erase(iterator);
break;
}
}
}

virtual void removeMorphTarget( const std::string& name ) {
for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator) {
if(iterator->getGeometry() && iterator->getGeometry()->getName() == name) {
_morphTargets.erase(iterator);
break;
}
}

}

void setWeight(unsigned int index, float morphWeight)
{
if (index < _morphTargets.size())
Expand Down Expand Up @@ -121,23 +141,44 @@ namespace osgAnimation

class OSGANIMATION_EXPORT UpdateMorph : public AnimationUpdateCallback<osg::NodeCallback>
{
protected:
std::map<int, osg::ref_ptr<osgAnimation::FloatTarget> > _weightTargets;

public:
typedef std::vector<std::string> TargetNames;
typedef std::map< int, osg::ref_ptr<osgAnimation::FloatTarget> > WeightTargets;

META_Object(osgAnimation, UpdateMorph);

UpdateMorph(const std::string& name = "");
UpdateMorph(const UpdateMorph& apc,const osg::CopyOp& copyop);

void addTarget(const std::string& name) { _targetNames.push_back(name); }
unsigned int getNumTarget() const { return _targetNames.size(); }
const std::string& getTargetName(unsigned int index) { return _targetNames[index]; }
void removeTarget(const std::string& name) {
TargetNames::iterator found = std::find(_targetNames.begin(), _targetNames.end(), name);
if(found != _targetNames.end())
_targetNames.erase(found);
}

// for serialization
const std::vector<std::string>& getTargetNames() const { return _targetNames; }
std::vector<std::string>& getTargetNames() { return _targetNames; }

void setTargetNames(const TargetNames& targetNames) {
_targetNames.assign(targetNames.begin(), targetNames.end());
}

/** Callback method called by the NodeVisitor when visiting a node.*/
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
bool needLink() const;
bool link(osgAnimation::Channel* channel);
int link(Animation* animation);

protected:
WeightTargets _weightTargets;
TargetNames _targetNames;
};

struct UpdateMorphGeometry : public osg::DrawableUpdateCallback
struct UpdateMorphGeometry : public osg::Drawable::UpdateCallback
{
UpdateMorphGeometry() {}

Expand Down
4 changes: 2 additions & 2 deletions src/osgAnimation/ActionVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ void UpdateActionVisitor::apply(ActionAnimation& action)
{
unsigned int frame = getLocalFrame();
apply(static_cast<Action&>(action));
int pri = static_cast<int>(_currentAnimationPriority);
_currentAnimationPriority++;
int pri = static_cast<int>(_currentAnimationPriority);
_currentAnimationPriority++;
action.updateAnimation(frame, -pri);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/osgAnimation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ SET(TARGET_H
${HEADER_PATH}/UpdateBone
${HEADER_PATH}/UpdateMaterial
${HEADER_PATH}/UpdateMatrixTransform
${HEADER_PATH}/UpdateUniform
${HEADER_PATH}/Vec3Packed
${HEADER_PATH}/VertexInfluence
)
Expand Down
27 changes: 27 additions & 0 deletions src/osgAnimation/MorphGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop)
setUseVertexBufferObjects(true);
}


void MorphGeometry::transformSoftwareMethod()
{
if (_dirty)
Expand Down Expand Up @@ -279,3 +280,29 @@ bool UpdateMorph::link(osgAnimation::Channel* channel)
}
return false;
}

int UpdateMorph::link(Animation* animation)
{
if (getNumTarget() == 0)
{
osg::notify(osg::WARN) << "An update callback has no name, it means it could link only with \"\" named Target, often an error, discard" << std::endl;
return 0;
}

unsigned int nbLinks = 0;
for (ChannelList::iterator channel = animation->getChannels().begin();
channel != animation->getChannels().end();
++channel)
{
std::string targetName = (*channel)->getTargetName();
for(int i = 0, num = getNumTarget(); i < num; ++i) {
if (targetName == getTargetName(i))
{
AnimationUpdateCallbackBase* a = this;
a->link((*channel).get());
nbLinks++;
}
}
}
return nbLinks;
}
6 changes: 3 additions & 3 deletions src/osgAnimation/RigTransformHardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ bool RigTransformHardware::createPalette(int nbVertexes, BoneMap boneMap, const
vertexIndexWeight.resize(nbVertexes);

int maxBonePerVertex = 0;
for (VertexInfluenceSet::VertexIndexToBoneWeightMap::const_iterator vit = vertexIndexToBoneWeightMap.begin(); vit != vertexIndexToBoneWeightMap.end(); ++vit)
for (VertexInfluenceSet::VertexIndexToBoneWeightMap::const_iterator it = vertexIndexToBoneWeightMap.begin(); it != vertexIndexToBoneWeightMap.end(); ++it)
{
int vertexIndex = vit->first;
const VertexInfluenceSet::BoneWeightList& boneWeightList = vit->second;
int vertexIndex = it->first;
const VertexInfluenceSet::BoneWeightList& boneWeightList = it->second;
int bonesForThisVertex = 0;
for (VertexInfluenceSet::BoneWeightList::const_iterator it = boneWeightList.begin(); it != boneWeightList.end(); ++it)
{
Expand Down
4 changes: 2 additions & 2 deletions src/osgAnimation/RigTransformSoftware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void RigTransformSoftware::operator()(RigGeometry& geom)
}
*positionDst = *positionSrc;
}
if (!positionDst->empty())
if (positionDst && !positionDst->empty())
{
compute<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(),
geom.getInvMatrixFromSkeletonToGeometry(),
Expand All @@ -96,7 +96,7 @@ void RigTransformSoftware::operator()(RigGeometry& geom)
}
*normalDst = *normalSrc;
}
if (!normalDst->empty())
if (normalDst && !normalDst->empty())
{
computeNormal<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(),
geom.getInvMatrixFromSkeletonToGeometry(),
Expand Down
1 change: 0 additions & 1 deletion src/osgAnimation/Skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Skeleton::UpdateSkeleton::UpdateSkeleton() : _needValidate(true) {}

Skeleton::UpdateSkeleton::UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop) :
osg::Object(us, copyop),
osg::Callback(us, copyop),
osg::NodeCallback(us, copyop)
{
_needValidate = true;
Expand Down
3 changes: 1 addition & 2 deletions src/osgAnimation/StackedTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ using namespace osgAnimation;

StackedTransform::StackedTransform() {}

StackedTransform::StackedTransform(const StackedTransform& rhs, const osg::CopyOp& co):
osg::MixinVector<osg::ref_ptr<StackedTransformElement> >()
StackedTransform::StackedTransform(const StackedTransform& rhs, const osg::CopyOp& co)
{
reserve(rhs.size());
for (StackedTransform::const_iterator it = rhs.begin(); it != rhs.end(); ++it)
Expand Down
6 changes: 3 additions & 3 deletions src/osgAnimation/StatsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct StatsGraph : public osg::MatrixTransform

void changeYposition(float y)
{
_pos = getMatrix().getTrans();
osg::Vec3 _pos = getMatrix().getTrans();
_pos[1] = y - _height;
setMatrix(osg::Matrix::translate(_pos));
}
Expand All @@ -106,7 +106,7 @@ struct StatsGraph : public osg::MatrixTransform

osg::ref_ptr<osg::Geode> _statsGraphGeode;

struct NeverCull : public osg::DrawableCullCallback
struct NeverCull : public osg::Drawable::CullCallback
{
NeverCull() {}
bool cull(osg::NodeVisitor* /*nv*/, osg::Drawable* /*drawable*/, osg::RenderInfo* /*renderInfo*/) const { return false;}
Expand Down Expand Up @@ -137,7 +137,7 @@ struct StatsGraph : public osg::MatrixTransform
};


struct GraphUpdateCallback : public osg::DrawableUpdateCallback
struct GraphUpdateCallback : public osg::Drawable::UpdateCallback
{

const unsigned int _width;
Expand Down
5 changes: 1 addition & 4 deletions src/osgAnimation/UpdateMatrixTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

using namespace osgAnimation;

UpdateMatrixTransform::UpdateMatrixTransform( const UpdateMatrixTransform& apc,const osg::CopyOp& copyop) :
osg::Object(apc,copyop),
osg::Callback(apc,copyop),
AnimationUpdateCallback<osg::NodeCallback>(apc, copyop)
UpdateMatrixTransform::UpdateMatrixTransform( const UpdateMatrixTransform& apc,const osg::CopyOp& copyop) : osg::Object(apc,copyop), AnimationUpdateCallback<osg::NodeCallback>(apc, copyop)
{
_transforms = StackedTransform(apc.getStackedTransforms(), copyop);
}
Expand Down
3 changes: 2 additions & 1 deletion src/osgPlugins/fbx/fbxRAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ void readKeys(FbxAnimCurve* curveX, FbxAnimCurve* curveY, FbxAnimCurve* curveZ,
if (lb == curveTimeMap[i].end()) --lb;
val[i] = lb->second;
}

keyFrameCntr.push_back(osgAnimation::Vec3Keyframe(fTime, val));
}
}
}

void readKeys(FbxAnimCurve* curveX, FbxAnimCurve* curveY, FbxAnimCurve* curveZ,
Expand Down

0 comments on commit 7c4218c

Please sign in to comment.