Replaced old Shape to Geometry conversion code as new convinience methods in include/osg/Shape provide these features
This commit is contained in:
parent
e5ab4355be
commit
1df27e4edb
File diff suppressed because it is too large
Load Diff
@ -19,79 +19,10 @@
|
|||||||
#include <osg/ShapeDrawable>
|
#include <osg/ShapeDrawable>
|
||||||
#include <osg/NodeVisitor>
|
#include <osg/NodeVisitor>
|
||||||
|
|
||||||
// arbitrary minima for rows & segments ( from shapedrawable.cpp )
|
|
||||||
const unsigned int MIN_NUM_ROWS = 3;
|
|
||||||
const unsigned int MIN_NUM_SEGMENTS = 5;
|
|
||||||
|
|
||||||
// osg::GLBeginEndAdapter descendant that stores data for osg::Geometry creation
|
|
||||||
class FakeGLBeginEndAdapter : public osg::GLBeginEndAdapter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FakeGLBeginEndAdapter();
|
|
||||||
|
|
||||||
void PushMatrix();
|
|
||||||
void MultMatrixd(const GLdouble* m);
|
|
||||||
void Translated(GLdouble x, GLdouble y, GLdouble z);
|
|
||||||
void Scaled(GLdouble x, GLdouble y, GLdouble z);
|
|
||||||
void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
|
|
||||||
void End();
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::Geometry> geometry;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ShapeToGeometryVisitor : public osg::ConstShapeVisitor
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
ShapeToGeometryVisitor(const osg::TessellationHints* hints)
|
|
||||||
: osg::ConstShapeVisitor(), _hints(hints)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void apply(const osg::Sphere&);
|
|
||||||
virtual void apply(const osg::Box&);
|
|
||||||
virtual void apply(const osg::Cone&);
|
|
||||||
virtual void apply(const osg::Cylinder&);
|
|
||||||
virtual void apply(const osg::Capsule&);
|
|
||||||
virtual void apply(const osg::InfinitePlane&);
|
|
||||||
|
|
||||||
virtual void apply(const osg::TriangleMesh&);
|
|
||||||
virtual void apply(const osg::ConvexHull&);
|
|
||||||
virtual void apply(const osg::HeightField&);
|
|
||||||
|
|
||||||
virtual void apply(const osg::CompositeShape&);
|
|
||||||
|
|
||||||
osg::Geometry* getGeometry() { return gl.geometry.get(); }
|
|
||||||
|
|
||||||
|
|
||||||
const osg::TessellationHints* _hints;
|
|
||||||
FakeGLBeginEndAdapter gl;
|
|
||||||
protected:
|
|
||||||
|
|
||||||
ShapeToGeometryVisitor& operator = (const ShapeToGeometryVisitor&) { return *this; }
|
|
||||||
enum SphereHalf { SphereTopHalf, SphereBottomHalf };
|
|
||||||
|
|
||||||
// helpers for apply( Cylinder | Sphere | Capsule )
|
|
||||||
void drawCylinderBody(unsigned int numSegments, float radius, float height);
|
|
||||||
void drawHalfSphere(unsigned int numSegments, unsigned int numRows, float radius, SphereHalf which, float zOffset = 0.0f);
|
|
||||||
};
|
|
||||||
|
|
||||||
osg::Geometry* convertShapeToGeometry(const osg::Shape& shape, const osg::TessellationHints* hints);
|
|
||||||
|
|
||||||
osg::Geometry* convertShapeToGeometry(const osg::Shape& shape, const osg::TessellationHints* hints, const osg::Vec4& color);
|
|
||||||
|
|
||||||
osg::Geode* convertShapeToGeode(const osg::Shape& shape, const osg::TessellationHints* hints);
|
osg::Geode* convertShapeToGeode(const osg::Shape& shape, const osg::TessellationHints* hints);
|
||||||
|
|
||||||
osg::Geode* convertShapeToGeode(const osg::Shape& shape, const osg::TessellationHints* hints, const osg::Vec4& color);
|
osg::Geode* convertShapeToGeode(const osg::Shape& shape, const osg::TessellationHints* hints, const osg::Vec4& color);
|
||||||
|
|
||||||
|
|
||||||
// example : how to use convertShapeToGeometry()
|
|
||||||
// osg::ref_ptr<osg::Capsule> shape = new osg::Capsule( osg::Vec3( 0.0, 0.0, 0.0 ), radius, height );
|
|
||||||
// osg::ref_ptr<osg::TessellationHints> tessHints = new osg::TessellationHints;
|
|
||||||
// tessHints->setDetailRatio(0.5f);
|
|
||||||
// tessHints->setCreateTextureCoords(true);
|
|
||||||
// osg::ref_ptr<osg::Geometry> capsuleGeometry = convertShapeToGeometry(*shape.get(), tessHints.get());
|
|
||||||
// osg::ref_ptr<osg::Geometry> redCapsuleGeometry = convertShapeToGeometry(*shape.get(), tessHints.get(), osg::Vec4(1.0,0.0,0.0,1.0) );
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -925,7 +925,7 @@ osg::Group* createCar( float detailRatio, const osg::Vec4& hullColor, const osg:
|
|||||||
|
|
||||||
osg::ref_ptr<osg::Group> root = new osg::Group;
|
osg::ref_ptr<osg::Group> root = new osg::Group;
|
||||||
osg::ref_ptr<osg::Cylinder> wheel = new osg::Cylinder( osg::Vec3( 0.0, 0.0, 0.0 ), 1.0, 0.6 );
|
osg::ref_ptr<osg::Cylinder> wheel = new osg::Cylinder( osg::Vec3( 0.0, 0.0, 0.0 ), 1.0, 0.6 );
|
||||||
osg::ref_ptr<osg::Geometry> wheelGeom = convertShapeToGeometry( *wheel.get(), tessHints.get(), wheelColor );
|
osg::ref_ptr<osg::Geometry> wheelGeom = osg::convertShapeToGeometry( *wheel.get(), tessHints.get(), wheelColor, osg::Array::BIND_PER_VERTEX );
|
||||||
// one random triangle on every wheel will use black color to show that wheel is rotating
|
// one random triangle on every wheel will use black color to show that wheel is rotating
|
||||||
osg::Vec4Array* colorArray = dynamic_cast<osg::Vec4Array*>( wheelGeom->getColorArray() );
|
osg::Vec4Array* colorArray = dynamic_cast<osg::Vec4Array*>( wheelGeom->getColorArray() );
|
||||||
if(colorArray!=NULL)
|
if(colorArray!=NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user