2013-08-08 01:08:38 +08:00
|
|
|
/* Copyright Robert Osfield, Licensed under the GPL
|
|
|
|
*
|
|
|
|
* Experimental base for refactor of Present3D
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/Geometry>
|
2013-08-10 00:51:06 +08:00
|
|
|
#include <osg/ScriptEngine>
|
|
|
|
#include <osg/UserDataContainer>
|
2013-08-08 01:08:38 +08:00
|
|
|
|
2013-08-22 15:49:22 +08:00
|
|
|
#include <osgPresentation/Presentation>
|
|
|
|
#include <osgPresentation/Slide>
|
|
|
|
#include <osgPresentation/Layer>
|
|
|
|
#include <osgPresentation/Element>
|
2013-09-02 16:29:09 +08:00
|
|
|
#include <osgPresentation/Model>
|
|
|
|
#include <osgPresentation/Volume>
|
|
|
|
#include <osgPresentation/Image>
|
|
|
|
#include <osgPresentation/Movie>
|
|
|
|
#include <osgPresentation/Text>
|
|
|
|
#include <osgPresentation/Audio>
|
2013-08-22 15:49:22 +08:00
|
|
|
|
2013-08-08 01:08:38 +08:00
|
|
|
#include <osgDB/ReadFile>
|
2013-08-22 15:49:22 +08:00
|
|
|
#include <osgDB/WriteFile>
|
2013-08-08 01:08:38 +08:00
|
|
|
#include <osgDB/FileUtils>
|
|
|
|
|
|
|
|
#include <osgGA/TrackballManipulator>
|
|
|
|
#include <osgViewer/Viewer>
|
|
|
|
|
|
|
|
|
2013-08-10 00:51:06 +08:00
|
|
|
int main(int argc, char** argv)
|
2013-08-08 01:08:38 +08:00
|
|
|
{
|
2013-08-10 00:51:06 +08:00
|
|
|
osg::ArgumentParser arguments(&argc, argv);
|
2013-08-08 01:08:38 +08:00
|
|
|
|
2013-08-10 00:51:06 +08:00
|
|
|
osgViewer::Viewer viewer(arguments);
|
2013-08-08 01:08:38 +08:00
|
|
|
|
2013-09-05 00:25:18 +08:00
|
|
|
#if 0
|
2013-08-10 00:51:06 +08:00
|
|
|
typedef std::list< osg::ref_ptr<osg::Script> > Scripts;
|
|
|
|
Scripts scripts;
|
2013-08-08 01:08:38 +08:00
|
|
|
|
2013-08-10 00:51:06 +08:00
|
|
|
std::string filename;
|
|
|
|
while(arguments.read("--script",filename))
|
2013-08-08 01:08:38 +08:00
|
|
|
{
|
2013-08-10 00:51:06 +08:00
|
|
|
osg::ref_ptr<osg::Script> script = osgDB::readFile<osg::Script>(filename);
|
|
|
|
if (script.valid()) scripts.push_back(script.get());
|
2013-08-08 01:08:38 +08:00
|
|
|
}
|
|
|
|
|
2013-08-10 00:51:06 +08:00
|
|
|
// assgin script engine to scene graphs
|
|
|
|
model->getOrCreateUserDataContainer()->addUserObject(osgDB::readFile<osg::ScriptEngine>("ScriptEngine.lua"));
|
|
|
|
model->getOrCreateUserDataContainer()->addUserObject(osgDB::readFile<osg::ScriptEngine>("ScriptEngine.python"));
|
|
|
|
model->getOrCreateUserDataContainer()->addUserObject(osgDB::readFile<osg::ScriptEngine>("ScriptEngine.js"));
|
2013-08-08 01:08:38 +08:00
|
|
|
|
2013-08-10 00:51:06 +08:00
|
|
|
// assign scripts to scene graph
|
|
|
|
for(Scripts::iterator itr = scripts.begin();
|
|
|
|
itr != scripts.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
model->addUpdateCallback(new osg::ScriptCallback(itr->get()));
|
|
|
|
}
|
2013-08-08 01:08:38 +08:00
|
|
|
|
2013-08-10 00:51:06 +08:00
|
|
|
std::string str;
|
|
|
|
osg::ref_ptr<osg::ScriptEngine> luaScriptEngine = osgDB::readFile<osg::ScriptEngine>("ScriptEngine.lua");
|
|
|
|
if (luaScriptEngine.valid())
|
2013-08-08 01:08:38 +08:00
|
|
|
{
|
2013-08-10 00:51:06 +08:00
|
|
|
while (arguments.read("--lua", str))
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Script> script = osgDB::readFile<osg::Script>(str);
|
|
|
|
if (script.valid())
|
|
|
|
{
|
|
|
|
luaScriptEngine->run(script.get());
|
2013-08-08 01:08:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-10 00:51:06 +08:00
|
|
|
osg::ref_ptr<osg::ScriptEngine> v8ScriptEngine = osgDB::readFile<osg::ScriptEngine>("ScriptEngine.V8");
|
|
|
|
if (v8ScriptEngine.valid())
|
2013-08-08 01:08:38 +08:00
|
|
|
{
|
2013-08-10 00:51:06 +08:00
|
|
|
while (arguments.read("--js",str))
|
2013-08-08 01:08:38 +08:00
|
|
|
{
|
2013-08-10 00:51:06 +08:00
|
|
|
osg::ref_ptr<osg::Script> script = osgDB::readFile<osg::Script>(str);
|
|
|
|
if (script.valid())
|
2013-08-08 01:08:38 +08:00
|
|
|
{
|
2013-08-10 00:51:06 +08:00
|
|
|
v8ScriptEngine->run(script.get());
|
2013-08-08 01:08:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-10 00:51:06 +08:00
|
|
|
osg::ref_ptr<osg::ScriptEngine> pythonScriptEngine = osgDB::readFile<osg::ScriptEngine>("ScriptEngine.python");
|
|
|
|
if (pythonScriptEngine.valid())
|
2013-08-08 01:08:38 +08:00
|
|
|
{
|
2013-08-10 00:51:06 +08:00
|
|
|
while (arguments.read("--python",str))
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Script> script = osgDB::readFile<osg::Script>(str);
|
|
|
|
if (script.valid())
|
|
|
|
{
|
|
|
|
pythonScriptEngine->run(script.get());
|
|
|
|
}
|
|
|
|
}
|
2013-08-08 01:08:38 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-08-22 15:49:22 +08:00
|
|
|
osg::ref_ptr<osgPresentation::Presentation> presentation = new osgPresentation::Presentation;
|
|
|
|
osg::ref_ptr<osgPresentation::Slide> slide = new osgPresentation::Slide;
|
|
|
|
osg::ref_ptr<osgPresentation::Layer> layer = new osgPresentation::Layer;
|
|
|
|
osg::ref_ptr<osgPresentation::Group> group = new osgPresentation::Group;
|
|
|
|
osg::ref_ptr<osgPresentation::Element> element = new osgPresentation::Element;
|
2013-09-05 00:25:18 +08:00
|
|
|
osg::ref_ptr<osgPresentation::Text> text = new osgPresentation::Text;
|
|
|
|
osg::ref_ptr<osgPresentation::Model> model = new osgPresentation::Model;
|
2013-09-06 17:35:56 +08:00
|
|
|
osg::ref_ptr<osgPresentation::Audio> audio = new osgPresentation::Audio;
|
|
|
|
osg::ref_ptr<osgPresentation::Image> image = new osgPresentation::Image;
|
|
|
|
osg::ref_ptr<osgPresentation::Movie> movie = new osgPresentation::Movie;
|
|
|
|
osg::ref_ptr<osgPresentation::Volume> volume = new osgPresentation::Volume;
|
2013-08-22 15:49:22 +08:00
|
|
|
presentation->addChild(slide.get());
|
|
|
|
slide->addChild(layer.get());
|
|
|
|
//layer->addChild(element.get());
|
2013-09-06 17:35:56 +08:00
|
|
|
//layer->addChild(group.get());
|
|
|
|
layer->addChild(element.get());
|
|
|
|
// layer->addChild(model.get());
|
|
|
|
layer->addChild(text.get());
|
|
|
|
layer->addChild(audio.get());
|
|
|
|
layer->addChild(image.get());
|
|
|
|
layer->addChild(movie.get());
|
|
|
|
layer->addChild(volume.get());
|
2013-08-22 15:49:22 +08:00
|
|
|
|
2013-09-04 18:33:11 +08:00
|
|
|
text->setProperty("string",std::string("This is a first test"));
|
|
|
|
text->setProperty("font",std::string("times.ttf"));
|
|
|
|
text->setProperty("character_size",2.2);
|
|
|
|
text->setProperty("width",std::string("103.2"));
|
|
|
|
|
2013-09-05 00:25:18 +08:00
|
|
|
model->setProperty("filename", std::string("dumptruck.osgt"));
|
2013-09-06 17:35:56 +08:00
|
|
|
|
|
|
|
image->setProperty("filename", std::string("Images/lz.rgb"));
|
|
|
|
image->setProperty("scale",0.75);
|
|
|
|
|
|
|
|
movie->setProperty("filename", std::string("/home/robert/Data/Movie/big_buck_bunny_1080p_stereo.ogg"));
|
|
|
|
movie->setProperty("scale",0.75);
|
|
|
|
|
|
|
|
volume->setProperty("filename", std::string("/home/robert/Data/MaleVisibleHumanHead"));
|
|
|
|
volume->setProperty("scale",0.75);
|
|
|
|
volume->setProperty("technique",std::string("iso-surface"));
|
|
|
|
|
|
|
|
presentation->setProperty("scale",1.0);
|
2013-09-05 00:25:18 +08:00
|
|
|
|
2013-09-04 18:33:11 +08:00
|
|
|
|
2013-09-04 23:39:17 +08:00
|
|
|
osgPresentation::PrintSupportedProperties psp(std::cout);
|
2013-09-03 23:50:28 +08:00
|
|
|
presentation->accept(psp);
|
|
|
|
|
2013-09-05 00:25:18 +08:00
|
|
|
osgPresentation::PrintProperties pp(std::cout);
|
|
|
|
presentation->accept(pp);
|
|
|
|
|
2013-09-04 18:33:11 +08:00
|
|
|
osgPresentation::LoadAction load;
|
|
|
|
presentation->accept( load );
|
|
|
|
|
2013-08-22 15:49:22 +08:00
|
|
|
viewer.setSceneData( presentation.get() );
|
|
|
|
|
|
|
|
|
|
|
|
osgDB::writeNodeFile(*presentation, "pres.osgt");
|
|
|
|
|
2013-08-08 01:08:38 +08:00
|
|
|
return viewer.run();
|
|
|
|
}
|