Loading...
Logo
Processing Forum
mary's Profile
1 Posts
0 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    My goal is to show a 3D model from rhino as an Augmented reality.

    For the moment am I testing with a simple yellow square that i made in Rhino and exported as an .obj. 
    The square that is shown has a lot of holes in the mesh.
    Is it an exporting issue from rhino ? or got it something to do with the objLoader?



    Here is the code I am using:

    1. import java.io.*; // for the loadPatternFilenames() function
      import processing.opengl.*; // for OPENGL rendering
      import jp.nyatla.nyar4psg.*; // the NyARToolkit Processing library
      import codeanticode.gsvideo.*; // the GSVideo library
      import codeanticode.glgraphics.*;
      import saito.objloader.*;

      MultiMarker nya;
      GSCapture cam;

      // declare that we need a OBJModel and we'll be calling it "model"
      OBJModel model;

      // these booleans will be used to turn on and off bits of the OBJModel
      //boolean bTexture = true;
      //boolean bStroke = false;
      //boolean bMaterial = false;
      String camPara = "/Users/marre_j/Documents/Processing/libraries/NyAR4psg/data/camera_para.dat";
      // the full path to the .patt pattern files
      String patternPath = "/Users/marre_j/Documents/Processing/libraries/NyAR4psg/patternMaker/examples/ARToolKit_Patterns";
      // the dimensions at which the AR will take place. with the current library 1280x720 is about the highest possible resolution.
      int arWidth = 640;
      int arHeight = 360;
      // the number of pattern markers (from the complete list of .patt files) that will be detected, here the first 10 from the list.
      int numMarkers = 10;

      void setup()
      {
          size(640, 480, P3D);
       
          // making an object called "model" that is a new instance of OBJModel
          model = new OBJModel(this,"b.obj", "relative");
         cam = new GSCapture(this, 640, 480); // initialize the webcam capture at a specific resolution (correct and/or possible settings depend on YOUR webcam)
         cam.start(); // start capturing
        // initialize the MultiMarker at a specific resolution (make sure to input images for detection EXACTLY at this resolution)
        nya = new MultiMarker(this, arWidth, arHeight, camPara, NyAR4PsgConfig.CONFIG_DEFAULT);
        // set the delay after which a lost marker is no longer displayed. by default set to something higher, but here manually set to immediate.
        nya.setLostDelay(1);
        // load the pattern filenames (markers)
        String[] patterns = loadPatternFilenames(patternPath);
        // for the selected number of markers...
        for (int i=0; i<numMarkers; i++) {
          // add the marker for detection
          nya.addARMarker(patternPath + "/" + patterns[i], 80);
          // turning on the debug output (it's all the stuff that spews out in the black box down the bottom)
          model.enableDebug();
         // model.translateToCenter();
          model.scale(0.9);
         // model.printModelInfo();
          noStroke();
      }
      }
      void draw()
      {
          if (cam.available()) {
          cam.read(); // read the cam image
          background(cam); // a background call is needed for correct display of the marker results
          image(cam, 0, 0, width, height); // display the image at the width and height of the sketch window
          // create a copy of the cam image at the resolution of the AR detection (otherwise nya.detect will throw an assertion error!)
          PImage cSmall = cam.get();
          cSmall.resize(arWidth, arHeight);
          nya.detect(cSmall); // detect markers in the image
          // set the AR perspective uniformly, this general point-of-view is the same for all markers
          nya.setARPerspective();
        
          drawimage();
          // reset to the default perspective
          perspective();
      }
      }
      void drawimage()
      {
       float time = millis() * 0.0001;
       nya.setARPerspective();
          lights();
      for (int i=0; i<numMarkers; i++) {
          // if the marker does NOT exist (the ! exlamation mark negates it)...
          if ((!nya.isExistMarker(i))) { continue; }
          //this will do nothing until the model material is turned off
        //  fill(255,0,255);
          setMatrix(nya.getMarkerMatrix(i));
        
          pushMatrix();
         //translate(width/2, height/2, -100);
         //rotateY( -3*sin(time)*2);
         model.draw();
          popMatrix();
      }

      }
      String[] loadPatternFilenames(String path) {
        File folder = new File(path);
        FilenameFilter pattFilter = new FilenameFilter() {
          public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".patt");
          }
        };
        return folder.list(pattFilter);
      }


    Thanks for the help!