Augmented reality and 3D images
in
Contributed Library Questions
•
9 months ago
Hi...
I m new to processing. By using nyartoolkit, saito.objloader(3D library) library, I m trying to import a .obj(3D file) model in processing . But everytime i run the program i got the .obj model just near to marke
r not on the top of marker. So how can i place the .obj model exact on the marker? And there is no proper tracking between the .obj(3D image) and the pattern.
thanking you in anticipation
requesting response
here is my code
- 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 = "C:/Documents and Settings/javed.hasan/My Documents/Processing/libraries/nyar4psg/data/camera_para.dat";
- // the full path to the .patt pattern files
- String patternPath = "C:/Documents and Settings/javed.hasan/My 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,"Lancer.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)
- camera(); // 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(.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);
- }
1