Removed osg::GeoSet for core osg lib and osgPlugin.

Commented out OpenDX plugin as its still based on GeoSet.

Added support for loading and converting GeoSet into the osgconv example.
This commit is contained in:
Robert Osfield
2003-05-21 12:15:45 +00:00
parent fcbbf12b75
commit 4a6bdad3e1
25 changed files with 109 additions and 4326 deletions

View File

@@ -34,8 +34,6 @@ CXXFILES =\
FrontFace.cpp\
GLExtensions.cpp\
Geometry.cpp\
GeoSet.cpp\
GeoSet_ogl.cpp\
Geode.cpp\
Group.cpp\
Image.cpp\

File diff suppressed because it is too large Load Diff

View File

@@ -1,521 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#endif
#include <stdio.h>
#include <osg/GL>
#include <osg/GeoSet>
#include <osg/Notify>
using namespace osg;
#define DEBUG
#define DO_SHADING 1
#define I_ON (1<<4)
#define C_ON (1<<3)
#define N_ON (1<<2)
#define T_ON (1<<1)
#define V_ON (1<<0)
void GeoSet::set_fast_path( void )
{
if( _iaformat != IA_OFF )
{
_fast_path = I_ON;
}
else
{
if( ( _normal_binding != BIND_PERPRIM) &&
( _nindex.null() || _nindex ==_cindex) &&
( _color_binding != BIND_PERPRIM) &&
( _colindex.null() || _colindex ==_cindex ) &&
( _primtype != FLAT_LINE_STRIP ) &&
( _primtype != FLAT_TRIANGLE_STRIP ) &&
( _primtype != FLAT_TRIANGLE_FAN )
)
_fast_path = V_ON;
else
{
_fast_path = 0;
#ifdef DEBUG
if( _normal_binding == BIND_PERPRIM )
notify( DEBUG ) << "Geoset - Failed fast path because NORMALS are bound PER_PRIM\n";
if( _nindex.valid() )
notify( DEBUG ) << "Geoset - Failed fast path because NORMAL indeces are specified\n";
if( _color_binding == BIND_PERPRIM )
notify( DEBUG ) << "Geoset - Failed fast path because COLORS are bound PER_PRIM\n";
if( _cindex.valid() )
notify( DEBUG ) << "Geoset - Failed fast path because COLOR indeces are specified\n";
if( _primtype == FLAT_LINE_STRIP )
notify( DEBUG ) << "Geoset - Failed fast path because primitive is FLAT_LINE_STRIP\n";
if ( _primtype == FLAT_TRIANGLE_STRIP )
notify( DEBUG ) << "Geoset - Failed fast path because primitive is FLAT_TRIANGLE_STRIP\n";
if ( _primtype == FLAT_TRIANGLE_FAN )
notify( DEBUG ) << "Geoset - Failed fast path because primitive is FLAT_TRIANGLE_FAN\n";
#endif
}
if( _fast_path )
{
if( _color_binding == BIND_PERVERTEX )
_fast_path |= C_ON;
if( _normal_binding == BIND_PERVERTEX )
_fast_path |= N_ON;
if( _texture_binding == BIND_PERVERTEX )
_fast_path |= T_ON;
}
}
#ifdef DEBUG
notify(INFO) << "GeoSet - fast path = " << _fast_path << "\n";
#endif
}
void GeoSet::draw_fast_path( State& state ) const
{
IndexPointer ocindex = _cindex;
switch( _fast_path )
{
case (I_ON) :
_cindex = _iaindex;
glInterleavedArrays( (GLenum)_ogliaformat, 0, _iarray );
break;
case (V_ON) :
state.disableNormalPointer();
state.disableColorPointer();
state.disableTexCoordPointersAboveAndIncluding(0);
state.setVertexPointer(3, GL_FLOAT, 0,_coords);
// glDisableClientState( GL_COLOR_ARRAY );
// glDisableClientState( GL_NORMAL_ARRAY );
// glDisableClientState( GL_TEXTURE_COORD_ARRAY );
// glEnableClientState( GL_VERTEX_ARRAY );
// glVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
break;
case (T_ON|V_ON) :
state.disableNormalPointer();
state.disableColorPointer();
state.setTexCoordPointer(0, 2, GL_FLOAT, 0, (GLfloat *)_tcoords );
state.disableTexCoordPointersAboveAndIncluding(1);
state.setVertexPointer(3, GL_FLOAT, 0,_coords);
// glDisableClientState( GL_COLOR_ARRAY );
// glDisableClientState( GL_NORMAL_ARRAY );
// glEnableClientState( GL_TEXTURE_COORD_ARRAY );
// glTexCoordPointer( 2, GL_FLOAT, 0, (GLfloat *)_tcoords );
// glEnableClientState( GL_VERTEX_ARRAY );
// glVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
break;
case (N_ON|V_ON) :
state.disableColorPointer();
state.disableTexCoordPointersAboveAndIncluding(0);
state.setVertexPointer(3, GL_FLOAT, 0,_coords);
state.setNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
// glDisableClientState( GL_COLOR_ARRAY );
// glEnableClientState( GL_NORMAL_ARRAY );
// glNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
// glDisableClientState( GL_TEXTURE_COORD_ARRAY );
// glEnableClientState( GL_VERTEX_ARRAY );
// glVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
break;
case (N_ON|T_ON|V_ON) :
state.disableColorPointer();
state.setNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
state.setTexCoordPointer(0, 2, GL_FLOAT, 0, (GLfloat *)_tcoords );
state.disableTexCoordPointersAboveAndIncluding(1);
state.setVertexPointer(3, GL_FLOAT, 0,_coords);
// glDisableClientState( GL_COLOR_ARRAY );
// glEnableClientState( GL_NORMAL_ARRAY );
// glNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
// glEnableClientState( GL_TEXTURE_COORD_ARRAY );
// glTexCoordPointer( 2, GL_FLOAT, 0, (GLfloat *)_tcoords );
// glEnableClientState( GL_VERTEX_ARRAY );
// glVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
break;
case (C_ON|V_ON) :
state.disableNormalPointer();
state.disableTexCoordPointersAboveAndIncluding(0);
state.setColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
state.setVertexPointer(3, GL_FLOAT, 0,_coords);
// glEnableClientState( GL_COLOR_ARRAY );
// glColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
// glDisableClientState( GL_NORMAL_ARRAY );
// glDisableClientState( GL_TEXTURE_COORD_ARRAY );
// glEnableClientState( GL_VERTEX_ARRAY );
// glVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
break;
case (C_ON|T_ON|V_ON) :
state.disableNormalPointer();
state.setColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
state.setTexCoordPointer(0, 2, GL_FLOAT, 0, (GLfloat *)_tcoords );
state.disableTexCoordPointersAboveAndIncluding(1);
state.setVertexPointer(3, GL_FLOAT, 0,_coords);
// glEnableClientState( GL_COLOR_ARRAY );
// glColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
// glDisableClientState( GL_NORMAL_ARRAY );
// glEnableClientState( GL_TEXTURE_COORD_ARRAY );
// glTexCoordPointer( 2, GL_FLOAT, 0, (GLfloat *)_tcoords );
// glEnableClientState( GL_VERTEX_ARRAY );
// glVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
break;
case (C_ON|N_ON|V_ON) :
state.disableTexCoordPointersAboveAndIncluding(0);
state.setNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
state.setColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
state.setVertexPointer(3, GL_FLOAT, 0,_coords);
// glEnableClientState( GL_COLOR_ARRAY );
// glColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
// glEnableClientState( GL_NORMAL_ARRAY );
// glNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
// glDisableClientState( GL_TEXTURE_COORD_ARRAY );
// glEnableClientState( GL_VERTEX_ARRAY );
// glVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
break;
case (C_ON|N_ON|T_ON|V_ON) :
state.setNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
state.setColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
state.setTexCoordPointer(0, 2, GL_FLOAT, 0, (GLfloat *)_tcoords );
state.disableTexCoordPointersAboveAndIncluding(1);
state.setVertexPointer(3, GL_FLOAT, 0,_coords);
// glEnableClientState( GL_COLOR_ARRAY );
// glColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
// glEnableClientState( GL_NORMAL_ARRAY );
// glNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
// glEnableClientState( GL_TEXTURE_COORD_ARRAY );
// glTexCoordPointer( 2, GL_FLOAT, 0, (GLfloat *)_tcoords );
// glEnableClientState( GL_VERTEX_ARRAY );
// glVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
break;
}
if( _color_binding == BIND_OVERALL )
{
if( _colindex.valid() )
glColor4fv( (GLfloat * )&_colors[_colindex[0]] );
else
glColor4fv( (GLfloat * )&_colors[0] );
}
if( _normal_binding == BIND_OVERALL )
{
if( _nindex.valid() )
glNormal3fv( (GLfloat * )&_normals[_nindex[0]] );
else
glNormal3fv( (GLfloat * )&_normals[0] );
}
if( _needprimlen ) // LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP,
// TRIANGLE_FAN, QUAD_STRIP, POLYGONS
{
int index = 0;
if( _primLengths == (int *)0 )
{
notify(WARN) << "GeoSet->draw() : " "Primitive lengths required\n";
return;
}
for( int i = 0; i < _numprims; i++ )
{
if( _cindex.valid() )
{
if (_cindex._is_ushort)
glDrawElements( (GLenum)_oglprimtype, _primLengths[i], GL_UNSIGNED_SHORT, &_cindex._ptr._ushort[index] );
else
glDrawElements( (GLenum)_oglprimtype, _primLengths[i], GL_UNSIGNED_INT, &_cindex._ptr._uint[index] );
}
else
glDrawArrays( (GLenum)_oglprimtype, index, _primLengths[i] );
index += _primLengths[i];
}
}
else // POINTS, LINES, TRIANGLES, QUADS
{
if( _cindex.valid())
{
if (_cindex._is_ushort)
glDrawElements( (GLenum)_oglprimtype, _cindex._size, GL_UNSIGNED_SHORT, _cindex._ptr._ushort );
else
glDrawElements( (GLenum)_oglprimtype, _cindex._size, GL_UNSIGNED_INT, _cindex._ptr._uint );
}
else
glDrawArrays( (GLenum)_oglprimtype, 0, _numcoords );
}
_cindex = ocindex;
}
void GeoSet::draw_alternate_path( State& state ) const
{
if( (_color_binding == BIND_PERVERTEX) && (_colindex.null() || _colindex ==_cindex) && (_flat_shaded_skip == 0) )
{
// glEnableClientState( GL_COLOR_ARRAY );
// glColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
state.setColorPointer( 4, GL_FLOAT, 0, (GLfloat *)_colors );
}
else
{
// glDisableClientState( GL_COLOR_ARRAY );
state.disableColorPointer();
if( _color_binding == BIND_OVERALL )
{
if( _colindex.valid() )
glColor4fv( (GLfloat *)&_colors[_colindex[0]] );
else
glColor4fv( (GLfloat *)&_colors[0] );
}
}
if( (_normal_binding == BIND_PERVERTEX) && (_nindex.null() || _nindex ==_cindex) && (_flat_shaded_skip == 0) )
{
// glEnableClientState( GL_NORMAL_ARRAY );
// glNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
state.setNormalPointer( GL_FLOAT, 0, (GLfloat *)_normals );
}
else
{
state.disableNormalPointer();
// glDisableClientState( GL_NORMAL_ARRAY );
if( _normal_binding == BIND_OVERALL )
{
if( _nindex.valid() )
glNormal3fv( (GLfloat *)&_normals[_nindex[0]] );
else
glNormal3fv( (GLfloat *)&_normals[0] );
}
}
if( (_texture_binding == BIND_PERVERTEX) && (_tindex.null()) )
{
// glEnableClientState( GL_TEXTURE_COORD_ARRAY );
// glTexCoordPointer( 2, GL_FLOAT, 0, _tcoords );
state.setTexCoordPointer( 0, 2, GL_FLOAT, 0, _tcoords );
state.disableTexCoordPointersAboveAndIncluding(1);
}
else
state.disableTexCoordPointersAboveAndIncluding(0);
// glDisableClientState( GL_TEXTURE_COORD_ARRAY );
// glEnableClientState( GL_VERTEX_ARRAY );
// glVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
state.setVertexPointer( 3, GL_FLOAT, 0, (GLfloat *)_coords );
if( _needprimlen ) // LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP,
// TRIANGLE_FAN, QUAD_STRIP, POLYGONS
// FLAT_LINE_STRIP, FLAT_TRIANGLE_STRIP, FLAT_TRIANGLE_FAN
{
int i, j;
int index = 0;
int ai = 0;
int ci = 0;
int ni = 0;
int ti = 0;
if( _primLengths == (int *)0 )
{
notify(WARN) << "GeoSet->draw() : " "Primitive lengths required\n";
return;
}
if( _flat_shaded_skip )
{
#ifdef DO_SHADING
glShadeModel( GL_FLAT );
#endif
}
for( i = 0; i < _numprims; i++ )
{
if( _color_binding == BIND_PERPRIM )
{
if( _colindex.valid() )
glColor4fv( (GLfloat *)&_colors[_colindex[ci++]] );
else
glColor4fv( (GLfloat *)&_colors[ci++] );
}
if( _normal_binding == BIND_PERPRIM )
{
if( _nindex.valid() )
glNormal3fv( (GLfloat *)&_normals[_nindex[ni++]] );
else
glNormal3fv( (GLfloat *)&_normals[ni++] );
}
if( _flat_shaded_skip )
{
glBegin( (GLenum)_oglprimtype );
for( j = 0; j < _primLengths[i]; j++ )
{
if( j >= _flat_shaded_skip )
{
if( _color_binding == BIND_PERVERTEX )
{
if( (_colindex.valid()) )
glColor4fv( (GLfloat *)&_colors[_colindex[ci++]] );
else
glColor4fv( (GLfloat *)&_colors[ci++] );
}
if( _normal_binding == BIND_PERVERTEX )
{
if(_nindex.valid())
glNormal3fv( (GLfloat *)&_normals[_nindex[ni++]] );
else
glNormal3fv( (GLfloat *)&_normals[ni++] );
}
}
if( _texture_binding == BIND_PERVERTEX )
{
if( _tindex.valid() )
glTexCoord2fv( (GLfloat *)&_tcoords[_tindex[ti++]] );
else
glTexCoord2fv( (GLfloat *)&_tcoords[ti++] );
}
if( _cindex.valid() )
glArrayElement( _cindex[ai++] );
else
glArrayElement( ai++ );
}
glEnd();
}
else
if( ((_color_binding == BIND_PERVERTEX ) && (_colindex.valid()) ) ||
((_normal_binding == BIND_PERVERTEX ) && (_nindex.valid()) ) ||
((_texture_binding == BIND_PERVERTEX ) && (_tindex.valid()) ) )
{
glBegin( (GLenum)_oglprimtype );
for( j = 0; j < _primLengths[i]; j++ )
{
if( (_color_binding == BIND_PERVERTEX) && (_colindex.valid()) )
glColor4fv( (GLfloat *)&_colors[_colindex[ci++]] );
if( (_normal_binding == BIND_PERVERTEX) && (_nindex.valid()) )
glNormal3fv( (GLfloat *)&_normals[_nindex[ni++]] );
if( (_texture_binding == BIND_PERVERTEX) && (_tindex.valid()) )
glTexCoord2fv( (GLfloat *)&_tcoords[_tindex[ti++]] );
if( _cindex.valid() )
glArrayElement( _cindex[ai++] );
else
glArrayElement( ai++ );
}
glEnd();
}
else
{
if( _cindex.valid() )
{
if (_cindex._is_ushort)
glDrawElements( (GLenum)_oglprimtype, _primLengths[i], GL_UNSIGNED_SHORT, &_cindex._ptr._ushort[index] );
else
glDrawElements( (GLenum)_oglprimtype, _primLengths[i], GL_UNSIGNED_INT, &_cindex._ptr._uint[index] );
}
else
glDrawArrays( (GLenum)_oglprimtype, index, _primLengths[i] );
}
index += _primLengths[i];
}
if( _flat_shaded_skip )
{
#ifdef DO_SHADING
glShadeModel( GL_SMOOTH );
#endif
}
}
else // POINTS, LINES, TRIANGLES, QUADS
{
int i, j;
if( _normal_binding == BIND_PERPRIM || _color_binding == BIND_PERPRIM ||
((_color_binding == BIND_PERVERTEX ) && (_colindex.valid()) ) ||
((_normal_binding == BIND_PERVERTEX ) && (_nindex.valid()) ) ||
((_texture_binding == BIND_PERVERTEX ) && (_tindex.valid()) ) )
{
glBegin( (GLenum)_oglprimtype );
for( i = 0; i < _numprims; i++ )
{
if( _color_binding == BIND_PERPRIM )
{
if( _colindex.valid() )
glColor4fv( (GLfloat *)&_colors[_colindex[i]] );
else
glColor4fv( (GLfloat *)&_colors[i] );
}
if( _normal_binding == BIND_PERPRIM )
{
if( _nindex.valid() )
glNormal3fv( (GLfloat *)&_normals[_nindex[i]] );
else
glNormal3fv( (GLfloat *)&_normals[i] );
}
for( j = 0; j < _primlength; j++ )
{
if( (_color_binding == BIND_PERVERTEX) && (_colindex.valid() ) )
glColor4fv( (GLfloat *)&_colors[_colindex[i*_primlength+j]] );
if( (_normal_binding == BIND_PERVERTEX) && (_nindex.valid() ) )
glNormal3fv( (GLfloat *)&_normals[_nindex[i*_primlength+j]] );
if( (_texture_binding == BIND_PERVERTEX) && (_tindex.valid() ) )
glTexCoord2fv( (GLfloat *)&_tcoords[_tindex[i*_primlength+j]] );
if( _cindex.valid())
glArrayElement( _cindex[i*_primlength+j] );
else
glArrayElement( i*_primlength+j );
}
}
glEnd();
}
else
{
if( _cindex.valid())
{
if (_cindex._is_ushort)
glDrawElements( (GLenum)_oglprimtype, _cindex._size, GL_UNSIGNED_SHORT, _cindex._ptr._ushort );
else
glDrawElements( (GLenum)_oglprimtype, _cindex._size, GL_UNSIGNED_INT, _cindex._ptr._uint );
}
else
glDrawArrays( (GLenum)_oglprimtype, 0, _numcoords );
}
}
}

View File

@@ -12,7 +12,6 @@
#include <osg/CullFace>
#include <osg/Geode>
#include <osg/Group>
#include <osg/GeoSet>
#include <osg/Light>
#include <osg/LightSource>
#include <osg/Material>
@@ -448,7 +447,11 @@ public:
fc.tesselate(verts, themat, ts, dwob, tmat);
nff+=nbegin; // the number of primitives generated
}
void buildDrawable(Group *grp, const std::vector<Vec3> verts, dwmaterial *themat, const int nverts) {
void buildDrawable(Group *grp, const std::vector<Vec3> verts, dwmaterial *themat, const int nverts)
{
// Geoff this needs to be update to create osg::Geometry rather than GeoSet...
#if 0
if (nload>0 && nff>0) { // there are some strips of this type
Geode *geode = new Geode;
GeoSet *gset = new GeoSet;
@@ -539,6 +542,7 @@ public:
primlengs=NULL; gsidx=NULL; nrmidx=NULL;
txidx=NULL; nrms=NULL; txcoords=NULL;;
}
#endif
}
void settmat(const Matrix *mx) {
tmat= mx;

View File

@@ -32,7 +32,6 @@
#include "transform.h"
#include <osg/Geode>
#include <osg/GeoSet>
#include <osg/StateSet>
#include <osg/Material>
#include <osg/Texture2D>

View File

@@ -19,7 +19,6 @@ CXXFILES =\
FrontFace.cpp\
Geode.cpp\
Geometry.cpp\
GeoSet.cpp\
Group.cpp\
Image.cpp\
Impostor.cpp\

File diff suppressed because it is too large Load Diff

View File

@@ -1,556 +0,0 @@
#include "ConvertToPerformer.h"
#include <osg/Group>
#include <osg/LOD>
#include <osg/Switch>
#include <osg/Geode>
#include <osg/Billboard>
#include <osg/Image>
#include <osg/Notify>
#include <osgDB/FileNameUtils>
#include <osgDB/ReadFile>
#include <Performer/pf/pfNode.h>
#include <Performer/pf/pfGeode.h>
#include <Performer/pf/pfBillboard.h>
#include <Performer/pf/pfScene.h>
#include <Performer/pf/pfGroup.h>
#include <Performer/pf/pfDCS.h>
#include <Performer/pf/pfSCS.h>
#include <Performer/pf/pfLOD.h>
#include <Performer/pf/pfSwitch.h>
#include <Performer/pf/pfSequence.h>
#include <Performer/pr/pfGeoState.h>
#include <Performer/pr/pfMaterial.h>
#include <Performer/pr/pfTexture.h>
extern "C"
{
extern pfNode *
pfdLoadFile_osg (char *fileName)
{
osg::Node* node = osgDB::readNodeFile(fileName);
if (node==NULL) return 0;
ConvertToPerformer converter;
return converter.convert(node);
}
};
ConvertToPerformer::ConvertToPerformer()
{
setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
_pfParent = NULL;
_pfRoot = NULL;
_gsetPrimMap[osg::GeoSet::POINTS] = PFGS_POINTS;
_gsetPrimMap[osg::GeoSet::LINES] = PFGS_LINES;
_gsetPrimMap[osg::GeoSet::LINE_STRIP] = PFGS_LINESTRIPS;
_gsetPrimMap[osg::GeoSet::TRIANGLES] = PFGS_TRIS;
_gsetPrimMap[osg::GeoSet::QUADS] = PFGS_QUADS;
_gsetPrimMap[osg::GeoSet::TRIANGLE_STRIP] = PFGS_TRISTRIPS;
_gsetPrimMap[osg::GeoSet::FLAT_LINE_STRIP] = PFGS_FLAT_LINESTRIPS;
_gsetPrimMap[osg::GeoSet::FLAT_TRIANGLE_STRIP] = PFGS_FLAT_TRISTRIPS;
_gsetPrimMap[osg::GeoSet::TRIANGLE_FAN] = PFGS_TRIFANS;
_gsetPrimMap[osg::GeoSet::FLAT_TRIANGLE_FAN] = PFGS_FLAT_TRIFANS;
_gsetPrimMap[osg::GeoSet::POLYGON] = PFGS_POLYS;
_gsetPrimMap[osg::GeoSet::NO_TYPE] = PFGS_NUM_PRIMS;
_gsetBindMap[osg::GeoSet::BIND_OFF] = PFGS_OFF;
_gsetBindMap[osg::GeoSet::BIND_OVERALL] = PFGS_OVERALL;
_gsetBindMap[osg::GeoSet::BIND_PERPRIM] = PFGS_PER_PRIM;
_gsetBindMap[osg::GeoSet::BIND_PERVERTEX] = PFGS_PER_VERTEX;
}
ConvertToPerformer::~ConvertToPerformer()
{
}
pfNode* ConvertToPerformer::convert(const osg::Node* node)
{
_pfRoot = NULL;
if (node)
{
// a hack to get round current limitation of node visitor which
// only handles non const operations.
osg::Node* non_const_node = const_cast<osg::Node*>(node);
non_const_node->accept(*this);
}
return _pfRoot;
}
pfObject* ConvertToPerformer::getPfObject(osg::Object* osgObj)
{
OsgObjectToPfObjectMap::iterator fitr = _osgToPfMap.find(osgObj);
if (fitr != _osgToPfMap.end())
{
osg::notify(osg::DEBUG_INFO) << "Found shared object"<<std::endl;
return (*fitr).second;
}
else return NULL;
}
void ConvertToPerformer::registerOsgObjectForPfObject(osg::Object* osgObj,pfObject* pfObj)
{
_osgToPfMap[osgObj] = pfObj;
}
void ConvertToPerformer::apply(osg::Node& node)
{
node.traverse(*this);
}
void ConvertToPerformer::apply(osg::Group& node)
{
pfGroup* parent = _pfParent;
pfGroup* pf_group = dynamic_cast<pfGroup*>(getPfObject(&node));
if (pf_group)
{
if (_pfParent) _pfParent->addChild(pf_group);
return;
}
pf_group = new pfGroup;
if (!_pfRoot) _pfRoot = pf_group;
if (_pfParent) _pfParent->addChild(pf_group);
registerOsgObjectForPfObject(&node,pf_group);
if (!node.getName().empty()) pf_group->setName(node.getName().c_str());
_pfParent = pf_group;
node.traverse(*this);
_pfParent = parent;
}
void ConvertToPerformer::apply(osg::MatrixTransform& osgTransform)
{
pfGroup* parent = _pfParent;
pfDCS* pf_dcs = dynamic_cast<pfDCS*>(getPfObject(&osgTransform));
if (pf_dcs)
{
if (_pfParent) _pfParent->addChild(pf_dcs);
return;
}
pf_dcs = new pfDCS;
if (!_pfRoot) _pfRoot = pf_dcs;
if (_pfParent) _pfParent->addChild(pf_dcs);
registerOsgObjectForPfObject(&osgTransform,pf_dcs);
if (!osgTransform.getName().empty()) pf_dcs->setName(osgTransform.getName().c_str());
const osg::Matrix& matrix = osgTransform.getMatrix();
pfMatrix pf_matrix(matrix(0,0),matrix(0,1),matrix(0,2),matrix(0,3),
matrix(1,0),matrix(1,1),matrix(1,2),matrix(1,3),
matrix(2,0),matrix(2,1),matrix(2,2),matrix(2,3),
matrix(3,0),matrix(3,1),matrix(3,2),matrix(3,3));
pf_dcs->setMat(pf_matrix);
_pfParent = pf_dcs;
osgTransform.traverse(*this);
_pfParent = parent;
}
void ConvertToPerformer::apply(osg::Switch& node)
{
pfGroup* parent = _pfParent;
pfSwitch* pf_switch = dynamic_cast<pfSwitch*>(getPfObject(&node));
if (pf_switch)
{
if (_pfParent) _pfParent->addChild(pf_switch);
return;
}
pf_switch = new pfSwitch;
if (!_pfRoot) _pfRoot = pf_switch;
if (_pfParent) _pfParent->addChild(pf_switch);
registerOsgObjectForPfObject(&node,pf_switch);
if (!node.getName().empty()) pf_switch->setName(node.getName().c_str());
_pfParent = pf_switch;
node.traverse(*this);
_pfParent = parent;
}
void ConvertToPerformer::apply(osg::LOD& node)
{
pfGroup* parent = _pfParent;
pfLOD* pf_lod = dynamic_cast<pfLOD*>(getPfObject(&node));
if (pf_lod)
{
if (_pfParent) _pfParent->addChild(pf_lod);
return;
}
pf_lod = new pfLOD;
if (!_pfRoot) _pfRoot = pf_lod;
if (_pfParent) _pfParent->addChild(pf_lod);
registerOsgObjectForPfObject(&node,pf_lod);
if (!node.getName().empty()) pf_lod->setName(node.getName().c_str());
_pfParent = pf_lod;
node.traverse(*this);
_pfParent = parent;
}
void ConvertToPerformer::apply(osg::Billboard& node)
{
pfGroup* parent = _pfParent;
pfBillboard* pf_billboard = dynamic_cast<pfBillboard*>(getPfObject(&node));
if (pf_billboard)
{
if (_pfParent) _pfParent->addChild(pf_billboard);
return;
}
pf_billboard = new pfBillboard;
if (!_pfRoot) _pfRoot = pf_billboard;
if (_pfParent) _pfParent->addChild(pf_billboard);
registerOsgObjectForPfObject(&node,pf_billboard);
if (!node.getName().empty()) pf_billboard->setName(node.getName().c_str());
for(unsigned int i=0;i<node.getNumDrawables();++i)
{
osg::GeoSet* osg_gset = dynamic_cast<osg::GeoSet*>(node.getDrawable(i));
if (osg_gset)
{
pfGeoSet* pf_geoset = visitGeoSet(osg_gset);
if (pf_geoset) pf_billboard->addGSet(pf_geoset);
}
}
_pfParent = parent;
}
void ConvertToPerformer::apply(osg::Geode& node)
{
pfGroup* parent = _pfParent;
pfGeode* pf_geode = dynamic_cast<pfGeode*>(getPfObject(&node));
if (pf_geode)
{
if (_pfParent) _pfParent->addChild(pf_geode);
return;
}
pf_geode = new pfGeode;
if (!_pfRoot) _pfRoot = pf_geode;
if (_pfParent) _pfParent->addChild(pf_geode);
registerOsgObjectForPfObject(&node,pf_geode);
if (!node.getName().empty()) pf_geode->setName(node.getName().c_str());
for(unsigned int i=0;i<node.getNumDrawables();++i)
{
osg::GeoSet* osg_gset = dynamic_cast<osg::GeoSet*>(node.getDrawable(i));
if (osg_gset)
{
pfGeoSet* pf_geoset = visitGeoSet(osg_gset);
if (pf_geoset) pf_geode->addGSet(pf_geoset);
}
}
_pfParent = parent;
}
pfGeoSet* ConvertToPerformer::visitGeoSet(osg::GeoSet* geoset)
{
if (geoset==NULL) return NULL;
osg::GeoSet::IndexPointer& cindex = geoset->getCoordIndices();
if (cindex.valid() && !cindex._is_ushort)
{
osg::notify(osg::WARN)<<"Warning: Cannot convert osg::GeoSet to pfGeoSet due to uint coord index."<<std::endl;
return NULL;
}
osg::GeoSet::IndexPointer& nindex = geoset->getNormalIndices();
if (nindex.valid() && !nindex._is_ushort)
{
osg::notify(osg::WARN)<<"Warning: Cannot convert osg::GeoSet to pfGeoSet due to uint normal index."<<std::endl;
return NULL;
}
osg::GeoSet::IndexPointer& colindex = geoset->getColorIndices();
if (colindex.valid() && !colindex._is_ushort)
{
osg::notify(osg::WARN)<<"Warning: Cannot convert osg::GeoSet to pfGeoSet due to uint color index."<<std::endl;
return NULL;
}
void* arena = pfGetSharedArena();
pfGeoSet* pf_geoset = new pfGeoSet();
pf_geoset->setGState(visitStateSet(geoset->getStateSet()));
int i;
// number of prims
int np = geoset->getNumPrims();
int *plen = geoset->getPrimLengths();
// Number of verticies (may be different than number of coords)
geoset->computeNumVerts();
pf_geoset->setPrimType(_gsetPrimMap[geoset->getPrimType()]);
pf_geoset->setNumPrims(np);
if (plen)
{
//int *pf_plen = new int [np];
int* pf_plen = (int*) pfMalloc(sizeof(int) * np, arena);
for(i=0;i<np;++i) pf_plen[i] = plen[i];
pf_geoset->setPrimLengths(pf_plen);
}
osg::Vec3 *coords = geoset->getCoords();
GLushort *ilist = cindex._ptr._ushort;
// copy the vertex coordinates across.
if( coords )
{
int cc = geoset->getNumCoords();
pfVec3* pf_coords = (pfVec3*) pfMalloc(sizeof(pfVec3) * cc, arena);
for( i = 0; i < cc; i++ )
{
pf_coords[i][0] = coords[i][0];
pf_coords[i][1] = coords[i][1];
pf_coords[i][2] = coords[i][2];
}
if(ilist)
{
int ni=geoset->getNumCoordIndices();
ushort* pf_cindex = (ushort*) pfMalloc(sizeof(ushort) * ni, arena);
for( i = 0; i < ni; i++ )
{
pf_cindex[i] = ilist[i];
}
pf_geoset->setAttr( PFGS_COORD3, PFGS_PER_VERTEX, pf_coords, pf_cindex );
}
else
{
pf_geoset->setAttr( PFGS_COORD3, PFGS_PER_VERTEX, pf_coords, NULL );
}
}
osg::Vec3 *norms = geoset->getNormals();
ilist = nindex._ptr._ushort;
// copy normals
if(norms)
{
int bind = _gsetBindMap[geoset->getNormalBinding()];
int cc = geoset->getNumNormals();
pfVec3* pf_norms = (pfVec3*) pfMalloc(sizeof(pfVec3) * cc, arena);
for( i = 0; i < cc; i++ )
{
pf_norms[i][0] = norms[i][0];
pf_norms[i][1] = norms[i][1];
pf_norms[i][2] = norms[i][2];
}
if(ilist)
{
int ni=geoset->getNumNormalIndices();
ushort* pf_nindex = (ushort*) pfMalloc(sizeof(ushort) * ni, arena);
for( i = 0; i < ni; i++ )
{
pf_nindex[i] = ilist[i];
}
pf_geoset->setAttr(PFGS_NORMAL3, bind, pf_norms,pf_nindex);
}
else
{
pf_geoset->setAttr(PFGS_NORMAL3, bind, pf_norms,NULL);
}
}
osg::Vec4 *colors = geoset->getColors();
ilist = colindex._ptr._ushort;
// copy colors
if(colors)
{
int bind = _gsetBindMap[geoset->getColorBinding()];
int cc = geoset->getNumColors();
pfVec4* pf_colors = (pfVec4*) pfMalloc(sizeof(pfVec4) * cc, arena);
for( i = 0; i < cc; i++ )
{
pf_colors[i][0] = colors[i][0];
pf_colors[i][1] = colors[i][1];
pf_colors[i][2] = colors[i][2];
pf_colors[i][3] = colors[i][3];
}
if(ilist)
{
int ni=geoset->getNumColorIndices();
ushort* pf_cindex = (ushort*) pfMalloc(sizeof(ushort) * ni, arena);
for( i = 0; i < ni; i++ )
{
pf_cindex[i] = ilist[i];
}
pf_geoset->setAttr(PFGS_COLOR4, bind, pf_colors,pf_cindex);
}
else
{
pf_geoset->setAttr(PFGS_COLOR4, bind, pf_colors,NULL);
}
}
// Copy texture coords
osg::Vec2 *tcoords = geoset->getTextureCoords();
ilist = geoset->getTextureIndices()._ptr._ushort;
if( tcoords )
{
int bind = _gsetBindMap[geoset->getTextureBinding()];
int ct = geoset->getNumTextureCoords();
pfVec2 *pf_tcoords = (pfVec2 *)pfMalloc( sizeof( pfVec2 ) * ct, arena );
for( i = 0; i < ct; i++ )
{
pf_tcoords[i].set( tcoords[i][0], tcoords[i][1] );
}
if( ilist )
{
int nt = geoset->getNumTextureIndices();
ushort *pf_tindex = (ushort *)pfMalloc( sizeof( ushort ) * nt, arena );
for( i = 0; i < nt; i++ )
pf_tindex[i] = ilist[i];
pf_geoset->setAttr( PFGS_TEXCOORD2, bind, pf_tcoords, pf_tindex );
}
else
pf_geoset->setAttr( PFGS_TEXCOORD2, bind, pf_tcoords, NULL );
}
return pf_geoset;
}
pfGeoState* ConvertToPerformer::visitStateSet(osg::StateSet* stateset)
{
if (stateset==NULL) return NULL;
pfGeoState* pf_geostate = new pfGeoState();
switch(stateset->getMode(GL_LIGHTING))
{
case(osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON):
case(osg::StateAttribute::ON): pf_geostate->setMode(PFSTATE_ENLIGHTING,PF_ON);break;
case(osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF):
case(osg::StateAttribute::OFF): pf_geostate->setMode(PFSTATE_ENLIGHTING,PF_OFF);break;
// pfGeostate value as default inherit.
case(osg::StateAttribute::INHERIT): break;
}
switch(stateset->getMode(GL_TEXTURE_2D))
{
case(osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON):
case(osg::StateAttribute::ON): pf_geostate->setMode(PFSTATE_ENTEXTURE,PF_ON);break;
case(osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF):
case(osg::StateAttribute::OFF): pf_geostate->setMode(PFSTATE_ENTEXTURE,PF_OFF);break;
// pfGeostate value as default inherit.
case(osg::StateAttribute::INHERIT): break;
}
const osg::Texture2D *tex = dynamic_cast<const osg::Texture2D *>(stateset->getAttribute( osg::StateAttribute::TEXTURE));
if( tex != NULL )
{
pfTexture *pf_tex = new pfTexture;
const osg::Image *img = tex->getImage();
int ns = img->s();
int nt = img->t();
int ncomp =
img->getPixelFormat() == GL_LUMINANCE ? 1 :
img->getPixelFormat() == GL_LUMINANCE_ALPHA ? 2 :
img->getPixelFormat() == GL_RGB ? 3 :
img->getPixelFormat() == GL_RGBA ? 4 : 3;
unsigned int *uim = (unsigned int *)pfMalloc( ns * nt * ncomp, pfGetSharedArena() );
memcpy( uim, img->data(), ns * nt * ncomp );
pf_tex->setImage( uim, ncomp, ns, nt, 0 );
pf_geostate->setAttr( PFSTATE_TEXTURE, pf_tex );
pf_geostate->setAttr( PFSTATE_TEXENV, new pfTexEnv );
}
return pf_geostate;
}
pfMaterial* ConvertToPerformer::visitMaterial(osg::Material* material)
{
if (material==NULL) return NULL;
pfMaterial* pf_material = new pfMaterial();
return pf_material;
}
pfTexture* ConvertToPerformer::visitTexture(osg::Texture2D* tex)
{
if (tex==NULL) return NULL;
pfTexture* pf_texture = new pfTexture();
return pf_texture;
}

View File

@@ -1,64 +0,0 @@
#ifndef __CONVERTTOPERFORMER_H
#define __CONVERTTOPERFORMER_H
#include <map>
#include <vector>
#include <string>
// Open Scene Graph includes.
#include <osg/Node>
#include <osg/NodeVisitor>
#include <osg/Group>
#include <osg/MatrixTransform>
#include <osg/GeoSet>
#include <osg/StateSet>
#include <osg/Material>
#include <osg/Texture2D>
// Performer includes.
#include <Performer/pf/pfNode.h>
class ConvertToPerformer : protected osg::NodeVisitor {
public:
ConvertToPerformer();
~ConvertToPerformer();
pfNode* convert(const osg::Node* node);
virtual void apply(osg::Node&);
virtual void apply(osg::Geode& node);
virtual void apply(osg::Billboard& node);
virtual void apply(osg::Group& node);
virtual void apply(osg::MatrixTransform& node);
virtual void apply(osg::Switch& node);
virtual void apply(osg::LOD& node);
private:
pfGroup* _pfParent;
pfNode* _pfRoot;
virtual pfObject* getPfObject(osg::Object* osgObj);
virtual void registerOsgObjectForPfObject(osg::Object* osgObj,pfObject* pfObj);
pfGeoSet* visitGeoSet(osg::GeoSet* geoset);
pfGeoState* visitStateSet(osg::StateSet* geostate);
pfMaterial* visitMaterial(osg::Material* material);
pfTexture* visitTexture(osg::Texture2D* tex);
typedef std::map<osg::Object*,pfObject*> OsgObjectToPfObjectMap;
typedef std::map<osg::GeoSet::PrimitiveType,int> GSetPrimitiveMap;
typedef std::map<osg::GeoSet::BindingType,int> GSetBindingMap;
OsgObjectToPfObjectMap _osgToPfMap;
GSetPrimitiveMap _gsetPrimMap;
GSetBindingMap _gsetBindMap;
};
#endif

View File

@@ -3,7 +3,6 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
ConvertFromPerformer.cpp\
ConvertToPerformer.cpp\
ReaderWriterPFB.cpp\
LIBS += $(OSG_LIBS) $(PF_XTRA_LIBS) $(OTHER_LIBS)

View File

@@ -8,7 +8,6 @@
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include "ConvertToPerformer.h"
#include "ConvertFromPerformer.h"
#include <Performer/pfdu.h>
@@ -179,26 +178,6 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
}
virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options*)
{
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
osg::notify(osg::INFO)<<"ReaderWriterPFB::writeNode( "<<fileName.c_str()<<" )\n";
initPerformer();
ConvertToPerformer converter;
pfNode* root = converter.convert(&node);
if (root)
{
if (pfdStoreFile(root,fileName.c_str())!=0) return WriteResult::FILE_SAVED;
else return std::string("Unable to write file from performer.");
}
else
{
return std::string("Unable to convert scene to performer, cannot write file.");
}
}
protected:

