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:
parent
fcbbf12b75
commit
4a6bdad3e1
@ -62,7 +62,7 @@ Ulrich Hertlein <u.hertlein@bit-side.com>
|
||||
- osg::Sequence support.
|
||||
- improvements to the pfb loader.
|
||||
- .lwo, .obj and .x (DirectX model) plugins.
|
||||
- osg::TextureRectangle.
|
||||
- osg::TextureRectangle * osgtexturerectangle example.
|
||||
|
||||
Axel Volley <volley@acm.org>
|
||||
- support for OBJECT_LINEAR and EYE_LINEAR TexGen modes.
|
||||
|
@ -79,7 +79,9 @@ else
|
||||
# comment in if you want Open DX support, currently not on by default
|
||||
# since we havn't yet checked compilation on all platforms yet.
|
||||
# note, moved to non Darwin build since it currently breaks the Drawin build.
|
||||
PLUGIN_DIRS += dx
|
||||
|
||||
# commented out while the DX plugin is converted across to use Geometry rather than GeoSet.
|
||||
# PLUGIN_DIRS += dx
|
||||
|
||||
|
||||
# comment in if you have libtiff installed.
|
||||
|
@ -1326,24 +1326,6 @@ Package=<4>
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "osgPlugin dx"=.\osgPlugins\dx\dx.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Core osg
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Core osgDB
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "osgPlugin flt"=.\osgPlugins\flt\flt.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
|
@ -172,6 +172,22 @@ LINK32=link.exe
|
||||
|
||||
|
||||
|
||||
SOURCE=..\..\..\examples\osgconv\GeoSet.cpp
|
||||
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
|
||||
|
||||
|
||||
SOURCE=..\..\..\examples\osgconv\IO_GeoSet.cpp
|
||||
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
|
||||
|
||||
|
||||
SOURCE=..\..\..\examples\osgconv\OrientationConverter.cpp
|
||||
|
||||
# End Source File
|
||||
|
@ -217,14 +217,6 @@ SOURCE=..\..\src\osg\Geometry.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\GeoSet.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\GeoSet_ogl.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\GLExtensions.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -593,10 +585,6 @@ SOURCE=..\..\Include\Osg\IndexedGeometry
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\GeoSet
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\Gl
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -158,10 +158,6 @@ SOURCE=..\..\..\src\osgPlugins\osg\Geode.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\osg\GeoSet.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\osg\Geometry.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -37,9 +37,9 @@ class CameraPacket {
|
||||
public:
|
||||
|
||||
CameraPacket():_masterKilled(false)
|
||||
{
|
||||
_byte_order = 0x12345678;
|
||||
}
|
||||
{
|
||||
_byte_order = 0x12345678;
|
||||
}
|
||||
|
||||
void setPacket(const osg::Matrix& matrix,const osg::FrameStamp* frameStamp)
|
||||
{
|
||||
@ -56,24 +56,24 @@ class CameraPacket {
|
||||
matrix = _matrix * osg::Matrix::rotate(angle_offset,0.0f,1.0f,0.0f);
|
||||
}
|
||||
|
||||
void checkByteOrder( void )
|
||||
{
|
||||
if( _byte_order == 0x78563412 ) // We're backwards
|
||||
{
|
||||
swapBytes( _byte_order );
|
||||
swapBytes( _masterKilled );
|
||||
for( int i = 0; i < 16; i++ )
|
||||
swapBytes( _matrix.ptr()[i] );
|
||||
void checkByteOrder( void )
|
||||
{
|
||||
if( _byte_order == 0x78563412 ) // We're backwards
|
||||
{
|
||||
swapBytes( _byte_order );
|
||||
swapBytes( _masterKilled );
|
||||
for( int i = 0; i < 16; i++ )
|
||||
swapBytes( _matrix.ptr()[i] );
|
||||
|
||||
// umm.. we should byte swap _frameStamp too...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setMasterKilled(const bool flag) { _masterKilled = flag; }
|
||||
const bool getMasterKilled() const { return _masterKilled; }
|
||||
|
||||
unsigned long _byte_order;
|
||||
unsigned long _byte_order;
|
||||
bool _masterKilled;
|
||||
osg::Matrix _matrix;
|
||||
|
||||
@ -170,11 +170,13 @@ int main( int argc, char **argv )
|
||||
// objects for managing the broadcasting and recieving of camera packets.
|
||||
Broadcaster bc;
|
||||
Receiver rc;
|
||||
|
||||
bc.setPort(socketNumber);
|
||||
rc.setPort(socketNumber);
|
||||
|
||||
while( !viewer.done() )
|
||||
bc.setPort(static_cast<short int>(socketNumber));
|
||||
rc.setPort(static_cast<short int>(socketNumber));
|
||||
|
||||
bool masterKilled = false;
|
||||
|
||||
while( !viewer.done() && !masterKilled )
|
||||
{
|
||||
// wait for all cull and draw threads to complete.
|
||||
viewer.sync();
|
||||
@ -197,7 +199,7 @@ int main( int argc, char **argv )
|
||||
cp.setPacket(modelview,viewer.getFrameStamp());
|
||||
|
||||
bc.setBuffer(&cp, sizeof( CameraPacket ));
|
||||
bc.sync();
|
||||
bc.sync();
|
||||
|
||||
}
|
||||
break;
|
||||
@ -206,9 +208,10 @@ int main( int argc, char **argv )
|
||||
CameraPacket cp;
|
||||
|
||||
rc.setBuffer(&cp, sizeof( CameraPacket ));
|
||||
rc.sync();
|
||||
|
||||
cp.checkByteOrder();
|
||||
rc.sync();
|
||||
|
||||
cp.checkByteOrder();
|
||||
|
||||
osg::Matrix modelview;
|
||||
cp.getModelView(modelview,camera_offset);
|
||||
@ -217,9 +220,9 @@ int main( int argc, char **argv )
|
||||
|
||||
if (cp.getMasterKilled())
|
||||
{
|
||||
std::cout << "recieved master killed"<<std::endl;
|
||||
std::cout << "received master killed"<<std::endl;
|
||||
// break out of while (!done) loop since we've now want to shut down.
|
||||
break;
|
||||
masterKilled = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -229,10 +232,11 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// fire off the cull and draw traversals of the scene.
|
||||
viewer.frame();
|
||||
if(!masterKilled)
|
||||
viewer.frame();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// wait for all cull and draw threads to complete before exit.
|
||||
viewer.sync();
|
||||
|
||||
@ -245,7 +249,7 @@ int main( int argc, char **argv )
|
||||
cp.setMasterKilled(true);
|
||||
|
||||
bc.setBuffer(&cp, sizeof( CameraPacket ));
|
||||
bc.sync();
|
||||
bc.sync();
|
||||
|
||||
std::cout << "broadcasting death"<<std::endl;
|
||||
|
||||
|
@ -2,6 +2,8 @@ TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
GeoSet.cpp\
|
||||
IO_GeoSet.cpp\
|
||||
OrientationConverter.cpp\
|
||||
osgconv.cpp\
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <osg/Group>
|
||||
#include <osg/Notify>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Geometry>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
@ -9,11 +10,48 @@
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
#include "OrientationConverter.h"
|
||||
#include "GeoSet.h"
|
||||
|
||||
typedef std::vector<std::string> FileNameList;
|
||||
|
||||
static bool do_convert = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Convert GeoSet To Geometry Visitor.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** ConvertGeoSetsToGeometryVisitor all the old GeoSet Drawables to the new Geometry Drawables.*/
|
||||
class ConvertGeoSetsToGeometryVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
ConvertGeoSetsToGeometryVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
||||
|
||||
virtual void 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void apply(osg::Node& node) { traverse(node); }
|
||||
|
||||
};
|
||||
|
||||
static void usage( const char *prog, const char *msg )
|
||||
{
|
||||
@ -231,6 +269,11 @@ int main( int argc, char **argv )
|
||||
|
||||
osg::ref_ptr<osg::Node> root = osgDB::readNodeFiles(fileNames);
|
||||
|
||||
// convert the old style GeoSet to Geometry
|
||||
ConvertGeoSetsToGeometryVisitor cgtg;
|
||||
root->accept(cgtg);
|
||||
|
||||
|
||||
if( do_convert )
|
||||
root = oc.convert( root.get() );
|
||||
|
||||
|
@ -24,7 +24,7 @@ button accelerates, the right mouse button decelerates, and the middle mouse
|
||||
button (or left and right simultaneously) stops dead.
|
||||
*/
|
||||
|
||||
class OSGGA_EXPORT GliderManipulator : public osgGA::MatrixManipulator
|
||||
class GliderManipulator : public osgGA::MatrixManipulator
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -1,716 +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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSG_GEOSET
|
||||
#define OSG_GEOSET 1
|
||||
|
||||
#include <osg/Drawable>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
// forward declare so that we don't need to include the header.
|
||||
class Geometry;
|
||||
|
||||
/** Note, osg::GeoSet is now deprecated, please use osg::Geometry instead.
|
||||
osg::GeoSet will be kept through to the beta release for
|
||||
backwards compatability only.
|
||||
|
||||
Encapsulates OpenGL drawing primitives, geometry and
|
||||
optional binding of normal, color and texture coordinates. Used
|
||||
for representing the visible objects in the scene. State attributes
|
||||
for a GeoSet are maintained in StateSet which the GeoSet maintains
|
||||
a referenced counted pointer to. Both GeoSet's and StateSet's can
|
||||
be shared for optimal memory usage and graphics performance.
|
||||
*/
|
||||
class SG_EXPORT GeoSet : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
|
||||
enum PrimitiveType {
|
||||
NO_TYPE,
|
||||
POINTS,
|
||||
LINES,
|
||||
LINE_STRIP,
|
||||
FLAT_LINE_STRIP,
|
||||
LINE_LOOP,
|
||||
TRIANGLES,
|
||||
TRIANGLE_STRIP,
|
||||
FLAT_TRIANGLE_STRIP,
|
||||
TRIANGLE_FAN,
|
||||
FLAT_TRIANGLE_FAN,
|
||||
QUADS,
|
||||
QUAD_STRIP,
|
||||
POLYGON
|
||||
};
|
||||
|
||||
enum BindingType {
|
||||
BIND_OFF,
|
||||
BIND_OVERALL,
|
||||
BIND_PERPRIM,
|
||||
BIND_PERVERTEX,
|
||||
BIND_DEFAULT
|
||||
};
|
||||
|
||||
enum InterleaveArrayType {
|
||||
IA_OFF,
|
||||
IA_V2F,
|
||||
IA_V3F,
|
||||
IA_C4UB_V2F,
|
||||
IA_C4UB_V3F,
|
||||
IA_C3F_V3F,
|
||||
IA_N3F_V3F,
|
||||
IA_C4F_N3F_V3F,
|
||||
IA_T2F_V3F,
|
||||
IA_T4F_V4F,
|
||||
IA_T2F_C4UB_V3F,
|
||||
IA_T2F_C3F_V3F,
|
||||
IA_T2F_N3F_V3F,
|
||||
IA_T2F_C4F_N3F_V3F,
|
||||
IA_T4F_C4F_N3F_V4F
|
||||
};
|
||||
|
||||
|
||||
struct SG_EXPORT IndexPointer
|
||||
{
|
||||
|
||||
mutable unsigned int _size;
|
||||
bool _is_ushort;
|
||||
union _TPtr
|
||||
{
|
||||
GLushort* _ushort;
|
||||
GLuint* _uint;
|
||||
} _ptr;
|
||||
|
||||
IndexPointer() { _size=0;_is_ushort=true;_ptr._ushort = (GLushort*)0; }
|
||||
|
||||
inline bool operator == (const IndexPointer& ip) const
|
||||
{
|
||||
return _size == ip._size &&
|
||||
_is_ushort == ip._is_ushort &&
|
||||
_ptr._ushort == ip._ptr._ushort;
|
||||
}
|
||||
|
||||
inline bool valid() const
|
||||
{
|
||||
return _ptr._ushort != (GLushort*)0;
|
||||
}
|
||||
|
||||
inline bool null() const
|
||||
{
|
||||
return _ptr._ushort == (GLushort*)0;
|
||||
}
|
||||
|
||||
inline void setToNull()
|
||||
{
|
||||
_size = 0;
|
||||
_is_ushort = true;
|
||||
_ptr._ushort = (GLushort*)0;
|
||||
}
|
||||
|
||||
inline void set(unsigned int size,GLushort* data)
|
||||
{
|
||||
_size = size;
|
||||
_is_ushort = true;
|
||||
_ptr._ushort = data;
|
||||
}
|
||||
|
||||
|
||||
void set(unsigned int size,GLuint* data)
|
||||
{
|
||||
_size = size;
|
||||
_is_ushort = false;
|
||||
_ptr._uint = data;
|
||||
}
|
||||
|
||||
inline unsigned int maxIndex() const
|
||||
{
|
||||
unsigned int max = 0;
|
||||
if (_is_ushort)
|
||||
{
|
||||
for(unsigned int ai = 0; ai < _size; ai++ )
|
||||
if( _ptr._ushort[ai] > max ) max = _ptr._ushort[ai];
|
||||
}
|
||||
else
|
||||
{
|
||||
for(unsigned int ai = 0; ai < _size; ai++ )
|
||||
if( _ptr._uint[ai] > max ) max = _ptr._uint[ai];
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
inline GLint operator [] (const GLuint pos) const
|
||||
{
|
||||
if (_is_ushort) return _ptr._ushort[pos];
|
||||
else return _ptr._uint[pos];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GeoSet();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
GeoSet(const GeoSet& geoset,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual Object* cloneType() const { return new GeoSet(); }
|
||||
|
||||
virtual Object* clone(const CopyOp& copyop) const { return new GeoSet(*this,copyop); }
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const GeoSet*>(obj)!=NULL; }
|
||||
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "GeoSet"; }
|
||||
|
||||
|
||||
// data access methods.
|
||||
inline void setNumPrims( int n ) { _numprims = n; _numcoords=0;}
|
||||
inline int getNumPrims() const { return _numprims; }
|
||||
|
||||
void setPrimType( PrimitiveType type );
|
||||
inline PrimitiveType getPrimType() const { return _primtype; }
|
||||
|
||||
inline void setPrimLengths( int *lens ) { _primLengths = lens; }
|
||||
inline int *getPrimLengths() { return _primLengths; }
|
||||
inline int *getPrimLengths() const { return _primLengths; }
|
||||
|
||||
void computeNumVerts() const;
|
||||
|
||||
/** get the number of coords required by the defined primitives. */
|
||||
inline int getNumCoords() const
|
||||
{ if( _numcoords == 0 ) computeNumVerts(); return _numcoords; }
|
||||
/** get a pointer to Vec3 coord array. */
|
||||
inline Vec3* getCoords() { return _coords; }
|
||||
/** get a const pointer to Vec3 coord array. */
|
||||
inline const Vec3* getCoords() const { return _coords; }
|
||||
/** get the number of indices required by the defined primitives. */
|
||||
inline int getNumCoordIndices() const { return _cindex._size; }
|
||||
/** get the coord index array. */
|
||||
inline IndexPointer& getCoordIndices() { return _cindex; }
|
||||
/** get the const coord index array. */
|
||||
inline const IndexPointer& getCoordIndices() const { return _cindex; }
|
||||
/** set the coords (i.e the geometry) of the geoset.*/
|
||||
void setCoords( Vec3 *cp );
|
||||
/** set the coords (i.e the geometry) and ushort indices of the geoset.
|
||||
To reduce memory footprint and bandwidth for small datasets it is
|
||||
recommended the ushort indices are used instead of unit indices.*/
|
||||
void setCoords( Vec3 *cp, GLushort *ci );
|
||||
/** set the coords (i.e the geometry) and unsigned int indices of the geoset.
|
||||
Unless your data set exceeds 65536 indices prefer ushort indices
|
||||
over unsigned int indices, only use this unit indices version if necessary.*/
|
||||
void setCoords( Vec3 *cp, GLuint *ci );
|
||||
/** set the coords (i.e the geometry) and indices of the geoset.*/
|
||||
void setCoords( Vec3 *cp, IndexPointer& ip );
|
||||
|
||||
/** get the number of normals required by the defined primitives and normals binding.*/
|
||||
inline int getNumNormals() const { return _numnormals; }
|
||||
/** get a pointer to Vec3 normal array. */
|
||||
inline Vec3* getNormals() { return _normals; }
|
||||
/** get a const pointer to Vec3 normal array. */
|
||||
inline const Vec3* getNormals() const { return _normals; }
|
||||
/** get the number of normal indices required by the defined primitives and normals binding.*/
|
||||
inline int getNumNormalIndices() const { return _nindex._size; }
|
||||
/** get the normal index array. */
|
||||
inline IndexPointer& getNormalIndices() { return _nindex; }
|
||||
/** get the const normal index array. */
|
||||
inline const IndexPointer& getNormalIndices() const { return _nindex; }
|
||||
/** set the normals of the geoset.*/
|
||||
void setNormals( Vec3 *np );
|
||||
/** set the normals and normal indices of the geoset.*/
|
||||
void setNormals( Vec3 *np, GLushort *ni );
|
||||
/** set the normals and normal indices of the geoset.*/
|
||||
void setNormals( Vec3 *np, GLuint *ni );
|
||||
/** set the normals and normal indices of the geoset.*/
|
||||
void setNormals( Vec3 *np, IndexPointer& ip );
|
||||
/** set the normals binding to the vertices/primitives/overall.*/
|
||||
void setNormalBinding( BindingType binding );
|
||||
inline BindingType getNormalBinding() const { return _normal_binding; }
|
||||
|
||||
/** get the number of colors required by the defined primitives and color binding.*/
|
||||
inline int getNumColors() const { return _numcolors; }
|
||||
/** get a pointer to Vec4 color array. */
|
||||
inline Vec4* getColors() { return _colors; }
|
||||
/** get a pointer to Vec4 color array. */
|
||||
inline const Vec4* getColors() const { return _colors; }
|
||||
/** get the number of colors indices required by the defined primitives and color binding.*/
|
||||
inline int getNumColorIndices() const { return _colindex._size; }
|
||||
/** get the color index array. */
|
||||
inline IndexPointer& getColorIndices() { return _colindex; }
|
||||
/** get the const color index array. */
|
||||
inline const IndexPointer& getColorIndices() const { return _colindex; }
|
||||
/** set the colors of the geoset.*/
|
||||
void setColors( Vec4 *cp );
|
||||
/** set the colors and color indices of the geoset.*/
|
||||
void setColors( Vec4 *cp, GLushort *li );
|
||||
/** set the colors and color indices of the geoset.*/
|
||||
void setColors( Vec4 *cp, GLuint *li );
|
||||
/** set the colors and color indices of the geoset.*/
|
||||
void setColors( Vec4 *cp, IndexPointer& ip );
|
||||
/** set the color binding to the vertices/primitives/overall.*/
|
||||
void setColorBinding( BindingType binding );
|
||||
inline BindingType getColorBinding() const { return _color_binding; }
|
||||
|
||||
/** get the number of texture coords required by the defined primitives and textures binding.*/
|
||||
inline int getNumTextureCoords() const { return _numtcoords; }
|
||||
/** get a pointer to Vec4 color array. */
|
||||
inline Vec2* getTextureCoords() { return _tcoords; }
|
||||
/** get a pointer to Vec4 color array. */
|
||||
inline const Vec2* getTextureCoords() const { return _tcoords; }
|
||||
/** get the number of texture coord indices required by the defined primitives and texture binding.*/
|
||||
inline int getNumTextureIndices() const { return _tindex._size; }
|
||||
/** get the texture index array. */
|
||||
inline IndexPointer& getTextureIndices() { return _tindex; }
|
||||
/** get the texture index array. */
|
||||
inline const IndexPointer& getTextureIndices() const { return _tindex; }
|
||||
/** set the texture coords of the geoset.*/
|
||||
void setTextureCoords( Vec2 *tc );
|
||||
/** set the texture coords and texture coord indices of the geoset.*/
|
||||
void setTextureCoords( Vec2 *tc, GLushort *ti );
|
||||
/** set the texture coords and texture coord indices of the geoset.*/
|
||||
void setTextureCoords( Vec2 *tc, GLuint *ti );
|
||||
/** set the texture coords and texture indices of the geoset.*/
|
||||
void setTextureCoords( Vec2 *tc, IndexPointer& ip );
|
||||
/** set the texture coord binding to the vertices/primitives/overall.*/
|
||||
void setTextureBinding( BindingType binding );
|
||||
inline BindingType getTextureBinding() const { return _texture_binding; }
|
||||
|
||||
/** get the number of texture coords required by the defined primitives and textures binding.*/
|
||||
inline int getNumInterleavedCoords() const { return _numcoords; }
|
||||
/** get a pointer to interleaved float array. */
|
||||
inline void* getInterleavedArray() { return _iarray; }
|
||||
/** get a const pointer to interleaved float array. */
|
||||
inline const void* getInterleavedArray() const { return _iarray; }
|
||||
/** get the number of texture coord indices required by the defined primitives and texture binding.*/
|
||||
inline int getNumInterleavedIndices() const { return _iaindex._size; }
|
||||
/** get the texture index array. */
|
||||
inline IndexPointer& getInterleavedIndices() { return _iaindex; }
|
||||
/** get the interleaved index array. */
|
||||
inline const IndexPointer& getInterleavedIndices() const { return _iaindex; }
|
||||
/** get the interleaved array storage format. */
|
||||
inline InterleaveArrayType getInterleavedFormat() const { return _iaformat; }
|
||||
|
||||
/** set the interleaved arrays of the geoset.*/
|
||||
void setInterleavedArray( InterleaveArrayType format, float *ia );
|
||||
void setInterleavedArray( InterleaveArrayType format, float *ia, GLushort *iai );
|
||||
void setInterleavedArray( InterleaveArrayType format, float *ia, GLuint *iai );
|
||||
void setInterleavedArray( InterleaveArrayType format, float *ia, IndexPointer& iai );
|
||||
|
||||
/** draw geoset 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 GeoSet for user-drawn objects.
|
||||
*/
|
||||
virtual void drawImplementation(State& state) const;
|
||||
|
||||
bool check() const;
|
||||
|
||||
|
||||
/** function object which is used to handling the clean up of attribute arrays
|
||||
* associated with GeoSet's. A default is provided which assumes that all
|
||||
* momory attached to the GeoSet is owned by this GeoSet and can be deleted
|
||||
* using delete []. If this is not the cause derive your own AttributeDeleteFunctor
|
||||
* a specify your own memory deletion operation.*/
|
||||
struct SG_EXPORT AttributeDeleteFunctor : public osg::Referenced
|
||||
{
|
||||
// see GeoSet.cpp for implemention.
|
||||
virtual void operator() (GeoSet* gset);
|
||||
};
|
||||
|
||||
/** set an alternative AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
||||
void setAttributeDeleteFunctor(AttributeDeleteFunctor* adf) { _adf = adf; }
|
||||
|
||||
/** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
||||
AttributeDeleteFunctor* getAttributeDeleteFunctor() { return _adf.get(); }
|
||||
|
||||
/** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
||||
const AttributeDeleteFunctor* getAttributeDeleteFunctor() const { return _adf.get(); }
|
||||
|
||||
/** return true, osg::GeoSet does support accept(AttributeFunctor&).*/
|
||||
virtual bool supports(AttributeFunctor&) const { return true; }
|
||||
|
||||
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
|
||||
virtual void accept(AttributeFunctor& af);
|
||||
|
||||
/** return true, osg::GeoSet does support accept(ConstAttributeFunctor&).*/
|
||||
virtual bool supports(ConstAttributeFunctor&) const { return true; }
|
||||
|
||||
/** accept an ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
|
||||
virtual void accept(ConstAttributeFunctor& af) const;
|
||||
|
||||
/** return true, osg::GeoSet does support accept(PrimitiveFunctor&) .*/
|
||||
virtual bool supports(PrimitiveFunctor&) const { return true; }
|
||||
|
||||
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
|
||||
virtual void accept(PrimitiveFunctor& pf) const;
|
||||
|
||||
/** convinience function for converting GeoSet's to equivilant Geometry nodes.*/
|
||||
Geometry* convertToGeometry();
|
||||
|
||||
protected:
|
||||
|
||||
GeoSet& operator = (const GeoSet&) { return *this;}
|
||||
|
||||
virtual ~GeoSet();
|
||||
|
||||
virtual bool computeBound() const;
|
||||
|
||||
ref_ptr<AttributeDeleteFunctor> _adf;
|
||||
|
||||
int _numprims;
|
||||
PrimitiveType _primtype;
|
||||
int _needprimlen;
|
||||
unsigned int _oglprimtype;
|
||||
int *_primLengths;
|
||||
mutable unsigned char _primlength;
|
||||
unsigned char _flat_shaded_skip;
|
||||
|
||||
mutable int _numcoords;
|
||||
Vec3 *_coords;
|
||||
mutable IndexPointer _cindex;
|
||||
|
||||
BindingType _normal_binding;
|
||||
mutable int _numnormals;
|
||||
Vec3 *_normals;
|
||||
IndexPointer _nindex;
|
||||
|
||||
BindingType _color_binding;
|
||||
mutable int _numcolors;
|
||||
Vec4 *_colors;
|
||||
IndexPointer _colindex;
|
||||
|
||||
BindingType _texture_binding;
|
||||
mutable int _numtcoords;
|
||||
Vec2 *_tcoords;
|
||||
IndexPointer _tindex;
|
||||
|
||||
void *_iarray;
|
||||
IndexPointer _iaindex;
|
||||
InterleaveArrayType _iaformat;
|
||||
unsigned int _ogliaformat;
|
||||
|
||||
|
||||
int _fast_path;
|
||||
|
||||
void set_fast_path( void );
|
||||
void draw_fast_path( State& state ) const;
|
||||
void draw_alternate_path( State& state ) const;
|
||||
|
||||
};
|
||||
|
||||
/** 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_triangle(GeoSet& gset,T& op)
|
||||
{
|
||||
switch(gset.getPrimType())
|
||||
{
|
||||
case(GeoSet::TRIANGLE_STRIP):
|
||||
case(GeoSet::FLAT_TRIANGLE_STRIP):
|
||||
{
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
GLushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
GLushort* iend = iptr+primLength;
|
||||
for(int j = 2; j < primLength; j++ )
|
||||
{
|
||||
if( !(j%2) )
|
||||
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
||||
else
|
||||
op(vptr[*(iptr)],vptr[*(iptr+2)],vptr[*(iptr+1)]);
|
||||
++iptr;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* iptr = gset.getCoordIndices()._ptr._uint;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
GLuint* iend = iptr+primLength;
|
||||
for(int j = 2; j < primLength; j++ )
|
||||
{
|
||||
if( !(j%2) )
|
||||
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
||||
else
|
||||
op(vptr[*(iptr)],vptr[*(iptr+2)],vptr[*(iptr+1)]);
|
||||
++iptr;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
Vec3* vend = vptr+primLength;
|
||||
for(int j = 2; j < primLength; j++ )
|
||||
{
|
||||
if( !(j%2) )
|
||||
op(*(vptr),*(vptr+1),*(vptr+2));
|
||||
else
|
||||
op(*(vptr),*(vptr+2),*(vptr+1));
|
||||
++vptr;
|
||||
}
|
||||
vptr=vend;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case(GeoSet::TRIANGLES):
|
||||
{
|
||||
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
GLushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
||||
iptr+=3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* iptr = gset.getCoordIndices()._ptr._uint;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
||||
iptr+=3;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(*(vptr),*(vptr+1),*(vptr+2));
|
||||
vptr+=3;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case(GeoSet::QUAD_STRIP):
|
||||
{
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
GLushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
GLushort* iend = iptr+primLength;
|
||||
for(int j = 3; j < primLength; j+=2 )
|
||||
{
|
||||
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
||||
op(vptr[*(iptr+1)],vptr[*(iptr+3)],vptr[*(iptr+2)]);
|
||||
iptr+=2;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* iptr = gset.getCoordIndices()._ptr._uint;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
GLuint* iend = iptr+primLength;
|
||||
for(int j = 3; j < primLength; j+=2 )
|
||||
{
|
||||
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
||||
op(vptr[*(iptr+1)],vptr[*(iptr+3)],vptr[*(iptr+2)]);
|
||||
iptr+=2;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
Vec3* vend = vptr+primLength;
|
||||
for(int j = 3; j < primLength; j+=2 )
|
||||
{
|
||||
op(*(vptr),*(vptr+1),*(vptr+2));
|
||||
op(*(vptr+1),*(vptr+3),*(vptr+2));
|
||||
vptr+=2;
|
||||
}
|
||||
vptr=vend;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case(GeoSet::QUADS):
|
||||
{
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
GLushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
||||
op(vptr[*(iptr)],vptr[*(iptr+2)],vptr[*(iptr+3)]);
|
||||
iptr+=4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* iptr = gset.getCoordIndices()._ptr._uint;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
||||
op(vptr[*(iptr)],vptr[*(iptr+2)],vptr[*(iptr+3)]);
|
||||
iptr+=4;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
op(*(vptr),*(vptr+1),*(vptr+2));
|
||||
op(*(vptr),*(vptr+2),*(vptr+3));
|
||||
vptr+=4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case(GeoSet::FLAT_TRIANGLE_FAN):
|
||||
case(GeoSet::TRIANGLE_FAN):
|
||||
case(GeoSet::POLYGON):
|
||||
{
|
||||
if (gset.getCoordIndices().valid())
|
||||
{
|
||||
if (gset.getCoordIndices()._is_ushort)
|
||||
{
|
||||
GLushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
if (primLength>0)
|
||||
{
|
||||
const Vec3& start = vptr[*(iptr)];
|
||||
GLushort* iend = iptr+primLength;
|
||||
++iptr;
|
||||
for(int j = 2; j < primLength; ++j )
|
||||
{
|
||||
op(start,vptr[*(iptr)],vptr[*(iptr+1)]);
|
||||
++iptr;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLuint* iptr = gset.getCoordIndices()._ptr._uint;
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
if (primLength>0)
|
||||
{
|
||||
const Vec3& start = vptr[*(iptr)];
|
||||
GLuint* iend = iptr+primLength;
|
||||
++iptr;
|
||||
for(int j = 2; j < primLength; ++j )
|
||||
{
|
||||
op(start,vptr[*(iptr)],vptr[*(iptr+1)]);
|
||||
++iptr;
|
||||
}
|
||||
iptr=iend;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec3* vptr = gset.getCoords();
|
||||
const int numPrim = gset.getNumPrims();
|
||||
for(int i=0; i<numPrim; ++i )
|
||||
{
|
||||
const int primLength = gset.getPrimLengths()[i];
|
||||
if (primLength>0)
|
||||
{
|
||||
const Vec3& start = *vptr;
|
||||
Vec3* vend = vptr+primLength;
|
||||
++vptr;
|
||||
for(int j = 2; j < primLength; ++j)
|
||||
{
|
||||
op(start,*(vptr),*(vptr+1));
|
||||
++vptr;
|
||||
}
|
||||
vptr = vend;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -150,12 +150,16 @@ class SG_EXPORT VertexProgram : public StateAttribute
|
||||
}
|
||||
|
||||
/** Set the vertex program using C++ style string.*/
|
||||
inline void setVertexProgram( const std::string& program ) { _vertexProgram = program; }
|
||||
inline void setVertexProgram( const std::string& program )
|
||||
{
|
||||
_vertexProgram = program;
|
||||
dirtyVertexProgramObject();
|
||||
}
|
||||
|
||||
/** Set the vertex program using a C style string.*/
|
||||
inline void setVertexProgram( const char* program )
|
||||
{
|
||||
_vertexProgram = program;
|
||||
|
||||
dirtyVertexProgramObject();
|
||||
}
|
||||
/** Get the vertex program.*/
|
||||
|
@ -53,17 +53,6 @@ class OSGUTIL_EXPORT Optimizer
|
||||
virtual void optimize(osg::Node* node, unsigned int options = ALL_OPTIMIZATIONS);
|
||||
|
||||
|
||||
/** ConvertGeoSetsToGeometryVisitor all the old GeoSet Drawables to the new Geometry Drawables.*/
|
||||
class OSGUTIL_EXPORT ConvertGeoSetsToGeometryVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
ConvertGeoSetsToGeometryVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
||||
|
||||
virtual void apply(osg::Geode& geode);
|
||||
virtual void apply(osg::Node& node) { traverse(node); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** Flatten Static Trasform nodes by applying their transform to the
|
||||
|
@ -34,8 +34,6 @@ CXXFILES =\
|
||||
FrontFace.cpp\
|
||||
GLExtensions.cpp\
|
||||
Geometry.cpp\
|
||||
GeoSet.cpp\
|
||||
GeoSet_ogl.cpp\
|
||||
Geode.cpp\
|
||||
Group.cpp\
|
||||
Image.cpp\
|
||||
|
1232
src/osg/GeoSet.cpp
1232
src/osg/GeoSet.cpp
File diff suppressed because it is too large
Load Diff
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "transform.h"
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Material>
|
||||
#include <osg/Texture2D>
|
||||
|
@ -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
@ -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;
|
||||
}
|
@ -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
|
@ -3,7 +3,6 @@ include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
ConvertFromPerformer.cpp\
|
||||
ConvertToPerformer.cpp\
|
||||
ReaderWriterPFB.cpp\
|
||||
|
||||
LIBS += $(OSG_LIBS) $(PF_XTRA_LIBS) $(OTHER_LIBS)
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user