OBJExport library

edited June 2015 in Library Questions

So I have an interactive program running where the user creates bugs which walk around in 3D space and leave traces. Those traces make a pattern that I want to export as a 3D Object to later 3D print. I read that for 3D printing, the nervoussystem library is best and studied their examples, so I tried to create a OBJExport object in the way they do in their examples with the

`OBJExport obj = (OBJExport) createGraphics(100,100,"nervoussystem.obj.OBJExport","filename.obj");`

statement and then just draw my stuff in between the obj.beginDraw(); and obj.EndDraw(); statements:

public void li(PGraphics pg){
        pushStyle();
        for(int i=0; i<history.size()-1; i++){
          PVector act = (PVector) history.get(i);
          pg.fill(green); pg.strokeWeight(5);
          pushMatrix(); translate(act.x,act.y,act.z);
          pg.sphere(1); 
        }
        popStyle();
      }

now when I try to run it, I get a java.lang.IllegalArgument exception: width or height must be >0 for resize

I have no idea what to do with this and google can't seem to help. Is it maybe generally not allowed to have loops i bwetween beginDraw and endDraw? None of the examples I've seen had loops.

Thanks in advance! :)

Answers

  • did you read

    http://n-e-r-v-o-u-s.com/tools/obj/

    you follow example 2?

  • exactly, but i am not using PShape, my for loop creates ellipses instead of using 'vertex', but it says nowhere that you cannot do that and in another example they use box() so i guess it should be possible?

    their examples run in my processing too so it's not a problem of compability with the library or so :/ don't have the slightest clue how my version gets the exception

  • try your code with box or sphere instead

  • i did try unsing translate and drawing spheres, which doesn't work either :/

  • and when you use the principle of the 1st example instead?

  • edited June 2015

    okay i found a way that worked out ( one had to use beginShape() and endShape() around the sphere() statement, even though there's no call to vertex. had left it out before because i didn't think they had anything to do with a call to sphere )

    so now i succesfully imported an .obj file BUT even though i wait until a couple of spheres were drawn until i record ; the output file is always a model of only one sphere. is it maybe possible that this export only works for one-piece-meshes/models?

    at the moment my function looks like the following, so it seems the shape stops drawing after the first round of the foor loop is done, even though i don't call endShape until after the loop closes?

    thanks again!

    public void li(PGraphics pg){
        pushStyle();
        pg.beginShape();
        for(int i=0; i<history.size()-1; i++){
          PVector act = (PVector) history.get(i);
          pg.fill(green); pg.strokeWeight(5);
          pushMatrix(); translate(act.x,act.y,act.z);
          pg.sphere(1); 
        }
        pg.endShape();
        popStyle();
      }
    
  • Answer ✓

    well, this can export 2 items

    maybe you have to show your entire sketch after all...

    import nervoussystem.obj.*;
    boolean record = false;
    
    void setup() {
      size(400, 400, P3D);
    }
    
    void draw() {
      if (record) {
        beginRecord("nervoussystem.obj.OBJExport", "filename.obj");
      }  
    
      box(100, 100, 100);
    
      translate(22, 200); 
      sphere (100);
    
    
      if (record) {
        endRecord();
        record = false;
        println("done"); 
      }
    }
    
    void mousePressed() {
      record = true;
    }
    
  • edited June 2015

    Hey, thanks for that, it shows me that at least in theory, it should work. Could you maybe try and see why it won't work for me?

    Here's the code, when I try it in processing, it shows the entire petal, but when I export it, the OBJ file contains only one piece of it?

      void petal(float p, float x, float y, float l, float angle, float dir) {
      pushStyle(); pushMatrix(); 
      stroke(100,0,200); fill(200,0,200);
      strokeWeight(l / 20);
      float aa = dir * PI/4; 
    
      float endX = x + cos(angle + aa) * l;
      float endY = y + sin(angle + aa) * l;
    
      float ca = PI/5; 
      float cp = 0.35 * dist (x, y, endX, endY); 
      float cox = x + cos (angle + aa + ca) * cp;
      float coy = y + sin (angle + aa + ca) * cp;
    
      float ctx = x + cos (angle + aa - ca) * cp;
      float cty = y + sin (angle + aa - ca) * cp;
    
      beginShape();
      curveVertex (ctx, cty, 0);
      curveVertex (x, y, 0);
      curveVertex (cox, coy, 10);
      curveVertex (endX, endY, 0);
      curveVertex (endX, endY, 0);
      curveVertex (ctx, cty, 0);
      curveVertex (x, y, 0);
      curveVertex (cox, coy, 10);
      endShape(CLOSE);
      line (x, y, 0, endX, endY, 0);
      popStyle(); popMatrix();
    }
    

    Update: I've tried exporting to a DFX file with the DFX library and then converting the DFX to an OBJ and I get the same result doing that.

    Another Update: I've tried to export HEMESH meshes ( in particular the grid as it could maybe be of use but also the cone for trying purposes ) and even with those , the OBJ file opener says it won't find faces? What's going wrong here?

  • Hey sissi,

    I'm experimenting a bit with this OBJ export library too and I've had the same issues. I've found that putting a "kind" parameter in beginShape works to some extent. eg beginShape(TRIANGLES); or beginShape(QUADS); there are other kinds on the processing reference https://processing.org/reference/beginShape_.html POINTS,LINES & TRIANGLE (singular) all seem to give the same "w & h must be>0" error. I'm not really sure why but thought I'd let you know. I'm trying to do a 3D triangulation thing and have a hard time with getting the per vertex color exporting correctly. Working with Quads seems to work fine but triangles are a whole different story it seems.

    hope that helps.

Sign In or Register to comment.