From 6d0e1bd50bc222841bc16eb69d53c023eed97d0c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 20 Dec 2012 12:14:53 +0000 Subject: [PATCH] Added region="$xmin $ymin $zmin $xmax $ymax $zmax" support to tag, along with animation support via the support. --- include/osgPresentation/SlideShowConstructor | 1 + src/osgPlugins/p3d/ReaderWriterP3D.cpp | 6 + src/osgPresentation/SlideShowConstructor.cpp | 113 ++++++++++++++++++- 3 files changed, 117 insertions(+), 3 deletions(-) diff --git a/include/osgPresentation/SlideShowConstructor b/include/osgPresentation/SlideShowConstructor index dc1ca0846..8b717d855 100644 --- a/include/osgPresentation/SlideShowConstructor +++ b/include/osgPresentation/SlideShowConstructor @@ -231,6 +231,7 @@ public: { ModelData() {} + std::string region; std::string effect; std::string options; }; diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index ae9b4ef2e..0bf8ddbe1 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -832,6 +832,12 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid OSG_NOTIFY(_notifyLevel)<<"in getProperties(ModelData)"< #include #include +#include +#include #include #include @@ -1769,6 +1771,62 @@ std::string SlideShowConstructor::findFileAndRecordPath(const std::string& filen } +struct ClipRegionCallback : public osg::NodeCallback +{ +public: + ClipRegionCallback(const osg::Matrixd& originalMatrix, const std::string& str): + _matrix(originalMatrix), + _source(str) {} + + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) + { + osg::MatrixTransform* transform = dynamic_cast(node); + if (transform) + { + PropertyReader pr(nv->getNodePath(), _source); + + float xMin=0.0; + float yMin=0.0; + float zMin=0.0; + float xMax=1.0; + float yMax=1.0; + float zMax=1.0; + + pr>>xMin>>yMin>>zMin>>xMax>>yMax>>zMax; + + if (pr.ok()) + { + OSG_NOTICE<<"ClipRegionCallback : xMin="<setOptionString(modelData.options); } - osg::Node* subgraph = 0; + osg::ref_ptr subgraph; if (filename=="sphere") { @@ -1802,9 +1860,58 @@ void SlideShowConstructor::addModel(const std::string& filename, const PositionD if (subgraph) recordOptionsFilePath(options.get()); } - if (subgraph) + if (!modelData.region.empty()) { - addModel(subgraph, positionData, modelData); + osg::ref_ptr clipnode = new osg::ClipNode; + clipnode->createClipBox(osg::BoundingBox(0.0,0.0,0.0,1.0,1.0,1.0),0); + clipnode->setCullingActive(false); + + osg::ref_ptr transform = new osg::MatrixTransform; + transform->addChild(clipnode.get()); + + osg::ref_ptr group = new osg::Group; + group->addChild(subgraph.get()); + group->addChild(transform.get()); + + //clipnode->setStateSetModes(*(group->getOrCreateStateSet()), osg::StateAttribute::ON); + group->setStateSet(clipnode->getStateSet()); + + osg::ComputeBoundsVisitor cbbv(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN); + subgraph->accept(cbbv); + osg::BoundingBox bb = cbbv.getBoundingBox(); + double width = bb.xMax()-bb.xMin(); + double length = bb.yMax()-bb.yMin(); + double height = bb.zMax()-bb.zMin(); + + osg::Matrixd matrix = osg::Matrixd::translate(-0.5,-0.5,-0.5)*osg::Matrixd::scale(width,length,height)*osg::Matrixd::translate(bb.center()); + transform->setMatrix(matrix); + + if (containsPropertyReference(modelData.region)) + { + transform->addUpdateCallback(new ClipRegionCallback(matrix, modelData.region)); + } + else + { + double region[6]; + std::istringstream sstream(modelData.region); + sstream>>region[0]>>region[1]>>region[2]>>region[3]>>region[4]>>region[5]; + + osg::Matrix tm = osg::Matrix::scale(region[3]-region[0], region[4]-region[1], region[5]-region[2]) * + osg::Matrix::translate(region[0],region[1],region[2]); + + transform->setMatrix( tm * matrix ); + } + + subgraph = group; + + osgDB::writeNodeFile(*subgraph, "output.osgt"); + + } + + + if (subgraph.valid()) + { + addModel(subgraph.get(), positionData, modelData); } OSG_INFO<<"end of SlideShowConstructor::addModel("<