Added movie volume animation control to <image> and <stereo_image> tags to be used in the form:

<slide>
        <properties>
            <property name="volume" type="float">0.20</property>
        </properties>

        <property_animation>
            <key_frame time="0.0">
                <property name="volume" type="float">0.0</property>
            </key_frame>
            <key_frame time="2.0">
                <property name="volume" type="float">1.0</property>
            </key_frame>
            <key_frame time="10.0">
                <property name="volume" type="float">1.0</property>
            </key_frame>
            <key_frame time="12.0">
                <property name="volume" type="float">0.0</property>
            </key_frame>
        </property_animation>

        <layer>
              <image volume="$volume" looping="ON">big_buck_bunny_1080p_stereo.ogg</image>
       </layer>
    </slide>
This commit is contained in:
Robert Osfield
2013-01-11 11:30:44 +00:00
parent 4f8847dd50
commit 93334e7df0
4 changed files with 93 additions and 4 deletions

View File

@@ -89,6 +89,7 @@ extern OSGPRESENTATION_EXPORT bool containsPropertyReference(const std::string&
struct PropertyReader
{
PropertyReader(const osg::NodePath& nodePath, const std::string& str):
_errorGenerated(false),
_nodePath(nodePath),
_sstream(str) {}
@@ -117,11 +118,12 @@ struct PropertyReader
}
template<typename T>
PropertyReader& operator>>( T& value ) { read(value); return *this; }
PropertyReader& operator>>( T& value ) { if (!read(value)) _errorGenerated=true; return *this; }
bool ok() { return !_sstream.fail(); }
bool fail() { return _sstream.fail(); }
bool ok() { return !_sstream.fail() && !_errorGenerated; }
bool fail() { return _sstream.fail() || _errorGenerated; }
bool _errorGenerated;
osg::NodePath _nodePath;
std::istringstream _sstream;
};

View File

@@ -255,7 +255,8 @@ public:
blendingHint(USE_IMAGE_ALPHA),
delayTime(0.0),
startTime(0.0),
stopTime(-1.0)
stopTime(-1.0),
volume("")
{}
std::string options;
@@ -293,6 +294,7 @@ public:
double delayTime;
double startTime;
double stopTime;
std::string volume;
};
@@ -499,6 +501,7 @@ protected:
void findImageStreamsAndAddCallbacks(osg::Node* node);
osg::Geometry* createTexturedQuadGeometry(const osg::Vec3& pos, const osg::Vec4& rotation, float width,float height, osg::Image* image, bool& usedTextureRectangle);
void setUpMovieVolume(osg::Node* subgraph, osg::ImageStream* imageStream, const ImageData& imageData);
osg::Vec3 computePositionInModelCoords(const PositionData& positionData) const;
void updatePositionFromInModelCoords(const osg::Vec3& vertex, PositionData& positionData) const;

View File

@@ -974,6 +974,12 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
OSG_NOTIFY(_notifyLevel)<<"read stop \""<<value.stopTime<<"\""<<std::endl;
}
if (getProperty(cur, "volume", value.volume))
{
propertiesRead = true;
OSG_NOTIFY(_notifyLevel)<<"read volume \""<<value.volume<<"\""<<std::endl;
}
/*
if (getProperty(cur, "texcoord_offset", value.texcoord_offset))
{

View File

@@ -1121,6 +1121,67 @@ osg::Image* SlideShowConstructor::readImage(const std::string& filename, const I
return image.release();
}
struct VolumeCallback : public osg::NodeCallback
{
public:
VolumeCallback(osg::ImageStream* movie, const std::string& str):
_movie(movie),
_source(str) {}
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
PropertyReader pr(nv->getNodePath(), _source);
float volume=0.0f;
pr>>volume;
if (pr.ok())
{
OSG_NOTICE<<"VolumeCallback : volume="<<volume<<", from "<<_source<<std::endl;
_movie->setVolume(volume);
}
else
{
OSG_NOTICE<<"Problem in reading, VolumeCallback : volume="<<volume<<std::endl;
}
// note, callback is responsible for scenegraph traversal so
// they must call traverse(node,nv) to ensure that the
// scene graph subtree (and associated callbacks) are traversed.
traverse(node, nv);
}
protected:
osg::ref_ptr<osg::ImageStream> _movie;
std::string _source;
};
void SlideShowConstructor::setUpMovieVolume(osg::Node* subgraph, osg::ImageStream* imageStream, const ImageData& imageData)
{
if (containsPropertyReference(imageData.volume))
{
subgraph->addUpdateCallback(new VolumeCallback(imageStream, imageData.volume));
}
else
{
float volume;
std::istringstream sstream(imageData.volume);
sstream>>volume;
if (!sstream.fail())
{
OSG_NOTICE<<"Setting volume "<<volume<<std::endl;
imageStream->setVolume( volume );
}
else
{
OSG_NOTICE<<"Invalid volume setting: "<<imageData.volume<<std::endl;
}
}
}
void SlideShowConstructor::addImage(const std::string& filename, const PositionData& positionData, const ImageData& imageData)
{
@@ -1215,6 +1276,12 @@ void SlideShowConstructor::addImage(const std::string& filename, const PositionD
pictureStateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
}
if (imageStream && !imageData.volume.empty())
{
setUpMovieVolume(subgraph, imageStream, imageData);
}
osg::ImageSequence* imageSequence = dynamic_cast<osg::ImageSequence*>(image.get());
if (imageSequence)
{
@@ -1418,6 +1485,16 @@ void SlideShowConstructor::addStereoImagePair(const std::string& filenameLeft, c
subgraph->addChild(pictureLeft);
subgraph->addChild(pictureRight);
if (imageStreamLeft && !imageDataLeft.volume.empty())
{
setUpMovieVolume(subgraph, imageStreamLeft, imageDataLeft);
}
if (imageStreamRight && !imageDataRight.volume.empty())
{
setUpMovieVolume(subgraph, imageStreamRight, imageDataRight);
}
osg::ImageSequence* imageSequence = dynamic_cast<osg::ImageSequence*>(imageLeft.get());
if (imageSequence)
{
@@ -1775,6 +1852,7 @@ std::string SlideShowConstructor::findFileAndRecordPath(const std::string& filen
}
struct ClipRegionCallback : public osg::NodeCallback
{
public: