Added IO support for new intialBound and callbacks to .osg, and initialBound to .ive

This commit is contained in:
Robert Osfield 2005-05-12 14:48:56 +00:00
parent bf4d63f6ea
commit 54abc6f471
6 changed files with 179 additions and 30 deletions

View File

@ -184,19 +184,25 @@ class OSG_EXPORT Drawable : public Object
virtual BoundingBox computeBound() const;
/** Callback to allow users to override the default computation of bounding volume.*/
struct ComputeBoundCallback : public osg::Referenced
struct ComputeBoundingBoxCallback : public osg::Object
{
virtual BoundingBox computeBound(const osg::Drawable&) const = 0;
ComputeBoundingBoxCallback() {}
ComputeBoundingBoxCallback(const ComputeBoundingBoxCallback&,const CopyOp&) {}
META_Object(osg,ComputeBoundingBoxCallback);
virtual BoundingBox computeBound(const osg::Drawable&) const { return BoundingBox(); }
};
/** Set the compute bound callback to override the default computeBound.*/
void setComputeBoundCallback(ComputeBoundCallback* callback) { _computeBoundCallback = callback; }
void setComputeBoundingBoxCallback(ComputeBoundingBoxCallback* callback) { _computeBoundCallback = callback; }
/** Get the compute bound callback.*/
ComputeBoundCallback* getComputeBoundCallback() { return _computeBoundCallback.get(); }
ComputeBoundingBoxCallback* getComputeBoundingBoxCallback() { return _computeBoundCallback.get(); }
/** Get the const compute bound callback.*/
const ComputeBoundCallback* getComputeBoundCallback() const { return _computeBoundCallback.get(); }
const ComputeBoundingBoxCallback* getComputeBoundingBoxCallback() const { return _computeBoundCallback.get(); }
/** Set the Shape of the \c Drawable. The shape can be used to
@ -741,10 +747,10 @@ class OSG_EXPORT Drawable : public Object
ref_ptr<StateSet> _stateset;
BoundingBox _initialBound;
ref_ptr<ComputeBoundCallback> _computeBoundCallback;
mutable BoundingBox _boundingBox;
mutable bool _boundingBoxComputed;
BoundingBox _initialBound;
ref_ptr<ComputeBoundingBoxCallback> _computeBoundCallback;
mutable BoundingBox _boundingBox;
mutable bool _boundingBoxComputed;
ref_ptr<Shape> _shape;

View File

@ -268,19 +268,25 @@ class OSG_EXPORT Node : public Object
virtual BoundingSphere computeBound() const;
/** Callback to allow users to override the default computation of bounding volume.*/
struct ComputeBoundCallback : public osg::Referenced
struct ComputeBoundingSphereCallback : public osg::Object
{
virtual BoundingSphere computeBound(const osg::Node&) const = 0;
ComputeBoundingSphereCallback() {}
ComputeBoundingSphereCallback(const ComputeBoundingSphereCallback&,const CopyOp&) {}
META_Object(osg,ComputeBoundingSphereCallback);
virtual BoundingSphere computeBound(const osg::Node&) const { return BoundingSphere(); }
};
/** Set the compute bound callback to override the default computeBound.*/
void setComputeBoundCallback(ComputeBoundCallback* callback) { _computeBoundCallback = callback; }
void setComputeBoundingSphereCallback(ComputeBoundingSphereCallback* callback) { _computeBoundCallback = callback; }
/** Get the compute bound callback.*/
ComputeBoundCallback* getComputeBoundCallback() { return _computeBoundCallback.get(); }
ComputeBoundingSphereCallback* getComputeBoundingSphereCallback() { return _computeBoundCallback.get(); }
/** Get the const compute bound callback.*/
const ComputeBoundCallback* getComputeBoundCallback() const { return _computeBoundCallback.get(); }
const ComputeBoundingSphereCallback* getComputeBoundingSphereCallback() const { return _computeBoundCallback.get(); }
/** If State is non-zero, this function releases any associated OpenGL objects for
@ -302,10 +308,10 @@ class OSG_EXPORT Node : public Object
BoundingSphere _initialBound;
ref_ptr<ComputeBoundCallback> _computeBoundCallback;
mutable BoundingSphere _boundingSphere;
mutable bool _boundingSphereComputed;
BoundingSphere _initialBound;
ref_ptr<ComputeBoundingSphereCallback> _computeBoundCallback;
mutable BoundingSphere _boundingSphere;
mutable bool _boundingSphereComputed;
std::string _name;

View File

@ -50,6 +50,22 @@ void Drawable::write(DataOutputStream* out)
((ive::ClusterCullingCallback*)(ccc))->write(out);
}
if (out->getVersion() >= VERSION_0010)
{
const osg::BoundingBox& bb = getInitialBound();
out->writeBool(bb.valid());
if (bb.valid())
{
out->writeFloat(bb.xMin());
out->writeFloat(bb.yMin());
out->writeFloat(bb.zMin());
out->writeFloat(bb.xMax());
out->writeFloat(bb.yMax());
out->writeFloat(bb.zMax());
}
}
// Write support display list.
out->writeBool(getSupportsDisplayList());
@ -91,6 +107,22 @@ void Drawable::read(DataInputStream* in)
setCullCallback(ccc);
}
if (in->getVersion() >= VERSION_0010)
{
if (in->readBool())
{
osg::BoundingBox bb;
bb.xMin() = in->readFloat();
bb.yMin() = in->readFloat();
bb.zMin() = in->readFloat();
bb.xMax() = in->readFloat();
bb.yMax() = in->readFloat();
bb.zMax() = in->readFloat();
setInitialBound(bb);
}
}
// Read support display list
setSupportsDisplayList(in->readBool());

View File

@ -74,6 +74,17 @@ void Node::write(DataOutputStream* out){
}
}
if (out->getVersion() >= VERSION_0010)
{
const osg::BoundingSphere& bs = getInitialBound();
out->writeBool(bs.valid());
if (bs.valid())
{
out->writeVec3(bs.center());
out->writeFloat(bs.radius());
}
}
// Write NodeMask
out->writeUInt(getNodeMask());
}
@ -125,6 +136,17 @@ void Node::read(DataInputStream* in){
}
}
if (in->getVersion() >= VERSION_0010)
{
if (in->readBool())
{
osg::BoundingSphere bs;
bs.center() = in->readVec3();
bs.radius() = in->readFloat();
setInitialBound(bs);
}
}
// Read NodeMask
setNodeMask(in->readUInt());
}

View File

@ -36,27 +36,52 @@ bool Drawable_readLocalData(Object& obj, Input& fr)
}
Shape* shape = static_cast<Shape *>(fr.readObjectOfType(type_wrapper<Shape>()));
if (shape) {
drawable.setShape(shape);
iteratorAdvanced = true;
if (shape)
{
drawable.setShape(shape);
iteratorAdvanced = true;
}
Drawable::UpdateCallback* uc = dynamic_cast<Drawable::UpdateCallback *>(fr.readObjectOfType(type_wrapper<Drawable::UpdateCallback>()));
if (uc) {
drawable.setUpdateCallback(uc);
iteratorAdvanced = true;
if (uc)
{
drawable.setUpdateCallback(uc);
iteratorAdvanced = true;
}
Drawable::CullCallback* cc = dynamic_cast<Drawable::CullCallback *>(fr.readObjectOfType(type_wrapper<Drawable::CullCallback>()));
if (cc) {
drawable.setCullCallback(cc);
iteratorAdvanced = true;
if (cc)
{
drawable.setCullCallback(cc);
iteratorAdvanced = true;
}
Drawable::DrawCallback* dc = dynamic_cast<Drawable::DrawCallback *>(fr.readObjectOfType(type_wrapper<Drawable::DrawCallback>()));
if (dc) {
drawable.setDrawCallback(dc);
iteratorAdvanced = true;
if (dc)
{
drawable.setDrawCallback(dc);
iteratorAdvanced = true;
}
if (fr.matchSequence("initialBound %f %f %f %f %f %f"))
{
BoundingBox bb;
fr[1].getFloat(bb.xMin());
fr[2].getFloat(bb.yMin());
fr[3].getFloat(bb.zMin());
fr[4].getFloat(bb.xMax());
fr[5].getFloat(bb.yMax());
fr[6].getFloat(bb.zMax());
drawable.setInitialBound(bb);
fr += 7;
iteratorAdvanced = true;
}
Drawable::ComputeBoundingBoxCallback* cbc = dynamic_cast<Drawable::ComputeBoundingBoxCallback *>(fr.readObjectOfType(type_wrapper<Drawable::ComputeBoundingBoxCallback>()));
if (cbc)
{
drawable.setComputeBoundingBoxCallback(cbc);
iteratorAdvanced = true;
}
if (fr[0].matchWord("supportsDisplayList"))
@ -146,6 +171,19 @@ bool Drawable_writeLocalData(const Object& obj, Output& fw)
}
if (drawable.getInitialBound().valid())
{
const osg::BoundingBox& bb = drawable.getInitialBound();
fw.indent()<<"initialBound "<<bb.xMin()<<" "<<bb.yMin()<<" "<<bb.zMin()<<" "
<<bb.xMax()<<" "<<bb.yMax()<<" "<<bb.zMax()<<std::endl;
}
if (drawable.getComputeBoundingBoxCallback())
{
fw.writeObject(*drawable.getComputeBoundingBoxCallback());
}
if (!drawable.getSupportsDisplayList())
{
fw.indent()<<"supportsDisplayList ";

View File

@ -1,4 +1,5 @@
#include "osg/Node"
#include "osg/io_utils"
#include "osgDB/Registry"
#include "osgDB/Input"
@ -152,6 +153,35 @@ bool Node_readLocalData(Object& obj, Input& fr)
}
if (fr.matchSequence("initialBound %f %f %f %f"))
{
BoundingSphere bs;
fr[1].getFloat(bs.center().x());
fr[2].getFloat(bs.center().y());
fr[3].getFloat(bs.center().z());
fr[4].getFloat(bs.radius());
node.setInitialBound(bs);
fr += 5;
iteratorAdvanced = true;
}
while (fr.matchSequence("ComputeBoundingSphereCallback {"))
{
int entry = fr[0].getNoNestedBrackets();
fr += 2;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
Node::ComputeBoundingSphereCallback* callback = dynamic_cast<Node::ComputeBoundingSphereCallback*>(fr.readObjectOfType(type_wrapper<Node::ComputeBoundingSphereCallback>()));
if (callback) {
node.setComputeBoundingSphereCallback(callback);
}
else ++fr;
}
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
@ -222,5 +252,20 @@ bool Node_writeLocalData(const Object& obj, Output& fw)
fw.indent() << "}" << std::endl;
}
if (node.getInitialBound().valid())
{
const osg::BoundingSphere& bs = node.getInitialBound();
fw.indent()<<"initialBound "<<bs.center()<<" "<<bs.radius()<<std::endl;
}
if (node.getComputeBoundingSphereCallback())
{
fw.indent() << "ComputeBoundingSphereCallback {" << std::endl;
fw.moveIn();
fw.writeObject(*node.getComputeBoundingSphereCallback());
fw.moveOut();
fw.indent() << "}" << std::endl;
}
return true;
}