Applying a fill to 3d obj file

edited May 2016 in Library Questions

I'm trying to fill a 3d object with a color. When I apply a fill(color);, an error message is displayed saying this sort of function does not exist. I tried to solve this by texturing the .mtl with a color, but doing that for every color would be a hassle.

Does anyone know how to apply a fill to an obj?

This is my current code:

import saito.objloader.*;
import processing.opengl.*;
OBJModel model;
float a = 0;

void setup(){
  size(800,600, OPENGL);
  model = new OBJModel (this, "Bureaustoel.obj");
  model.scale(1);
  model.translateToCenter();
  noStroke();
  frameRate(30);
  smooth();
 }

void draw(){
  background(255);
  pushMatrix();
  translate(width/2, height/2, -100);
  a = mouseX * 0.01;
  rotateY(a);
  model.draw();
  popMatrix();
 }
Tagged:

Answers

  • shouldn't that be done inside the obj-file?

  • Yes I tried it. but is there a way to change it in processing? I want to apply this on multiple objects.

  • You can try to load the obj into a PShape using loadShape():

    https://www.processing.org/reference/loadShape_.html

    Then you will have more options, see the javadoc:

    http://www.processing.org/reference/javadoc/core/processing/core/PShape.html

  • The above did not work unfortunately. We searched for a way to draw a mask over the object so that mask might have a fill but didn't find anything. Is it possible to do this?

    The current entire code looks like this:

    // we need to import the TUIO library
    // and declare a TuioProcessing client variable
    import TUIO.*;
    import java.util.*;
    import saito.objloader.*;
    import processing.opengl.*;
    TuioProcessing tuioClient;
    OBJModel model;
    
    // these are some helper variables which are used
    // to create scalable graphical feedback
    float a = 0;
    float cursor_size = 15;
    float object_size = 60;
    float table_size = 760;
    float scale_factor = 1;
    PFont font;
    
    void setup()
    {
      //size(screen.width,screen.height);
      size(1000,800, OPENGL);
      model = new OBJModel (this, "Bureaustoel.obj");
      model.scale(1);
      model.translateToCenter();
      noStroke();
      fill(0);
      loop();
      frameRate(100);
      //noLoop();
    
      hint(ENABLE_NATIVE_FONTS);
      font = createFont("Arial", 18);
      scale_factor = height/table_size;
    
      // we create an instance of the TuioProcessing client
      // since we add "this" class as an argument the TuioProcessing class expects
      // an implementation of the TUIO callback methods (see below)
      tuioClient  = new TuioProcessing(this);
    }
    
    // within the draw method we retrieve a Vector (List) of TuioObject and TuioCursor (polling)
    // from the TuioProcessing client and then loop over both lists to draw the graphical feedback.
    void draw()
    {
      background(255);
      textFont(font,18*scale_factor);
      float obj_size = object_size*scale_factor; 
      float cur_size = cursor_size*scale_factor; 
      Vector tuioObjectList = tuioClient.getTuioObjects();
      for (int i=0;i<tuioObjectList.size();i++) {
        TuioObject tobj = (TuioObject)tuioObjectList.elementAt(i);
        if (tobj.getSymbolID() == 42 || tobj.getSymbolID() == 39 ) {
         pushMatrix();
         a = tobj.getAngle();
         rotateY(tobj.getAngle());   
         popMatrix();
      translate(width/2, height/2, -100);
      rotateY(a);
      model.draw();
        }
      }
    
    
       Vector tuioCursorList = tuioClient.getTuioCursors();
       for (int i=0;i<tuioCursorList.size();i++) {
          TuioCursor tcur = (TuioCursor)tuioCursorList.elementAt(i);
          Vector pointList = tcur.getPath();
    
          if (pointList.size()>0) {
            stroke(0,0,255);
            TuioPoint start_point = (TuioPoint)pointList.firstElement();;
            for (int j=0;j<pointList.size();j++) {
               TuioPoint end_point = (TuioPoint)pointList.elementAt(j);
               line(start_point.getScreenX(width),start_point.getScreenY(height),end_point.getScreenX(width),end_point.getScreenY(height));
               start_point = end_point;
            }
          }
       }
    
    }
    
    // these callback methods are called whenever a TUIO event occurs
    
    // called when an object is added to the scene
    void addTuioObject(TuioObject tobj) {
      println("add object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle());
    }
    
    // called when an object is removed from the scene
    void removeTuioObject(TuioObject tobj) {
      println("remove object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");
    }
    
    // called when an object is moved
    void updateTuioObject (TuioObject tobj) {
      println("update object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle()
              +" "+tobj.getMotionSpeed()+" "+tobj.getRotationSpeed()+" "+tobj.getMotionAccel()+" "+tobj.getRotationAccel());
    }
    
    // called when a cursor is added to the scene
    void addTuioCursor(TuioCursor tcur) {
      println("add cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY());
    }
    
    // called when a cursor is moved
    void updateTuioCursor (TuioCursor tcur) {
      println("update cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY()
              +" "+tcur.getMotionSpeed()+" "+tcur.getMotionAccel());
    }
    
    // called when a cursor is removed from the scene
    void removeTuioCursor(TuioCursor tcur) {
      println("remove cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+")");
    }
    
    // called after each message bundle
    // representing the end of an image frame
    void refresh(TuioTime bundleTime) { 
      redraw();
    }
    
Sign In or Register to comment.