Skip to content

Commit

Permalink
Added preliminary support for <property_animation>
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Nov 27, 2012
1 parent efd55f8 commit f703ead
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 90 deletions.
8 changes: 6 additions & 2 deletions include/osgPresentation/PropertyManager
Expand Up @@ -62,7 +62,7 @@ protected:

};

class PropertyAnimation : public osg::NodeCallback
class OSGPRESENTATION_EXPORT PropertyAnimation : public osg::NodeCallback
{
public:
PropertyAnimation():
Expand Down Expand Up @@ -93,12 +93,16 @@ public:

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);

virtual void update();
virtual void update(osg::Node* node);


protected:

osg::ref_ptr<PropertyManager> _pm;

void assign(osg::UserDataContainer* destination, osg::UserDataContainer* source);
void assign(osg::UserDataContainer* udc, osg::Object* obj);

KeyFrameMap _keyFrameMap;

double _firstTime;
Expand Down
64 changes: 1 addition & 63 deletions include/osgPresentation/SlideEventHandler
Expand Up @@ -22,6 +22,7 @@
#include <osgViewer/Viewer>

#include <osgPresentation/CompileSlideCallback>
#include <osgPresentation/PropertyManager>

namespace osgPresentation
{
Expand Down Expand Up @@ -237,69 +238,6 @@ protected:

};

class PropertyManager : protected osg::Object
{
public:

PropertyManager() {}
PropertyManager(const PropertyManager& pm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(pm,copyop) {}

META_Object(osgPresentation, PropertyManager)

/** Convinience method that casts the named UserObject to osg::TemplateValueObject<T> and gets the value.
* To use this template method you need to include the osg/ValueObject header.*/
template<typename T>
bool getProperty(const std::string& name, T& value) const
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return getUserValue(name, value);
}

/** Convinience method that creates the osg::TemplateValueObject<T> to store the
* specified value and adds it as a named UserObject.
* To use this template method you need to include the osg/ValueObject header. */
template<typename T>
void setProperty(const std::string& name, const T& value)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return setUserValue(name, value);
}

int ref() const { return osg::Referenced::ref(); }
int unref() const { return osg::Referenced::unref(); }

protected:

mutable OpenThreads::Mutex _mutex;

};


struct OSGPRESENTATION_EXPORT ImageSequenceUpdateCallback : public osg::NodeCallback
{
ImageSequenceUpdateCallback(osg::ImageSequence* is, PropertyManager* pm, const std::string& propertyName):
_imageSequence(is),
_propertyManager(pm),
_propertyName(propertyName) {}

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);

osg::ref_ptr<osg::ImageSequence> _imageSequence;
osg::ref_ptr<PropertyManager> _propertyManager;
std::string _propertyName;
};

struct OSGPRESENTATION_EXPORT PropertyEventCallback : public osgGA::GUIEventHandler
{
PropertyEventCallback(PropertyManager* pm):
_propertyManager(pm) {}

virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);

osg::ref_ptr<PropertyManager> _propertyManager;
};

class OSGPRESENTATION_EXPORT SlideEventHandler : public osgGA::GUIEventHandler
{
public:
Expand Down
3 changes: 3 additions & 0 deletions include/osgPresentation/SlideShowConstructor
Expand Up @@ -30,6 +30,7 @@

#include <osgPresentation/AnimationMaterial>
#include <osgPresentation/SlideEventHandler>
#include <osgPresentation/PropertyManager>

namespace osgPresentation
{
Expand Down Expand Up @@ -436,6 +437,8 @@ public:
void layerClickToDoOperation(const std::string& command, Operation operation, const JumpData& jumpData=JumpData());
void layerClickEventOperation(const KeyPosition& keyPos, const JumpData& jumpData=JumpData());

void addPropertyAnimation(PresentationContext presentationContext, PropertyAnimation* propertyAnimation);

void addToCurrentLayer(osg::Node* subgraph);

void addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData);
Expand Down
126 changes: 124 additions & 2 deletions src/osgPlugins/p3d/ReaderWriterP3D.cpp
@@ -1,4 +1,4 @@
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
*
* This software is open source and may be redistributed and/or modified under
* the terms of the GNU General Public License (GPL) version 2.0.
Expand Down Expand Up @@ -122,6 +122,9 @@ class ReaderWriterP3DXML : public osgDB::ReaderWriter

osg::Node* parseXmlGraph(osgDB::XmlNode* root, bool readOnlyHoldingPage, osgDB::Options* options) const;

bool parseProperties(osgDB::XmlNode* root, osg::UserDataContainer& udc) const;
bool parsePropertyAnimation(osgDB::XmlNode* root, osgPresentation::PropertyAnimation& pa) const;

void parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;

osg::TransferFunction1D* readTransferFunctionFile(const std::string& filename, float scale) const;
Expand Down Expand Up @@ -196,6 +199,7 @@ class ReaderWriterP3DXML : public osgDB::ReaderWriter
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const;
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const;
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const;

bool getJumpProperties(osgDB::XmlNode*cur, osgPresentation::JumpData& jumpData) const;

bool getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const;
Expand Down Expand Up @@ -967,7 +971,101 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
return propertiesRead;
}

bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, osgPresentation::JumpData& jumpData) const
bool ReaderWriterP3DXML::parseProperties(osgDB::XmlNode* root, osg::UserDataContainer& udc) const
{
bool readProperties = false;
OSG_NOTICE<<"Doing parseProperties()"<<std::endl;
for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
itr != root->children.end();
++itr)
{
osgDB::XmlNode* cur = itr->get();

if (cur->name == "property")
{
std::string name;
std::string type;

getProperty(cur, "name", name);
getProperty(cur, "type", type);

if (type=="float")
{
float value;
std::stringstream str(cur->contents);
str>>value;

udc.setUserValue(name, value);
readProperties = true;

OSG_NOTICE<<"Adding property float "<<value<<std::endl;
}
else if (type=="int")
{
int value;
std::stringstream str(cur->contents);
str>>value;

udc.setUserValue(name, value);
readProperties = true;

OSG_NOTICE<<"Adding property int "<<value<<std::endl;
}
else
{
udc.setUserValue(name, cur->contents);
readProperties = true;
OSG_NOTICE<<"Adding property string "<<cur->contents<<std::endl;
}
}
else
{
OSG_NOTICE<<"Unhandled tag["<<cur->name<<"] expecting <property>"<<std::endl;
}
}
return readProperties;
}

bool ReaderWriterP3DXML::parsePropertyAnimation(osgDB::XmlNode* root, osgPresentation::PropertyAnimation& pa) const
{
bool readKeyframes = false;
OSG_NOTICE<<"Doing parsePropertyAnimation()"<<std::endl;
for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
itr != root->children.end();
++itr)
{
osgDB::XmlNode* cur = itr->get();

if (cur->name == "key_frame")
{

double time;
if (getProperty(cur, "time", time))
{
osg::ref_ptr<osg::UserDataContainer> udc = new osg::DefaultUserDataContainer;
if (parseProperties(cur, *udc))
{
OSG_NOTICE<<"Adding keyframe"<<std::endl;
pa.addKeyFrame(time, udc);
readKeyframes = true;
}
}
else
{
OSG_NOTICE<<"No time assigned to key_frame, ignoring <key_frame>"<<std::endl;
}
}
else
{
OSG_NOTICE<<"Unhandled tag["<<cur->name<<"] expecting <key_frame>"<<std::endl;
}
}

return readKeyframes;
}


bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode* cur, osgPresentation::JumpData& jumpData) const
{
bool propertyRead = false;

Expand Down Expand Up @@ -1556,6 +1654,14 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
{
constructor.setLayerDuration(osg::asciiToDouble(cur->contents.c_str()));
}
else if (cur->name == "property_animation")
{
osg::ref_ptr<osgPresentation::PropertyAnimation> pa = new osgPresentation::PropertyAnimation;
if (parsePropertyAnimation(cur,*pa))
{
constructor.addPropertyAnimation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, pa.get());
}
}
else if (getKeyPosition(cur, keyPosition))
{
constructor.addLayerKey(keyPosition);
Expand Down Expand Up @@ -1822,6 +1928,14 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons
{
constructor.setSlideDuration(osg::asciiToDouble(cur->contents.c_str()));
}
else if (cur->name == "property_animation")
{
osg::ref_ptr<osgPresentation::PropertyAnimation> pa = new osgPresentation::PropertyAnimation;
if (parsePropertyAnimation(cur,*pa))
{
constructor.addPropertyAnimation(osgPresentation::SlideShowConstructor::CURRENT_SLIDE, pa.get());
}
}
else if (getKeyPosition(cur, keyPosition))
{
constructor.addSlideKey(keyPosition);
Expand Down Expand Up @@ -2518,6 +2632,14 @@ osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode* root, bool readOnly
std::cout<<"Defining template slide "<<name<<std::endl;
}
}
else if (!readOnlyHoldingPage && cur->name == "property_animation")
{
osg::ref_ptr<osgPresentation::PropertyAnimation> pa = new osgPresentation::PropertyAnimation;
if (parsePropertyAnimation(cur,*pa))
{
constructor.addPropertyAnimation(osgPresentation::SlideShowConstructor::CURRENT_PRESENTATION, pa.get());
}
}
}

osgDB::getDataFilePathList() = previousPaths;
Expand Down

0 comments on commit f703ead

Please sign in to comment.