Removed long unused and out of date DX writer plugin from distribution, will now
be placed on the wiki just in case its needed.
This commit is contained in:
@@ -1,642 +0,0 @@
|
||||
#include <osg/GeoSet>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "AreaGeoSetTriangulator.h"
|
||||
|
||||
namespace dx {
|
||||
|
||||
class AreaGeoSetTriangulator
|
||||
// Used to convert area primitive GeoSets into TRIANGLE Geosets.
|
||||
// Efficiently collects the various data arrays, which GeoSet can't do.
|
||||
{
|
||||
protected:
|
||||
std::vector< unsigned int > _cindex;
|
||||
std::vector< unsigned int > _nindex;
|
||||
std::vector< unsigned int > _colindex;
|
||||
std::vector< unsigned int > _tindex;
|
||||
const osg::GeoSet &_area_geoset;
|
||||
|
||||
public:
|
||||
AreaGeoSetTriangulator( const osg::GeoSet &area_geoset );
|
||||
|
||||
void operator() ( unsigned int v1, unsigned int v2, unsigned int v3,
|
||||
unsigned int prim_index, unsigned int prim_tri_index,
|
||||
unsigned int v1_geoset, unsigned int v2_geoset,
|
||||
unsigned int v3_geoset );
|
||||
// Passed triangles as primitives are triangulated
|
||||
|
||||
osg::GeoSet *BuildGeoSet();
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
AreaGeoSetTriangulator::AreaGeoSetTriangulator( const osg::GeoSet &area_geoset)
|
||||
: _area_geoset(area_geoset)
|
||||
{
|
||||
// Check type
|
||||
switch ( area_geoset.getPrimType() ) {
|
||||
case osg::GeoSet::TRIANGLE_STRIP:
|
||||
case osg::GeoSet::FLAT_TRIANGLE_STRIP:
|
||||
case osg::GeoSet::TRIANGLES:
|
||||
case osg::GeoSet::QUAD_STRIP:
|
||||
case osg::GeoSet::QUADS:
|
||||
case osg::GeoSet::TRIANGLE_FAN:
|
||||
case osg::GeoSet::FLAT_TRIANGLE_FAN:
|
||||
case osg::GeoSet::POLYGON:
|
||||
break;
|
||||
default:
|
||||
fprintf( stderr,
|
||||
"Invalid primitive type passed to AreaGeoSetTriangulator\n" );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: _coords, _normals, _colors, and _tcoords are maintained
|
||||
// from the original geoset. The new geoset will always have
|
||||
// indexed coords/normals/colors/tcoords (to save space).
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
void AreaGeoSetTriangulator::operator() (
|
||||
unsigned int v1, unsigned int v2, unsigned int v3,
|
||||
unsigned int prim_index, unsigned int prim_tri_index,
|
||||
unsigned int v1_geoset, unsigned int v2_geoset,
|
||||
unsigned int v3_geoset )
|
||||
// Passed triangles as primitives are triangulated from the original
|
||||
// GeoSet. Note that the v? params are indicies into the Coord array,
|
||||
// whereas the v?_geoset params are vertex numbers relative to the
|
||||
// entire "area GeoSet" (which are different when the coords are
|
||||
// indexed). The latter is needed to look up colors/normals/tcoords).
|
||||
{
|
||||
osg::GeoSet::BindingType binding;
|
||||
osg::GeoSet::PrimitiveType primtype = _area_geoset.getPrimType();
|
||||
int area_is_flatprim = ( primtype == osg::GeoSet::FLAT_TRIANGLE_STRIP ||
|
||||
primtype == osg::GeoSet::FLAT_TRIANGLE_FAN );
|
||||
|
||||
// Store the triangle coord indicies
|
||||
_cindex.push_back( v1 );
|
||||
_cindex.push_back( v2 );
|
||||
_cindex.push_back( v3 );
|
||||
|
||||
int index;
|
||||
const osg::GeoSet::IndexPointer *ip;
|
||||
|
||||
// Store normals (as needed)
|
||||
if ( _area_geoset.getNumNormals() ) {
|
||||
ip = &_area_geoset.getNormalIndices();
|
||||
|
||||
// Grrr... FLAT_ primitives lie about binding type... like Performer
|
||||
binding = _area_geoset.getNormalBinding();
|
||||
if ( area_is_flatprim && binding == osg::GeoSet::BIND_PERVERTEX )
|
||||
binding = osg::GeoSet::BIND_PERPRIM;
|
||||
|
||||
switch ( binding ) {
|
||||
|
||||
case osg::GeoSet::BIND_OVERALL : // Only once
|
||||
if ( prim_index == 0 && prim_tri_index == 0 ) {
|
||||
index = ip->valid() ? (*ip)[0] : 0;
|
||||
_nindex.push_back( index );
|
||||
break;
|
||||
}
|
||||
|
||||
case osg::GeoSet::BIND_PERPRIM : // Once per tri
|
||||
index = ip->valid() ? (*ip)[prim_index] : prim_index;
|
||||
_nindex.push_back( index );
|
||||
break;
|
||||
|
||||
case osg::GeoSet::BIND_PERVERTEX : // Each vertex
|
||||
index = ip->valid() ? (*ip)[v1_geoset] : v1_geoset;
|
||||
_nindex.push_back( index );
|
||||
index = ip->valid() ? (*ip)[v2_geoset] : v2_geoset;
|
||||
_nindex.push_back( index );
|
||||
index = ip->valid() ? (*ip)[v3_geoset] : v3_geoset;
|
||||
_nindex.push_back( index );
|
||||
break;
|
||||
|
||||
case osg::GeoSet::BIND_OFF:
|
||||
case osg::GeoSet::BIND_DEFAULT:
|
||||
// Nonsensical cases
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Store colors (as needed)
|
||||
if ( _area_geoset.getNumColors() ) {
|
||||
ip = &_area_geoset.getColorIndices();
|
||||
|
||||
// Grrr... FLAT_ primitives lie about binding type... like Performer
|
||||
binding = _area_geoset.getColorBinding();
|
||||
if ( area_is_flatprim && binding == osg::GeoSet::BIND_PERVERTEX )
|
||||
binding = osg::GeoSet::BIND_PERPRIM;
|
||||
|
||||
switch ( binding ) {
|
||||
|
||||
case osg::GeoSet::BIND_OVERALL : // Only once
|
||||
if ( prim_index == 0 && prim_tri_index == 0 ) {
|
||||
index = ip->valid() ? (*ip)[0] : 0;
|
||||
_colindex.push_back( index );
|
||||
break;
|
||||
}
|
||||
|
||||
case osg::GeoSet::BIND_PERPRIM : // Once per tri
|
||||
index = ip->valid() ? (*ip)[prim_index] : prim_index;
|
||||
_colindex.push_back( index );
|
||||
break;
|
||||
|
||||
case osg::GeoSet::BIND_PERVERTEX : // Each vertex
|
||||
index = ip->valid() ? (*ip)[v1_geoset] : v1_geoset;
|
||||
_colindex.push_back( index );
|
||||
index = ip->valid() ? (*ip)[v2_geoset] : v2_geoset;
|
||||
_colindex.push_back( index );
|
||||
index = ip->valid() ? (*ip)[v3_geoset] : v3_geoset;
|
||||
_colindex.push_back( index );
|
||||
break;
|
||||
|
||||
case osg::GeoSet::BIND_OFF:
|
||||
case osg::GeoSet::BIND_DEFAULT:
|
||||
// Nonsensical cases
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Store tcoords (as needed)
|
||||
if ( _area_geoset.getNumTextureCoords() ) {
|
||||
ip = &_area_geoset.getTextureIndices();
|
||||
|
||||
switch ( _area_geoset.getTextureBinding() ) {
|
||||
|
||||
case osg::GeoSet::BIND_OVERALL : // Only once
|
||||
if ( prim_index == 0 && prim_tri_index == 0 ) {
|
||||
index = ip->valid() ? (*ip)[0] : 0;
|
||||
_tindex.push_back( index );
|
||||
break;
|
||||
}
|
||||
|
||||
case osg::GeoSet::BIND_PERPRIM : // Once per tri
|
||||
index = ip->valid() ? (*ip)[prim_index] : prim_index;
|
||||
_tindex.push_back( index );
|
||||
break;
|
||||
|
||||
case osg::GeoSet::BIND_PERVERTEX : // Each vertex
|
||||
index = ip->valid() ? (*ip)[v1_geoset] : v1_geoset;
|
||||
_tindex.push_back( index );
|
||||
index = ip->valid() ? (*ip)[v2_geoset] : v2_geoset;
|
||||
_tindex.push_back( index );
|
||||
index = ip->valid() ? (*ip)[v3_geoset] : v3_geoset;
|
||||
_tindex.push_back( index );
|
||||
break;
|
||||
|
||||
case osg::GeoSet::BIND_OFF:
|
||||
case osg::GeoSet::BIND_DEFAULT:
|
||||
// Nonsensical cases
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Shamelessly lifted from the GeoSet header and adapted for our uses
|
||||
// This is the same except that: 1) it passes the coordinate indices
|
||||
// to the op function insted of the Vec3s, and 2) it passes an original
|
||||
// primitive index and "triangle-in-primitive" index to the op function,
|
||||
// 3) it also passes the absolute vertex numbers in the primitive so they
|
||||
// can be used to look up normals/colors/tcoords, and 4) fixes some
|
||||
// problems with vertex ordering which caused FRONT/BACK confusion with
|
||||
// normals and lighting.
|
||||
// With this, we can construct a new TRIANGLE GeoSet from any area GeoSet.
|
||||
|
||||
/** Template function for iterating through a GeoSet operating on triangles
|
||||
with templated functor. Function automatically decomposes quads and polygons
|
||||
into sub triangles which are passed onto functor.*/
|
||||
|
||||
template<class T>
|
||||
void for_each_triangle2(const osg::GeoSet& gset,T& op)
|
||||
{
|
||||
switch(gset.getPrimType())
|
||||
{
|
||||
case(osg::GeoSet::TRIANGLE_STRIP):
|
||||
case(osg::GeoSet::FLAT_TRIANGLE_STRIP):
|
||||
{
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
unsigned short* base = gset.getCoordIndices()._ptr._ushort;
|
||||
unsigned short* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
unsigned short* iend = iptr+primLength;
|
||||
int tri=0;
|
||||
for(int j = 2; j < primLength; j++ )
|
||||
{
|
||||
if( !(j%2) )
|
||||
op(*(iptr),*(iptr+1),*(iptr+2),i,tri++,
|
||||
iptr-base,(iptr+1)-base,(iptr+2)-base);
|
||||
else
|
||||
op(*(iptr),*(iptr+2),*(iptr+1),i,tri++,
|
||||
iptr-base,(iptr+2)-base,(iptr+1)-base);
|
||||
++iptr;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* base = gset.getCoordIndices()._ptr._uint;
|
||||
GLuint* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
GLuint* iend = iptr+primLength;
|
||||
int tri=0;
|
||||
for(int j = 2; j < primLength; j++ )
|
||||
{
|
||||
if( !(j%2) )
|
||||
op(*(iptr),*(iptr+1),*(iptr+2),i,tri++,
|
||||
iptr-base,(iptr+1)-base,(iptr+2)-base);
|
||||
else
|
||||
op(*(iptr),*(iptr+2),*(iptr+1),i,tri++,
|
||||
iptr-base,(iptr+2)-base,(iptr+1)-base);
|
||||
++iptr;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int cindex = 0;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
unsigned int cindex_end = cindex+primLength;
|
||||
int tri=0;
|
||||
for(int j = 2; j < primLength; j++ )
|
||||
{
|
||||
if( !(j%2) )
|
||||
op(cindex,cindex+1,cindex+2,i,tri++,
|
||||
cindex,cindex+1,cindex+2);
|
||||
else
|
||||
op(cindex,cindex+2,cindex+1,i,tri++,
|
||||
cindex,cindex+2,cindex+1);
|
||||
++cindex;
|
||||
}
|
||||
cindex = cindex_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case(osg::GeoSet::TRIANGLES):
|
||||
{
|
||||
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
unsigned short* base = gset.getCoordIndices()._ptr._ushort;
|
||||
unsigned short* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(*(iptr),*(iptr+1),*(iptr+2),i,0,
|
||||
iptr-base,(iptr+1)-base,(iptr+2)-base);
|
||||
iptr+=3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* base = gset.getCoordIndices()._ptr._uint;
|
||||
GLuint* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(*(iptr),*(iptr+1),*(iptr+2),i,0,
|
||||
iptr-base,(iptr+1)-base,(iptr+2)-base);
|
||||
iptr+=3;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int cindex = 0;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(cindex,cindex+1,cindex+2,i,0,
|
||||
cindex,cindex+1,cindex+2);
|
||||
cindex+=3;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case(osg::GeoSet::QUAD_STRIP):
|
||||
{
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
unsigned short* base = gset.getCoordIndices()._ptr._ushort;
|
||||
unsigned short* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
unsigned short* iend = iptr+primLength;
|
||||
int tri=0;
|
||||
for(int j = 3; j < primLength; j+=2 )
|
||||
{
|
||||
op(*(iptr),*(iptr+1),*(iptr+2),i,tri++,
|
||||
iptr-base,(iptr+1)-base,(iptr+2)-base);
|
||||
// rhh FIXME: FIXED 1st vert offset
|
||||
op(*(iptr+1),*(iptr+3),*(iptr+2),i,tri++,
|
||||
(iptr+1)-base,(iptr+3)-base,(iptr+2)-base);
|
||||
iptr+=2;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* base = gset.getCoordIndices()._ptr._uint;
|
||||
GLuint* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
GLuint* iend = iptr+primLength;
|
||||
int tri=0;
|
||||
for(int j = 3; j < primLength; j+=2 )
|
||||
{
|
||||
op(*(iptr),*(iptr+1),*(iptr+2),i,tri++,
|
||||
iptr-base,(iptr+1)-base,(iptr+2)-base);
|
||||
op(*(iptr+1),*(iptr+3),*(iptr+2),i,tri++,
|
||||
(iptr+1)-base,(iptr+3)-base,(iptr+2)-base);
|
||||
iptr+=2;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int cindex = 0;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
unsigned int cindex_end = cindex+primLength;
|
||||
int tri=0;
|
||||
for(int j = 3; j < primLength; j+=2 )
|
||||
{
|
||||
op(cindex,cindex+1,cindex+2,i,tri++,
|
||||
cindex,cindex+1,cindex+2);
|
||||
op(cindex+1,cindex+3,cindex+2,i,tri++,
|
||||
cindex+1,cindex+3,cindex+2);
|
||||
cindex+=2;
|
||||
}
|
||||
cindex = cindex_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case(osg::GeoSet::QUADS):
|
||||
{
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
unsigned short* base = gset.getCoordIndices()._ptr._ushort;
|
||||
unsigned short* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(*(iptr),*(iptr+1),*(iptr+2),i,0,
|
||||
iptr-base,(iptr+1)-base,(iptr+2)-base);
|
||||
// rhh FIXME: FIXED 2nd & 3rd vert offset
|
||||
op(*(iptr),*(iptr+2),*(iptr+3),i,1,
|
||||
iptr-base,(iptr+2)-base,(iptr+3)-base);
|
||||
iptr+=4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* base = gset.getCoordIndices()._ptr._uint;
|
||||
GLuint* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(*(iptr),*(iptr+1),*(iptr+2),i,0,
|
||||
iptr-base,(iptr+1)-base,(iptr+2)-base);
|
||||
op(*(iptr),*(iptr+2),*(iptr+3),i,1,
|
||||
iptr-base,(iptr+2)-base,(iptr+3)-base);
|
||||
iptr+=4;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int cindex = 0;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(cindex,cindex+1,cindex+2,i,0,
|
||||
cindex,cindex+1,cindex+2);
|
||||
op(cindex,cindex+2,cindex+3,i,1,
|
||||
cindex,cindex+2,cindex+3);
|
||||
cindex+=4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case(osg::GeoSet::TRIANGLE_FAN):
|
||||
case(osg::GeoSet::FLAT_TRIANGLE_FAN): // FIXME: rhh added
|
||||
case(osg::GeoSet::POLYGON):
|
||||
{
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
unsigned short* base = gset.getCoordIndices()._ptr._ushort;
|
||||
unsigned short* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
int tri=0;
|
||||
if (primLength>0)
|
||||
{
|
||||
unsigned short *start = iptr;
|
||||
unsigned short* iend = iptr+primLength;
|
||||
++iptr;
|
||||
for(int j = 2; j < primLength; ++j )
|
||||
{
|
||||
op(*start,*(iptr),*(iptr+1),i,tri++,
|
||||
start-base, iptr-base,(iptr+1)-base);
|
||||
++iptr;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* base = gset.getCoordIndices()._ptr._uint;
|
||||
GLuint* iptr = base;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
int tri=0;
|
||||
if (primLength>0)
|
||||
{
|
||||
GLuint *start = iptr;
|
||||
GLuint* iend = iptr+primLength;
|
||||
++iptr;
|
||||
for(int j = 2; j < primLength; ++j )
|
||||
{
|
||||
op(*start,*(iptr),*(iptr+1),i,tri++,
|
||||
start-base, iptr-base,(iptr+1)-base);
|
||||
++iptr;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int cindex = 0;
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
int tri=0;
|
||||
if (primLength>0)
|
||||
{
|
||||
unsigned int cindex_start = cindex;
|
||||
unsigned int cindex_end = cindex+primLength;
|
||||
++cindex;
|
||||
for(int j = 2; j < primLength; ++j)
|
||||
{
|
||||
op(cindex_start,cindex,cindex+1,i,tri++,
|
||||
cindex_start,cindex,cindex+1);
|
||||
++cindex;
|
||||
}
|
||||
cindex = cindex_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
osg::GeoSet *AreaGeoSetTriangulator::BuildGeoSet()
|
||||
// After a triangulation pass, generate a valid TRIANGLE GeoSet containing
|
||||
// the resulting triangles (w/ colors, normals, and tcoords).
|
||||
{
|
||||
int num_tris = _cindex.size() / 3;
|
||||
|
||||
osg::GeoSet *res = new osg::GeoSet;
|
||||
res->setPrimType( osg::GeoSet::TRIANGLES );
|
||||
res->setNumPrims( num_tris );
|
||||
|
||||
// First, dup all of the data arrays -- they haven't changed
|
||||
// NOTE: We generate fresh arrays for the new GeoSet to be compatible
|
||||
// with the delete [] behavior of the default GeoSet
|
||||
// AttributeDeleteFunctor, which is invoked in GeoSet::~GeoSet.
|
||||
|
||||
osg::Vec3 *new_coords = 0;
|
||||
osg::Vec3 *new_normals = 0;
|
||||
osg::Vec4 *new_colors = 0;
|
||||
osg::Vec2 *new_tcoords = 0;
|
||||
|
||||
const osg::Vec3 *coords = _area_geoset.getCoords();
|
||||
const osg::Vec3 *normals = _area_geoset.getNormals();
|
||||
const osg::Vec4 *colors = _area_geoset.getColors();
|
||||
const osg::Vec2 *tcoords = _area_geoset.getTextureCoords();
|
||||
|
||||
if ( coords )
|
||||
new_coords = new osg::Vec3[ _area_geoset.getNumCoords() ];
|
||||
if ( normals )
|
||||
new_normals = new osg::Vec3[ _area_geoset.getNumNormals() ];
|
||||
if ( colors )
|
||||
new_colors = new osg::Vec4[ _area_geoset.getNumColors() ];
|
||||
if ( tcoords )
|
||||
new_tcoords = new osg::Vec2[ _area_geoset.getNumTextureCoords() ];
|
||||
|
||||
memcpy( new_coords, coords,
|
||||
sizeof(osg::Vec3) * _area_geoset.getNumCoords() );
|
||||
memcpy( new_normals, normals,
|
||||
sizeof(osg::Vec3) * _area_geoset.getNumNormals() );
|
||||
memcpy( new_colors, colors,
|
||||
sizeof(osg::Vec4) * _area_geoset.getNumColors() );
|
||||
memcpy( new_tcoords, tcoords,
|
||||
sizeof(osg::Vec2) * _area_geoset.getNumTextureCoords() );
|
||||
|
||||
// Now generate the index arrays
|
||||
GLuint *new_cindex = 0;
|
||||
GLuint *new_nindex = 0;
|
||||
GLuint *new_colindex = 0;
|
||||
GLuint *new_tindex = 0;
|
||||
|
||||
if ( _cindex.size() ) new_cindex = new GLuint[ _cindex.size() ];
|
||||
if ( _nindex.size() ) new_nindex = new GLuint[ _nindex.size() ];
|
||||
if ( _colindex.size() ) new_colindex = new GLuint[ _colindex.size() ];
|
||||
if ( _tindex.size() ) new_tindex = new GLuint[ _tindex.size() ];
|
||||
|
||||
memcpy( new_cindex , &_cindex [0], sizeof(GLuint) * _cindex.size() );
|
||||
memcpy( new_nindex , &_nindex [0], sizeof(GLuint) * _nindex.size() );
|
||||
memcpy( new_colindex, &_colindex[0], sizeof(GLuint) * _colindex.size() );
|
||||
memcpy( new_tindex , &_tindex [0], sizeof(GLuint) * _tindex.size() );
|
||||
|
||||
res->setCoords ( new_coords , new_cindex );
|
||||
res->setNormals( new_normals, new_nindex );
|
||||
res->setColors ( new_colors , new_colindex );
|
||||
res->setTextureCoords( new_tcoords, new_tindex );
|
||||
|
||||
// And finally, set the normal/color/tcoord binding
|
||||
// (Grrr... FLAT_ primitives lie about binding type... like Performer)
|
||||
osg::GeoSet::BindingType nbinding = _area_geoset.getNormalBinding();
|
||||
osg::GeoSet::BindingType cbinding = _area_geoset.getColorBinding();
|
||||
if ( _area_geoset.getPrimType() == osg::GeoSet::FLAT_TRIANGLE_STRIP ||
|
||||
_area_geoset.getPrimType() == osg::GeoSet::FLAT_TRIANGLE_FAN ) {
|
||||
if ( nbinding == osg::GeoSet::BIND_PERVERTEX )
|
||||
nbinding = osg::GeoSet::BIND_PERPRIM;
|
||||
if ( cbinding == osg::GeoSet::BIND_PERVERTEX )
|
||||
cbinding = osg::GeoSet::BIND_PERPRIM;
|
||||
}
|
||||
|
||||
res->setNormalBinding ( nbinding );
|
||||
res->setColorBinding ( cbinding );
|
||||
res->setTextureBinding( _area_geoset.getTextureBinding() );
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
osg::GeoSet *TriangulateAreaGeoSet( const osg::GeoSet &geoset )
|
||||
// The strategy here is to generate new coord/normal/color/tcoord index
|
||||
// arrays as we bust up the primitives into triangles. The data arrays
|
||||
// don't change between the old and new geoset.
|
||||
{
|
||||
geoset.computeNumVerts(); // Update # coords/# normals from index arrays
|
||||
|
||||
AreaGeoSetTriangulator triangulator( geoset );
|
||||
for_each_triangle2( geoset, triangulator );
|
||||
return triangulator.BuildGeoSet();
|
||||
}
|
||||
|
||||
}; // namespace dx
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef __OSG_AREA_GEOSET_TRIANGULATOR_H
|
||||
#define __OSG_AREA_GEOSET_TRIANGULATOR_H
|
||||
|
||||
#include <osg/GeoSet>
|
||||
|
||||
namespace dx {
|
||||
|
||||
osg::GeoSet *TriangulateAreaGeoSet( const osg::GeoSet &geoset );
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,49 +0,0 @@
|
||||
// This plugin writes an IBM Data Explorer (aka OpenDX) native file.
|
||||
// (c) Randall Hopper, 2002.
|
||||
//
|
||||
// For details on the OpenDX visualization tool, its use, and its file format,
|
||||
// refer to:
|
||||
//
|
||||
// http://www.opendx.org/
|
||||
// http://www.opendx.org/support.html#docs
|
||||
// http://www.research.ibm.com/dx/
|
||||
// http://ftp.cs.umt.edu/DX/
|
||||
//
|
||||
// SUPPORTED : Refer to DXWriter.cpp
|
||||
// UNSUPPORTED: Refer to DXWriter.cpp
|
||||
//
|
||||
|
||||
// DXWriter.h
|
||||
|
||||
#ifndef __OSG_DXWRITER_H
|
||||
#define __OSG_DXWRITER_H
|
||||
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Node>
|
||||
|
||||
const int DX_PATH_MAX = 512;
|
||||
|
||||
namespace dx {
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
struct WriterParms {
|
||||
bool set_default_color; // Give color to uncolored objects
|
||||
osg::Vec4 default_color; // Color to assign to uncolored objects
|
||||
char outfile[ DX_PATH_MAX ]; // Output pathname
|
||||
//bool binary_mode; // Write DX arrays in binary format
|
||||
|
||||
WriterParms()
|
||||
{ set_default_color = 0, outfile[0] = '\0'; }
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
bool WriteDX( const osg::Node &node, WriterParms &parms,
|
||||
std::string &messages );
|
||||
|
||||
}; // namespace dx
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#endif // __OSG_DXWRITER_H
|
||||
@@ -1,16 +0,0 @@
|
||||
TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
ReaderWriterDX.cpp \
|
||||
DXWriter.cpp \
|
||||
AreaGeoSetTriangulator.cpp \
|
||||
StateSetStr.cpp
|
||||
|
||||
LIBS += $(OSG_LIBS) $(GLUT_LIBS) $(OTHER_LIBS)
|
||||
|
||||
TARGET_BASENAME = dx
|
||||
include $(TOPDIR)/Make/cygwin_plugin_def
|
||||
PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
@@ -1,75 +0,0 @@
|
||||
// This plugin writes an IBM Data Explorer (aka OpenDX) native file.
|
||||
// (c) Randall Hopper, 2002.
|
||||
//
|
||||
// For details on the OpenDX visualization tool, its use, and its file format,
|
||||
// refer to:
|
||||
//
|
||||
// http://www.opendx.org/
|
||||
// http://www.opendx.org/support.html#docs
|
||||
// http://www.research.ibm.com/dx/
|
||||
// http://ftp.cs.umt.edu/DX/
|
||||
//
|
||||
// SUPPORTED : Refer to DXWriter.cpp
|
||||
// UNSUPPORTED: Refer to DXWriter.cpp
|
||||
//
|
||||
|
||||
// ReaderWriterDX.cpp
|
||||
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
#include "ReaderWriterDX.h"
|
||||
#include "DXWriter.h"
|
||||
|
||||
// FIXME: Support options
|
||||
osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeObject(const osg::Object &obj, const std::string &filename, const Options *options ) const
|
||||
{
|
||||
const osg::Node *node = dynamic_cast<const osg::Node *>(&obj);
|
||||
|
||||
if ( node != 0 )
|
||||
return writeNode( *node, filename, options );
|
||||
else
|
||||
// FIXME: This should probably be "OBJECT_NOT_HANDLED"
|
||||
return osgDB::ReaderWriter::WriteResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeNode(const osg::Node &node, const std::string &filename, const Options *) const
|
||||
{
|
||||
dx::WriterParms parms;
|
||||
std::string messages;
|
||||
bool ret;
|
||||
osgDB::ReaderWriter::WriteResult result;
|
||||
|
||||
std::string ext = osgDB::getFileExtension(filename);
|
||||
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
|
||||
|
||||
parms.outfile[0] = '\0';
|
||||
strncat( parms.outfile, filename.c_str(), sizeof(parms.outfile)-1 );
|
||||
|
||||
// FIXME: Allow specification via Options
|
||||
parms.set_default_color = 1;
|
||||
parms.default_color[0] =
|
||||
parms.default_color[1] =
|
||||
parms.default_color[2] = 0.75;
|
||||
parms.default_color[3] = 1.0; // opaque light gray
|
||||
|
||||
ret = dx::WriteDX( node, parms, messages );
|
||||
|
||||
if ( ret )
|
||||
result = osgDB::ReaderWriter::WriteResult(
|
||||
osgDB::ReaderWriter::WriteResult::FILE_SAVED );
|
||||
else
|
||||
result = osgDB::ReaderWriter::WriteResult( messages );
|
||||
|
||||
osg::notify( osg::DEBUG_INFO ) << messages;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// now register with Registry to instantiate the above
|
||||
// reader/writer.
|
||||
osgDB::RegisterReaderWriterProxy<ReaderWriterDX> g_dxReaderWriterProxy;
|
||||
@@ -1,43 +0,0 @@
|
||||
// This plugin writes an IBM Data Explorer (aka OpenDX) native file.
|
||||
// (c) Randall Hopper, 2002.
|
||||
//
|
||||
// For details on the OpenDX visualization tool, its use, and its file format,
|
||||
// refer to:
|
||||
//
|
||||
// http://www.opendx.org/
|
||||
// http://www.opendx.org/support.html#docs
|
||||
// http://www.research.ibm.com/dx/
|
||||
// http://ftp.cs.umt.edu/DX/
|
||||
//
|
||||
// SUPPORTED : Refer to DXWriter.cpp
|
||||
// UNSUPPORTED: Refer to DXWriter.cpp
|
||||
//
|
||||
|
||||
// ReaderWriterDX.h
|
||||
|
||||
#ifndef __OSG_READER_WRITER_DX_H
|
||||
#define __OSG_READER_WRITER_DX_H
|
||||
|
||||
#include <string>
|
||||
#include <osg/Object>
|
||||
#include <osg/Node>
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
|
||||
class ReaderWriterDX : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
|
||||
virtual const char* className() { return "OpenDX Writer"; }
|
||||
virtual bool acceptsExtension( const std::string &extension ) const
|
||||
{ return osgDB::equalCaseInsensitive( extension, "dx" ); }
|
||||
|
||||
virtual WriteResult writeObject( const osg::Object &obj, const std::string &filename, const Options *options = NULL ) const;
|
||||
|
||||
virtual WriteResult writeNode ( const osg::Node&node, const std::string &filename, const Options *options = NULL ) const;
|
||||
|
||||
};
|
||||
|
||||
#endif // __READER_WRITER_DX_H
|
||||
@@ -1,159 +0,0 @@
|
||||
#include <osg/StateAttribute>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
namespace dx {
|
||||
|
||||
typedef std::map<osg::StateAttribute::GLMode,std::string> ModeMap;
|
||||
|
||||
static ModeMap S_mode_map;
|
||||
|
||||
#define ADD_NAME(str,mode) (S_mode_map[(mode)] = (str));
|
||||
|
||||
// This is a copy of some of the code in src/osgPlugins/osg/StateSet.cpp.
|
||||
// We need to translate GLModes and StateSet attributes into strings,
|
||||
// and that's not available in an OSG public API (yet).
|
||||
|
||||
static void initGLNames()
|
||||
{
|
||||
static bool first_time = true;
|
||||
if (!first_time) return;
|
||||
|
||||
ADD_NAME("GL_ALPHA_TEST",GL_ALPHA_TEST)
|
||||
ADD_NAME("GL_BLEND",GL_BLEND)
|
||||
ADD_NAME("GL_COLOR_MATERIAL",GL_COLOR_MATERIAL)
|
||||
ADD_NAME("GL_CULL_FACE",GL_CULL_FACE)
|
||||
ADD_NAME("GL_DEPTH_TEST",GL_DEPTH_TEST)
|
||||
ADD_NAME("GL_FOG",GL_FOG)
|
||||
ADD_NAME("GL_LIGHTING",GL_LIGHTING)
|
||||
ADD_NAME("GL_POINT_SMOOTH",GL_POINT_SMOOTH)
|
||||
ADD_NAME("GL_POLYGON_OFFSET_FILL",GL_POLYGON_OFFSET_FILL)
|
||||
ADD_NAME("GL_POLYGON_OFFSET_LINE",GL_POLYGON_OFFSET_LINE)
|
||||
ADD_NAME("GL_POLYGON_OFFSET_POINT",GL_POLYGON_OFFSET_POINT)
|
||||
|
||||
ADD_NAME("GL_TEXTURE_2D",GL_TEXTURE_2D)
|
||||
ADD_NAME("GL_TEXTURE_GEN_Q",GL_TEXTURE_GEN_Q)
|
||||
ADD_NAME("GL_TEXTURE_GEN_R",GL_TEXTURE_GEN_R)
|
||||
ADD_NAME("GL_TEXTURE_GEN_S",GL_TEXTURE_GEN_S)
|
||||
ADD_NAME("GL_TEXTURE_GEN_T",GL_TEXTURE_GEN_T)
|
||||
|
||||
ADD_NAME("GL_STENCIL_TEST",GL_STENCIL_TEST)
|
||||
|
||||
ADD_NAME("GL_CLIP_PLANE0",GL_CLIP_PLANE0);
|
||||
ADD_NAME("GL_CLIP_PLANE1",GL_CLIP_PLANE1);
|
||||
ADD_NAME("GL_CLIP_PLANE2",GL_CLIP_PLANE2);
|
||||
ADD_NAME("GL_CLIP_PLANE3",GL_CLIP_PLANE3);
|
||||
ADD_NAME("GL_CLIP_PLANE4",GL_CLIP_PLANE4);
|
||||
ADD_NAME("GL_CLIP_PLANE5",GL_CLIP_PLANE5);
|
||||
|
||||
ADD_NAME("GL_LIGHT0",GL_LIGHT0);
|
||||
ADD_NAME("GL_LIGHT1",GL_LIGHT1);
|
||||
ADD_NAME("GL_LIGHT2",GL_LIGHT2);
|
||||
ADD_NAME("GL_LIGHT3",GL_LIGHT3);
|
||||
ADD_NAME("GL_LIGHT4",GL_LIGHT4);
|
||||
ADD_NAME("GL_LIGHT5",GL_LIGHT5);
|
||||
ADD_NAME("GL_LIGHT6",GL_LIGHT6);
|
||||
ADD_NAME("GL_LIGHT7",GL_LIGHT7);
|
||||
|
||||
first_time = false;
|
||||
}
|
||||
|
||||
const char *GLModeToModeStr( osg::StateAttribute::GLMode mode )
|
||||
{
|
||||
initGLNames();
|
||||
ModeMap::const_iterator mitr = S_mode_map.find(mode);
|
||||
if ( mitr != S_mode_map.end() )
|
||||
return mitr->second.c_str();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::StateAttribute::GLMode GLModeStrToMode( const char mode_str[] )
|
||||
{
|
||||
initGLNames();
|
||||
for( ModeMap::const_iterator mitr = S_mode_map.begin();
|
||||
mitr != S_mode_map.end();
|
||||
++mitr )
|
||||
if ( strcmp( mode_str, mitr->second.c_str() ) == 0 )
|
||||
return mitr->first;
|
||||
return (osg::StateAttribute::GLMode) -1;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
||||
typedef std::map<osg::StateAttribute::Type,std::string> AttrMap;
|
||||
|
||||
static AttrMap S_attr_map;
|
||||
|
||||
#define ADD_ATTR(attr,str) (S_attr_map[(attr)] = (str));
|
||||
|
||||
static void initOSGAttrNames()
|
||||
{
|
||||
static bool first_time = true;
|
||||
if (!first_time) return;
|
||||
|
||||
ADD_ATTR( osg::StateAttribute::TEXTURE , "TEXTURE" );
|
||||
ADD_ATTR( osg::StateAttribute::MATERIAL , "MATERIAL" );
|
||||
ADD_ATTR( osg::StateAttribute::ALPHAFUNC , "ALPHAFUNC" );
|
||||
ADD_ATTR( osg::StateAttribute::ANTIALIAS , "ANTIALIAS" );
|
||||
ADD_ATTR( osg::StateAttribute::COLORTABLE , "COLORTABLE" );
|
||||
ADD_ATTR( osg::StateAttribute::CULLFACE , "CULLFACE" );
|
||||
ADD_ATTR( osg::StateAttribute::FOG , "FOG" );
|
||||
ADD_ATTR( osg::StateAttribute::FRONTFACE , "FRONTFACE" );
|
||||
ADD_ATTR( osg::StateAttribute::LIGHT , "LIGHT" );
|
||||
ADD_ATTR( osg::StateAttribute::LIGHT_0 , "LIGHT_0" );
|
||||
ADD_ATTR( osg::StateAttribute::LIGHT_1 , "LIGHT_1" );
|
||||
ADD_ATTR( osg::StateAttribute::LIGHT_2 , "LIGHT_2" );
|
||||
ADD_ATTR( osg::StateAttribute::LIGHT_3 , "LIGHT_3" );
|
||||
ADD_ATTR( osg::StateAttribute::LIGHT_4 , "LIGHT_4" );
|
||||
ADD_ATTR( osg::StateAttribute::LIGHT_5 , "LIGHT_5" );
|
||||
ADD_ATTR( osg::StateAttribute::LIGHT_6 , "LIGHT_6" );
|
||||
ADD_ATTR( osg::StateAttribute::LIGHT_7 , "LIGHT_7" );
|
||||
ADD_ATTR( osg::StateAttribute::POINT , "POINT" );
|
||||
ADD_ATTR( osg::StateAttribute::LINEWIDTH , "LINEWIDTH" );
|
||||
ADD_ATTR( osg::StateAttribute::POLYGONMODE , "POLYGONMODE" );
|
||||
ADD_ATTR( osg::StateAttribute::POLYGONOFFSET , "POLYGONOFFSET");
|
||||
ADD_ATTR( osg::StateAttribute::TEXENV , "TEXENV" );
|
||||
ADD_ATTR( osg::StateAttribute::TEXGEN , "TEXGEN" );
|
||||
ADD_ATTR( osg::StateAttribute::TEXMAT , "TEXMAT" );
|
||||
ADD_ATTR( osg::StateAttribute::BLENDFUNC , "BLENDFUNC" );
|
||||
ADD_ATTR( osg::StateAttribute::STENCIL , "STENCIL" );
|
||||
ADD_ATTR( osg::StateAttribute::COLORMASK , "COLORMASK" );
|
||||
ADD_ATTR( osg::StateAttribute::DEPTH , "DEPTH" );
|
||||
ADD_ATTR( osg::StateAttribute::VIEWPORT , "VIEWPORT" );
|
||||
ADD_ATTR( osg::StateAttribute::CLIPPLANE , "CLIPPLANE" );
|
||||
ADD_ATTR( osg::StateAttribute::CLIPPLANE_0 , "CLIPPLANE_0" );
|
||||
ADD_ATTR( osg::StateAttribute::CLIPPLANE_1 , "CLIPPLANE_1" );
|
||||
ADD_ATTR( osg::StateAttribute::CLIPPLANE_2 , "CLIPPLANE_2" );
|
||||
ADD_ATTR( osg::StateAttribute::CLIPPLANE_3 , "CLIPPLANE_3" );
|
||||
ADD_ATTR( osg::StateAttribute::CLIPPLANE_4 , "CLIPPLANE_4" );
|
||||
ADD_ATTR( osg::StateAttribute::CLIPPLANE_5 , "CLIPPLANE_5" );
|
||||
ADD_ATTR( osg::StateAttribute::COLORMATRIX , "COLORMATRIX" );
|
||||
|
||||
first_time = false;
|
||||
}
|
||||
|
||||
const char *OSGAttrToAttrStr( osg::StateAttribute::Type attr )
|
||||
{
|
||||
initOSGAttrNames();
|
||||
AttrMap::const_iterator aitr = S_attr_map.find(attr);
|
||||
if ( aitr != S_attr_map.end() )
|
||||
return aitr->second.c_str();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::StateAttribute::Type OSGAttrStrToAttr( const char attr_str[] )
|
||||
{
|
||||
initGLNames();
|
||||
for( AttrMap::const_iterator aitr = S_attr_map.begin();
|
||||
aitr != S_attr_map.end();
|
||||
++aitr )
|
||||
if ( strcmp( attr_str, aitr->second.c_str() ) == 0 )
|
||||
return aitr->first;
|
||||
return (osg::StateAttribute::Type) -1;
|
||||
}
|
||||
|
||||
}; // namespace dx
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef __OSG_STATESETSTR_H
|
||||
#define __OSG_STATESETSTR_H
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
|
||||
namespace dx {
|
||||
|
||||
const char *GLModeToModeStr( osg::StateAttribute::GLMode mode );
|
||||
|
||||
osg::StateAttribute::GLMode GLModeStrToMode( const char mode_str[] );
|
||||
|
||||
const char *OSGAttrToAttrStr( osg::StateAttribute::Type attr );
|
||||
|
||||
osg::StateAttribute::Type OSGAttrStrToAttr( const char attr_str[] );
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user