• fullscreen
  • Loading_3D_OBJ_Model.pde
  • import codeanticode.glgraphics.*;
    //import processing.opengl.*;
    //import javax.media.opengl.*;
    import saito.objloader.*;
    // declare that we need a OBJModel and we'll be calling it "model"
    OBJModel model;
    float rotX;
    float rotY;
    PImage tex;
    // these booleans will be used to turn on and off bits of the OBJModel
    boolean bTexture = true;
    boolean bStroke = false;
    boolean bMaterial = false;
    void setup()
        size(800, 800, P3D);
        // making an object called "model" that is a new instance of OBJModel
        model = new OBJModel(this,"Lancer.obj", "relative", POLYGON);
        // turning on the debug output (it's all the stuff that spews out in the black box down the bottom)
    void draw()
        //this will do nothing until the model material is turned off
      //  fill(255,0,255);
        translate(width/2, height/2, 0);
    void keyPressed() {
        // turns on and off the texture listed in .mtl file
        if(key == 't') {
            if(!bTexture) {
                bTexture = true;
            else {
                bTexture = false;
        else if(key == 'm') {
            // turns on and off the material listed in .mtl file
            if(!bMaterial) {
                bMaterial = true;
            else {
                bMaterial = false;
        else if(key == 's') {
            if(!bStroke) {
                stroke(10, 10, 10);
                bStroke = true;
            else {
                bStroke = false;
        // the follwing changes the render modes
        // POINTS mode is a little flakey in OPENGL (known processing bug)
        // the best one to use is the one you exported the obj as
        // when in doubt try TRIANGLES or POLYGON
        else if(key=='1') {
            stroke(10, 10, 10);
            bStroke = true;
        else if(key=='2') {
            stroke(10, 10, 10);
            bStroke = true;
        else if(key=='3') {
        else if(key=='4') {
        else if(key=='5') {
        else if(key=='6') {
        else if(key=='7') {
    void mouseDragged()
        rotX += (mouseX - pmouseX) * 0.01;
        rotY -= (mouseY - pmouseY) * 0.01;


    tweaks (9)

    about this sketch

    This sketch is running as Java applet, exported from Processing.



    Report Sketch

    Report for inappropriate content

    Please provide details if possible:

    Your have successfully reported the sketch. Thank you very much for helping to keep OpenProcessing clean and tidy :)

    Make a Copyright Infringement claim



    Add to Faves Me Likey@! 4
    You must login/register to add this sketch to your favorites.

    I simply use (OBJLoader) SAITO Library to import 3D Model. Press & Drag the mouse to rotate the model.

    Press 1-7 to check the ShapeMode...
    Also Press m-for material,
    t- for texture,
    s- for Stroke...

    8 Apr 2013
    Hi there im glad i found your sketch, i've been stuck on my own for a long time, been trying to get so the obj can load all my textures as they are exported along with the obj as separate jpegs, how did you result with a .bmp file that contains all your textures unwrapped? I am really new at this and needing to find a way to do this because i am determined to learn for my project. I currently have my .obj and mtl and jpegs that go with it, how do i change it so my images combined into one jpeg/image file similar to yours?

    I hope you can help

    10 Apr 2013
    HI jwang,

    Actually I have faced the similar problem when an object has more texture files.
    In this example there is only one texture file.

    But m trying to load the texture files on object with the help of objImport Library . And its worked fine . For me the problem releated to texture is reduced now. So if a 3D object has more than one texture files, the problem of UV mapped can be solved through this way . This library imports .obj files and supports groups, material references, vertex-, normal-, and texture-coordinates. You can get this library from here : http://www.pixelnerve.com/processing/libraries/objimport/

    10 Apr 2013
    I downloaded the OBJimport library and was trying to put mine in but the example code was very complicated, i think it was an example to load an entire scene? so i wasn't able to figure how to load just a simple obj with that library because I am still learning the code, do u know the code to load a simple obj into the library? My 3D model does not have a uv map just jpegs that the .obj and .mtl are linked with.

    Do you know the code for how to simply display the 3D model with multiple textures with this objimport library?

    Thanks so much for the reply! I may be able to solve my problem if this works.
    11 Apr 2013
    Hello jwang,

    Can you please provide me your email Id, so I can send you the simplest code for this.
    14 Oct 2013
    hey even m facing the same problem as PROCESSJW can u resolve my doubt too? please
    15 Oct 2013
    Hi Sanjana ..
    give me your email add... want to discuss it with you..
    27 Dec 2013
    hello , how can i make the .obj file ..the 3d object to rotate smoothly ?
    You need to login/register to comment.