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;
};
}

View File

@@ -289,6 +289,32 @@ InputStream& InputStream::operator>>( osg::Matrixd& mat )
}
#endif
InputStream& InputStream::operator>>( osg::BoundingBoxf& bb)
{
float p0, p1, p2, p3, p4, p5; *this >> p0 >> p1 >> p2 >> p3>> p4>> p5;
bb.set( p0, p1, p2, p3, p4, p5 ); return *this;
}
InputStream& InputStream::operator>>( osg::BoundingBoxd& bb)
{
double p0, p1, p2, p3, p4, p5; *this >> p0 >> p1 >> p2 >> p3>> p4>> p5;
bb.set( p0, p1, p2, p3, p4, p5 ); return *this;
}
InputStream& InputStream::operator>>( osg::BoundingSpheref& bs)
{
float p0, p1, p2, p3; *this >> p0 >> p1 >> p2 >> p3;
bs.set( osg::Vec3f(p0, p1, p2), p3 ); return *this;
}
InputStream& InputStream::operator>>( osg::BoundingSphered& bs)
{
double p0, p1, p2, p3; *this >> p0 >> p1 >> p2 >> p3;
bs.set( osg::Vec3d(p0, p1, p2), p3 ); return *this;
}
osg::Array* InputStream::readArray()
{
osg::ref_ptr<osg::Array> array = NULL;

View File

@@ -160,6 +160,18 @@ OutputStream& OutputStream::operator<<( const osg::Plane& p )
{ *this << (double)p[0] << (double)p[1] << (double)p[2] << (double)p[3]; return *this; }
OutputStream& OutputStream::operator<<( const osg::BoundingBoxf& bb)
{ *this << bb.xMin() << bb.yMin() << bb.zMin() << bb.xMax() << bb.yMax() << bb.zMax(); return *this; }
OutputStream& OutputStream::operator<<( const osg::BoundingBoxd& bb)
{ *this << bb.xMin() << bb.yMin() << bb.zMin() << bb.xMax() << bb.yMax() << bb.zMax(); return *this; }
OutputStream& OutputStream::operator<<( const osg::BoundingSpheref& bs)
{ *this << bs.center().x() << bs.center().y() << bs.center().z() << bs.radius(); return *this; }
OutputStream& OutputStream::operator<<( const osg::BoundingSphered& bs)
{ *this << bs.center().x() << bs.center().y() << bs.center().z() << bs.radius(); return *this; }
#if 0
OutputStream& OutputStream::operator<<( const osg::Matrixf& mat )
{

View File

@@ -208,6 +208,13 @@ PropertyInterface::PropertyInterface():
TYPENAME(MATRIXF)
TYPENAME(MATRIXD)
TYPENAME(MATRIX)
TYPENAME(BOUNDINGBOXF)
TYPENAME(BOUNDINGBOXD)
TYPENAME(BOUNDINGSPHEREF)
TYPENAME(BOUNDINGSPHERED)
TYPENAME(GLENUM)
TYPENAME(STRING)
TYPENAME(ENUM)
@@ -439,6 +446,10 @@ public:
virtual void apply(const osg::Plane& /*value*/) { type = osgDB::BaseSerializer::RW_PLANE; }
virtual void apply(const osg::Matrixf& /*value*/) { type = osgDB::BaseSerializer::RW_MATRIXF; }
virtual void apply(const osg::Matrixd& /*value*/) { type = osgDB::BaseSerializer::RW_MATRIXD; }
virtual void apply(const osg::BoundingBoxf& /*value*/) { type = osgDB::BaseSerializer::RW_BOUNDINGBOXF; }
virtual void apply(const osg::BoundingBoxd& /*value*/) { type = osgDB::BaseSerializer::RW_BOUNDINGBOXD; }
virtual void apply(const osg::BoundingSpheref& /*value*/) { type = osgDB::BaseSerializer::RW_BOUNDINGSPHEREF; }
virtual void apply(const osg::BoundingSphered& /*value*/) { type = osgDB::BaseSerializer::RW_BOUNDINGSPHERED; }
};
bool PropertyInterface::getPropertyType(const osg::Object* object, const std::string& propertyName, osgDB::BaseSerializer::Type& type) const

View File

@@ -42,7 +42,7 @@ Widget::Widget(const Widget& widget, const osg::CopyOp& copyop):
setNumChildrenRequiringEventTraversal(1);
}
void Widget::setExtents(const osg::BoundingBox& bb)
void Widget::setExtents(const osg::BoundingBoxf& bb)
{
_extents = bb;
}

