From 54abc6f471fea919aebc2fe15fddbe396673e8c5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 May 2005 14:48:56 +0000 Subject: [PATCH] Added IO support for new intialBound and callbacks to .osg, and initialBound to .ive --- include/osg/Drawable | 24 ++++++++----- include/osg/Node | 24 ++++++++----- src/osgPlugins/ive/Drawable.cpp | 32 +++++++++++++++++ src/osgPlugins/ive/Node.cpp | 22 ++++++++++++ src/osgPlugins/osg/Drawable.cpp | 62 ++++++++++++++++++++++++++------- src/osgPlugins/osg/Node.cpp | 45 ++++++++++++++++++++++++ 6 files changed, 179 insertions(+), 30 deletions(-) diff --git a/include/osg/Drawable b/include/osg/Drawable index bc3bcbbda..1d00ae7f7 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -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; - BoundingBox _initialBound; - ref_ptr _computeBoundCallback; - mutable BoundingBox _boundingBox; - mutable bool _boundingBoxComputed; + BoundingBox _initialBound; + ref_ptr _computeBoundCallback; + mutable BoundingBox _boundingBox; + mutable bool _boundingBoxComputed; ref_ptr _shape; diff --git a/include/osg/Node b/include/osg/Node index 5015a413c..670f94f8d 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -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; - mutable BoundingSphere _boundingSphere; - mutable bool _boundingSphereComputed; + BoundingSphere _initialBound; + ref_ptr _computeBoundCallback; + mutable BoundingSphere _boundingSphere; + mutable bool _boundingSphereComputed; std::string _name; diff --git a/src/osgPlugins/ive/Drawable.cpp b/src/osgPlugins/ive/Drawable.cpp index 4fdda57dc..92b801175 100644 --- a/src/osgPlugins/ive/Drawable.cpp +++ b/src/osgPlugins/ive/Drawable.cpp @@ -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()); diff --git a/src/osgPlugins/ive/Node.cpp b/src/osgPlugins/ive/Node.cpp index 3a89abc10..e0c0a9b70 100644 --- a/src/osgPlugins/ive/Node.cpp +++ b/src/osgPlugins/ive/Node.cpp @@ -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()); } diff --git a/src/osgPlugins/osg/Drawable.cpp b/src/osgPlugins/osg/Drawable.cpp index 531788dac..74e1779e4 100644 --- a/src/osgPlugins/osg/Drawable.cpp +++ b/src/osgPlugins/osg/Drawable.cpp @@ -36,27 +36,52 @@ bool Drawable_readLocalData(Object& obj, Input& fr) } Shape* shape = static_cast(fr.readObjectOfType(type_wrapper())); - if (shape) { - drawable.setShape(shape); - iteratorAdvanced = true; + if (shape) + { + drawable.setShape(shape); + iteratorAdvanced = true; } Drawable::UpdateCallback* uc = dynamic_cast(fr.readObjectOfType(type_wrapper())); - if (uc) { - drawable.setUpdateCallback(uc); - iteratorAdvanced = true; + if (uc) + { + drawable.setUpdateCallback(uc); + iteratorAdvanced = true; } Drawable::CullCallback* cc = dynamic_cast(fr.readObjectOfType(type_wrapper())); - if (cc) { - drawable.setCullCallback(cc); - iteratorAdvanced = true; + if (cc) + { + drawable.setCullCallback(cc); + iteratorAdvanced = true; } Drawable::DrawCallback* dc = dynamic_cast(fr.readObjectOfType(type_wrapper())); - 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(fr.readObjectOfType(type_wrapper())); + if (cbc) + { + drawable.setComputeBoundingBoxCallback(cbc); + iteratorAdvanced = true; } if (fr[0].matchWord("supportsDisplayList")) @@ -145,6 +170,19 @@ bool Drawable_writeLocalData(const Object& obj, Output& fw) fw.writeObject(*drawable.getDrawCallback()); } + + if (drawable.getInitialBound().valid()) + { + const osg::BoundingBox& bb = drawable.getInitialBound(); + fw.indent()<<"initialBound "<entry) + { + Node::ComputeBoundingSphereCallback* callback = dynamic_cast(fr.readObjectOfType(type_wrapper())); + 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 "<