Re: [osg-users] Painting in Textures

2009-07-01 Thread Großer Martin
Hey Maxim,

first, thanks for your help. Now I know the way to manipulate values in
my image. But now I have the problem to find out the right pixel in the
texture. A little example: I have a complex object with a texture. All
triangles of the object are randomly distributed on the texture. And I
would like project a texture on my object (planar mapping?!). This
texture is my paint brush. Now I want to copy the image data of the
paint brush texture in the texture of the object.
Can you see my problem?

Cheers,

Martin

PS: However, your code example are very helpful.


Am Mittwoch, den 01.07.2009, 00:50 +0600 schrieb Maxim Gammer:
 FindTextureVisitor .. in files)
 
 2009/7/1 Maxim Gammer maxgam...@gmail.com:
  //Находим объект
 osg::ref_ptrFindNamedNodeVisitor 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_ptrFindTextureVisitor 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 (x0) x= 0;
 if (y0) 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_castosg::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
 
 
 
 
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 

Re: [osg-users] Painting in Textures

2009-07-01 Thread J.P. Delport

Hi Martin,

you have already hinted at a search term you can use. Google for 
projective texturing. Also try automatic texture coordinate 
generation. An example in OSG of this is the OverlayNode of osgSim 
(this is used to project a texture onto terrain e.g.).


Using this technique you can project your painted texture onto an 
object, but the texture would not become part (be baked into) of the 
object (I suspect you actaully want to do this).


You can also maybe have a look at MeshLab, I know they recently added 
projective painting, but I'm also not sure how the data is stored in the 
end.


jp

Großer Martin wrote:

Hey Maxim,

first, thanks for your help. Now I know the way to manipulate values in
my image. But now I have the problem to find out the right pixel in the
texture. A little example: I have a complex object with a texture. All
triangles of the object are randomly distributed on the texture. And I
would like project a texture on my object (planar mapping?!). This
texture is my paint brush. Now I want to copy the image data of the
paint brush texture in the texture of the object.
Can you see my problem?

Cheers,

Martin

PS: However, your code example are very helpful.


Am Mittwoch, den 01.07.2009, 00:50 +0600 schrieb Maxim Gammer:

FindTextureVisitor .. in files)

2009/7/1 Maxim Gammer maxgam...@gmail.com:

//Находим объект
   osg::ref_ptrFindNamedNodeVisitor 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_ptrFindTextureVisitor 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 (x0) x= 0;
   if (y0) 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_castosg::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 

Re: [osg-users] Painting in Textures

2009-07-01 Thread Großer Martin
Hi JP,

I want to baked into the texture to create a new painted texture
with the same texture coordinates like the original texture of the
object. The exact use case is the creation of a heigh map. That is to
say first I would like paint into the texture and after this I want to
change the position of the vertices in the direction of the normal. So I
can spread material on my object.

Cheers,

Martin

Am Mittwoch, den 01.07.2009, 08:59 +0200 schrieb J.P. Delport:
 Hi Martin,
 
 you have already hinted at a search term you can use. Google for 
 projective texturing. Also try automatic texture coordinate 
 generation. An example in OSG of this is the OverlayNode of osgSim 
 (this is used to project a texture onto terrain e.g.).
 
 Using this technique you can project your painted texture onto an 
 object, but the texture would not become part (be baked into) of the 
 object (I suspect you actaully want to do this).
 
 You can also maybe have a look at MeshLab, I know they recently added 
 projective painting, but I'm also not sure how the data is stored in the 
 end.
 
 jp
 
 Großer Martin wrote:
  Hey Maxim,
  
  first, thanks for your help. Now I know the way to manipulate values in
  my image. But now I have the problem to find out the right pixel in the
  texture. A little example: I have a complex object with a texture. All
  triangles of the object are randomly distributed on the texture. And I
  would like project a texture on my object (planar mapping?!). This
  texture is my paint brush. Now I want to copy the image data of the
  paint brush texture in the texture of the object.
  Can you see my problem?
  
  Cheers,
  
  Martin
  
  PS: However, your code example are very helpful.
  
  
  Am Mittwoch, den 01.07.2009, 00:50 +0600 schrieb Maxim Gammer:
  FindTextureVisitor .. in files)
 
  2009/7/1 Maxim Gammer maxgam...@gmail.com:
  //Находим объект
 osg::ref_ptrFindNamedNodeVisitor 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_ptrFindTextureVisitor 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 (x0) x= 0;
 if (y0) 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_castosg::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;
   

[osg-users] Painting in Textures

2009-06-30 Thread Großer Martin
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


Re: [osg-users] Painting in Textures

2009-06-30 Thread Maxim Gammer
//Находим объект
osg::ref_ptrFindNamedNodeVisitor 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_ptrFindTextureVisitor 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 (x0) x= 0;
if (y0) 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_castosg::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
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Painting in Textures

2009-06-30 Thread Maxim Gammer
FindTextureVisitor .. in files)

2009/7/1 Maxim Gammer maxgam...@gmail.com:
 //Находим объект
osg::ref_ptrFindNamedNodeVisitor 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_ptrFindTextureVisitor 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 (x0) x= 0;
if (y0) 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_castosg::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(0x);
setNodeMaskOverride(0x);
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_ptrosg::Texture2D texture;