⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expgeometryrecords.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            writeContinuationRecord( (vertSize * thisVertCount) );        }    }}voidFltExportVisitor::writeMultitexture( const osg::Geometry& geom ){    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) );    _records->writeInt16( (int16) MULTITEXTURE_OP );    _records->writeUInt16( length );    _records->writeInt32( flags );    const osg::StateSet* ss = getCurrentStateSet();    for( idx=1; idx<8; idx++)    {        if( isTextured( idx, geom ) )        {            int16 textureIndex( -1 );            const osg::Texture2D* texture = static_cast<const osg::Texture2D*>(                ss->getTextureAttribute( idx, osg::StateAttribute::TEXTURE )  );            if (texture != NULL)                textureIndex = _texturePalette->add( idx, texture );            else            {                std::ostringstream warning;                warning << "fltexp: No Texture2D for unit " << idx;                osg::notify( osg::WARN ) << warning.str() << std::endl;                _fltOpt->getWriteResult().warn( warning.str() );            }            // texture index (this value is an unsigned int, but has a -1 default per oflt spec: ugh)            _records->writeUInt16( static_cast< uint16 >( textureIndex ) );            _records->writeUInt16( 0 ); // TBD effect             // mapping index (this value is an unsigned int, but has a -1 default per oflt spec: ugh)            _records->writeUInt16( static_cast< uint16 >( -1 ) );            _records->writeUInt16( 0 ); // data        }    }}voidFltExportVisitor::writeUVList( int numVerts, const osg::Geometry& geom ){    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. );    const osg::StateSet* ss = getCurrentStateSet();    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 (t2->getNumElements() != numVerts)            {                std::ostringstream warning;                warning << "fltexp: Invalid number of texture coordinates for unit " << idx;                osg::notify( osg::WARN ) << warning.str() << std::endl;                _fltOpt->getWriteResult().warn( warning.str() );            }            const int size = t2->getNumElements();            int vIdx;            for( vIdx=0; vIdx<numVerts; vIdx++)            {                osg::Vec2& tc( defaultCoord );                if (vIdx < size)                    tc = (*t2)[ vIdx ];                _records->writeFloat32( tc[0] );                _records->writeFloat32( tc[1] );            }        }    }}voidFltExportVisitor::handleDrawArrays( const osg::DrawArrays* da, const osg::Geometry& geom, const osg::Geode& geode ){    GLint first = da->getFirst();    GLsizei count = da->getCount();    GLenum mode = da->getMode();    int n( 0 );    bool useMesh( false );    switch( mode )    {    case GL_TRIANGLE_STRIP:    case GL_TRIANGLE_FAN:    case GL_QUAD_STRIP:        useMesh = true;        break;    case GL_POINTS:        n = 1;        break;    case GL_LINES:        n = 2;        break;    case GL_TRIANGLES:        n = 3;        break;    case GL_QUADS:        n = 4;        break;    case GL_LINE_STRIP:    case GL_LINE_LOOP:    case GL_POLYGON:    default:        n = count;        break;    }    if (useMesh)    {        std::vector< unsigned int > indices;        int jdx;        for (jdx=0; jdx<count; jdx++)            indices.push_back( first+jdx );        writeMeshPrimitive( indices, mode );    }    else    {        const unsigned int max( first+count );        while ((unsigned int)( first+n ) <= max)        {            writeFace( geode, geom, mode );            writeMatrix( geode.getUserData() );            writeComment( geode );            writeMultitexture( geom );            writePush();            // Write vertex list records.            int numVerts = writeVertexList( first, n );            first += n;            writeUVList( numVerts, geom );            writePop();        }    }}voidFltExportVisitor::handleDrawArrayLengths( const osg::DrawArrayLengths* dal, const osg::Geometry& geom, const osg::Geode& geode ){    GLint first = dal->getFirst();    GLenum mode = dal->getMode();    int n( 0 );    bool useMesh( false );    switch( mode )    {    case GL_TRIANGLE_STRIP:    case GL_TRIANGLE_FAN:    case GL_QUAD_STRIP:        useMesh = true;        break;    case GL_POINTS:        n = 1;        break;    case GL_LINES:        n = 2;        break;    case GL_TRIANGLES:        n = 3;        break;    case GL_QUADS:        n = 4;        break;    case GL_LINE_STRIP:    case GL_LINE_LOOP:    case GL_POLYGON:    default:        break;    }    // Push and pop subfaces if polygon offset is on.    SubfaceHelper subface( *this, getCurrentStateSet() );    if (useMesh)    {        int idx( 0 );        for( osg::DrawArrayLengths::const_iterator itr=dal->begin();             itr!=dal->end(); itr++ )        {            std::vector< unsigned int > indices;            int jdx;            for (jdx=0; jdx<(*itr); idx++, jdx++)                indices.push_back( idx );            writeMeshPrimitive( indices, mode );        }    }    else    {        // Hm. You wouldn't usually use DrawArrayLengths for non-strip/fan prims...        for( osg::DrawArrayLengths::const_iterator itr=dal->begin();             itr!=dal->end(); itr++ )        {            while (first+n <= *itr)            {                writeFace( geode, geom, mode );                writeMatrix( geode.getUserData() );                writeComment( geode );                writeMultitexture( geom );                writePush();                // Write vertex list records.                int numVerts;                if (n == 0)                {                    numVerts = writeVertexList( first, *itr );                    first += *itr;                }                else                {                    numVerts = writeVertexList( first, n );                    first += n;                }                writeUVList( numVerts, geom );                writePop();            }            first += *itr;        }    }}voidFltExportVisitor::handleDrawElements( const osg::DrawElements* de, const osg::Geometry& geom, const osg::Geode& geode ){    GLenum mode = de->getMode();    int n( 0 );    bool useMesh( false );    switch( mode )    {    case GL_TRIANGLE_STRIP:    case GL_TRIANGLE_FAN:    case GL_QUAD_STRIP:        n = de->getNumIndices();        useMesh = true;        break;    case GL_POINTS:        n = 1;        break;    case GL_LINES:        n = 2;        break;    case GL_TRIANGLES:        n = 3;        break;    case GL_QUADS:        n = 4;        break;    case GL_LINE_STRIP:    case GL_LINE_LOOP:    case GL_POLYGON:    default:        n = de->getNumIndices();        break;    }    // Push and pop subfaces if polygon offset is on.    SubfaceHelper subface( *this, getCurrentStateSet() );    if (useMesh)    {        std::vector< unsigned int > indices;        int idx;        for (idx=0; idx<n; idx++)            indices.push_back( de->index( idx ) );        writeMeshPrimitive( indices, mode );    }    else    {        unsigned int first( 0 );        while (first+n <= de->getNumIndices())        {            // Need:            // * Geode for record name (but also need to handle            //   multi Geometry objects and multi PrimitiveSet objects;            //   all Face records can't have the same name).            // * Mode            writeFace( geode, geom, mode );            writeMatrix( geode.getUserData() );            writeComment( geode );            writeMultitexture( geom );            writePush();            // Write vertex list records.            std::vector<unsigned int> indices;            int idx;            for(idx=0; idx<n; idx++)                indices.push_back( de->index( first+idx ) );            int numVerts = writeVertexList( indices, n );            first += n;            writeUVList( numVerts, geom );            writePop();        }    }}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -