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

📄 daermaterials.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    return ss;}bool daeReader::processColorOrTextureType( domCommon_color_or_texture_type *cot, osg::Material::ColorMode channel,osg::Material *mat,domCommon_float_or_param_type *fop,osg::StateAttribute **sa ){    if ( cot == NULL )    {        return false;    }    bool retVal = false;    //osg::StateAttribute *sa = NULL;    //TODO: Make all channels process <param ref=""> type of value    if ( channel == osg::Material::EMISSION )    {        if ( cot->getColor() != NULL )        {            domFloat4 &f4 = cot->getColor()->getValue();            mat->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );            retVal = true;        }        else if (cot->getParam() != NULL)        {            domFloat4 f4;            if (GetFloat4Param(cot->getParam()->getRef(), f4))            {                mat->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );                retVal = true;            }        }        else        {            osg::notify( osg::WARN ) << "Currently no support for <texture> in Emission channel " << std::endl;        }           }    else if ( channel == osg::Material::AMBIENT )    {        if ( cot->getColor() != NULL )        {            domFloat4 &f4 = cot->getColor()->getValue();            mat->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );            retVal = true;        }        else if (cot->getParam() != NULL)        {            domFloat4 f4;            if (GetFloat4Param(cot->getParam()->getRef(), f4))            {                mat->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );                retVal = true;            }        }        else        {            osg::notify( osg::WARN ) << "Currently no support for <texture> in Ambient channel " << std::endl;        }    }    else if ( channel == osg::Material::DIFFUSE )    {        if ( cot->getColor() != NULL )        {            domFloat4 &f4 = cot->getColor()->getValue();            mat->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );            retVal = true;        }        else if ( cot->getTexture() != NULL && sa != NULL )        {            *sa = processTexture( cot->getTexture() );            domExtra *extra = cot->getTexture()->getExtra();            if ( extra != NULL && extra->getType() != NULL &&                  strcmp( extra->getType(), "color" ) == 0 )            {                //the extra data for osg. Diffuse color can happen with a texture.                for ( unsigned int i = 0; i < extra->getTechnique_array().getCount(); i++ )                {                    domTechnique *teq = extra->getTechnique_array()[i];                    if ( strcmp( teq->getProfile(), "SCEI" ) == 0 )                    {                        osg::Vec4 col;                        domAny *dcol = (domAny*)(daeElement*)teq->getContents()[0];                        std::istringstream diffuse_colour((const char *)dcol->getValue());                        diffuse_colour >> col.r() >> col.g() >> col.b() >> col.a();                        mat->setDiffuse( osg::Material::FRONT_AND_BACK, col );                        retVal = true;                        break;                    }                }            }        }        else if (cot->getParam() != NULL)        {            domFloat4 f4;            if (GetFloat4Param(cot->getParam()->getRef(), f4))            {                mat->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );                retVal = true;            }        }    }    else if ( channel == osg::Material::SPECULAR )    {        if ( cot->getColor() != NULL )        {            domFloat4 &f4 = cot->getColor()->getValue();            mat->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );            retVal = true;        }         else if (cot->getParam() != NULL)        {            domFloat4 f4;            if (GetFloat4Param(cot->getParam()->getRef(), f4))            {                mat->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );                retVal = true;            }        }       else        {            osg::notify( osg::WARN ) << "Currently no support for <texture> in Specular channel " << std::endl;        }        if ( fop != NULL && fop->getFloat() != NULL )        {            mat->setShininess( osg::Material::FRONT_AND_BACK, fop->getFloat()->getValue() );            retVal = true;        }    }    return retVal;}bool daeReader::GetFloat4Param(xsNCName Reference, domFloat4 &f4){    std::string MyReference = Reference;    MyReference.insert(0, "./");    daeSIDResolver Resolver(currentEffect, MyReference.c_str());    daeElement *el = Resolver.getElement();    if (NULL == el)            return false;    if (NULL != currentInstance_effect)    {        // look here first for setparams        // I am sure there must be a better way of doing this        // Maybe the Collada DAE guys can give us a parameter management mechanism !        const domInstance_effect::domSetparam_Array& SetParamArray = currentInstance_effect->getSetparam_array();        size_t NumberOfSetParams = SetParamArray.getCount();        for (size_t i = 0; i < NumberOfSetParams; i++)        {            // Just do a simple comaprison of the ref strings for the time being            if (0 == strcmp(SetParamArray[i]->getRef(), Reference))            {                if (NULL != SetParamArray[i]->getFx_basic_type_common() && (NULL != SetParamArray[i]->getFx_basic_type_common()->getFloat4()))                {                    f4 = SetParamArray[i]->getFx_basic_type_common()->getFloat4()->getValue();                    return true;                }            }        }    }    domCommon_newparam_type *cnp = daeSafeCast< domCommon_newparam_type >( el );     domFx_newparam_common *npc = daeSafeCast< domFx_newparam_common >( el );    if ((cnp != NULL) && (NULL != cnp->getFloat4()))    {        f4 = cnp->getFloat4()->getValue();        return true;    }    else if ((npc != NULL) && (NULL != npc->getFx_basic_type_common()) && (NULL != npc->getFx_basic_type_common()->getFloat4()))    {        f4 = npc->getFx_basic_type_common()->getFloat4()->getValue();        return true;    }    else        return false;}bool daeReader::GetFloatParam(xsNCName Reference, domFloat &f){    std::string MyReference = Reference;    MyReference.insert(0, "./");    daeSIDResolver Resolver(currentEffect, MyReference.c_str());    daeElement *el = Resolver.getElement();    if (NULL == el)        return false;    if (NULL != currentInstance_effect)    {        // look here first for setparams        // I am sure there must be a better way of doing this        // Maybe the Collada DAE guys can give us a parameter management mechanism !        const domInstance_effect::domSetparam_Array& SetParamArray = currentInstance_effect->getSetparam_array();        size_t NumberOfSetParams = SetParamArray.getCount();        for (size_t i = 0; i < NumberOfSetParams; i++)        {            // Just do a simple comaprison of the ref strings for the time being            if (0 == strcmp(SetParamArray[i]->getRef(), Reference))            {                if (NULL != SetParamArray[i]->getFx_basic_type_common() && (NULL != SetParamArray[i]->getFx_basic_type_common()->getFloat()))                {                    f = SetParamArray[i]->getFx_basic_type_common()->getFloat()->getValue();                    return true;                }            }        }    }    domCommon_newparam_type *cnp = daeSafeCast< domCommon_newparam_type >( el );     domFx_newparam_common *npc = daeSafeCast< domFx_newparam_common >( el );    if ((cnp != NULL) && (NULL != cnp->getFloat()))    {        f = cnp->getFloat()->getValue();        return true;    }    else if ((npc != NULL) && (NULL != npc->getFx_basic_type_common()) && (NULL != npc->getFx_basic_type_common()->getFloat()))    {        f = npc->getFx_basic_type_common()->getFloat()->getValue();        return true;    }    else        return false;}osg::StateAttribute *daeReader::processTexture( domCommon_color_or_texture_type_complexType::domTexture *tex ){    //find the newparam for the sampler based on the texture attribute    domFx_sampler2D_common *sampler = NULL;    domFx_surface_common *surface = NULL;    domImage *dImg = NULL;    std::string target = std::string("./") + std::string(tex->getTexture());    osg::notify(osg::NOTICE)<<"processTexture("<<target<<")"<<std::endl;        daeSIDResolver res1( currentEffect, target.c_str() );    daeElement *el = res1.getElement();    if ( el == NULL )    {        osg::notify( osg::WARN ) << "Could not locate newparam for texture sampler2D" << tex->getTexture() << std::endl;        osg::notify( osg::WARN ) << "Checking if data does incorrect linking straight to the image" << std::endl;        dae->getDatabase()->getElement( (daeElement**)&dImg, 0, tex->getTexture(), "image" );        if ( dImg != NULL )        {            osg::notify( osg::WARN ) << "Direct image link found. Data is incorrect but will continue to load texture" << std::endl;        }    }    else    {        domCommon_newparam_type *cnp = daeSafeCast< domCommon_newparam_type >( el );         domFx_newparam_common *npc = daeSafeCast< domFx_newparam_common >( el );        if ( cnp != NULL )        {            sampler = cnp->getSampler2D();        }        else if ( npc != NULL )        {            sampler = npc->getFx_basic_type_common()->getSampler2D();        }        if ( sampler == NULL )        {            osg::notify( osg::WARN ) << "Wrong newparam type. Expected sampler2D" << std::endl;            return NULL;        }        //find the newparam for the surface based on the sampler2D->source value        target = std::string("./") + std::string( sampler->getSource()->getValue() );        daeSIDResolver res2( currentEffect, target.c_str() );        el = res2.getElement();        if ( el == NULL )        {            osg::notify( osg::WARN ) << "Could not locate newparam for source " << sampler->getSource()->getValue() << std::endl;            return NULL;        }        cnp = daeSafeCast< domCommon_newparam_type >( el );         npc = daeSafeCast< domFx_newparam_common >( el );        if ( cnp != NULL )        {            surface = cnp->getSurface();        }        else if ( npc != NULL )        {            surface = npc->getFx_basic_type_common()->getSurface();        }        if ( surface == NULL )        {            osg::notify( osg::WARN ) << "Wrong newparam type. Expected surface" << std::endl;            return NULL;        }        //look for the domImage based on the surface initialization stuff        daeIDRef &ref = surface->getFx_surface_init_common()->getInit_from_array()[0]->getValue();        dImg = daeSafeCast< domImage >( getElementFromIDRef( ref ) );    }    if ( dImg == NULL )    {

⌨️ 快捷键说明

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