Added a AnimationPathCallback which can update both a MatrixTransform and a
PositionAttitudeTransform, removed the equivialnt callbacks once found in these transform classes. Changed the NodeCallback class so its derived from osg::Object instead of osg::Referenced to allow it to be saved out in the .osg format. Added support for Update and Cull callbacks into the .osg file format. Added support for AnimationPathCallback into the .osg file format.
This commit is contained in:
@@ -143,7 +143,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
|
||||
positioned->addChild(glider);
|
||||
|
||||
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform;
|
||||
xform->setUpdateCallback(new osg::PositionAttitudeTransform::AnimationPathCallback(animationPath,0.0,1.0));
|
||||
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0,1.0));
|
||||
xform->addChild(positioned);
|
||||
|
||||
model->addChild(xform);
|
||||
@@ -164,7 +164,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
|
||||
positioned->addChild(cessna);
|
||||
|
||||
osg::MatrixTransform* xform = new osg::MatrixTransform;
|
||||
xform->setUpdateCallback(new osg::MatrixTransform::AnimationPathCallback(animationPath,0.0f,2.0));
|
||||
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0));
|
||||
xform->addChild(positioned);
|
||||
|
||||
model->addChild(xform);
|
||||
|
||||
@@ -124,7 +124,7 @@ osg::Node* createLights(osg::BoundingBox& bb,osg::StateSet* rootStateSet)
|
||||
animationPath->insert(8.0,osg::AnimationPath::ControlPoint(bb.corner(0)));
|
||||
animationPath->setLoopMode(osg::AnimationPath::SWING);
|
||||
|
||||
mt->setUpdateCallback(new osg::MatrixTransform::AnimationPathCallback(animationPath));
|
||||
mt->setUpdateCallback(new osg::AnimationPathCallback(animationPath));
|
||||
}
|
||||
|
||||
// create marker for point light.
|
||||
|
||||
@@ -248,7 +248,7 @@ class MyGeometryCallback :
|
||||
osg::Vec3* end = begin+count;
|
||||
for (osg::Vec3* itr=begin;itr<end;++itr)
|
||||
{
|
||||
osg::Vec3 dv(*itr-_origin);
|
||||
osg::Vepc3 dv(*itr-_origin);
|
||||
osg::Vec3 local(dv*_xAxis,dv*_yAxis,dv*_zAxis);
|
||||
|
||||
local.z() = local.x()*_amplitude*
|
||||
|
||||
@@ -138,7 +138,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
|
||||
positioned->addChild(cessna);
|
||||
|
||||
osg::MatrixTransform* xform = new osg::MatrixTransform;
|
||||
xform->setUpdateCallback(new osg::MatrixTransform::AnimationPathCallback(animationPath,0.0f,2.0));
|
||||
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0));
|
||||
xform->addChild(positioned);
|
||||
|
||||
model->addChild(xform);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <osg/AnimationPath>
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
@@ -67,3 +68,43 @@ bool AnimationPath::getInterpolatedControlPoint(double time,ControlPoint& contro
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void AnimationPathCallback::operator()(Node* node, NodeVisitor* nv)
|
||||
{
|
||||
if (_animationPath.valid() &&
|
||||
nv->getVisitorType()==NodeVisitor::UPDATE_VISITOR &&
|
||||
nv->getFrameStamp())
|
||||
{
|
||||
double time = nv->getFrameStamp()->getReferenceTime();
|
||||
if (_firstTime==0.0) _firstTime = time;
|
||||
|
||||
_animationTime = ((time-_firstTime)-_timeOffset)*_timeMultiplier;
|
||||
|
||||
node->accept(*this);
|
||||
|
||||
}
|
||||
|
||||
// must call any nested node callbacks and continue subgraph traversal.
|
||||
NodeCallback::traverse(node,nv);
|
||||
}
|
||||
|
||||
void AnimationPathCallback::apply(MatrixTransform& mt)
|
||||
{
|
||||
Matrix matrix;
|
||||
if (_animationPath->getMatrix(_animationTime,matrix))
|
||||
{
|
||||
mt.setMatrix(matrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AnimationPathCallback::apply(PositionAttitudeTransform& pat)
|
||||
{
|
||||
AnimationPath::ControlPoint cp;
|
||||
if (_animationPath->getInterpolatedControlPoint(_animationTime,cp))
|
||||
{
|
||||
pat.setPosition(cp._position);
|
||||
pat.setAttitude(cp._rotation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,8 @@ MatrixTransform::MatrixTransform(const MatrixTransform& transform,const CopyOp&
|
||||
Transform(transform,copyop),
|
||||
_matrix(new Matrix(*transform._matrix)),
|
||||
_inverse(new Matrix(*transform._inverse)),
|
||||
_inverseDirty(transform._inverseDirty),
|
||||
_animationPath(dynamic_cast<AnimationPath*>(copyop(transform._animationPath.get())))
|
||||
_inverseDirty(transform._inverseDirty)
|
||||
{
|
||||
if (_animationPath.valid()) setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
||||
}
|
||||
|
||||
MatrixTransform::MatrixTransform(const Matrix& mat )
|
||||
@@ -33,38 +31,30 @@ MatrixTransform::~MatrixTransform()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MatrixTransform::traverse(NodeVisitor& nv)
|
||||
bool MatrixTransform::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
// if app traversal update the frame count.
|
||||
if (_animationPath.valid() &&
|
||||
nv.getVisitorType()==NodeVisitor::UPDATE_VISITOR &&
|
||||
nv.getFrameStamp())
|
||||
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
||||
{
|
||||
double time = nv.getFrameStamp()->getReferenceTime();
|
||||
_animationPath->getMatrix(time,*_matrix);
|
||||
matrix.preMult(*_matrix);
|
||||
}
|
||||
|
||||
// must call any nested node callbacks and continue subgraph traversal.
|
||||
Transform::traverse(nv);
|
||||
else // absolute
|
||||
{
|
||||
matrix = *_matrix;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MatrixTransform::AnimationPathCallback::operator()(Node* node, NodeVisitor* nv)
|
||||
bool MatrixTransform::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
MatrixTransform* mt = dynamic_cast<MatrixTransform*>(node);
|
||||
if (mt &&
|
||||
_animationPath.valid() &&
|
||||
nv->getVisitorType()==NodeVisitor::UPDATE_VISITOR &&
|
||||
nv->getFrameStamp())
|
||||
const Matrix& inverse = getInverseMatrix();
|
||||
|
||||
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
||||
{
|
||||
double time = nv->getFrameStamp()->getReferenceTime();
|
||||
if (_firstTime==0.0) _firstTime = time;
|
||||
Matrix matrix;
|
||||
if (_animationPath->getMatrix(((time-_firstTime)-_timeOffset)*_timeMultiplier,matrix))
|
||||
{
|
||||
mt->setMatrix(matrix);
|
||||
}
|
||||
matrix.postMult(inverse);
|
||||
}
|
||||
// must call any nested node callbacks and continue subgraph traversal.
|
||||
traverse(node,nv);
|
||||
else // absolute
|
||||
{
|
||||
matrix = inverse;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ NodeVisitor::NodeVisitor(TraversalMode tm)
|
||||
_visitorType = NODE_VISITOR;
|
||||
_traversalNumber = -1;
|
||||
|
||||
_traversalVisitor = NULL;
|
||||
_traversalMode = tm;
|
||||
_traversalMask = 0xffffffff;
|
||||
_nodeMaskOverride = 0x0;
|
||||
@@ -20,7 +19,6 @@ NodeVisitor::NodeVisitor(VisitorType type,TraversalMode tm)
|
||||
_visitorType = type;
|
||||
_traversalNumber = -1;
|
||||
|
||||
_traversalVisitor = NULL;
|
||||
_traversalMode = tm;
|
||||
_traversalMask = 0xffffffff;
|
||||
_nodeMaskOverride = 0x0;
|
||||
@@ -32,32 +30,6 @@ NodeVisitor::~NodeVisitor()
|
||||
// if (_traversalVisitor) detach from _traversalVisitor;
|
||||
}
|
||||
|
||||
|
||||
void NodeVisitor::setTraversalMode(TraversalMode mode)
|
||||
{
|
||||
if (_traversalMode==mode) return;
|
||||
if (mode==TRAVERSE_VISITOR)
|
||||
{
|
||||
if (_traversalVisitor==NULL) _traversalMode = TRAVERSE_NONE;
|
||||
else _traversalMode = TRAVERSE_VISITOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_traversalVisitor.valid()) _traversalVisitor=NULL;
|
||||
_traversalMode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NodeVisitor::setTraversalVisitor(NodeVisitor* nv)
|
||||
{
|
||||
if (_traversalVisitor==nv) return;
|
||||
_traversalVisitor = nv;
|
||||
if (_traversalVisitor.valid()) _traversalMode = TRAVERSE_VISITOR;
|
||||
else _traversalMode = TRAVERSE_NONE;
|
||||
}
|
||||
|
||||
|
||||
class TransformVisitor : public NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -40,24 +40,3 @@ bool PositionAttitudeTransform::computeWorldToLocalMatrix(Matrix& matrix,NodeVis
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PositionAttitudeTransform::AnimationPathCallback::operator()(Node* node, NodeVisitor* nv)
|
||||
{
|
||||
PositionAttitudeTransform* pat = dynamic_cast<PositionAttitudeTransform*>(node);
|
||||
if (pat &&
|
||||
_animationPath.valid() &&
|
||||
nv->getVisitorType()==NodeVisitor::UPDATE_VISITOR &&
|
||||
nv->getFrameStamp())
|
||||
{
|
||||
double time = nv->getFrameStamp()->getReferenceTime();
|
||||
if (_firstTime==0.0) _firstTime = time;
|
||||
AnimationPath::ControlPoint cp;
|
||||
if (_animationPath->getInterpolatedControlPoint(((time-_firstTime)-_timeOffset)*_timeMultiplier,cp))
|
||||
{
|
||||
pat->setPosition(cp._position);
|
||||
pat->setAttitude(cp._rotation);
|
||||
}
|
||||
}
|
||||
// must call any nested node callbacks and continue subgraph traversal.
|
||||
traverse(node,nv);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ FltFile::FltFile(
|
||||
TexturePool* pTexturePool,
|
||||
MaterialPool* pMaterialPool)
|
||||
{
|
||||
_useTextureAlphaForTransparancyBinning = true;
|
||||
|
||||
if (pColorPool)
|
||||
{
|
||||
// use external color palette, ignore internal
|
||||
@@ -91,6 +93,7 @@ osg::Node* FltFile::readNode(const std::string& fileName)
|
||||
osg::Group* FltFile::convert()
|
||||
{
|
||||
ConvertFromFLT visit;
|
||||
visit.setUseTextureAlphaForTransparancyBinning(getUseTextureAlphaForTransparancyBinning());
|
||||
return visit.convert(getHeaderRecord());
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ class FltFile : public osg::Referenced
|
||||
inline const bool useInternalTexturePalette() const { return _useInternalTexturePalette; }
|
||||
inline const bool useInternalMaterialPalette() const { return _useInternalMaterialPalette; }
|
||||
|
||||
void setUseTextureAlphaForTransparancyBinning(bool flag) { _useTextureAlphaForTransparancyBinning=flag; }
|
||||
bool getUseTextureAlphaForTransparancyBinning() const { return _useTextureAlphaForTransparancyBinning; }
|
||||
|
||||
int getFlightVersion() const;
|
||||
inline HeaderRecord* getHeaderRecord() { return _headerRecord.get(); }
|
||||
|
||||
@@ -61,6 +64,7 @@ class FltFile : public osg::Referenced
|
||||
bool _useInternalColorPalette;
|
||||
bool _useInternalTexturePalette;
|
||||
bool _useInternalMaterialPalette;
|
||||
bool _useTextureAlphaForTransparancyBinning;
|
||||
|
||||
std::string _directory;
|
||||
|
||||
|
||||
@@ -20,14 +20,19 @@ osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readObject(const std::string& f
|
||||
}
|
||||
|
||||
|
||||
osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options)
|
||||
{
|
||||
if( !acceptsExtension(osgDB::getFileExtension(fileName) ))
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::ref_ptr<FltFile> read = new FltFile;
|
||||
|
||||
if (options)
|
||||
{
|
||||
read->setUseTextureAlphaForTransparancyBinning(options->getOptionString().find("noTextureAlphaForTransparancyBinning")!=std::string::npos);
|
||||
}
|
||||
|
||||
osg::Node* node = read.get()->readNode(fileName);
|
||||
osg::Node* node = read->readNode(fileName);
|
||||
if (node) return node;
|
||||
else return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ ConvertFromFLT::ConvertFromFLT() :
|
||||
_wObjTransparency = 0;
|
||||
_nSubfaceLevel = 0;
|
||||
_unitScale = 1.0;
|
||||
_useTextureAlphaForTranspancyBinning = true;
|
||||
_bHdrRgbMode = false;
|
||||
}
|
||||
|
||||
@@ -1180,7 +1181,7 @@ void ConvertFromFLT::setTexture ( FaceRecord *rec, SFace *pSFace, osg::StateSet
|
||||
if (osgTexture)
|
||||
{
|
||||
osg::Image* osgImage = osgTexture->getImage();
|
||||
if (osgImage->isImageTranslucent()) bBlend = true;
|
||||
if (getUseTextureAlphaForTransparancyBinning() && osgImage->isImageTranslucent()) bBlend = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -153,6 +153,10 @@ class ConvertFromFLT
|
||||
int visitVertexList(GeoSetBuilder* pParent, VertexListRecord* rec);
|
||||
int visitLocalVertexPool(GeoSetBuilder* pBuilder, LocalVertexPoolRecord* rec);
|
||||
|
||||
|
||||
void setUseTextureAlphaForTransparancyBinning(bool flag) { _useTextureAlphaForTranspancyBinning=flag; }
|
||||
bool getUseTextureAlphaForTransparancyBinning() const { return _useTextureAlphaForTranspancyBinning; }
|
||||
|
||||
private:
|
||||
|
||||
int addMeshPrimitives ( osg::Group &osgParent, GeoSetBuilder *pBuilder, MeshRecord *rec );
|
||||
@@ -188,6 +192,7 @@ class ConvertFromFLT
|
||||
double _unitScale;
|
||||
bool _bHdrRgbMode;
|
||||
osg::Vec4 _faceColor;
|
||||
bool _useTextureAlphaForTranspancyBinning;
|
||||
|
||||
osg::Group* _osgParent;
|
||||
};
|
||||
|
||||
@@ -61,85 +61,45 @@ bool AnimationPath_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
|
||||
if (fr.matchSequence("ControlPoints {"))
|
||||
{
|
||||
int entry = fr[1].getNoNestedBrackets();
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
|
||||
fr += 2;
|
||||
|
||||
float fTime = -1;
|
||||
|
||||
osg::AnimationPath::ControlPoint CtrlPoint;
|
||||
bool bPosParsed = false;
|
||||
bool bRotParsed = false;
|
||||
bool bScaleParsed = false;
|
||||
|
||||
float time;
|
||||
Vec3 position,scale;
|
||||
Quat rotation;
|
||||
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
||||
{
|
||||
bool handled=false;
|
||||
|
||||
if (fr[0].matchWord("Time") &&
|
||||
fr[1].isFloat())
|
||||
if (fr[0].getFloat(time) &&
|
||||
fr[1].getFloat(position[0]) &&
|
||||
fr[2].getFloat(position[1]) &&
|
||||
fr[3].getFloat(position[2]) &&
|
||||
fr[4].getFloat(rotation[0]) &&
|
||||
fr[5].getFloat(rotation[1]) &&
|
||||
fr[6].getFloat(rotation[2]) &&
|
||||
fr[7].getFloat(rotation[3]) &&
|
||||
fr[8].getFloat(scale[0]) &&
|
||||
fr[9].getFloat(scale[1]) &&
|
||||
fr[10].getFloat(scale[2]))
|
||||
{
|
||||
if (bPosParsed || bRotParsed || bScaleParsed)
|
||||
{
|
||||
ap->insert(fTime, CtrlPoint);
|
||||
|
||||
bPosParsed = false;
|
||||
bRotParsed = false;
|
||||
bScaleParsed = false;
|
||||
}
|
||||
|
||||
fr[1].getFloat(fTime);
|
||||
fr+=2;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
Vec3 vec3;
|
||||
if (fr[0].matchWord("Position") &&
|
||||
fr[1].getFloat(vec3[0]) &&
|
||||
fr[2].getFloat(vec3[1]) &&
|
||||
fr[3].getFloat(vec3[2]))
|
||||
{
|
||||
CtrlPoint._position = vec3;
|
||||
fr+=4;
|
||||
bPosParsed = true;
|
||||
handled = true;
|
||||
osg::AnimationPath::ControlPoint ctrlPoint;
|
||||
ctrlPoint._position = position;
|
||||
ctrlPoint._rotation = rotation;
|
||||
ctrlPoint._scale = scale;
|
||||
|
||||
ap->insert(time, ctrlPoint);
|
||||
|
||||
fr+=11;
|
||||
}
|
||||
|
||||
|
||||
Vec4 vec4;
|
||||
if (fr[0].matchWord("Rotation") &&
|
||||
fr[1].getFloat(vec4[0]) &&
|
||||
fr[2].getFloat(vec4[1]) &&
|
||||
fr[3].getFloat(vec4[2]) &&
|
||||
fr[4].getFloat(vec4[3]))
|
||||
{
|
||||
CtrlPoint._rotation.makeRotate(vec4[0], vec4[1], vec4[2], vec4[3]);
|
||||
fr+=5;
|
||||
bRotParsed = true;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
|
||||
if (fr[0].matchWord("Scale") &&
|
||||
fr[1].getFloat(vec3[0]) &&
|
||||
fr[2].getFloat(vec3[1]) &&
|
||||
fr[3].getFloat(vec3[2]))
|
||||
{
|
||||
CtrlPoint._scale = vec3;
|
||||
fr+=4;
|
||||
bScaleParsed = true;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
if (!handled) fr.advanceOverCurrentFieldOrBlock();
|
||||
else fr.advanceOverCurrentFieldOrBlock();
|
||||
|
||||
}
|
||||
|
||||
// If all values have been parsed in
|
||||
if (bPosParsed && bRotParsed && bScaleParsed)
|
||||
{
|
||||
ap->insert(fTime, CtrlPoint);
|
||||
}
|
||||
itAdvanced = true;
|
||||
|
||||
}
|
||||
|
||||
@@ -171,43 +131,11 @@ bool AnimationPath_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
fw.indent() << "ControlPoints {"<< std::endl;
|
||||
fw.moveIn();
|
||||
|
||||
bool bPosSet = false;
|
||||
bool bRotSet = false;
|
||||
bool bScaleSet = false;
|
||||
AnimationPath::TimeControlPointMap::const_iterator itr;
|
||||
for (itr=tcpm.begin();
|
||||
for (AnimationPath::TimeControlPointMap::const_iterator itr=tcpm.begin();
|
||||
itr!=tcpm.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->second._position != Vec3(0,0,0))
|
||||
bPosSet = true;
|
||||
if (itr->second._rotation.asVec4() != Vec4(0,0,0,1))
|
||||
bRotSet = true;
|
||||
if (itr->second._scale != Vec3(1,1,1))
|
||||
bScaleSet = true;
|
||||
}
|
||||
|
||||
for (itr=tcpm.begin();
|
||||
itr!=tcpm.end();
|
||||
++itr)
|
||||
{
|
||||
Vec4 Rot;
|
||||
|
||||
fw.indent() << "Time " << itr->first;
|
||||
|
||||
if (bPosSet)
|
||||
fw << " Position " << itr->second._position;
|
||||
|
||||
if (bRotSet)
|
||||
{
|
||||
itr->second._rotation.getRotate (Rot[0], Rot[1], Rot[2], Rot[3]);
|
||||
fw << " Rotation " << Rot;
|
||||
}
|
||||
|
||||
if (bScaleSet)
|
||||
fw << " Scale " << itr->second._scale;
|
||||
|
||||
fw << std::endl;
|
||||
fw.indent() << itr->first << " " << itr->second._position << " " << itr->second._rotation << " " << itr->second._scale << std::endl;
|
||||
|
||||
}
|
||||
|
||||
@@ -216,3 +144,51 @@ bool AnimationPath_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// forward declare functions to use later.
|
||||
bool AnimationPathCallback_readLocalData(osg::Object &obj, osgDB::Input &fr);
|
||||
bool AnimationPathCallback_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
|
||||
|
||||
|
||||
// register the read and write functions with the osgDB::Registry.
|
||||
osgDB::RegisterDotOsgWrapperProxy AnimationPathCallback_Proxy
|
||||
(
|
||||
new osg::AnimationPathCallback,
|
||||
"AnimationPathCallback",
|
||||
"Object AnimationPathCallback",
|
||||
AnimationPathCallback_readLocalData,
|
||||
AnimationPathCallback_writeLocalData,
|
||||
DotOsgWrapper::READ_AND_WRITE
|
||||
);
|
||||
|
||||
bool AnimationPathCallback_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osg::AnimationPathCallback *apc = dynamic_cast<osg::AnimationPathCallback*>(&obj);
|
||||
if (!apc) return false;
|
||||
|
||||
static osg::ref_ptr<osg::AnimationPath> s_path = new osg::AnimationPath;
|
||||
ref_ptr<osg::Object> object = fr.readObjectOfType(*s_path);
|
||||
osg::AnimationPath* animpath = dynamic_cast<osg::AnimationPath*>(object.get());
|
||||
if (animpath) apc->setAnimationPath(animpath);
|
||||
|
||||
bool itrAdvanced = object.valid();
|
||||
|
||||
return itrAdvanced;
|
||||
}
|
||||
|
||||
|
||||
bool AnimationPathCallback_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osg::AnimationPathCallback* apc = dynamic_cast<const osg::AnimationPathCallback*>(&obj);
|
||||
if (!apc) return false;
|
||||
|
||||
if (apc->getAnimationPath())
|
||||
{
|
||||
fw.writeObject(*(apc->getAnimationPath()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "osg/MatrixTransform"
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
#include "osgDB/Registry"
|
||||
#include "osgDB/Input"
|
||||
#include "osgDB/Output"
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgDB;
|
||||
@@ -68,22 +68,6 @@ bool MatrixTransform_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("AnimationPath"))
|
||||
{
|
||||
static osg::ref_ptr<osg::AnimationPath> prototype = new osg::AnimationPath;
|
||||
osg::ref_ptr<osg::Object> object = fr.readObjectOfType(*prototype);
|
||||
osg::AnimationPath* path = dynamic_cast<osg::AnimationPath*>(object.get());
|
||||
if (path)
|
||||
{
|
||||
transform.setAnimationPath(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::Node* node = dynamic_cast<osg::Node*>(object.get());
|
||||
if (node) transform.addChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
@@ -94,10 +78,5 @@ bool MatrixTransform_writeLocalData(const Object& obj, Output& fw)
|
||||
|
||||
fw.writeObject(transform.getMatrix());
|
||||
|
||||
if (transform.getAnimationPath())
|
||||
{
|
||||
fw.writeObject(*transform.getAnimationPath());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -95,6 +95,37 @@ bool Node_readLocalData(Object& obj, Input& fr)
|
||||
}
|
||||
|
||||
|
||||
static ref_ptr<NodeCallback> s_nodecallback = new osg::NodeCallback;
|
||||
while (fr.matchSequence("UpdateCallback {"))
|
||||
{
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
fr += 2;
|
||||
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
||||
{
|
||||
NodeCallback* nodecallback = dynamic_cast<NodeCallback*>(fr.readObjectOfType(*s_nodecallback));
|
||||
if (nodecallback) node.setUpdateCallback(nodecallback);
|
||||
else ++fr;
|
||||
}
|
||||
iteratorAdvanced = true;
|
||||
|
||||
}
|
||||
|
||||
while (fr.matchSequence("CullCallback {"))
|
||||
{
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
fr += 2;
|
||||
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
||||
{
|
||||
NodeCallback* nodecallback = dynamic_cast<NodeCallback*>(fr.readObjectOfType(*s_nodecallback));
|
||||
if (nodecallback) node.setUpdateCallback(nodecallback);
|
||||
else ++fr;
|
||||
}
|
||||
iteratorAdvanced = true;
|
||||
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
@@ -147,6 +178,24 @@ bool Node_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
fw.writeObject(*node.getStateSet());
|
||||
}
|
||||
|
||||
if (node.getUpdateCallback())
|
||||
{
|
||||
fw.indent() << "UpdateCallbacks {" << std::endl;
|
||||
fw.moveIn();
|
||||
fw.writeObject(*node.getUpdateCallback());
|
||||
fw.moveOut();
|
||||
fw.indent() << "}" << std::endl;
|
||||
}
|
||||
|
||||
if (node.getCullCallback())
|
||||
{
|
||||
fw.indent() << "CullCallbacks {" << std::endl;
|
||||
fw.moveIn();
|
||||
fw.writeObject(*node.getCullCallback());
|
||||
fw.moveOut();
|
||||
fw.indent() << "}" << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user