From Katherina Plugge, "if using multitexturing and converting osg files to OpenFlight texture coordinates get corrupted. The texture coordinates for slot 1 and following are not computed correctly (see thread http://forum.openscenegraph.org/viewtopic.php?t=6993).
The attached files solve the problem. "
This commit is contained in:
@@ -136,7 +136,8 @@ public:
|
||||
void writeMeshPrimitive( const std::vector<unsigned int>& indices, GLenum mode );
|
||||
void writeLocalVertexPool( const osg::Geometry& geom );
|
||||
void writeMultitexture( const osg::Geometry& geom );
|
||||
void writeUVList( int numVerts, const osg::Geometry& geom );
|
||||
void writeUVList( int numVerts, const osg::Geometry& geom, const std::vector<unsigned int>& indices );
|
||||
void writeUVList( int numVerts, const osg::Geometry& geom, unsigned int first);
|
||||
|
||||
// Light Point records
|
||||
void writeLightPoint();
|
||||
|
||||
@@ -770,7 +770,7 @@ FltExportVisitor::writeMultitexture( const osg::Geometry& geom )
|
||||
}
|
||||
|
||||
void
|
||||
FltExportVisitor::writeUVList( int numVerts, const osg::Geometry& geom )
|
||||
FltExportVisitor::writeUVList( int numVerts, const osg::Geometry& geom, const std::vector<unsigned int>& indices )
|
||||
{
|
||||
unsigned int numLayers( 0 );
|
||||
uint32 flags( 0 );
|
||||
@@ -808,7 +808,61 @@ FltExportVisitor::writeUVList( int numVerts, const osg::Geometry& geom )
|
||||
_fltOpt->getWriteResult().warn( warning.str() );
|
||||
t2 = new osg::Vec2Array;
|
||||
}
|
||||
else if (static_cast<int>(t2->getNumElements()) != numVerts)
|
||||
|
||||
const int size = t2->getNumElements();
|
||||
for( int cIdx=0; cIdx<numVerts; cIdx++)
|
||||
{
|
||||
int vIdx = indices[cIdx];
|
||||
osg::Vec2& tc( defaultCoord );
|
||||
if (vIdx < size)
|
||||
tc = (*t2)[ vIdx ];
|
||||
_records->writeFloat32( tc[0] );
|
||||
_records->writeFloat32( tc[1] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FltExportVisitor::writeUVList( int numVerts, const osg::Geometry& geom, unsigned int first )
|
||||
{
|
||||
unsigned int numLayers( 0 );
|
||||
uint32 flags( 0 );
|
||||
unsigned int idx;
|
||||
for( idx=1; idx<8; idx++)
|
||||
{
|
||||
if( isTextured( idx, geom ) )
|
||||
{
|
||||
flags |= LAYER_1 >> (idx-1);
|
||||
numLayers++;
|
||||
}
|
||||
}
|
||||
if( numLayers == 0 )
|
||||
return;
|
||||
|
||||
uint16 length( 8 + (8*numLayers*numVerts) );
|
||||
|
||||
_records->writeInt16( (int16) UV_LIST_OP );
|
||||
_records->writeUInt16( length );
|
||||
_records->writeInt32( flags );
|
||||
|
||||
osg::Vec2 defaultCoord( 0., 0. );
|
||||
for( idx=1; idx<8; idx++)
|
||||
{
|
||||
if( isTextured( idx, geom ) )
|
||||
{
|
||||
osg::Array* t = const_cast<osg::Array*>( geom.getTexCoordArray( idx ) );
|
||||
osg::ref_ptr<osg::Vec2Array> t2 = dynamic_cast<osg::Vec2Array*>( t );
|
||||
if (!t2.valid())
|
||||
{
|
||||
std::ostringstream warning;
|
||||
warning << "fltexp: No Texture2D for unit " << idx;
|
||||
osg::notify( osg::WARN ) << warning.str() << std::endl;
|
||||
_fltOpt->getWriteResult().warn( warning.str() );
|
||||
t2 = new osg::Vec2Array;
|
||||
}
|
||||
else if (static_cast<int>(t2->getNumElements()) < first + numVerts)
|
||||
{
|
||||
std::ostringstream warning;
|
||||
warning << "fltexp: Invalid number of texture coordinates for unit " << idx;
|
||||
@@ -817,9 +871,10 @@ FltExportVisitor::writeUVList( int numVerts, const osg::Geometry& geom )
|
||||
}
|
||||
|
||||
const int size = t2->getNumElements();
|
||||
int vIdx;
|
||||
for( vIdx=0; vIdx<numVerts; vIdx++)
|
||||
int cIdx;
|
||||
for( cIdx=0; cIdx<numVerts; cIdx++)
|
||||
{
|
||||
int vIdx = first + cIdx;
|
||||
osg::Vec2& tc( defaultCoord );
|
||||
if (vIdx < size)
|
||||
tc = (*t2)[ vIdx ];
|
||||
@@ -892,7 +947,7 @@ FltExportVisitor::handleDrawArrays( const osg::DrawArrays* da, const osg::Geomet
|
||||
int numVerts = writeVertexList( first, n );
|
||||
first += n;
|
||||
|
||||
writeUVList( numVerts, geom );
|
||||
writeUVList( numVerts, geom, first );
|
||||
|
||||
writePop();
|
||||
}
|
||||
@@ -977,7 +1032,7 @@ FltExportVisitor::handleDrawArrayLengths( const osg::DrawArrayLengths* dal, cons
|
||||
first += n;
|
||||
}
|
||||
|
||||
writeUVList( numVerts, geom );
|
||||
writeUVList( numVerts, geom, first );
|
||||
|
||||
writePop();
|
||||
}
|
||||
@@ -1058,7 +1113,7 @@ FltExportVisitor::handleDrawElements( const osg::DrawElements* de, const osg::Ge
|
||||
int numVerts = writeVertexList( indices, n );
|
||||
first += n;
|
||||
|
||||
writeUVList( numVerts, geom );
|
||||
writeUVList( numVerts, geom, indices );
|
||||
|
||||
writePop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user