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

📄 daermaterials.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        osg::notify( osg::WARN ) << "Could not locate image for texture" << std::endl;        return NULL;    }    //Got a sampler and a surface and an imaged. Time to create the texture stuff for osg    osg::Image *img = NULL;    if ( dImg->getInit_from() != NULL )    {        // daeURI uri = dImg->getInit_from()->getValue();        dImg->getInit_from()->getValue().validate();        if ( std::string( dImg->getInit_from()->getValue().getProtocol() ) == std::string( "file" ) )        {            //unsigned int bufSize = 1; //for the null char            //bufSize += dImg->getInit_from()->getValue().pathDir().size();            //bufSize += dImg->getInit_from()->getValue().pathFile().size();           std::string path =  dImg->getInit_from()->getValue().pathDir()+                                  dImg->getInit_from()->getValue().pathFile();              // remove space encodings              //              path = cdom::uriToNativePath(path);           if(path.empty())           {              osg::notify( osg::WARN ) << "Unable to get path from URI." << std::endl;              return NULL;           }#ifdef WIN32            // If the path has a drive specifier or a UNC name then strip the leading /            const char* filename =path.c_str();            if ((path[2] == ':') || ((path[1] == '/') && (path[2] == '/')))               ++filename;// = path+1;//            else//                filename = path;#else            const char* filename = path.c_str();#endif            img = osgDB::readImageFile( filename );            osg::notify(osg::INFO)<<"  processTexture(..) - readImage("<<filename<<")"<<std::endl;                        //Moved this below the osg::notify - Parag, 24/7/2007            //delete [] path;                    }        else        {            osg::notify( osg::WARN ) << "Only images with a \"file\" scheme URI are supported in this version." << std::endl;            return NULL;        }    }    else    {        osg::notify( osg::WARN ) << "Embedded image data is not supported in this version." << std::endl;            return NULL;    }    osg::Texture2D *t2D = new osg::Texture2D( img );    //set texture parameters    if ( sampler != NULL )    {        if ( sampler->getWrap_s() != NULL )        {            osg::Texture::WrapMode wrap;            switch( sampler->getWrap_s()->getValue() )            {            case FX_SAMPLER_WRAP_COMMON_WRAP:                wrap = osg::Texture::REPEAT;                break;            case FX_SAMPLER_WRAP_COMMON_MIRROR:                wrap = osg::Texture::MIRROR;                break;            case FX_SAMPLER_WRAP_COMMON_CLAMP:                wrap = osg::Texture::CLAMP_TO_EDGE;                break;            case FX_SAMPLER_WRAP_COMMON_NONE:            case FX_SAMPLER_WRAP_COMMON_BORDER:                wrap = osg::Texture::CLAMP_TO_BORDER;                break;            default:                wrap = osg::Texture::CLAMP;                break;            }            t2D->setWrap( osg::Texture::WRAP_S, wrap );        }        else        {            t2D->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );        }        if ( sampler->getWrap_t() != NULL )        {            osg::Texture::WrapMode wrap;            switch( sampler->getWrap_t()->getValue() )            {            case FX_SAMPLER_WRAP_COMMON_WRAP:                wrap = osg::Texture::REPEAT;                break;            case FX_SAMPLER_WRAP_COMMON_MIRROR:                wrap = osg::Texture::MIRROR;                break;            case FX_SAMPLER_WRAP_COMMON_CLAMP:                wrap = osg::Texture::CLAMP_TO_EDGE;                break;            case FX_SAMPLER_WRAP_COMMON_NONE:            case FX_SAMPLER_WRAP_COMMON_BORDER:                wrap = osg::Texture::CLAMP_TO_BORDER;                break;            default:                wrap = osg::Texture::CLAMP;                break;            }            t2D->setWrap( osg::Texture::WRAP_T, wrap );        }        else        {            t2D->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );        }        if ( sampler->getMinfilter() != NULL )        {            osg::Texture::FilterMode mode;            switch( sampler->getMinfilter()->getValue() )            {            case FX_SAMPLER_FILTER_COMMON_NEAREST:                mode = osg::Texture::NEAREST;                break;            case FX_SAMPLER_FILTER_COMMON_LINEAR:                mode = osg::Texture::LINEAR;                break;            case FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_NEAREST:                mode = osg::Texture::NEAREST_MIPMAP_NEAREST;                break;            case FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_NEAREST:                mode = osg::Texture::LINEAR_MIPMAP_NEAREST;                break;            case FX_SAMPLER_FILTER_COMMON_NONE:            case FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_LINEAR:                mode = osg::Texture::NEAREST_MIPMAP_LINEAR;                break;            case FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_LINEAR:                mode = osg::Texture::LINEAR_MIPMAP_LINEAR;                break;            default:                mode = osg::Texture::LINEAR;                break;            }            t2D->setFilter( osg::Texture::MIN_FILTER, mode );        }        else        {            t2D->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST_MIPMAP_LINEAR );        }        if ( sampler->getMagfilter() != NULL )        {            osg::Texture::FilterMode mode;            switch( sampler->getMagfilter()->getValue() )            {            case FX_SAMPLER_FILTER_COMMON_NEAREST:                mode = osg::Texture::NEAREST;                break;            case FX_SAMPLER_FILTER_COMMON_NONE:            case FX_SAMPLER_FILTER_COMMON_LINEAR:                mode = osg::Texture::LINEAR;                break;            case FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_NEAREST:                mode = osg::Texture::NEAREST_MIPMAP_NEAREST;                break;            case FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_NEAREST:                mode = osg::Texture::LINEAR_MIPMAP_NEAREST;                break;            case FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_LINEAR:                mode = osg::Texture::NEAREST_MIPMAP_LINEAR;                break;            case FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_LINEAR:                mode = osg::Texture::LINEAR_MIPMAP_LINEAR;                break;            default:                mode = osg::Texture::LINEAR;                break;            }            t2D->setFilter( osg::Texture::MAG_FILTER, mode );        }        else        {            t2D->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );        }        if ( sampler->getBorder_color() != NULL )        {            const domFloat4 &col = sampler->getBorder_color()->getValue();            t2D->setBorderColor( osg::Vec4( col[0], col[1], col[2], col[3] ) );        }    }    else     {        t2D->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );        t2D->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );        t2D->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST_MIPMAP_LINEAR );        t2D->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );    }    return t2D;}osg::StateAttribute *daeReader::processTransparencySettings( domCommon_transparent_type *ctt,  domCommon_float_or_param_type *pTransparency, osg::StateSet *ss ){    if (NULL == ctt && NULL == pTransparency)        return NULL;    if (ctt && ctt->getTexture() != NULL)    {        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        // The transparency functionality needs to be put in here as well        // but I suspect it will neeed a shader program to acheive it.        // Whenever someone gets round to this the default setting stuff in the        // color path below needs making common to both paths. This will involve some        // reorganisation of the code.        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        osg::StateAttribute *sa = NULL;        sa = processTexture( ctt->getTexture() );        osg::BlendFunc *bf = new osg::BlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );        ss->setAttribute( bf );        ss->setMode( GL_BLEND, GL_TRUE );        ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );        ss->setRenderBinDetails( 10, "DepthSortedBin" );        return sa;    }        // Fix up defaults acoording to 1.4.1 release notes    domFloat4 f4;    domFx_opaque_enum Opaque = FX_OPAQUE_ENUM_A_ONE;    if (NULL == ctt)    {        f4.append(0.0f);        f4.append(0.0f);        f4.append(0.0f);        f4.append(1.0f);    }    else    {        Opaque = ctt->getOpaque();        if (NULL != ctt->getColor())        {            f4 = ctt->getColor()->getValue();        }        else if ((NULL == ctt->getParam()) || !GetFloat4Param(ctt->getParam()->getRef(), f4))        {            f4.append(0.0f);            f4.append(0.0f);            f4.append(0.0f);            f4.append(1.0f);        }    }    domFloat Transparency;    if (NULL == pTransparency)        Transparency = 1.0f;    else    {        if (NULL != pTransparency->getFloat())        {            Transparency = pTransparency->getFloat()->getValue();            if (m_AuthoringTool == GOOGLE_SKETCHUP) // Google back to front support                Transparency = 1.0f - Transparency;        }        else if (NULL != pTransparency->getParam())        {            if (GetFloatParam(pTransparency->getParam()->getRef(), Transparency))            {                if (m_AuthoringTool == GOOGLE_SKETCHUP) // Google back to front support                    Transparency = 1.0f - Transparency;            }            else                Transparency = 1.0f;        }    }    osg::BlendColor *bc = new osg::BlendColor();    bc->setConstantColor(osg::Vec4( f4[0] * Transparency, f4[1] * Transparency, f4[2] * Transparency, f4[3] * Transparency ));    ss->setAttribute( bc );    osg::BlendFunc *bf;    if (FX_OPAQUE_ENUM_A_ONE == Opaque)        bf = new osg::BlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);    else        bf = new osg::BlendFunc(GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_COLOR);    ss->setAttribute( bf );    ss->setMode( GL_BLEND, GL_TRUE );    if (FX_OPAQUE_ENUM_A_ONE == Opaque)    {        if (Transparency  * f4[3] > 0.99f)            // Material is really opaque so dont put it in the transparent bin            return NULL;    }    else    {        if ((Transparency  * f4[0] < 0.01f) &&            (Transparency  * f4[1] < 0.01f) &&            (Transparency  * f4[2] < 0.01f) &&            (Transparency  * f4[3] < 0.01f))            // Material is really opaque so dont put it in the transparent bin            return NULL;    }    ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );    ss->setRenderBinDetails( 10, "DepthSortedBin" );    return NULL;}

⌨️ 快捷键说明

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