FindTextureVisitor .. in files)

2009/7/1 Maxim Gammer <maxgam...@gmail.com>:
> //Находим объект
>        osg::ref_ptr<FindNamedNodeVisitor> fnnv = new 
> FindNamedNodeVisitor(ObjectName);
>    root->accept(*fnnv.get());
>        //Если такой объект есть, ищем текстуру
>        if (!fnnv->_foundNodes.empty())
>        {
>                if (fnnv->_foundNodes.size()>1) std::cout << "Warning: 
> Duplicate
> names - " << ObjectName << std::endl;
>                osg::ref_ptr<FindTextureVisitor> zzz = new 
> FindTextureVisitor(UnitNumber);
>                fnnv->_foundNodes.front().get()->accept (*zzz.get());
>                //Если текстура есть
>                if (zzz->image.get())
>                {
>                        /*
>                        std::cout << "texture find";
>                        std::cout << zzz->image->s() << std::endl; //ширина
>                        std::cout << zzz->image->t() << std::endl; //высота
>                        std::cout << zzz->image->r() << std::endl; //глубина
>                        */
>                        int format = zzz->image->getPixelSizeInBits();
>                        //std::cout <<"getPixelSizeInBits : "<< format 
> <<std::endl;
>            int width = zzz->image->s();
>                        int heught = zzz->image->t();
>                        //
>                        GLubyte *ptr;
>                        int inc=0;
>                        ptr = zzz->image->data();
>                        if (x>=width) x= 0;
>                        if (y>=heught) y= 0;
>                        if (x<0) x= 0;
>                        if (y<0) y= 0;
>                        inc=(y*width + x)*format/8; //смещение по 
> RGBARGBARGBA... или 4
>                        *(ptr+inc+0) = (GLubyte)(r*255.0f);
>                        *(ptr+inc+1) = (GLubyte)(g*255.0f);
>                        *(ptr+inc+2) = (GLubyte)(b*255.0f);
>                        //если RGBA
>                        if ((format/8)>24)
>                        {
>                                *(ptr+inc+3) = (GLubyte)(a*255.0f);
>                        }
>                        //Отправляем текстуру в видеопамять)
>                        if (flush)
>                        {
>                                //osg::Image* dest =dynamic_cast<osg::Image*>
> (zzz->image->clone(osg::CopyOp::DEEP_COPY_ALL));
>                                //zzz->texture->setImage(dest);//zzz->image
>
>                                // dirty the image (increments the modified 
> count) so that any textures
>                                // using the image can be informed that they 
> need to update.
>                                zzz->image->dirty();
>
>                                
> //zzz->texture->setDataVariance(osg::Object::DYNAMIC);
>                                
> //zzz->stateset->setTextureAttributeAndModes(UnitNumber,
> zzz->texture, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
>                                //zzz->drawable->setStateSet(zzz->stateset);
>                        }
>                }
>                else
>                {
>                        std::cout << "texture NOT find";
>                        //delete zzz;
>                        //delete fnnv;
>                        return false;
>                }
>                //Чистим мусор
>                //delete zzz;
>        }
>        else
>        {
>                std::cout << "Find objects in Root - FALSE! " << ObjectName << 
> std::endl;
>                //delete fnnv;
>                return false;
>        }
>        //Чистим мусор
>        //delete fnnv;
>        return true;
>
> 2009/6/30 Großer Martin <grosser.mar...@gmx.de>:
>> Hello,
>>
>> i would like paint on a 3d object in my scene. This object has a texture
>> and i want to paint into this texture. My paint brush should be another
>> texture. There are a nice solution in OSG? This problem is not trivial
>> for me.
>>
>> I hope everyone can give me a example, a tip or a suitable keyword for
>> my research.
>>
>>
>> Cheers,
>>
>>
>> Martin
>>
>> _______________________________________________
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
>
>
> --
> Maxim Gammer
>



-- 
Maxim Gammer
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>
#include <osg/PositionAttitudeTransform>
#include <osg/MatrixTransform>
#include <osg/Material>
#include <iostream>

class FindTextureVisitor : public osg::NodeVisitor
{
public:
    FindTextureVisitor(unsigned int channel=0):
        osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) 
                {
                        Channel = channel;
                        setTraversalMask(0xffffffff);
                        setNodeMaskOverride(0xffffffff);
                        Sucessful=false;
                }
    
    virtual void apply(osg::Node& node);

    virtual void apply(osg::MatrixTransform& node);
        
        virtual void apply(osg::Geode& geode);
     
        virtual void apply(osg::Group& group);

        unsigned int Channel;
        osg::ref_ptr<osg::Texture2D> texture;
        osg::ref_ptr<osg::Image> image;
        osg::ref_ptr<osg::Material> material;
        osg::ref_ptr<osg::StateSet> stateset;
        osg::ref_ptr<osg::Drawable> drawable;
private:
        bool Sucessful;

};
/***************************************************************************
FindTexture.cpp  -  Êëàññ äëÿ íàõîæäåíèÿ òåêñòóðû è öâåòà ìàòåðèàëà óêàçàííîãî 
îáûåêòà
-------------------
begin                : 15 ìàÿ 2007
copyright            : (C) 2007 by Ãàììåð Ìàêñèì Äìèòðèåâè÷ (maximum2000)
email                : gammer...@yandex.ru
***************************************************************************/

#include "FindTexture.h"


void FindTextureVisitor::apply(osg::Node& node)
{
        traverse(node);
}

void FindTextureVisitor::apply(osg::Geode& geode)
{
        for(unsigned int i=0;i<geode.getNumDrawables();i++) //++i 
    {
                if (Sucessful==true) return;
                //std::cout << "+";
                if (geode.getDrawable(i)->getStateSet())
                {
                        drawable = geode.getDrawable(i);
                        //òåêñòóðà
                        stateset = geode.getDrawable(i)->getStateSet(); 
//getOrCreateStateSet(); 
                        texture = 
dynamic_cast<osg::Texture2D*>(geode.getDrawable(i)->getStateSet()->getTextureAttribute(Channel,osg::StateAttribute::TEXTURE));
                        if (texture.get()) 
                        {
                                image = texture->getImage();
                                Sucessful=true;
                        }
                        else
                        {
                                image=NULL;
                        }
                        //ðàçìåð  è ò.ä.
                        //öâåò
                        //material->setDiffuse(osg::Material::FRONT_AND_BACK, 
color);
                        //stateset->setAttributeAndModes(material, 
osg::StateAttribute::ON);

                        material = 
dynamic_cast<osg::Material*>(geode.getDrawable(i)->getStateSet()->getAttribute(osg::StateAttribute::MATERIAL));
                        if (material.get()) 
                        {
                                //std::cout << "@";
                        }
                }
        }
}

void FindTextureVisitor::apply(osg::Group& group) 
{
        traverse(group); 
}
        
void FindTextureVisitor::apply(osg::MatrixTransform& node)
{
      apply((osg::Node&)node);
}

        
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to