Added IO support for new intialBound and callbacks to .osg, and initialBound to .ive
This commit is contained in:
parent
bf4d63f6ea
commit
54abc6f471
@ -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
|
||||
@ -742,7 +748,7 @@ class OSG_EXPORT Drawable : public Object
|
||||
ref_ptr<StateSet> _stateset;
|
||||
|
||||
BoundingBox _initialBound;
|
||||
ref_ptr<ComputeBoundCallback> _computeBoundCallback;
|
||||
ref_ptr<ComputeBoundingBoxCallback> _computeBoundCallback;
|
||||
mutable BoundingBox _boundingBox;
|
||||
mutable bool _boundingBoxComputed;
|
||||
|
||||
|
@ -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
|
||||
@ -303,7 +309,7 @@ class OSG_EXPORT Node : public Object
|
||||
|
||||
|
||||
BoundingSphere _initialBound;
|
||||
ref_ptr<ComputeBoundCallback> _computeBoundCallback;
|
||||
ref_ptr<ComputeBoundingSphereCallback> _computeBoundCallback;
|
||||
mutable BoundingSphere _boundingSphere;
|
||||
mutable bool _boundingSphereComputed;
|
||||
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -36,29 +36,54 @@ bool Drawable_readLocalData(Object& obj, Input& fr)
|
||||
}
|
||||
|
||||
Shape* shape = static_cast<Shape *>(fr.readObjectOfType(type_wrapper<Shape>()));
|
||||
if (shape) {
|
||||
if (shape)
|
||||
{
|
||||
drawable.setShape(shape);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
Drawable::UpdateCallback* uc = dynamic_cast<Drawable::UpdateCallback *>(fr.readObjectOfType(type_wrapper<Drawable::UpdateCallback>()));
|
||||
if (uc) {
|
||||
if (uc)
|
||||
{
|
||||
drawable.setUpdateCallback(uc);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
Drawable::CullCallback* cc = dynamic_cast<Drawable::CullCallback *>(fr.readObjectOfType(type_wrapper<Drawable::CullCallback>()));
|
||||
if (cc) {
|
||||
if (cc)
|
||||
{
|
||||
drawable.setCullCallback(cc);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
Drawable::DrawCallback* dc = dynamic_cast<Drawable::DrawCallback *>(fr.readObjectOfType(type_wrapper<Drawable::DrawCallback>()));
|
||||
if (dc) {
|
||||
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"))
|
||||
{
|
||||
if (fr[1].matchWord("TRUE"))
|
||||
@ -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 ";
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user