Initial work on integtasting osgUI into Present3D
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14370 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -74,6 +74,8 @@ SET(TARGET_SRC
|
||||
|
||||
SET(TARGET_LIBRARIES
|
||||
osgViewer
|
||||
osgUI
|
||||
osgWidget
|
||||
osgManipulator
|
||||
osgVolume
|
||||
osgFX
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <osg/ComputeBoundsVisitor>
|
||||
#include <osg/Notify>
|
||||
#include <osg/io_utils>
|
||||
#include <osg/ValueObject>
|
||||
|
||||
#include <osgUtil/TransformCallback>
|
||||
|
||||
@@ -42,6 +43,8 @@
|
||||
|
||||
#include <osgWidget/PdfReader>
|
||||
|
||||
#include <osgUI/Widget>
|
||||
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
|
||||
#include <osgText/Text>
|
||||
@@ -2115,7 +2118,7 @@ void SlideShowConstructor::addModel(const std::string& filename, const PositionD
|
||||
|
||||
subgraph = group;
|
||||
|
||||
osgDB::writeNodeFile(*subgraph, "output.osgt");
|
||||
// osgDB::writeNodeFile(*subgraph, "output.osgt");
|
||||
|
||||
}
|
||||
|
||||
@@ -2510,11 +2513,33 @@ protected:
|
||||
std::string _source;
|
||||
};
|
||||
|
||||
struct CollectVolumeSettingsVisitor : public osgVolume::PropertyVisitor
|
||||
struct CollectVolumeSettingsVisitor : public osgVolume::PropertyVisitor, public osg::NodeVisitor
|
||||
{
|
||||
CollectVolumeSettingsVisitor():
|
||||
osgVolume::PropertyVisitor(false) {}
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
osgVolume::VolumeTile* tile = dynamic_cast<osgVolume::VolumeTile*>(&node);
|
||||
if (tile)
|
||||
{
|
||||
OSG_NOTICE<<"Found Tile "<<tile<<std::endl;
|
||||
tile->getLayer()->getProperty()->accept(*this);
|
||||
return;
|
||||
}
|
||||
|
||||
osgUI::Widget* widget = dynamic_cast<osgUI::Widget*>(&node);
|
||||
if (widget)
|
||||
{
|
||||
OSG_NOTICE<<"Found Widget "<<widget<<std::endl;
|
||||
_widgets.push_back(widget);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
node.traverse(*this);
|
||||
}
|
||||
|
||||
virtual void apply(osgVolume::VolumeSettings& vs)
|
||||
{
|
||||
_vsList.push_back(&vs);
|
||||
@@ -2522,14 +2547,19 @@ struct CollectVolumeSettingsVisitor : public osgVolume::PropertyVisitor
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osgVolume::VolumeSettings> > VolumeSettingsList;
|
||||
VolumeSettingsList _vsList;
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osgUI::Widget> > WidgetList;
|
||||
WidgetList _widgets;
|
||||
};
|
||||
|
||||
struct VolumeSettingsCallback : public osgGA::GUIEventHandler
|
||||
{
|
||||
|
||||
VolumeSettingsCallback():
|
||||
_saveKey(19), // Ctril-S
|
||||
_editKey(05) // Ctrl-E
|
||||
//_saveKey(19), // Ctril-S
|
||||
//_editKey(05) // Ctrl-E
|
||||
_saveKey('W'),
|
||||
_editKey('E')
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2540,8 +2570,8 @@ struct VolumeSettingsCallback : public osgGA::GUIEventHandler
|
||||
{
|
||||
if (ea.getHandled()) return false;
|
||||
|
||||
osgVolume::VolumeTile* tile = dynamic_cast<osgVolume::VolumeTile*>(object);
|
||||
if (!tile)
|
||||
osg::Node* node = dynamic_cast<osg::Node*>(object);
|
||||
if (!node)
|
||||
{
|
||||
OSG_NOTICE<<"Warning: VolumeSettingsCallback assigned to a node other than VolumeTile, cannot operate edit/save."<<std::endl;
|
||||
return false;
|
||||
@@ -2554,7 +2584,7 @@ struct VolumeSettingsCallback : public osgGA::GUIEventHandler
|
||||
if (ea.getKey()==_saveKey)
|
||||
{
|
||||
CollectVolumeSettingsVisitor cvsv;
|
||||
tile->getLayer()->getProperty()->accept(cvsv);
|
||||
node->accept(cvsv);
|
||||
|
||||
for(CollectVolumeSettingsVisitor::VolumeSettingsList::iterator itr = cvsv._vsList.begin();
|
||||
itr != cvsv._vsList.end();
|
||||
@@ -2578,6 +2608,19 @@ struct VolumeSettingsCallback : public osgGA::GUIEventHandler
|
||||
if (ea.getKey()==_editKey)
|
||||
{
|
||||
OSG_NOTICE<<"Need to edit VolumeSettings "<<std::endl;
|
||||
|
||||
CollectVolumeSettingsVisitor cvsv;
|
||||
node->accept(cvsv);
|
||||
|
||||
for(CollectVolumeSettingsVisitor::WidgetList::iterator itr = cvsv._widgets.begin();
|
||||
itr != cvsv._widgets.end();
|
||||
++itr)
|
||||
{
|
||||
osgUI::Widget* widget = itr->get();
|
||||
OSG_NOTICE<<"Toggling visibility of Widget "<<widget<<std::endl;
|
||||
|
||||
widget->setVisible(!widget->getVisible());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2748,6 +2791,8 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
|
||||
volume->addChild(tile.get());
|
||||
}
|
||||
|
||||
osg::ref_ptr<osgVolume::VolumeSettings> vs = volumeData.volumeSettings;
|
||||
|
||||
if (!layer)
|
||||
{
|
||||
if (!image) return;
|
||||
@@ -2809,8 +2854,6 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
|
||||
groupPropetry->addProperty(sp.get());
|
||||
|
||||
|
||||
osg::ref_ptr<osgVolume::VolumeSettings> vs = volumeData.volumeSettings;
|
||||
|
||||
osg::ref_ptr<osgVolume::AlphaFuncProperty> ap = vs.valid() ? vs->getCutoffProperty() : new osgVolume::AlphaFuncProperty(0.1f);
|
||||
setUpVolumeScalarProperty(tile.get(), ap.get(), volumeData.cutoffValue);
|
||||
|
||||
@@ -3016,10 +3059,16 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Node> model = volume.get();
|
||||
osg::ref_ptr<osg::Group> group = dynamic_cast<osg::Group*>(model.get());
|
||||
|
||||
if (volumeData.useTabbedDragger || volumeData.useTrackballDragger)
|
||||
{
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
||||
if (!group)
|
||||
{
|
||||
group = new osg::Group;
|
||||
group->addChild(volume.get());
|
||||
model = group.get();
|
||||
}
|
||||
|
||||
osg::ref_ptr<osgManipulator::Dragger> dragger;
|
||||
if (volumeData.useTabbedDragger)
|
||||
@@ -3038,20 +3087,47 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
|
||||
dragger->addDraggerCallback(new DraggerVolumeTileCallback(tile.get(), tile->getLocator()));
|
||||
dragger->setMatrix(osg::Matrix::translate(0.5,0.5,0.5)*tile->getLocator()->getTransform());
|
||||
|
||||
|
||||
group->addChild(dragger.get());
|
||||
|
||||
//dragger->addChild(volume.get());
|
||||
|
||||
group->addChild(volume.get());
|
||||
|
||||
model = group.get();
|
||||
}
|
||||
|
||||
tile->addEventCallback(new VolumeSettingsCallback());
|
||||
|
||||
|
||||
model->addEventCallback(new VolumeSettingsCallback());
|
||||
|
||||
ModelData modelData;
|
||||
addModel(model.get(), positionData, modelData, scriptData);
|
||||
|
||||
#if 0
|
||||
osgUI::Widget* widget = vs.valid() ? osgDB::readFile<osgUI::Widget>("VolumeSettings.lua") : 0;
|
||||
if (widget)
|
||||
{
|
||||
OSG_NOTICE<<"Addig widget"<<std::endl;
|
||||
|
||||
widget->setVisible(true);
|
||||
vs->setName("VolumeSettings");
|
||||
widget->getOrCreateUserDataContainer()->addUserObject(vs.get());
|
||||
|
||||
osg::Vec3 pos = convertSlideToModel(osg::Vec3(0.0f,0.0f,0.0f));
|
||||
|
||||
const osg::BoundingBox& bb = widget->getExtents();
|
||||
float slide_scale = 0.5f*_slideWidth/(bb.xMax()-bb.xMin());
|
||||
|
||||
osg::MatrixTransform* transform = new osg::MatrixTransform;
|
||||
transform->setDataVariance(osg::Object::DYNAMIC);
|
||||
transform->setMatrix(osg::Matrix::rotate(osg::inDegrees(90.0f),osg::Vec3(1.0f,0.0f,0.0f)) * osg::Matrix::scale(slide_scale,slide_scale,slide_scale)*osg::Matrix::translate(pos));
|
||||
transform->addChild(widget);
|
||||
|
||||
#if 1
|
||||
HUDTransform* hudTransform = new HUDTransform(_hudSettings.get());
|
||||
hudTransform->addChild(transform);
|
||||
|
||||
addToCurrentLayer(hudTransform);
|
||||
#else
|
||||
addToCurrentLayer(transform);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SlideShowConstructor::attachTexMat(osg::StateSet* stateset, const ImageData& imageData, float s, float t, bool textureRectangle)
|
||||
|
||||
Reference in New Issue
Block a user