| 1 | #include <osg/Shape> |
|---|
| 2 | #include <osg/Notify> |
|---|
| 3 | #include <osg/io_utils> |
|---|
| 4 | |
|---|
| 5 | #include <osgDB/Registry> |
|---|
| 6 | #include <osgDB/Input> |
|---|
| 7 | #include <osgDB/ParameterOutput> |
|---|
| 8 | |
|---|
| 9 | using namespace osg; |
|---|
| 10 | using namespace osgDB; |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | bool CompositeShape_readLocalData(Object& obj, Input& fr); |
|---|
| 16 | bool CompositeShape_writeLocalData(const Object& obj, Output& fw); |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | REGISTER_DOTOSGWRAPPER(CompositeShape) |
|---|
| 20 | ( |
|---|
| 21 | new osg::CompositeShape, |
|---|
| 22 | "CompositeShape", |
|---|
| 23 | "Object CompositeShape", |
|---|
| 24 | &CompositeShape_readLocalData, |
|---|
| 25 | &CompositeShape_writeLocalData, |
|---|
| 26 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 27 | ); |
|---|
| 28 | |
|---|
| 29 | bool CompositeShape_readLocalData(Object& obj, Input& fr) |
|---|
| 30 | { |
|---|
| 31 | bool iteratorAdvanced = false; |
|---|
| 32 | |
|---|
| 33 | CompositeShape& composite = static_cast<CompositeShape&>(obj); |
|---|
| 34 | |
|---|
| 35 | ref_ptr<Object> readObject; |
|---|
| 36 | if (fr[0].matchWord("Shape")) |
|---|
| 37 | { |
|---|
| 38 | readObject = fr.readObject(); |
|---|
| 39 | if (readObject.valid()) |
|---|
| 40 | { |
|---|
| 41 | osg::Shape* shape = dynamic_cast<osg::Shape*>(readObject.get()); |
|---|
| 42 | if (shape) composite.setShape(shape); |
|---|
| 43 | else notify(WARN)<<"Warning:: "<<readObject->className()<<" loaded but cannot not be attached to Drawable."<<std::endl; |
|---|
| 44 | iteratorAdvanced = true; |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | while((readObject=fr.readObjectOfType(type_wrapper<osg::Shape>())).valid()) |
|---|
| 49 | { |
|---|
| 50 | osg::Shape* shape = static_cast<osg::Shape*>(readObject.get()); |
|---|
| 51 | composite.addChild(shape); |
|---|
| 52 | iteratorAdvanced = true; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | return iteratorAdvanced; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | bool CompositeShape_writeLocalData(const Object& obj, Output& fw) |
|---|
| 59 | { |
|---|
| 60 | const CompositeShape& composite = static_cast<const CompositeShape&>(obj); |
|---|
| 61 | |
|---|
| 62 | if (composite.getShape()) |
|---|
| 63 | { |
|---|
| 64 | fw.indent() << "Shape "; |
|---|
| 65 | fw.writeObject(*composite.getShape()); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | for(unsigned int i=0;i<composite.getNumChildren();++i) |
|---|
| 69 | { |
|---|
| 70 | fw.writeObject(*composite.getChild(i)); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | return true; |
|---|
| 74 | } |
|---|