Added support for set/getColor to ShapeDrawable.
This commit is contained in:
@@ -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> _tessellationHints;
|
||||
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
#include <osg/ShapeDrawable>
|
||||
#include <osg/GL>
|
||||
#include <osg/Notify>
|
||||
|
||||
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."<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual void apply(const Sphere&);
|
||||
virtual void apply(const Box&);
|
||||
@@ -1249,17 +1257,21 @@ void PrimitiveShapeVisitor::apply(const CompositeShape& group)
|
||||
//
|
||||
|
||||
|
||||
ShapeDrawable::ShapeDrawable()
|
||||
ShapeDrawable::ShapeDrawable():
|
||||
_color(1.0f,1.0f,1.0f,1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
ShapeDrawable::ShapeDrawable(Shape* shape)
|
||||
ShapeDrawable::ShapeDrawable(Shape* shape):
|
||||
_color(1.0f,1.0f,1.0f,1.0f)
|
||||
{
|
||||
setShape(shape);
|
||||
}
|
||||
|
||||
ShapeDrawable::ShapeDrawable(const ShapeDrawable& pg,const CopyOp& copyop):
|
||||
Drawable(pg,copyop)
|
||||
Drawable(pg,copyop),
|
||||
_color(pg._color),
|
||||
_tessellationHints(pg._tessellationHints)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1271,7 +1283,10 @@ void ShapeDrawable::drawImplementation(State& state) const
|
||||
{
|
||||
if (_shape.valid())
|
||||
{
|
||||
glColor4fv(_color.ptr());
|
||||
|
||||
DrawShapeVisitor dsv(state,_tessellationHints.get());
|
||||
|
||||
_shape->accept(dsv);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ShapeDrawable&>(obj);
|
||||
//
|
||||
// bool matchedFirst = false;
|
||||
//
|
||||
// return iteratorAdvanced;
|
||||
// }
|
||||
//
|
||||
// bool ShapeDrawable_writeLocalData(const Object& obj, Output& fw)
|
||||
// {
|
||||
// const ShapeDrawable& geom = static_cast<const ShapeDrawable&>(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<ShapeDrawable&>(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<const ShapeDrawable&>(obj);
|
||||
|
||||
fw.indent() << "color " << geom.getColor() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user