forked from mirror/openmw-tes3mp
Add 'showSceneGraph' command to export the scene or a particular object to .osgt for debugging purposes
parent
e90941a8b3
commit
34deb6e7b1
@ -0,0 +1,119 @@
|
||||
#include "serialize.hpp"
|
||||
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include <components/sceneutil/positionattitudetransform.hpp>
|
||||
#include <components/sceneutil/skeleton.hpp>
|
||||
#include <components/sceneutil/riggeometry.hpp>
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
|
||||
template <class Cls>
|
||||
static osg::Object* createInstanceFunc() { return new Cls; }
|
||||
|
||||
class PositionAttitudeTransformSerializer : public osgDB::ObjectWrapper
|
||||
{
|
||||
public:
|
||||
PositionAttitudeTransformSerializer()
|
||||
: osgDB::ObjectWrapper(createInstanceFunc<SceneUtil::PositionAttitudeTransform>, "SceneUtil::PositionAttitudeTransform", "osg::Object osg::Node osg::Group osg::Transform SceneUtil::PositionAttitudeTransform")
|
||||
{
|
||||
addSerializer( new osgDB::PropByRefSerializer< SceneUtil::PositionAttitudeTransform, osg::Vec3f >(
|
||||
"position", osg::Vec3f(), &SceneUtil::PositionAttitudeTransform::getPosition, &SceneUtil::PositionAttitudeTransform::setPosition), osgDB::BaseSerializer::RW_VEC3F );
|
||||
addSerializer( new osgDB::PropByRefSerializer< SceneUtil::PositionAttitudeTransform, osg::Quat >(
|
||||
"attitude", osg::Quat(), &SceneUtil::PositionAttitudeTransform::getAttitude, &SceneUtil::PositionAttitudeTransform::setAttitude), osgDB::BaseSerializer::RW_QUAT );
|
||||
addSerializer( new osgDB::PropByRefSerializer< SceneUtil::PositionAttitudeTransform, osg::Vec3f >(
|
||||
"scale", osg::Vec3f(), &SceneUtil::PositionAttitudeTransform::getScale, &SceneUtil::PositionAttitudeTransform::setScale), osgDB::BaseSerializer::RW_VEC3F );
|
||||
}
|
||||
};
|
||||
|
||||
class SkeletonSerializer : public osgDB::ObjectWrapper
|
||||
{
|
||||
public:
|
||||
SkeletonSerializer()
|
||||
: osgDB::ObjectWrapper(createInstanceFunc<SceneUtil::Skeleton>, "SceneUtil::Skeleton", "osg::Object osg::Node osg::Group SceneUtil::Skeleton")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class FrameSwitchSerializer : public osgDB::ObjectWrapper
|
||||
{
|
||||
public:
|
||||
FrameSwitchSerializer()
|
||||
: osgDB::ObjectWrapper(createInstanceFunc<osg::Group>, "NifOsg::FrameSwitch", "osg::Object osg::Node osg::Group NifOsg::FrameSwitch")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class RigGeometrySerializer : public osgDB::ObjectWrapper
|
||||
{
|
||||
public:
|
||||
RigGeometrySerializer()
|
||||
: osgDB::ObjectWrapper(createInstanceFunc<SceneUtil::RigGeometry>, "SceneUtil::RigGeometry", "osg::Object osg::Node osg::Drawable osg::Geometry SceneUtil::RigGeometry")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class LightManagerSerializer : public osgDB::ObjectWrapper
|
||||
{
|
||||
public:
|
||||
LightManagerSerializer()
|
||||
: osgDB::ObjectWrapper(createInstanceFunc<osg::Group>, "SceneUtil::LightManager", "osg::Object osg::Node osg::Group SceneUtil::LightManager")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
osgDB::ObjectWrapper* makeDummySerializer(const std::string& classname)
|
||||
{
|
||||
return new osgDB::ObjectWrapper(createInstanceFunc<osg::DummyObject>, classname, "osg::Object");
|
||||
}
|
||||
|
||||
|
||||
void registerSerializers()
|
||||
{
|
||||
static bool done = false;
|
||||
if (!done)
|
||||
{
|
||||
osgDB::Registry::instance()->getObjectWrapperManager()->addWrapper(new PositionAttitudeTransformSerializer);
|
||||
osgDB::Registry::instance()->getObjectWrapperManager()->addWrapper(new SkeletonSerializer);
|
||||
osgDB::Registry::instance()->getObjectWrapperManager()->addWrapper(new FrameSwitchSerializer);
|
||||
osgDB::Registry::instance()->getObjectWrapperManager()->addWrapper(new RigGeometrySerializer);
|
||||
osgDB::Registry::instance()->getObjectWrapperManager()->addWrapper(new LightManagerSerializer);
|
||||
|
||||
// ignore the below for now to avoid warning spam
|
||||
const char* ignore[] = {
|
||||
"MWRender::PtrHolder",
|
||||
"MWRender::CameraRelativeTransform",
|
||||
"Resource::TemplateRef",
|
||||
"SceneUtil::LightListCallback",
|
||||
"SceneUtil::LightManagerUpdateCallback",
|
||||
"SceneUtil::UpdateRigBounds",
|
||||
"SceneUtil::UpdateRigGeometry",
|
||||
"SceneUtil::LightSource",
|
||||
"NifOsg::NodeUserData",
|
||||
"NifOsg::FlipController",
|
||||
"NifOsg::KeyframeController",
|
||||
"NifOsg::TextKeyMapHolder",
|
||||
"NifOsg::Emitter",
|
||||
"NifOsg::ParticleSystem",
|
||||
"NifOsg::GrowFadeAffector",
|
||||
"NifOsg::InverseWorldMatrix",
|
||||
"NifOsg::StaticBoundingBoxCallback",
|
||||
"NifOsg::GeomMorpherController",
|
||||
"NifOsg::UpdateMorphGeometry",
|
||||
"osgMyGUI::Drawable",
|
||||
"osg::DrawCallback",
|
||||
"osg::DummyObject"
|
||||
};
|
||||
for (size_t i=0; i<sizeof(ignore)/sizeof(ignore[0]); ++i)
|
||||
{
|
||||
osgDB::Registry::instance()->getObjectWrapperManager()->addWrapper(makeDummySerializer(ignore[i]));
|
||||
}
|
||||
|
||||
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
#ifndef OPENMW_COMPONENTS_SCENEUTIL_SERIALIZE_H
|
||||
#define OPENMW_COMPONENTS_SCENEUTIL_SERIALIZE_H
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
|
||||
/// Register osg node serializers for certain SceneUtil classes if not already done so
|
||||
void registerSerializers();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,26 @@
|
||||
#include "writescene.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#include "serialize.hpp"
|
||||
|
||||
void SceneUtil::writeScene(osg::Node *node, const std::string& filename, const std::string& format)
|
||||
{
|
||||
registerSerializers();
|
||||
|
||||
osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgt");
|
||||
if (!rw)
|
||||
throw std::runtime_error("can not find readerwriter for " + format);
|
||||
|
||||
boost::filesystem::ofstream stream;
|
||||
stream.open(filename);
|
||||
|
||||
osg::ref_ptr<osgDB::Options> options = new osgDB::Options;
|
||||
options->setPluginStringData("fileType", format);
|
||||
|
||||
rw->writeNode(*node, stream, options);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
#ifndef OPENMW_COMPONENTS_WRITESCENE_H
|
||||
#define OPENMW_COMPONENTS_WRITESCENE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
|
||||
void writeScene(osg::Node* node, const std::string& filename, const std::string& format);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue