//virtual
void EffectsListWidget::keyPressEvent(QKeyEvent *e)
{
    if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
        emit applyEffect(currentEffect());
        e->accept();
        return;
    }
    QTreeWidget::keyPressEvent(e);
}
Exemple #2
0
std::shared_ptr<TextureParameters> processTexture(
    domCommon_color_or_texture_type_complexType::domTexture *tex
)
{
    std::shared_ptr<TextureParameters> parameters(new TextureParameters);
    //parameters.transparent = tuu == TRANSPARENCY_MAP_UNIT;
    //parameters.opaque = opaque;
    //parameters.transparency = transparency;

    //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_INFO<<"processTexture("<<target<<")"<<std::endl;

    daeSIDResolver res1( /*_currentEffect*/currentEffect(), target.c_str() );
    daeElement *el = res1.getElement();

    if (el == NULL )
    {
        std::cout << "Could not locate newparam for texture sampler2D \"" << tex->getTexture() <<
            "\". Checking if data does incorrect linking straight to the image" << std::endl;
        GetDAE().getDatabase()->getElement( (daeElement**)&dImg, 0, tex->getTexture(), "image" );
        if (dImg != NULL )
        {
            std::cout << "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 )
        {
            std::cout << "Wrong newparam type. Expected sampler2D" << std::endl;
            return nullptr;
        }

        if (sampler->getSource() == NULL )
        {
            std::cout << "Could not locate source for sampler2D" << std::endl;
            return nullptr;
        }

        //find the newparam for the surface based on the sampler2D->source value
        target = std::string("./") + std::string( sampler->getSource()->getValue() );
        daeSIDResolver res2( /*_currentEffect*/currentEffect(), target.c_str() );
        el = res2.getElement();
        if (el == NULL )
        {
            std::cout << "Could not locate newparam for source " << sampler->getSource()->getValue() << std::endl;
            return nullptr;
        }
        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 )
        {
            std::cout << "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 ) );
    }

    parameters->filename = processImagePath(dImg);
	std::cout << "ImagePath: " << parameters->filename << std::endl;
    if (parameters->filename.empty())
    {
		
        return NULL;
    }
	

    //set texture parameters
    if (sampler)
    {
        if (sampler->getWrap_s())
        {
            parameters->wrap_s = sampler->getWrap_s()->getValue();//getWrapMode(sampler->getWrap_s()->getValue());
        }
        if (sampler->getWrap_t())
        {
            parameters->wrap_t = sampler->getWrap_t()->getValue();//getWrapMode(sampler->getWrap_s()->getValue());
        }

        if (sampler->getMinfilter() && sampler->getMinfilter()->getValue() != FX_SAMPLER_FILTER_COMMON_NONE)
        {
            parameters->filter_min = sampler->getMinfilter()->getValue();//getFilterMode(sampler->getMinfilter()->getValue(), true);
        }
        if (sampler->getMagfilter() && sampler->getMagfilter()->getValue() != FX_SAMPLER_FILTER_COMMON_NONE)
        {
            parameters->filter_mag = sampler->getMagfilter()->getValue();//getFilterMode(sampler->getMagfilter()->getValue(), false);
        }

        if (sampler->getBorder_color() != NULL )
        {
            const domFloat4& col = sampler->getBorder_color()->getValue();
            parameters->border = col;// parameters.border.set(col[0], col[1], col[2], col[3]);
        }
    }

	   
	//osg::Texture2D* t2D = NULL;
    //TextureParametersMap::const_iterator mapIt = _textureParamMap.find(parameters);
    //if (mapIt != _textureParamMap.end())
    //{
    //    t2D = mapIt->second.get();
    //}
    //else
    //{
    //    osg::ref_ptr<osg::Image> img = osgDB::readRefImageFile(parameters.filename);

    //    if (!img.valid())
    //    {
    //        _textureParamMap[parameters] = NULL;
    //        return NULL;
    //    }

    //    OSG_INFO<<"  processTexture(..) - readImage("<<parameters.filename<<")"<<std::endl;

    //    if (tuu == TRANSPARENCY_MAP_UNIT)
    //    {
    //        img = processImageTransparency(img.get(), opaque, transparency);
    //    }

    //    t2D = new osg::Texture2D(img.get());

    //    t2D->setWrap( osg::Texture::WRAP_S, parameters.wrap_s);
    //    t2D->setWrap( osg::Texture::WRAP_T, parameters.wrap_t);
    //    t2D->setFilter( osg::Texture::MIN_FILTER, parameters.filter_min);
    //    t2D->setFilter( osg::Texture::MAG_FILTER, parameters.filter_mag);
    //    t2D->setBorderColor(parameters.border);

    //    _textureParamMap[parameters] = t2D;
    //}

    //_texCoordSetMap[TextureToCoordSetMap::key_type(ss, tuu)] = tex->getTexcoord();

    return /*t2D*/parameters;
}