View File

@@ -527,8 +527,12 @@ public:
virtual void apply(osg::Vec4d& value) { _lsg->getValue(value); _numberToPop = 4; }
virtual void apply(osg::Quat& value) { _lsg->getValue(value); _numberToPop = 4; }
virtual void apply(osg::Plane& value) { _lsg->getValue(value); _numberToPop = 4; }
virtual void apply(osg::Matrixf& value) { _lsg->getValue(value); }
virtual void apply(osg::Matrixd& value) { _lsg->getValue(value); }
virtual void apply(osg::Matrixf& value) { _lsg->getValue(value); }
virtual void apply(osg::Matrixd& value) { _lsg->getValue(value); }
virtual void apply(osg::BoundingBoxf& value) { _lsg->getValue(value); }
virtual void apply(osg::BoundingBoxd& value) { _lsg->getValue(value); }
virtual void apply(osg::BoundingSpheref& value) { _lsg->getValue(value); }
virtual void apply(osg::BoundingSphered& value) { _lsg->getValue(value); }
};
int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string& propertyName) const
@@ -650,19 +654,6 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
}
break;
}
#ifdef OSG_USE_FLOAT_MATRIX
case(osgDB::BaseSerializer::RW_MATRIX):
#endif
case(osgDB::BaseSerializer::RW_MATRIXF):
{
osg::Matrixf value;
if (_pi.getProperty(object, propertyName, value))
{
pushValue(value);
return 1;
}
break;
}
case(osgDB::BaseSerializer::RW_VEC2D):
{
osg::Vec2d value;
@@ -693,6 +684,19 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
}
break;
}
#ifdef OSG_USE_FLOAT_MATRIX
case(osgDB::BaseSerializer::RW_MATRIX):
#endif
case(osgDB::BaseSerializer::RW_MATRIXF):
{
osg::Matrixf value;
if (_pi.getProperty(object, propertyName, value))
{
pushValue(value);
return 1;
}
break;
}
#ifndef OSG_USE_FLOAT_MATRIX
case(osgDB::BaseSerializer::RW_MATRIX):
#endif
@@ -706,6 +710,46 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
}
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGBOXF):
{
osg::BoundingBoxf value;
if (_pi.getProperty(object, propertyName, value))
{
pushValue(value);
return 1;
}
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGBOXD):
{
osg::BoundingBoxd value;
if (_pi.getProperty(object, propertyName, value))
{
pushValue(value);
return 1;
}
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGSPHEREF):
{
osg::BoundingSpheref value;
if (_pi.getProperty(object, propertyName, value))
{
pushValue(value);
return 1;
}
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGSPHERED):
{
osg::BoundingSphered value;
if (_pi.getProperty(object, propertyName, value))
{
pushValue(value);
return 1;
}
break;
}
case(osgDB::BaseSerializer::RW_LIST):
{
OSG_NOTICE<<"Need to implement RW_LIST support"<<std::endl;
@@ -859,19 +903,6 @@ int LuaScriptEngine::setPropertyFromStack(osg::Object* object, const std::string
}
break;
}
#ifdef OSG_USE_FLOAT_MATRIX
case(osgDB::BaseSerializer::RW_MATRIX):
#endif
case(osgDB::BaseSerializer::RW_MATRIXF):
{
osg::Matrixf value;
if (getValue(value))
{
_pi.setProperty(object, propertyName, value);
return 0;
}
break;
}
case(osgDB::BaseSerializer::RW_VEC2D):
{
osg::Vec2d value;
@@ -922,6 +953,19 @@ int LuaScriptEngine::setPropertyFromStack(osg::Object* object, const std::string
}
break;
}
#ifdef OSG_USE_FLOAT_MATRIX
case(osgDB::BaseSerializer::RW_MATRIX):
#endif
case(osgDB::BaseSerializer::RW_MATRIXF):
{
osg::Matrixd value;
if (getValue(value))
{
_pi.setProperty(object, propertyName, value);
return 0;
}
break;
}
#ifndef OSG_USE_FLOAT_MATRIX
case(osgDB::BaseSerializer::RW_MATRIX):
#endif
@@ -935,6 +979,46 @@ int LuaScriptEngine::setPropertyFromStack(osg::Object* object, const std::string
}
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGBOXF):
{
osg::BoundingBoxf value;
if (getValue(value))
{
_pi.setProperty(object, propertyName, value);
return 0;
}
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGBOXD):
{
osg::BoundingBoxd value;
if (getValue(value))
{
_pi.setProperty(object, propertyName, value);
return 0;
}
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGSPHEREF):
{
osg::BoundingSpheref value;
if (getValue(value))
{
_pi.setProperty(object, propertyName, value);
return 0;
}
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGSPHERED):
{
osg::BoundingSphered value;
if (getValue(value))
{
_pi.setProperty(object, propertyName, value);
return 0;
}
break;
}
case(osgDB::BaseSerializer::RW_LIST):
{
OSG_NOTICE<<"Need to implement RW_LIST support"<<std::endl;
@@ -1026,6 +1110,29 @@ bool LuaScriptEngine::getfields(const char* f1, const char* f2, const char* f3,
return true;
}
bool LuaScriptEngine::getfields(const char* f1, const char* f2, const char* f3, const char* f4, const char* f5, const char* f6, int type) const
{
lua_getfield(_lua, -1, f1);
if (lua_type(_lua, -1)!=type) { lua_pop(_lua, 1); return false; }
lua_getfield(_lua, -2, f2);
if (lua_type(_lua, -1)!=type) { lua_pop(_lua, 2); return false; }
lua_getfield(_lua, -3, f3);
if (lua_type(_lua, -1)!=type) { lua_pop(_lua, 3); return false; }
lua_getfield(_lua, -4, f4);
if (lua_type(_lua, -1)!=type) { lua_pop(_lua, 4); return false; }
lua_getfield(_lua, -5, f5);
if (lua_type(_lua, -1)!=type) { lua_pop(_lua, 5); return false; }
lua_getfield(_lua, -6, f6);
if (lua_type(_lua, -1)!=type) { lua_pop(_lua, 6); return false; }
return true;
}
bool LuaScriptEngine::getelements(int numElements, int type) const
{
int abs_pos = lua_gettop(_lua);
@@ -1097,6 +1204,11 @@ osgDB::BaseSerializer::Type LuaScriptEngine::getType() const
OSG_NOTICE<<"Could be Matrixd"<<std::endl;
return osgDB::BaseSerializer::RW_MATRIXD;
}
else if ((numNumberKeys==6) && (numNumberFields==6))
{
OSG_NOTICE<<"Could be BoundingBoxd"<<std::endl;
return osgDB::BaseSerializer::RW_BOUNDINGBOXD;
}
// not supported
OSG_NOTICE<<"Warning: LuaScriptEngine::getType() Lua table configuration not supported."<<std::endl;
break;
@@ -1166,6 +1278,32 @@ bool LuaScriptEngine::getmatrix() const
return false;
}
bool LuaScriptEngine::getboundingbox() const
{
if (lua_istable(_lua, -1))
{
if (getfields("xMin", "yMin", "zMin", "xMax", "yMax", "zMax", LUA_TNUMBER) ||
getelements(6, LUA_TNUMBER))
{
return true;
}
}
return false;
}
bool LuaScriptEngine::getboundingsphere() const
{
if (lua_istable(_lua, -1))
{
if (getfields("x", "y", "z", "radius", LUA_TNUMBER) ||
getelements(4, LUA_TNUMBER))
{
return true;
}
}
return false;
}
bool LuaScriptEngine::getValue(osg::Vec2f& value) const
{
if (!getvec2()) return false;
@@ -1262,6 +1400,38 @@ bool LuaScriptEngine::getValue(osg::Matrixd& value) const
return true;
}
bool LuaScriptEngine::getValue(osg::BoundingBoxf& value) const
{
if (!getboundingbox()) return false;
value.set(lua_tonumber(_lua, -6), lua_tonumber(_lua, -5), lua_tonumber(_lua, -4), lua_tonumber(_lua, -3), lua_tonumber(_lua, -2), lua_tonumber(_lua, -1));
lua_pop(_lua, 6);
return true;
}
bool LuaScriptEngine::getValue(osg::BoundingBoxd& value) const
{
if (!getboundingbox()) return false;
value.set(lua_tonumber(_lua, -6), lua_tonumber(_lua, -5), lua_tonumber(_lua, -4), lua_tonumber(_lua, -3), lua_tonumber(_lua, -2), lua_tonumber(_lua, -1));
lua_pop(_lua, 6);
return true;
}
bool LuaScriptEngine::getValue(osg::BoundingSpheref& value) const
{
if (!getboundingsphere()) return false;
value.set(osg::Vec3f(lua_tonumber(_lua, -4), lua_tonumber(_lua, -3), lua_tonumber(_lua, -2)), lua_tonumber(_lua, -1));
lua_pop(_lua, 4);
return true;
}
bool LuaScriptEngine::getValue(osg::BoundingSphered& value) const
{
if (!getboundingsphere()) return false;
value.set(osg::Vec3d(lua_tonumber(_lua, -4), lua_tonumber(_lua, -3), lua_tonumber(_lua, -2)), lua_tonumber(_lua, -1));
lua_pop(_lua, 4);
return true;
}
void LuaScriptEngine::pushValue(const osg::Vec2f& value) const
{
lua_newtable(_lua);
@@ -1354,6 +1524,46 @@ void LuaScriptEngine::pushValue(const osg::Matrixd& value) const
}
}
void LuaScriptEngine::pushValue(const osg::BoundingBoxf& value) const
{
lua_newtable(_lua);
lua_pushstring(_lua, "xMin"); lua_pushnumber(_lua, value.xMin()); lua_settable(_lua, -3);
lua_pushstring(_lua, "yMin"); lua_pushnumber(_lua, value.yMin()); lua_settable(_lua, -3);
lua_pushstring(_lua, "zMin"); lua_pushnumber(_lua, value.zMin()); lua_settable(_lua, -3);
lua_pushstring(_lua, "xMax"); lua_pushnumber(_lua, value.xMax()); lua_settable(_lua, -3);
lua_pushstring(_lua, "yMax"); lua_pushnumber(_lua, value.yMax()); lua_settable(_lua, -3);
lua_pushstring(_lua, "zMax"); lua_pushnumber(_lua, value.zMax()); lua_settable(_lua, -3);
}
void LuaScriptEngine::pushValue(const osg::BoundingBoxd& value) const
{
lua_newtable(_lua);
lua_pushstring(_lua, "xMin"); lua_pushnumber(_lua, value.xMin()); lua_settable(_lua, -3);
lua_pushstring(_lua, "yMin"); lua_pushnumber(_lua, value.yMin()); lua_settable(_lua, -3);
lua_pushstring(_lua, "zMin"); lua_pushnumber(_lua, value.zMin()); lua_settable(_lua, -3);
lua_pushstring(_lua, "xMax"); lua_pushnumber(_lua, value.xMax()); lua_settable(_lua, -3);
lua_pushstring(_lua, "yMax"); lua_pushnumber(_lua, value.yMax()); lua_settable(_lua, -3);
lua_pushstring(_lua, "zMax"); lua_pushnumber(_lua, value.zMax()); lua_settable(_lua, -3);
}
void LuaScriptEngine::pushValue(const osg::BoundingSpheref& value) const
{
lua_newtable(_lua);
lua_pushstring(_lua, "x"); lua_pushnumber(_lua, value.center().x()); lua_settable(_lua, -3);
lua_pushstring(_lua, "y"); lua_pushnumber(_lua, value.center().y()); lua_settable(_lua, -3);
lua_pushstring(_lua, "z"); lua_pushnumber(_lua, value.center().z()); lua_settable(_lua, -3);
lua_pushstring(_lua, "radius"); lua_pushnumber(_lua, value.radius()); lua_settable(_lua, -3);
}
void LuaScriptEngine::pushValue(const osg::BoundingSphered& value) const
{
lua_newtable(_lua);
lua_pushstring(_lua, "x"); lua_pushnumber(_lua, value.center().x()); lua_settable(_lua, -3);
lua_pushstring(_lua, "y"); lua_pushnumber(_lua, value.center().y()); lua_settable(_lua, -3);
lua_pushstring(_lua, "z"); lua_pushnumber(_lua, value.center().z()); lua_settable(_lua, -3);
lua_pushstring(_lua, "radius"); lua_pushnumber(_lua, value.radius()); lua_settable(_lua, -3);
}
bool LuaScriptEngine::pushParameter(osg::Object* object) const
{
osg::ValueObject* vo = dynamic_cast<osg::ValueObject*>(object);
@@ -1491,6 +1701,30 @@ osg::Object* LuaScriptEngine::popParameterObject() const
if (getValue(value)) object = new osg::MatrixdValueObject("", value);
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGBOXF):
{
osg::BoundingBoxf value;
if (getValue(value)) object = new osg::BoundingBoxfValueObject("", value);
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGBOXD):
{
osg::BoundingBoxd value;
if (getValue(value)) object = new osg::BoundingBoxdValueObject("", value);
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGSPHEREF):
{
osg::BoundingSpheref value;
if (getValue(value)) object = new osg::BoundingSpherefValueObject("", value);
break;
}
case(osgDB::BaseSerializer::RW_BOUNDINGSPHERED):
{
osg::BoundingSphered value;
if (getValue(value)) object = new osg::BoundingSpheredValueObject("", value);
break;
}
case(osgDB::BaseSerializer::RW_LIST):
{
OSG_NOTICE<<"Need to implement RW_LIST support"<<std::endl;

View File

@@ -57,37 +57,54 @@ class LuaScriptEngine : public osg::ScriptEngine
bool getfields(const char* f1, const char* f2, int type) const;
bool getfields(const char* f1, const char* f2, const char* f3, int type) const;
bool getfields(const char* f1, const char* f2, const char* f3, const char* f4, int type) const;
bool getfields(const char* f1, const char* f2, const char* f3, const char* f4, const char* f5, const char* f6, int type) const;
bool getelements(int numElements, int type) const;
bool getvec2() const;
bool getvec3() const;
bool getvec4() const;
bool getmatrix() const;
bool getboundingbox() const;
bool getboundingsphere() const;
bool getValue(osg::Vec2f& value) const;
bool getValue(osg::Vec3f& value) const;
bool getValue(osg::Vec4f& value) const;
bool getValue(osg::Matrixf& value) const;
bool getValue(osg::Vec2d& value) const;
bool getValue(osg::Vec3d& value) const;
bool getValue(osg::Vec4d& value) const;
bool getValue(osg::Quat& value) const;
bool getValue(osg::Plane& value) const;
bool getValue(osg::Matrixf& value) const;
bool getValue(osg::Matrixd& value) const;
bool getValue(osg::BoundingBoxf& value) const;
bool getValue(osg::BoundingBoxd& value) const;
bool getValue(osg::BoundingSpheref& value) const;
bool getValue(osg::BoundingSphered& value) const;
void pushValue(const osg::Vec2f& value) const;
void pushValue(const osg::Vec3f& value) const;
void pushValue(const osg::Vec4f& value) const;
void pushValue(const osg::Matrixf& value) const;
void pushValue(const osg::Vec2d& value) const;
void pushValue(const osg::Vec3d& value) const;
void pushValue(const osg::Vec4d& value) const;
void pushValue(const osg::Quat& value) const;
void pushValue(const osg::Plane& value) const;
void pushValue(const osg::Matrixf& value) const;
void pushValue(const osg::Matrixd& value) const;
void pushValue(const osg::BoundingBoxf& value) const;
void pushValue(const osg::BoundingBoxd& value) const;
void pushValue(const osg::BoundingSpheref& value) const;
void pushValue(const osg::BoundingSphered& value) const;
bool pushParameter(osg::Object* object) const;
bool popParameter(osg::Object* object) const;
osg::Object* popParameterObject() const;

View File

@@ -4,6 +4,7 @@
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
struct CreateGraphics : public osgDB::MethodObject
{
virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const
@@ -77,6 +78,8 @@ REGISTER_OBJECT_WRAPPER( Widget,
ADD_BOOL_SERIALIZER(HasEventFocus, false);
ADD_BOUNDINGBOXF_SERIALIZER(Extents, osg::BoundingBoxf());
ADD_METHOD_OBJECT( "createGraphics", CreateGraphics );
ADD_METHOD_OBJECT( "createGraphicsImplementation", CreateGraphicsImplementation );