diff --git a/include/osg/ShapeDrawable b/include/osg/ShapeDrawable index 26ae13a50..fb1f821d9 100644 --- a/include/osg/ShapeDrawable +++ b/include/osg/ShapeDrawable @@ -123,12 +123,19 @@ class SG_EXPORT ShapeDrawable : public Drawable virtual const char* libraryName() const { return "osg"; } virtual const char* className() const { return "ShapeDrawable"; } + /** set the color of the shape.*/ + void setColor(const Vec4& color) { _color = color; } + + /** get the color of the shape.*/ + const Vec4& getColor() const { return _color; } void setTessellationHints(TessellationHints* hints) { _tessellationHints = hints; } + TessellationHints* getTessellationHints() { return _tessellationHints.get(); } const TessellationHints* getTessellationHints() const { return _tessellationHints.get(); } + /** draw ShapeDrawable directly ignoring an OpenGL display list which could be attached. * This is the internal draw method which does the drawing itself, * and is the method to override when deriving from ShapeDrawable for user-drawn objects. @@ -158,6 +165,8 @@ class SG_EXPORT ShapeDrawable : public Drawable virtual bool computeBound() const; + Vec4 _color; + ref_ptr _tessellationHints; }; diff --git a/src/osg/ShapeDrawable.cpp b/src/osg/ShapeDrawable.cpp index c91779801..8e850704f 100644 --- a/src/osg/ShapeDrawable.cpp +++ b/src/osg/ShapeDrawable.cpp @@ -12,6 +12,7 @@ */ #include #include +#include using namespace osg; @@ -26,7 +27,14 @@ class DrawShapeVisitor : public ConstShapeVisitor DrawShapeVisitor(State& state,const TessellationHints* hints): _state(state), - _hints(hints) {} + _hints(hints) + { + if (hints) + { + notify(NOTICE)<<"Warning: TessellationHints ignored in present osg::ShapeDrawable implementation."<accept(dsv); } } diff --git a/src/osgPlugins/osg/ShapeDrawable.cpp b/src/osgPlugins/osg/ShapeDrawable.cpp index a4fbe4c6f..c35089fcd 100644 --- a/src/osgPlugins/osg/ShapeDrawable.cpp +++ b/src/osgPlugins/osg/ShapeDrawable.cpp @@ -11,41 +11,55 @@ using namespace osgDB; bool ShapeDrawable_readLocalData(Object& obj, Input& fr); bool ShapeDrawable_writeLocalData(const Object& obj, Output& fw); -//register the read and write functions with the osgDB::Registry. -RegisterDotOsgWrapperProxy g_ShapeDrawableFuncProxy -( - new osg::ShapeDrawable, - "ShapeDrawable", - "Object Drawable ShapeDrawable", - 0, - 0, - DotOsgWrapper::READ_AND_WRITE -); - +// //register the read and write functions with the osgDB::Registry. // RegisterDotOsgWrapperProxy g_ShapeDrawableFuncProxy // ( // new osg::ShapeDrawable, // "ShapeDrawable", // "Object Drawable ShapeDrawable", -// &ShapeDrawable_readLocalData, -// &ShapeDrawable_writeLocalData, +// 0, +// 0, // DotOsgWrapper::READ_AND_WRITE // ); -// -// bool ShapeDrawable_readLocalData(Object& obj, Input& fr) -// { -// bool iteratorAdvanced = false; -// -// ShapeDrawable& geom = static_cast(obj); -// -// bool matchedFirst = false; -// -// return iteratorAdvanced; -// } -// -// bool ShapeDrawable_writeLocalData(const Object& obj, Output& fw) -// { -// const ShapeDrawable& geom = static_cast(obj); -// -// return true; -// } + +RegisterDotOsgWrapperProxy g_ShapeDrawableFuncProxy +( + new osg::ShapeDrawable, + "ShapeDrawable", + "Object Drawable ShapeDrawable", + &ShapeDrawable_readLocalData, + &ShapeDrawable_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool ShapeDrawable_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + ShapeDrawable& geom = static_cast(obj); + + if (fr.matchSequence("color %f %f %f %f")) + { + osg::Vec4 color; + fr[1].getFloat(color[0]); + fr[2].getFloat(color[1]); + fr[3].getFloat(color[2]); + fr[4].getFloat(color[3]); + + geom.setColor(color); + + fr+=5; + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool ShapeDrawable_writeLocalData(const Object& obj, Output& fw) +{ + const ShapeDrawable& geom = static_cast(obj); + + fw.indent() << "color " << geom.getColor() << std::endl; + + return true; +}