View File

@@ -19,7 +19,6 @@
#include <osg/Impostor>
#include <osg/Billboard>
#include <osg/Geometry>
#include <osg/GeoSet>
#include <osg/Notify>
#include <osg/OccluderNode>
#include <osg/Sequence>
@@ -31,10 +30,9 @@
using namespace osgUtil;
// #define CONVERT_GEOSET_TO_GEOMETRY
////////////////////////////////////////////////////////////////////////////
// Overall Optimizetion function.
// Overall Optimization function.
////////////////////////////////////////////////////////////////////////////
static bool isNodeEmpty(const osg::Node& node)
@@ -90,11 +88,6 @@ void Optimizer::optimize(osg::Node* node, unsigned int options)
}
#if defined(CONVERT_GEOSET_TO_GEOMETRY)
// convert the old style GeoSet to Geometry
ConvertGeoSetsToGeometryVisitor cgtg;
node->accept(cgtg);
#endif
if (options & SHARE_DUPLICATE_STATE)
{
@@ -149,34 +142,6 @@ class TransformFunctor : public osg::Drawable::AttributeFunctor
};
////////////////////////////////////////////////////////////////////////////
// Convert GeoSet To Geometry Visitor.
////////////////////////////////////////////////////////////////////////////
void Optimizer::ConvertGeoSetsToGeometryVisitor::apply(osg::Geode& geode)
{
for(unsigned int i=0;i<geode.getNumDrawables();++i)
{
osg::GeoSet* geoset = dynamic_cast<osg::GeoSet*>(geode.getDrawable(i));
if (geoset)
{
osg::Geometry* geom = geoset->convertToGeometry();
if (geom)
{
std::cout<<"Successfully converted GeoSet to Geometry"<<std::endl;
geode.replaceDrawable(geoset,geom);
}
else
{
std::cout<<"*** Failed to convert GeoSet to Geometry"<<std::endl;
}
}
}
}
////////////////////////////////////////////////////////////////////////////
// Optimize State Visitor