Added support for reading and writing OccluderNode's to the .osg file format.

This commit is contained in:
Robert Osfield
2002-06-19 16:06:03 +00:00
parent b12e36cede
commit 77e1fb7f80
8 changed files with 230 additions and 10 deletions

View File

@@ -114,6 +114,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\ColorMatrix.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\ConvexPlanerPolygon.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\CullFace.cpp
# End Source File
# Begin Source File

View File

@@ -57,6 +57,11 @@ class SG_EXPORT BoundingBox
return _max.x()>=_min.x();
}
inline const bool valid() const
{
return _max.x()>=_min.x();
}
inline void set (float xmin,float ymin,float zmin,
float xmax,float ymax,float zmax)
{

View File

@@ -10,6 +10,8 @@
namespace osg {
class BoundingBox;
/** General purpose bounding sphere class for enclosing nodes/objects/vertices.
Used to bound internal osg::Node's in the scene,
to assist in view frustum culling etc. Similar in function to BoundingBox
@@ -40,6 +42,10 @@ class SG_EXPORT BoundingSphere
false if the bounding sphere is effectively unset.*/
inline const bool isValid() const { return _radius>=0.0f; }
/** return true if the bounding sphere contains valid values,
false if the bounding sphere is effectively unset.*/
inline const bool valid() const { return _radius>=0.0f; }
/** set bounding sphere.*/
inline void set(const Vec3& center,float radius)
{
@@ -86,6 +92,17 @@ class SG_EXPORT BoundingSphere
If this sphere is empty then move the centrer to v and set radius to 0. */
void expandRadiusBy(const BoundingSphere& sh);
/** If incomming box is outwith the sphere expand to ecompass incomming box.
calculates the combination of movement of center and radius which
minimizes the radius increase. If this boz is empty then
move the centrer to v and set radius to 0.*/
void expandBy(const BoundingBox& bb);
/** If incomming box is outwith the sphere expand radius to ecompass incomming box.
Unlike update, does not move the center, just increasing the radius.
If this sphere is empty then move the centrer to v and set radius to 0. */
void expandRadiusBy(const BoundingBox& bb);
/** return true is vertex v is within the sphere.*/
inline const bool contains(const Vec3& v) const
{

View File

@@ -6,7 +6,7 @@
#define OSG_CONVEXPLANEROCCLUDER 1
#include <osg/ConvexPlanerPolygon>
#include <osg/Referenced>
#include <osg/Object>
namespace osg {
@@ -14,14 +14,18 @@ class OccluderVolume;
/** A class for representing convex clipping volumes made up.
* When adding planes, their normals should point inwards (into the volume) */
class SG_EXPORT ConvexPlanerOccluder : public Referenced
class SG_EXPORT ConvexPlanerOccluder : public Object
{
public:
inline ConvexPlanerOccluder() {}
ConvexPlanerOccluder():Object() {}
ConvexPlanerOccluder(const ConvexPlanerOccluder& cpo,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Object(cpo,copyop),
_occluder(cpo._occluder),
_holeList(cpo._holeList) {}
META_Object(osg,ConvexPlanerOccluder)
void setOccluder(const ConvexPlanerPolygon& cpp) { _occluder = cpp; }
@@ -47,9 +51,7 @@ class SG_EXPORT ConvexPlanerOccluder : public Referenced
protected:
float _area;
Vec3 _center;
Vec3 _normal;
~ConvexPlanerOccluder() {}
ConvexPlanerPolygon _occluder;
HoleList _holeList;

View File

@@ -41,6 +41,9 @@ class SG_EXPORT OccluderNode : public Group
virtual ~OccluderNode() {}
/** Override's Group's computeBound.*/
virtual const bool computeBound() const;
ref_ptr<ConvexPlanerOccluder> _occluder;
};

View File

@@ -0,0 +1,174 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#endif
#include "osg/ConvexPlanerOccluder"
#include "osg/Types"
#include "osg/Notify"
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool ConvexPlanerOccluder_readLocalData(Object& obj, Input& fr);
bool ConvexPlanerOccluder_writeLocalData(const Object& obj, Output& fw);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_ConvexPlanerOccluderFuncProxy
(
osgNew osg::ConvexPlanerOccluder,
"ConvexPlanerOccluder",
"Object ConvexPlanerOccluder",
&ConvexPlanerOccluder_readLocalData,
&ConvexPlanerOccluder_writeLocalData,
DotOsgWrapper::READ_AND_WRITE
);
bool ConvexPlanerOccluder_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
ConvexPlanerOccluder& cpo = static_cast<ConvexPlanerOccluder&>(obj);
bool matchFirst;
if ((matchFirst=fr.matchSequence("Occluder {")) || fr.matchSequence("Occluder %i {"))
{
ConvexPlanerPolygon& cpp = cpo.getOccluder();
ConvexPlanerPolygon::VertexList& vertexList = cpp.getVertexList();
// set up coordinates.
int entry = fr[0].getNoNestedBrackets();
if (matchFirst)
{
fr += 2;
}
else
{
int capacity;
fr[1].getInt(capacity);
vertexList.reserve(capacity);
fr += 3;
}
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
Vec3 v;
if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()))
{
fr += 3;
vertexList.push_back(v);
}
else
{
++fr;
}
}
iteratorAdvanced = true;
++fr;
}
ConvexPlanerOccluder::HoleList& holeList = cpo.getHoleList();
while ((matchFirst=fr.matchSequence("Hole {")) || fr.matchSequence("Hole %i {"))
{
holeList.push_back(ConvexPlanerPolygon());
ConvexPlanerPolygon& cpp = holeList.back();
ConvexPlanerPolygon::VertexList& vertexList = cpp.getVertexList();
// set up coordinates.
int entry = fr[0].getNoNestedBrackets();
if (matchFirst)
{
fr += 2;
}
else
{
int capacity;
fr[1].getInt(capacity);
vertexList.reserve(capacity);
fr += 3;
}
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
Vec3 v;
if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()))
{
fr += 3;
vertexList.push_back(v);
}
else
{
++fr;
}
}
iteratorAdvanced = true;
++fr;
}
return iteratorAdvanced;
}
bool ConvexPlanerOccluder_writeLocalData(const Object& obj, Output& fw)
{
const ConvexPlanerOccluder& cpo = static_cast<const ConvexPlanerOccluder&>(obj);
// write out the occluder polygon.
{
const ConvexPlanerPolygon::VertexList& vertexList = cpo.getOccluder().getVertexList();
fw.indent() << "Occluder " << vertexList.size()<< "{"<< std::endl;
fw.moveIn();
for(ConvexPlanerPolygon::VertexList::const_iterator itr=vertexList.begin();
itr!=vertexList.end();
++itr)
{
fw.indent() << (*itr)[0] << ' ' << (*itr)[1] << ' ' << (*itr)[2] << std::endl;
}
fw.moveOut();
fw.indent()<<"}"<< std::endl;
}
// write out any holes.
const ConvexPlanerOccluder::HoleList& holeList = cpo.getHoleList();
for(ConvexPlanerOccluder::HoleList::const_iterator holeItr=holeList.begin();
holeItr!=holeList.end();
++holeItr)
{
const ConvexPlanerPolygon::VertexList& vertexList = holeItr->getVertexList();
fw.indent() << "Hole " << vertexList.size() << "{"<< std::endl;
fw.moveIn();
for(ConvexPlanerPolygon::VertexList::const_iterator itr=vertexList.begin();
itr!=vertexList.end();
++itr)
{
fw.indent() << (*itr)[0] << ' ' << (*itr)[1] << ' ' << (*itr)[2] << std::endl;
}
fw.moveOut();
fw.indent()<<"}"<< std::endl;
}
return true;
}

