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

📄 daewmaterials.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            magfilter->setValue( FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_NEAREST );            break;        case osg::Texture::NEAREST:            magfilter->setValue( FX_SAMPLER_FILTER_COMMON_NEAREST );            break;        case osg::Texture::NEAREST_MIPMAP_LINEAR:            magfilter->setValue( FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_LINEAR );            break;        case osg::Texture::NEAREST_MIPMAP_NEAREST:            magfilter->setValue( FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_NEAREST );            break;        }        domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "diffuse" ) );        domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot->createAndPlace( "texture" ) );        dtex->setTexture( sampName.c_str() );        dtex->setTexcoord( "texcoord0" );#else        domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "diffuse" ) );        domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot->createAndPlace( "texture" ) );        dtex->setTexture( iName.c_str() );        dtex->setTexcoord( "texcoord0" );#endif        domInstance_material::domBind_vertex_input *bvi = daeSafeCast< domInstance_material::domBind_vertex_input >( im->createAndPlace( "bind_vertex_input" ) );        bvi->setSemantic( "texcoord0" );        bvi->setInput_semantic( "TEXCOORD" );        bvi->setInput_set( 0 );/*  I dont think this belongs here RFJ        //take care of blending if any        osg::BlendFunc *bf = static_cast< osg::BlendFunc * >( ssClean->getAttribute( osg::StateAttribute::BLENDFUNC ) );        osg::BlendColor *bc = static_cast< osg::BlendColor * >( ssClean->getAttribute( osg::StateAttribute::BLENDCOLOR ) );        if ( bc != NULL )        {            domCommon_transparent_type *ctt = daeSafeCast< domCommon_transparent_type >( phong->createAndPlace( "transparent" ) );            ctt->setOpaque( FX_OPAQUE_ENUM_RGB_ZERO );            domCommon_color_or_texture_type_complexType::domColor *tcol = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( ctt->createAndPlace( "color" ) );            tcol->getValue().append( bc->getConstantColor().r() );            tcol->getValue().append( bc->getConstantColor().r() );            tcol->getValue().append( bc->getConstantColor().r() );            tcol->getValue().append( bc->getConstantColor().r() );        }        else if ( bf != NULL )        {            domCommon_transparent_type *ctt = daeSafeCast< domCommon_transparent_type >( phong->createAndPlace( "transparent" ) );            ctt->setOpaque( FX_OPAQUE_ENUM_A_ONE );            dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( ctt->createAndPlace( "texture" ) );#ifndef EARTH_TEX            dtex->setTexture( sampName.c_str() );#else            dtex->setTexture( iName.c_str() );#endif            dtex->setTexcoord( "texcoord0" );                   }*/           }    osg::Material *osgmat = static_cast<osg::Material*>(ssClean->getAttribute( osg::StateAttribute::MATERIAL ));    if ( osgmat != NULL )    {        const osg::Vec4 &eCol = osgmat->getEmissionFrontAndBack()?osgmat->getEmission( osg::Material::FRONT_AND_BACK ):osgmat->getEmission( osg::Material::FRONT );        const osg::Vec4 &aCol = osgmat->getAmbientFrontAndBack()?osgmat->getAmbient( osg::Material::FRONT_AND_BACK ):osgmat->getAmbient( osg::Material::FRONT );        const osg::Vec4 &dCol = osgmat->getDiffuseFrontAndBack()?osgmat->getDiffuse( osg::Material::FRONT_AND_BACK ):osgmat->getDiffuse( osg::Material::FRONT );        const osg::Vec4 &sCol = osgmat->getSpecularFrontAndBack()?osgmat->getSpecular( osg::Material::FRONT_AND_BACK ):osgmat->getSpecular( osg::Material::FRONT );        float shininess = osgmat->getShininessFrontAndBack()?osgmat->getShininess( osg::Material::FRONT_AND_BACK ):osgmat->getShininess( osg::Material::FRONT );                domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "emission" ) );        domCommon_color_or_texture_type_complexType::domColor *col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->createAndPlace( "color" ) );        col->getValue().append( eCol.r() );        col->getValue().append( eCol.g() );        col->getValue().append( eCol.b() );        col->getValue().append( eCol.a() );        cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "ambient" ) );        col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->createAndPlace( "color" ) );        col->getValue().append( aCol.r() );        col->getValue().append( aCol.g() );        col->getValue().append( aCol.b() );        col->getValue().append( aCol.a() );                //### check if we really have a texture        if ( phong->getDiffuse() == NULL )        {            cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "diffuse" ) );            col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->createAndPlace( "color" ) );            col->getValue().append( dCol.r() );            col->getValue().append( dCol.g() );            col->getValue().append( dCol.b() );            col->getValue().append( dCol.a() );        }        else        {            cot = phong->getDiffuse();                        domCommon_color_or_texture_type_complexType::domTexture *dtex = cot->getTexture();            domExtra *extra = daeSafeCast< domExtra >( dtex->createAndPlace( COLLADA_ELEMENT_EXTRA ) );            extra->setType( "color" );            domTechnique *teq = daeSafeCast< domTechnique >( extra->createAndPlace( COLLADA_ELEMENT_TECHNIQUE ) );            teq->setProfile( "SCEI" );            domAny *any = (domAny*)(daeElement*)teq->createAndPlace( "color" );            std::ostringstream colVal;            colVal << dCol.r() << " " << dCol.g() << " " << dCol.b() << " " << dCol.a();            any->setValue( colVal.str().c_str() );        }        cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "specular" ) );        col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->createAndPlace( "color" ) );        col->getValue().append( sCol.r() );        col->getValue().append( sCol.g() );        col->getValue().append( sCol.b() );        col->getValue().append( sCol.a() );        domCommon_float_or_param_type *fop = daeSafeCast< domCommon_float_or_param_type >( phong->createAndPlace( "shininess" ) );        domCommon_float_or_param_type_complexType::domFloat *f = daeSafeCast< domCommon_float_or_param_type_complexType::domFloat >( fop->createAndPlace( "float" ) );        f->setValue( shininess );    }    // Do common transparency stuff here    // if (osg::StateSet::TRANSPARENT_BIN == ssClean->getRenderingHint()) cannot do this at the moment because stateSet::merge does does not handle the hints    if (osg::StateSet::TRANSPARENT_BIN == m_CurrentRenderingHint)    {        osg::BlendFunc *pBlendFunc = static_cast< osg::BlendFunc * >( ssClean->getAttribute( osg::StateAttribute::BLENDFUNC ) );        osg::BlendColor *pBlendColor = static_cast< osg::BlendColor * >( ssClean->getAttribute( osg::StateAttribute::BLENDCOLOR ) );        if ((NULL != pBlendFunc) && (NULL != pBlendColor))        {            if ((GL_CONSTANT_ALPHA == pBlendFunc->getSource()) && (GL_ONE_MINUS_CONSTANT_ALPHA == pBlendFunc->getDestination()))            {                // A_ONE opaque mode                domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->createAndPlace("transparent"));                pTransparent->setOpaque(FX_OPAQUE_ENUM_A_ONE);                domCommon_color_or_texture_type_complexType::domColor *pColor = daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(pTransparent->createAndPlace("color"));                domCommon_float_or_param_type *pFop = daeSafeCast<domCommon_float_or_param_type>(phong->createAndPlace( "transparency"));                domCommon_float_or_param_type_complexType::domFloat *pTransparency = daeSafeCast<domCommon_float_or_param_type_complexType::domFloat>(pFop->createAndPlace("float"));                if (m_GoogleMode)                {                    pColor->getValue().append(1.0);                    pColor->getValue().append(1.0);                    pColor->getValue().append(1.0);                    pColor->getValue().append(1.0);                    pTransparency->setValue(1.0 - pBlendColor->getConstantColor().a());                }                else                {                    pColor->getValue().append(pBlendColor->getConstantColor().r());                    pColor->getValue().append(pBlendColor->getConstantColor().g());                    pColor->getValue().append(pBlendColor->getConstantColor().b());                    pColor->getValue().append(pBlendColor->getConstantColor().a());                    pTransparency->setValue(1.0);                }            }            else if ((GL_ONE_MINUS_CONSTANT_COLOR == pBlendFunc->getSource()) && (GL_CONSTANT_COLOR == pBlendFunc->getDestination()))            {                // RGB_ZERO opaque mode                domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->createAndPlace("transparent"));                pTransparent->setOpaque(FX_OPAQUE_ENUM_RGB_ZERO);                domCommon_color_or_texture_type_complexType::domColor *pColor = daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(pTransparent->createAndPlace("color"));                pColor->getValue().append(pBlendColor->getConstantColor().r());                pColor->getValue().append(pBlendColor->getConstantColor().g());                pColor->getValue().append(pBlendColor->getConstantColor().b());                pColor->getValue().append(pBlendColor->getConstantColor().a());                domCommon_float_or_param_type *pFop = daeSafeCast<domCommon_float_or_param_type>(phong->createAndPlace( "transparency"));                domCommon_float_or_param_type_complexType::domFloat *pTransparency = daeSafeCast<domCommon_float_or_param_type_complexType::domFloat>(pFop->createAndPlace("float"));                pTransparency->setValue(1.0);            }            else                osg::notify( osg::WARN ) << "Unsupported BlendFunction parameters in transparency processing." << std::endl;        }        else            osg::notify( osg::WARN ) << "Transparency processing - BlendFunction or BlendColor not found." << std::endl;    }    // Process GOOGLE one sided stuff here    if (osg::StateAttribute::INHERIT != ssClean->getMode(GL_CULL_FACE))    {        domExtra *pExtra = daeSafeCast<domExtra>(pc->createAndPlace(COLLADA_ELEMENT_EXTRA));        domTechnique *pTechnique = daeSafeCast<domTechnique>(pExtra->createAndPlace( COLLADA_ELEMENT_TECHNIQUE ) );        pTechnique->setProfile("GOOGLEEARTH");        domAny *pAny = (domAny*)(daeElement*)pTechnique->createAndPlace("double_sided");        if (GL_FALSE == ssClean->getMode(GL_CULL_FACE))            pAny->setValue("1");        else            pAny->setValue("0");    }    materialMap.insert( std::make_pair( ssClean, mat ) );}osg::StateSet* daeWriter::CleanStateSet(osg::StateSet* pStateSet) const{    // TODO - clean out all the the attributes and modes not used to define materials    osg::StateSet* pCleanedStateSet = new osg::StateSet;    pCleanedStateSet->setTextureAttributeList(pStateSet->getTextureAttributeList());    if (NULL != pStateSet->getAttribute(osg::StateAttribute::BLENDFUNC))        pCleanedStateSet->setAttribute(pStateSet->getAttribute(osg::StateAttribute::BLENDFUNC));    if (NULL != pStateSet->getAttribute(osg::StateAttribute::BLENDCOLOR))        pCleanedStateSet->setAttribute(pStateSet->getAttribute(osg::StateAttribute::BLENDCOLOR));    if (NULL != pStateSet->getAttribute(osg::StateAttribute::MATERIAL))        pCleanedStateSet->setAttribute(pStateSet->getAttribute(osg::StateAttribute::MATERIAL));    // pCleanedStateSet->setRenderingHint(pStateSet->getRenderingHint()); does not work at the moment due to stateSet::merge    if (osg::StateAttribute::INHERIT != pStateSet->getMode(GL_CULL_FACE))        pCleanedStateSet->setMode(GL_CULL_FACE, pStateSet->getMode(GL_CULL_FACE));    return pCleanedStateSet;}

⌨️ 快捷键说明

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