Added support for serailizing and scripting BoundingBox and BoundingSphere objects

This commit is contained in:
Robert Osfield
2014-02-10 16:44:13 +00:00
parent 3dcca431a9
commit 31e98b51df
15 changed files with 405 additions and 53 deletions

View File

@@ -73,6 +73,9 @@ class BoundingBoxImpl
-FLT_MAX);
}
inline bool operator == (const BoundingBoxImpl& rhs) const { return _min==rhs._min && _max==rhs._max; }
inline bool operator != (const BoundingBoxImpl& rhs) const { return _min!=rhs._min || _max!=rhs._max; }
/** Returns true if the bounding box extents are valid, false otherwise. */
inline bool valid() const
{

View File

@@ -63,6 +63,9 @@ class BoundingSphereImpl
* otherwise. */
inline bool valid() const { return _radius>=0.0; }
inline bool operator == (const BoundingSphereImpl& rhs) const { return _center==rhs._center && _radius==rhs._radius; }
inline bool operator != (const BoundingSphereImpl& rhs) const { return _center!=rhs._center || _radius==rhs._radius; }
/** Set the bounding sphere to the given center/radius using floats. */
inline void set(const vec_type& center,value_type radius)
{

View File

@@ -16,6 +16,8 @@
#include <osg/Object>
#include <osg/UserDataContainer>
#include <osg/BoundingBox>
#include <osg/BoundingSphere>
namespace osg {
@@ -65,6 +67,10 @@ class ValueObject : public Object
virtual void apply(const osg::Plane& /*value*/) {}
virtual void apply(const osg::Matrixf& /*value*/) {}
virtual void apply(const osg::Matrixd& /*value*/) {}
virtual void apply(const osg::BoundingBoxf& /*value*/) {}
virtual void apply(const osg::BoundingBoxd& /*value*/) {}
virtual void apply(const osg::BoundingSpheref& /*value*/) {}
virtual void apply(const osg::BoundingSphered& /*value*/) {}
};
class SetValueVisitor
@@ -91,6 +97,10 @@ class ValueObject : public Object
virtual void apply(osg::Plane& /*value*/) {}
virtual void apply(osg::Matrixf& /*value*/) {}
virtual void apply(osg::Matrixd& /*value*/) {}
virtual void apply(osg::BoundingBoxf& /*value*/) {}
virtual void apply(osg::BoundingBoxd& /*value*/) {}
virtual void apply(osg::BoundingSpheref& /*value*/) {}
virtual void apply(osg::BoundingSphered& /*value*/) {}
};
virtual bool get(GetValueVisitor& /*gvv*/) const { return false; }
@@ -168,6 +178,10 @@ META_ValueObject(Quat, QuatValueObject)
META_ValueObject(Plane, PlaneValueObject)
META_ValueObject(Matrixf, MatrixfValueObject)
META_ValueObject(Matrixd, MatrixdValueObject)
META_ValueObject(BoundingBoxf, BoundingBoxfValueObject)
META_ValueObject(BoundingBoxd, BoundingBoxdValueObject)
META_ValueObject(BoundingSpheref, BoundingSpherefValueObject)
META_ValueObject(BoundingSphered, BoundingSpheredValueObject)
/** provide implementation of osg::Object::getUserValue(..) template*/
template<typename T>

View File

@@ -27,6 +27,8 @@
#include <osg/Vec4ui>
#include <osg/Quat>
#include <osg/Matrix>
#include <osg/BoundingBox>
#include <osg/BoundingSphere>
#include <osg/Array>
#include <osg/PrimitiveSet>
#include <osgDB/ReaderWriter>
@@ -130,6 +132,10 @@ public:
InputStream& operator>>( osg::Plane& p );
InputStream& operator>>( osg::Matrixf& mat );
InputStream& operator>>( osg::Matrixd& mat );
InputStream& operator>>( osg::BoundingBoxf& bb );
InputStream& operator>>( osg::BoundingBoxd& bb );
InputStream& operator>>( osg::BoundingSpheref& bs );
InputStream& operator>>( osg::BoundingSphered& bs );
InputStream& operator>>( osg::Array*& a ) { a = readArray(); return *this; }
InputStream& operator>>( osg::Image*& img ) { img = readImage(); return *this; }

View File

@@ -20,6 +20,8 @@
#include <osg/Vec4>
#include <osg/Quat>
#include <osg/Matrix>
#include <osg/BoundingBox>
#include <osg/BoundingSphere>
#include <osg/Array>
#include <osg/PrimitiveSet>
#include <osgDB/ReaderWriter>
@@ -135,6 +137,10 @@ public:
OutputStream& operator<<( const osg::Plane& p );
OutputStream& operator<<( const osg::Matrixf& mat );
OutputStream& operator<<( const osg::Matrixd& mat );
OutputStream& operator<<( const osg::BoundingBoxf& bb );
OutputStream& operator<<( const osg::BoundingBoxd& bb );
OutputStream& operator<<( const osg::BoundingSpheref& bb );
OutputStream& operator<<( const osg::BoundingSphered& bb );
OutputStream& operator<<( const osg::Array* a ) { writeArray(a); return *this; }
OutputStream& operator<<( const osg::Image* img ) { writeImage(img); return *this; }

View File

@@ -105,6 +105,12 @@ DECLARE_TYPE(osg::Vec4us, VEC4US)
DECLARE_TYPE(osg::Vec4i, VEC4I)
DECLARE_TYPE(osg::Vec4ui, VEC4UI)
DECLARE_TYPE(osg::BoundingBoxf, BOUNDINGBOXF)
DECLARE_TYPE(osg::BoundingBoxd, BOUNDINGBOXD)
DECLARE_TYPE(osg::BoundingSpheref, BOUNDINGSPHEREF)
DECLARE_TYPE(osg::BoundingSphered, BOUNDINGSPHERED)
// forward decalare
class PropertyOutputIterator;
class PropertyInputIterator;

View File

@@ -133,7 +133,9 @@ public:
RW_MATRIXF, RW_MATRIXD, RW_MATRIX, RW_GLENUM, RW_STRING, RW_ENUM,
RW_VEC2B, RW_VEC2UB, RW_VEC2S, RW_VEC2US, RW_VEC2I, RW_VEC2UI,
RW_VEC3B, RW_VEC3UB, RW_VEC3S, RW_VEC3US, RW_VEC3I, RW_VEC3UI,
RW_VEC4B, RW_VEC4UB, RW_VEC4S, RW_VEC4US, RW_VEC4I, RW_VEC4UI
RW_VEC4B, RW_VEC4UB, RW_VEC4S, RW_VEC4US, RW_VEC4I, RW_VEC4UI,
RW_BOUNDINGBOXF, RW_BOUNDINGBOXD,
RW_BOUNDINGSPHEREF, RW_BOUNDINGSPHERED
};
BaseSerializer() : _firstVersion(0), _lastVersion(INT_MAX) {}
@@ -300,8 +302,7 @@ public:
if ( is.isBinary() )
{
is >> value;
if ( ParentType::_defaultValue!=value )
(object.*_setter)( value );
(object.*_setter)( value );
}
else if ( is.matchString(ParentType::_name) )
{
@@ -349,8 +350,7 @@ public:
if ( is.isBinary() )
{
readMatrixImplementation( is, value );
if ( ParentType::_defaultValue!=value )
(object.*_setter)( value );
(object.*_setter)( value );
}
else if ( is.matchString(ParentType::_name) )
{
@@ -417,8 +417,7 @@ public:
if ( is.isBinary() )
{
GLenum value; is >> value;
if ( ParentType::_defaultValue!=static_cast<P>(value) )
(object.*_setter)( static_cast<P>(value) );
(object.*_setter)( static_cast<P>(value) );
}
else if ( is.matchString(ParentType::_name) )
{
@@ -466,8 +465,7 @@ public:
if ( is.isBinary() )
{
is >> value;
if ( ParentType::_defaultValue!=value )
(object.*_setter)( value );
(object.*_setter)( value );
}
else if ( is.matchString(ParentType::_name) )
{
@@ -524,8 +522,7 @@ public:
if ( hasObject )
{
P* value = dynamic_cast<P*>( is.readObject() );
if ( ParentType::_defaultValue!=value )
(object.*_setter)( value );
(object.*_setter)( value );
}
}
else if ( is.matchString(ParentType::_name) )
@@ -535,8 +532,7 @@ public:
{
is >> is.BEGIN_BRACKET;
P* value = dynamic_cast<P*>( is.readObject() );
if ( ParentType::_defaultValue!=value )
(object.*_setter)( value );
(object.*_setter)( value );
is >> is.END_BRACKET;
}
}
@@ -596,8 +592,7 @@ public:
if ( hasObject )
{
P* value = dynamic_cast<P*>( is.readImage() );
if ( ParentType::_defaultValue!=value )
(object.*_setter)( value );
(object.*_setter)( value );
}
}
else if ( is.matchString(ParentType::_name) )
@@ -607,8 +602,7 @@ public:
{
is >> is.BEGIN_BRACKET;
P* value = dynamic_cast<P*>( is.readImage() );
if ( ParentType::_defaultValue!=value )
(object.*_setter)( value );
(object.*_setter)( value );
is >> is.END_BRACKET;
}
}
@@ -673,8 +667,7 @@ public:
if ( is.isBinary() )
{
is >> value;
if ( ParentType::_defaultValue!=static_cast<P>(value) )
(object.*_setter)( static_cast<P>(value) );
(object.*_setter)( static_cast<P>(value) );
}
else if ( is.matchString(ParentType::_name) )
{
@@ -1019,6 +1012,24 @@ public:
wrapper->addSerializer( new osgDB::MatrixSerializer< MyClass >( \
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIX )
#define ADD_BOUNDINGBOXF_SERIALIZER(PROP, DEF) \
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingBoxf >( \
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGBOXF )
#define ADD_BOUNDINGBOXD_SERIALIZER(PROP, DEF) \
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingBoxd >( \
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGBOXD )
#define ADD_BOUNDINGSPHEREF_SERIALIZER(PROP, DEF) \
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingSpheref >( \
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGSPHEREF )
#define ADD_BOUNDINGSPHERED_SERIALIZER(PROP, DEF) \
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingSphered >( \
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGSPHERED )
#define ADD_GLENUM_SERIALIZER(PROP, TYPE, DEF) \
wrapper->addSerializer( new osgDB::GLenumSerializer< MyClass, TYPE >( \
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_GLENUM )

View File

@@ -42,8 +42,8 @@ public:
virtual void createGraphics();
virtual void createGraphicsImplementation();
virtual void setExtents(const osg::BoundingBox& bb);
const osg::BoundingBox& getExtents() const { return _extents; }
virtual void setExtents(const osg::BoundingBoxf& bb);
const osg::BoundingBoxf& getExtents() const { return _extents; }
enum FocusBehaviour
{
@@ -82,7 +82,7 @@ protected:
bool _hasEventFocus;
bool _graphicsInitialized;
osg::BoundingBox _extents;
osg::BoundingBoxf _extents;
};
}