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

📄 vertexpalettemanager.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    for( idx=0; idx<v->size(); idx++)    {        uint32  packedColor( 0 );        if (c && colorPerVertex)        {            osg::Vec4 color = (*c)[ idx ];            packedColor = (int)(color[3]*255) << 24 |                (int)(color[2]*255) << 16 | (int)(color[1]*255) << 8 |                (int)(color[0]*255);        }        // Write fields common to all record types.        _vertices->writeInt16( opcode );        _vertices->writeUInt16( sizeBytes );        _vertices->writeUInt16( 0 ); // Color name        _vertices->writeInt16( flags ); // Flags        _vertices->writeVec3d( (*v)[ idx ] ); // Vertex        // Now write record-specific field.        switch( recType )        {        case VERTEX_C:            _vertices->writeInt32( packedColor ); // Packed color            _vertices->writeUInt32( 0 ); // Vertex color index            break;        case VERTEX_CN:            _vertices->writeVec3f( (*n)[ idx ] ); // Normal            _vertices->writeInt32( packedColor ); // Packed color            _vertices->writeUInt32( 0 ); // Vertex color index            if (_fltOpt.getFlightFileVersionNumber() > ExportOptions::VERSION_15_7)                _vertices->writeUInt32( 0 ); // Reserved            break;        case VERTEX_CNT:            _vertices->writeVec3f( (*n)[ idx ] ); // Normal            _vertices->writeVec2f( (*t)[ idx ] ); // Tex coord            _vertices->writeInt32( packedColor ); // Packed color            _vertices->writeUInt32( 0 ); // Vertex color index            _vertices->writeUInt32( 0 ); // Reserved            break;        case VERTEX_CT:            _vertices->writeVec2f( (*t)[ idx ] ); // Tex coord            _vertices->writeInt32( packedColor ); // Packed color            _vertices->writeUInt32( 0 ); // Vertex color index            break;        }    }}osg::ref_ptr< const osg::Vec2Array >VertexPaletteManager::asVec2Array( const osg::Array* in, const unsigned int n ){    if (!in)        return NULL;    osg::Array::Type arrayType = in->getType();    if (arrayType == osg::Array::Vec2ArrayType)    {        if (n <= in->getNumElements())        {            osg::ref_ptr< const osg::Vec2Array > v2f =                dynamic_cast< const osg::Vec2Array* >( in );            return v2f;        }    }    const unsigned int nToCopy = ( (n < in->getNumElements()) ? n : in->getNumElements() );    osg::ref_ptr< osg::Vec2Array > ret = new osg::Vec2Array( n );    switch( arrayType )    {    case osg::Array::Vec2ArrayType:    {        // No need to convert data, but must copy into correctly-sized array.        // If the size was correct, we wouldn't be here.        osg::ref_ptr< const osg::Vec2Array > v2f =            dynamic_cast< const osg::Vec2Array* >( in );        ret->assign( v2f->begin(), v2f->end() );;        ret->resize( n );        return ret.get();    }    case osg::Array::Vec2dArrayType:    {        osg::ref_ptr< const osg::Vec2dArray > v2d =            dynamic_cast< const osg::Vec2dArray* >( in );        unsigned int idx;        for (idx=0; idx<nToCopy; idx++ )            (*ret)[ idx ] = (*v2d)[ idx ]; // convert Vec2 double to Vec2 float        return ret.get();    }    default:    {        osg::notify( osg::WARN ) << "fltexp: Unsupported array type in conversion to Vec2Array: " << arrayType << std::endl;        return NULL;    }    }}osg::ref_ptr< const osg::Vec3Array >VertexPaletteManager::asVec3Array( const osg::Array* in, const unsigned int n ){    if (!in)        return NULL;    osg::Array::Type arrayType = in->getType();    if (arrayType == osg::Array::Vec3ArrayType)    {        if (n <= in->getNumElements())        {            osg::ref_ptr< const osg::Vec3Array > v3f =                dynamic_cast< const osg::Vec3Array* >( in );            return v3f;        }    }    const unsigned int nToCopy = ( (n < in->getNumElements()) ? n : in->getNumElements() );    osg::ref_ptr< osg::Vec3Array > ret = new osg::Vec3Array( n );    switch( arrayType )    {    case osg::Array::Vec3ArrayType:    {        // No need to convert data, but must copy into correctly-sized array.        // If the size was correct, we wouldn't be here.        osg::ref_ptr< const osg::Vec3Array > v3f =            dynamic_cast< const osg::Vec3Array* >( in );        ret->assign( v3f->begin(), v3f->end() );;        ret->resize( n );        return ret.get();    }    case osg::Array::Vec3dArrayType:    {        osg::ref_ptr< const osg::Vec3dArray > v3d =            dynamic_cast< const osg::Vec3dArray* >( in );        unsigned int idx;        for (idx=0; idx<nToCopy; idx++ )            (*ret)[ idx ] = (*v3d)[ idx ]; // convert Vec3 double to Vec3 float        return ret.get();    }    default:    {        osg::notify( osg::WARN ) << "fltexp: Unsupported array type in conversion to Vec3Array: " << arrayType << std::endl;        return NULL;    }    }}osg::ref_ptr< const osg::Vec3dArray >VertexPaletteManager::asVec3dArray( const osg::Array* in, const unsigned int n ){    if (!in)        return NULL;    osg::Array::Type arrayType = in->getType();    if (arrayType == osg::Array::Vec3dArrayType)    {        if (n <= in->getNumElements())        {            osg::ref_ptr< const osg::Vec3dArray > v3d =                dynamic_cast< const osg::Vec3dArray* >( in );            return v3d;        }    }    const unsigned int nToCopy = ( (n < in->getNumElements()) ? n : in->getNumElements() );    osg::ref_ptr< osg::Vec3dArray > ret = new osg::Vec3dArray( n );    switch( arrayType )    {    case osg::Array::Vec3dArrayType:    {        // No need to convert data, but must copy into correctly-sized array.        // If the size was correct, we wouldn't be here.        osg::ref_ptr< const osg::Vec3dArray > v3d =            dynamic_cast< const osg::Vec3dArray* >( in );        ret->assign( v3d->begin(), v3d->end() );;        ret->resize( n );        return ret.get();    }    case osg::Array::Vec3ArrayType:    {        osg::ref_ptr< const osg::Vec3Array > v3f =            dynamic_cast< const osg::Vec3Array* >( in );        unsigned int idx;        for (idx=0; idx<nToCopy; idx++ )            (*ret)[ idx ] = (*v3f)[ idx ]; // convert Vec3 float to Vec3 double        return ret.get();    }    default:    {        osg::notify( osg::WARN ) << "fltexp: Unsupported array type in conversion to Vec3dArray: " << arrayType << std::endl;        return NULL;    }    }}osg::ref_ptr< const osg::Vec4Array >VertexPaletteManager::asVec4Array( const osg::Array* in, const unsigned int n ){    if (!in)        return NULL;    osg::Array::Type arrayType = in->getType();    if (arrayType == osg::Array::Vec4ArrayType)    {        if (n <= in->getNumElements())        {            osg::ref_ptr< const osg::Vec4Array > v4f =                dynamic_cast< const osg::Vec4Array* >( in );            return v4f;        }    }    const unsigned int nToCopy = ( (n < in->getNumElements()) ? n : in->getNumElements() );    osg::ref_ptr< osg::Vec4Array > ret = new osg::Vec4Array( n );    switch( arrayType )    {    case osg::Array::Vec4ArrayType:    {        // No need to convert data, but must copy into correctly-sized array.        // If the size was correct, we wouldn't be here.        osg::ref_ptr< const osg::Vec4Array > v4f =            dynamic_cast< const osg::Vec4Array* >( in );        ret->assign( v4f->begin(), v4f->end() );;        ret->resize( n );        return ret.get();    }    case osg::Array::Vec4ubArrayType:    {        osg::ref_ptr< const osg::Vec4ubArray > v4ub =            dynamic_cast< const osg::Vec4ubArray* >( in );        unsigned int idx;        for (idx=0; idx<nToCopy; idx++ )        {            // convert Vec4 unsigned byte to Vec4 float            osg::Vec4& dest = (*ret)[ idx ];            osg::Vec4ub src = (*v4ub)[ idx ];            dest[0] = src[0] / 255.f;            dest[1] = src[1] / 255.f;            dest[2] = src[2] / 255.f;            dest[3] = src[3] / 255.f;        }        return ret.get();    }    default:    {        osg::notify( osg::WARN ) << "fltexp: Unsupported array type in conversion to Vec4Array: " << arrayType << std::endl;        return NULL;    }    }}VertexPaletteManager::ArrayInfo::ArrayInfo()  : _byteStart( 0 ),    _idxSizeBytes( 0 ),    _idxCount( 0 ){}}

⌨️ 快捷键说明

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