View File

@@ -6,7 +6,7 @@ CXXFILES =\
Billboard.cpp\
ClipPlane.cpp\
ColorMask.cpp\
ColorMatrix.cpp\
ConvexPlanerOccluder.cpp\
CullFace.cpp\
Depth.cpp\
Drawable.cpp\

View File

@@ -16,7 +16,7 @@ RegisterDotOsgWrapperProxy g_OccluderNodeProxy
(
osgNew osg::OccluderNode,
"OccluderNode",
"Object Node Group OccluderNode",
"Object Node OccluderNode Group",
&OccluderNode_readLocalData,
&OccluderNode_writeLocalData
);
@@ -26,6 +26,16 @@ bool OccluderNode_readLocalData(Object& obj, Input& fr)
bool iteratorAdvanced = false;
OccluderNode& occludernode = static_cast<OccluderNode&>(obj);
static ref_ptr<ConvexPlanerOccluder> s_occluder = osgNew ConvexPlanerOccluder;
ConvexPlanerOccluder* tmpOccluder = static_cast<ConvexPlanerOccluder*>(fr.readObjectOfType(*s_occluder));
if (tmpOccluder)
{
occludernode.setOccluder(tmpOccluder);
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
@@ -33,7 +43,12 @@ bool OccluderNode_readLocalData(Object& obj, Input& fr)
bool OccluderNode_writeLocalData(const Object& obj, Output& fw)
{
const OccluderNode& occludenode = static_cast<const OccluderNode&>(obj);
const OccluderNode& occludernode = static_cast<const OccluderNode&>(obj);
if (occludernode.getOccluder())
{
fw.writeObject(*occludernode.getOccluder());
}
return true;
}