[vtkusers] Multiple texture mapping

Tolga Birdal tbirdal at gmail.com
Wed Jan 9 15:10:28 EST 2008


Hello,

I am currently trying to form a 3D object from OBJ files. What I would 
like to do is to map multiple textures on the object. I know that the 
texture coordinates are in vtkPolyDataMapper but I couldn't make use of 
it. vtkImageAppend simply didn't work well. There are different textures 
for different places on the object.
Is this supported in VTK?

So far, I could only load a single texture using vtkTexture. Here is the 
code (The code is written in C# but exactly same with C++):

            vtkOBJReader vo = new vtkOBJReader();
            vo.SetFileName(@"C:\Objs\idle.obj");
            vo.Update();
           
            vtkPolyDataMapper stlMapper= new vtkPolyDataMapper();
            stlMapper.SetInput(vo.GetOutput());
           
            stlActor.SetMapper(stlMapper);

            vtkJPEGReader bmp1 = ReadTexture(@"C:\Objs\idle_hi.jpg");
           
            //other textures to load
            //vtkJPEGReader bmp2 = ReadTexture(@"C:\Objs\idle_L_hi.jpg");
            //vtkJPEGReader bmp3 = ReadTexture(@"C:\Objs\idle_R_hi.jpg");

            vtkTexture vt = new vtkTexture();
            vt.InterpolateOn();
           
            vt.AddInputConnection(bmp1.GetOutputPort());

            stlActor.SetTexture(vt);

            vtkRenderer ren1 = new vtkRenderer();
            ren1.AddActor(stlActor);
            vtkFormsWindowControl1.GetRenderWindow().AddRenderer(ren1);
            vtkFormsWindowControl1.GetRenderWindow().Render();


And here is the ReadTexture method:

private vtkJPEGReader ReadTexture(string fn)
        {
            vtkJPEGReader v = new vtkJPEGReader();
            v.SetFileName(fn);
            v.Update();
            return v;
        }

Thanks for any help,
Tolga




More information about the vtkusers mailing list