Skip to content

Instantly share code, notes, and snippets.

@Scylardor
Last active November 3, 2015 12:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scylardor/9244b13abbd46fee382c to your computer and use it in GitHub Desktop.
Save Scylardor/9244b13abbd46fee382c to your computer and use it in GitHub Desktop.
vtkTexturingHelper example
/*=========================================================================
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========================================================================*/
//
// This simple example shows how to use vtkTexturingHelper to texture an
// OBJ 3D model using two texture files in C++.
// The model used by this example (mannequine_clothed) can be found on Artec3D scan gallery
// link: http://www.artec3d.com/gallery/3d-models/
//
#include <iostream>
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkTexturingHelper.h"
int main()
{
vtkTexturingHelper helper;
try {
// Read the geometry file and extract texture coordinates data from OBJ file
helper.ReadGeometryFile("mannequin/mannequine_clothed.obj");
// Read 2 textures files called "mannequin/mannequine_clothed_0.jpg" and "mannequin/mannequine_clothed_1.jpg"
helper.ReadTextureFiles("mannequin/mannequine_clothed", ".jpg", 2);
// Bind the textures and texture units data onto the geometry
helper.ApplyTextures();
} catch (const vtkTexturingHelperException & helperExc) {
std::cout << "Whoops ! This isn't supported ! " << helperExc.what() << std::endl;
}
vtkSmartPointer<vtkActor> actor = helper.GetActor();
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// Add the actors to the renderer, set the background and size
ren1->AddActor(actor);
ren1->SetBackground(0.1, 0.2, 0.4);
ren1->ResetCamera();
renWin->SetSize(800, 600);
renWin->Render();
// This starts the event loop and as a side effect causes an initial render.
iren->Start();
// Exiting from here, we have to delete all the instances that
// have been created.
ren1->Delete();
renWin->Delete();
iren->Delete();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment