Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • Rotating object centering

    Please Format your code. Edit your post (gear on top right side of any of your posts), select your code and hit ctrl+o. Leave an empty line above and below your block of code. Details here: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text

    For the second question, you can check previous relevant posts: https://forum.processing.org/two/search?Search=OBJModel

    Kf

  • Rotating object centering

    Hi, I use a sample code for object loading and rotation. I would like to:

    1) Rotate the object around it's centroind. Now is the object placed with some offsett above the center of rotation. It can be done in Processing code or in obj creator?

    The code for drawing is here:

    background(0,0,0);
    
      // Set a new co-ordinate space
      pushMatrix();
    
      // Simple 3 point lighting for dramatic effect.
      // Slightly red light in upper right, slightly blue light in upper left, and white light from behind.
      pointLight(255, 200, 200,  400, 400,  500);
      pointLight(200, 200, 255, -400, 400,  500);
      pointLight(255, 255, 255,    0,   0, -500);
    
      // Move bunny from 0,0 in upper left corner to roughly center of screen.
      translate(300, 380, 0);
    
      // Rotate shapes around the X/Y/Z axis (values in radians, 0..Pi*2)
      rotateZ(radians(roll));
      rotateX(radians(pitch));
      rotateY(radians(yaw));
    
      pushMatrix();
      noStroke();
      model.draw();
      popMatrix();
      popMatrix();
      //print("draw");
    

    2) Load other object than bunny.obj. But, when I download and use any .obj sample, it can't be loaded. Where is the problem? The code is:``

          OBJModel model;
          size(640, 480, OPENGL);
          frameRate(30);
          model = new OBJModel(this);
          model.load("bunny.obj");
          model.scale(20);
    

    and saito obj loader is used. Can you recommend me any other method?

    Can you help me please?

    The full code is here: https://files.fm/u/6uq5n95y

  • Display obj file in 3D

    I haven't tried blender, only obj

    ok, I tried about 5 different obj

    https://opengameart.org/content/shuttle-2

    https://opengameart.org/content/hextraction-base-player-pod

    https://opengameart.org/content/low-poly-biplane

    new approach

    in fact instead of loadShape I tried saitoloader now but I haven't managed to apply the texture.

    I used this:

    https://opengameart.org/content/low-poly-biplane

    // see https : // github.com/taseenb/OBJLoader/
    
    // imports ================================================
    
    /** opengl **/
    // import processing.opengl.*;
    
    /** PeasyCam **/
    import peasy.*;
    
    // to display 
    import saito.objloader.*;
    
    // declare that we need a OBJModel and we'll be calling it "model"
    // OBJModel model;
    final int maxOBJModel = 1; 
    OBJModel[] model = new OBJModel[maxOBJModel];
    float rotX;
    float rotY;
    int [] Y_Correction = new int [maxOBJModel];
    
    PeasyCam cam1 ; 
    PImage imgDark;
    
    void setup() {
      size(800, 800, P3D);
    
    
      cam1 = new PeasyCam(this, 1110); 
      background(0); 
    
      model[0] = new OBJModel ( this, "biplane.obj", "relative", TRIANGLES);  // "cassini.obj", "relative", TRIANGLES);
    
      //model[0].setupGL();
    
      model[0].disableDebug();
    
      model[0].shapeMode(POLYGON);
    
      model[0].originalTexture();
    
    
      imgDark = loadImage ( "diffuse_512.jpg" ); 
      model[0].setTexture ( imgDark ) ; 
    
      model[0].scale(20);
      model[0].disableMaterial();
    
      model[0].enableTexture();
    
    
      noStroke();
      //  fill(255, 0, 0);
    }
    
    void draw() {
      background(0); 
    
      lights();
      model[0].draw();
    }
    
  • How to use 3D Saito OBJLoader to load a 3D model

    I got a F-22 3d model with its .mtl file and .png (texture) files. I used several 3d viewers like Microsoft 3D Builder, Open 3D Model Viewer etc. to open it, it works fine. But I used Saito OBJLoader to load it into Processing, it either just showed a shape or a black shape with some bars. The code is simple like "standard" ( you can find them in Processing examples on lost of web page): `import saito.objloader.*;

    OBJModel model;

    float rotX;

    float rotY;

    void setup() {

    size(1000, 1000, P3D);
    
    model = new OBJModel(this, "FA-22.obj", "relative", TRIANGLES);
    
    model.enableTexture();
    
    model.enableDebug();
    
    model.scale(30);
    
    noStroke();
    

    }

    void draw() {

    background(87,97,227);
    
    lights();
    
    fill(255,0,255);
    
    pushMatrix();
    
    translate(width/2, height/2, 0);
    
    rotateX(rotY);
    
    rotateY(rotX);
    
    model.draw();
    
    popMatrix();
    

    }

    void mouseDragged() {

    rotX += (mouseX - pmouseX) * 0.01;
    
    rotY -= (mouseY - pmouseY) * 0.01;
    

    }`

    Anyone with Saito OBJLoader experience could give a help? ( I would like to send all files to you by email)

  • Plotting a graph in real time for infinite time

    graphpic

    Hi, I am showing the IMU data through serial in real time. Now the problem is that if the values exceed the frame then i have to run the program again to further see the values. how can i do something like it will show the graph until i stop the program.thanks

    Here is my code

    `import processing.serial.*; import java.awt.datatransfer.*; import java.awt.Toolkit; import processing.opengl.*; import saito.objloader.*; import g4p_controls.*;

    PGraphics rollG; PGraphics rollG1; PGraphics rollG2; PGraphics pitchG; PGraphics pitchG1; PGraphics pitchG2; PGraphics yawG; PGraphics yawG1; PGraphics yawG2;

    float roll = 0.0F; float pitch = 0.0F; float yaw = 0.0F; float temp = 0.0F; float alt = 0.0F; float prevR; float prevR2; float prevP; float prevP2; float prevY; float prevY2;

    float roll2 = 0.0F; float pitch2 = 0.0F; float yaw2 = 0.0F;

    PFont f;

    OBJModel model;

    // Serial port state. Serial port; final String serialConfigFile = "serialconfig.txt"; boolean printSerial = false;

    // UI controls. GPanel configPanel; GDropList serialList; GLabel serialLabel; GLabel calLabel; GCheckbox printSerialCheckbox;

    void setup() { size(800, 800, OPENGL); frameRate(30); rollG=createGraphics(width,height/4); rollG1=createGraphics(width,height/5); rollG2=createGraphics(width,height/5);

    pitchG=createGraphics(width,height/4); pitchG1=createGraphics(width,height/5); pitchG2=createGraphics(width,height/5);

    yawG=createGraphics(width,height/4); yawG1=createGraphics(width,height/4); yawG2=createGraphics(width,height/4);

    // Serial port setup. // Grab list of serial ports and choose one that was persisted earlier or default to the first port. int selectedPort = 0; String[] availablePorts = Serial.list(); if (availablePorts == null) { println("ERROR: No serial ports available!"); exit(); } String[] serialConfig = loadStrings(serialConfigFile); if (serialConfig != null && serialConfig.length > 0) { String savedPort = serialConfig[0]; // Check if saved port is in available ports. for (int i = 0; i < availablePorts.length; ++i) { if (availablePorts[i].equals(savedPort)) { selectedPort = i; } } } // Build serial config UI. configPanel = new GPanel(this, 10, 10, width-20, 90, "Configuration (click to hide/show)"); serialLabel = new GLabel(this, 0, 20, 80, 25, "Serial port:"); configPanel.addControl(serialLabel); serialList = new GDropList(this, 90, 20, 200, 200, 6); serialList.setItems(availablePorts, selectedPort); configPanel.addControl(serialList); calLabel = new GLabel(this, 300, 20, 350, 25, "Calibration: Sys=? Gyro=? Accel=? Mag=?"); configPanel.addControl(calLabel); printSerialCheckbox = new GCheckbox(this, 5, 50, 200, 20, "Print serial data"); printSerialCheckbox.setSelected(printSerial); configPanel.addControl(printSerialCheckbox); // Set serial port. setSerialPort(serialList.getSelectedText()); f = createFont("Arial",16,true);

    }

    void draw() {

    background(0);
    //drawRoll2();
     drawRoll1();
     drawPitch1();
     drawYaw1();
    

    }

    void drawRoll1() { rollG.beginDraw(); for (int i = 0; i <= width; i += 50) { rollG.fill(0, 255, 0); rollG.textFont(f,26); rollG.text("Roll", 380, 20); //rollG.text(i/2, i-10, height-15); rollG.stroke(255); rollG.line(i, height, i, 0); } for (int j = 0; j < height; j += 33) { rollG.fill(0, 255, 0); //rollG.text(6-j/(height/6), 0, j); rollG.stroke(255); rollG.line(0, j, width, j); }

    rollG.endDraw(); image(rollG,0,130);

    rollG1.beginDraw(); float plotroll = roll*5; rollG1.stroke(255, 0, 0); rollG1.line(frameCount-1, prevR, frameCount, plotroll); prevR = plotroll;

    rollG1.endDraw(); image(rollG1,0,160);

    rollG2.beginDraw();
    

    float plotroll2 = roll2*5; rollG2.stroke(0, 255, 0); rollG2.line(frameCount-1, prevR2, frameCount, plotroll2); prevR2 = plotroll2;

    rollG2.endDraw(); image(rollG2,0,160);

    }

    void drawPitch1() { pitchG.beginDraw(); for (int i = 0; i <= width; i += 50) { pitchG.fill(0, 255, 0); pitchG.textFont(f,26); pitchG.text("Pitch", 380, 20); //pitchG.text(i/2, i-10, height-15); pitchG.stroke(255); pitchG.line(i, height, i, 0); } for (int j = 0; j < height; j += 33) { pitchG.fill(0, 255, 0); //pitchG.text(6-j/(height/6), 0, j); pitchG.stroke(255); pitchG.line(0, j, width, j); }

    pitchG.endDraw(); image(pitchG,0,350);

    pitchG1.beginDraw(); float plotpitch = pitch*5; pitchG1.stroke(255, 0, 0); pitchG1.line(frameCount-1, prevP, frameCount, plotpitch); prevP = plotpitch;

    pitchG1.endDraw(); image(pitchG1,0,360);

    pitchG2.beginDraw();
    

    float plotpitch2 = pitch2*5; pitchG2.stroke(0, 255, 0); pitchG2.line(frameCount-1, prevP2, frameCount, plotpitch2); prevP2 = plotpitch2;

    pitchG2.endDraw(); image(pitchG2,0,360);

    }

    void drawYaw1() { yawG.beginDraw(); for (int i = 0; i <= width; i += 50) { yawG.fill(0, 255, 0); yawG.textFont(f,26); yawG.text("Yaw", 380, 20); //yawG.text(i/2, i-10, height-15); yawG.stroke(255); yawG.line(i, height, i, 0); } for (int j = 0; j < height; j += 33) { yawG.fill(0, 255, 0); //yawG.text(6-j/(height/6), 0, j); yawG.stroke(255); yawG.line(0, j, width, j); }

    image(yawG,0,570); yawG.endDraw();

    yawG1.beginDraw(); float plotyaw = -1*yaw/2;

    yawG1.stroke(255, 0, 0); yawG1.line(frameCount-1, prevY, frameCount, plotyaw); prevY = plotyaw;

    image(yawG1,0,630); yawG1.endDraw();

    yawG2.beginDraw();
    

    float plotyaw2 = -1*yaw2/2; yawG2.stroke(0, 255, 0); yawG2.line(frameCount-1, prevY2, frameCount, plotyaw2); prevY2 = plotyaw2;

    image(yawG2,0,630); yawG2.endDraw();

    }

    void serialEvent(Serial p) { String incoming = p.readString(); if (printSerial) { println(incoming); }

    if ((incoming.length() > 8)) { String[] list = split(incoming, " "); if ( (list.length > 0) && (list[0].equals("Orientation:")) ) {

      roll  = float(list[1]); // Roll = Z
      pitch = float(list[2]); // Pitch = Y 
      yaw   = float(list[3]); // Yaw/Heading = X
    
    }
    
     if ( (list.length > 0) && (list[0].equals("Orientation2:")) ) 
    {
    
      roll2  = float(list[1]); // Roll = Z
      pitch2 = float(list[2]); // Pitch = Y 
      yaw2   = float(list[3]); // Yaw/Heading = X
    
    }
    
    if ( (list.length > 0) && (list[0].equals("Alt:")) ) 
    {
      alt  = float(list[1]);
    }
    if ( (list.length > 0) && (list[0].equals("Temp:")) ) 
    {
      temp  = float(list[1]);
    }
    if ( (list.length > 0) && (list[0].equals("Calibration:")) )
    {
      int sysCal   = int(list[1]);
      int gyroCal  = int(list[2]);
      int accelCal = int(list[3]);
      int magCal   = int(list[4]);
      calLabel.setText("Calibration: Sys=" + sysCal + " Gyro=" + gyroCal + " Accel=" + accelCal + " Mag=" + magCal);
    }
    

    } }

    // Set serial port to desired value. void setSerialPort(String portName) { // Close the port if it's currently open. if (port != null) { port.stop(); } try { // Open port. port = new Serial(this, portName, 115200); port.bufferUntil('\n'); // Persist port in configuration. saveStrings(serialConfigFile, new String[] { portName }); } catch (RuntimeException ex) { // Swallow error if port can't be opened, keep port closed. port = null; } }

    // UI event handlers

    void handlePanelEvents(GPanel panel, GEvent event) { // Panel events, do nothing. }

    void handleDropListEvents(GDropList list, GEvent event) { // Drop list events, check if new serial port is selected. if (list == serialList) { setSerialPort(serialList.getSelectedText()); } }

    void handleToggleControlEvents(GToggleControl checkbox, GEvent event) { // Checkbox toggle events, check if print events is toggled. if (checkbox == printSerialCheckbox) { printSerial = printSerialCheckbox.isSelected(); } }`

  • Second image doesnt dissapear

    Hello,i have this code with two image appearing as instruction,the first appears and dissapears well,but the second image doesnt disappear,i want to be disappear after some seconds,but it doesnt work,i tried boolean,framecount,custom count.but it doesnt disappear.I think maybe the problem is the if tracking statement.

    import peasy.*;
    import saito.objloader.*;
    import spout.*;
    import SimpleOpenNI.*;
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    Spout spout;
    
    SimpleOpenNI kinect;
    
    PeasyCam cam;
    
    float z=0;
    
    float r;
    float k;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector[] Bez;
    PVector[] Bez2;
    PVector Mouse;
    PVector Mouse2;
    PVector rightHand;
    PVector convertedRightHand;
    PVector leftHand;
    PVector convertedLeftHand;
    PVector rightShoulder;
    PVector convertedRightShoulder;
    PVector leftShoulder;
    PVector convertedleftShoulder;
    float rightHandZ;
    float ConrightHandZ;
    float leftHandZ;
    float ConleftHandZ;
    
    boolean Kin;
    
    boolean Text1;
    boolean Text2;
    
    PImage img;
    PImage img2;
    
    
    int Tmeter=0;
    
    int VECS = 800;
    
    
    void setup()
    {
      size(1920, 1440, P3D);
    
      //hypotenuse 2450
    
      frameRate(30);
      noStroke();
    
      kinect = new SimpleOpenNI(this);
      kinect.enableDepth();
      kinect.enableUser();
    
      //800*800-->200,1920*1440-->300
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(300);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(300);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(300);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 2610);
      //800*800 --> cam 1600,1920*1440--> cam 2610
      spout = new Spout(this);
      spout.createSender("Self kinect");
    
      img = loadImage("Text1.png");
      img2 = loadImage("Text2.png");
    }
    
    
    
    void draw()
    {
      background(0);
      pointLight(255, 255, 255, 
      width/2, height/2, width*2);
    
      kinect.update();
      IntVector userList = new IntVector();
      kinect.getUsers(userList);
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      Bez = new PVector[VertCount];
      Bez2 = new PVector[VertCount];
      r =300;
      k = k + 0.01;
    
    
    
      PVector psVerts[] = new PVector[VECS];
      PVector psVerts2[]= new PVector[VECS];
    
    
      cam.setMouseControlled(false);
    
      if (userList.size() <= 0) {
        Text1 = false;
        Text2= false;
        Tmeter=0;
      }
    
      if (userList.size() > 0) {
    
    
        int userId = userList.get(0);
        Text1 = true;
    
        if ( kinect.isTrackingSkeleton(userId)) {
    
    
    
          Kin= true;
    
    
          Text1 = false;
    
    
          Text2=true;
    
    
    
          pushMatrix();
          translate(0, 0, 1255);
          //the hypotenuse
    
          image(img2, 0, 0);
    
          popMatrix();
          Tmeter+=1;
    
    
          if (Tmeter>=10 ) {
            Text2=false;
            //print("ok");
            //print(Text2);
          }
    
          print(Tmeter);
    
          rightHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, rightHand);
    
          convertedRightHand = new PVector();
          kinect.convertRealWorldToProjective(rightHand, convertedRightHand);
    
          leftHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, leftHand);
    
          convertedLeftHand = new PVector();
          kinect.convertRealWorldToProjective(leftHand, convertedLeftHand);
    
    
          rightShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, rightShoulder);
    
          convertedRightShoulder = new PVector();
          kinect.convertRealWorldToProjective(rightShoulder, convertedRightShoulder);
    
    
          leftShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, leftShoulder);
    
          convertedleftShoulder = new PVector();
          kinect.convertRealWorldToProjective(leftShoulder, convertedleftShoulder);
    
    
    
    
    
    
          rightHandZ =  map(rightHand.z, 5500, 7500, 1100, 1500);
          ConrightHandZ = map(rightHandZ, 1100, 1500, 0, 1440);
    
          leftHandZ =map(leftHand.z, 5500, 7500, 1100, 1500);
          ConleftHandZ = map(leftHandZ, 1100, 1500, 0, 1440);
    
          Mouse = new PVector(rightHand.x, -rightHand.y, z);
          Mouse2 = new PVector(leftHand.x, -leftHand.y, z);
    
    
          pushMatrix();
          translate(width/2, height/2, 0);
    
    
    
          pushMatrix();
          //-----------------HERE
          translate(Mouse2.x, Mouse2.y, Mouse2.z);
          //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 2450);
          popMatrix();
    
    
    
          pushMatrix();
          //-----------------HERE
          translate(Mouse.x, Mouse.y, Mouse.z);
          //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 2450);
          popMatrix();
    
    
          popMatrix();
        }
      }
    
      pushMatrix();
    
    
    
    
      translate(width/2, height/2, 0);
    
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
    
    
    
        //+4 for 1920*1440
        float randX = noise(randomGaussian())+4;
        float randY = noise(randomGaussian())+4;
        float randZ = noise(randomGaussian())+4;
    
        PVector Ran = new PVector(randX, randY, randZ);
    
    
    
    
        Verts[i].x+=Ran.x;
        Verts[i].y+=Ran.y;
        Verts[i].z+=Ran.z;
    
        if (Verts[i].x > width/2 ) {
          Verts[i].x=-width/2;
        } else if (Verts[i].x < -width/2) {
          Verts[i].x=width/2;
        }
        if (Verts[i].y > height/2 ) {
          Verts[i].y=-height/2;
        } else if (Verts[i].y < -height/2) {
          Verts[i].y=height/2;
        }
    
        if (Verts[i].z < -width/2 ) {  
          Verts[i].z=800/2;
        } else if ( Verts[i].z > width/2) {
          Verts[i].z=-width/2;
        }
    
    
        pushMatrix();
        translate(width/2, height/2, 0);
        rotateY(k);
        tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
        popMatrix();
    
    
    
    
        if (Kin==true) {
          if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1225 && Verts[i].z <  Mouse.z  + 1225)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1225 && Verts[i].z <  Mouse2.z  + 1225)) {
    
    
    
    
            pushMatrix();
            rotateY(k);
    
    
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
            popMatrix();
          }
        }
      }
    
    
    
    
      rotateY(k);
      noStroke();
      tmpmodel.draw();
    
    
    
    
    
    
    
    
      popMatrix();
      if (Text1==true) {
    
        pushMatrix();
        translate(0, 0, 1255);
        //the hypotenuse
    
        image(img, 0, 0);
    
        popMatrix();
      }
    
    
    
    
    
      spout.sendTexture();
      //println(Tmeter);
    }
    
    
    
    
    void onNewUser(SimpleOpenNI kinect, int userID) {
      kinect.startTrackingSkeleton(userID);
    }
    
    
    void onEndCalibration(int userId, boolean successful) {
      if (successful) {
        println(" User calibrated !!!");
        kinect.startTrackingSkeleton(userId);
      } else {
        println("  Failed to calibrate user !!!");
        kinect.startTrackingSkeleton(userId);
      }
    }
    
  • Kinect,RotateY,PopMatrix,PushMatrix

    first problem solved.i just move up the animation functions

    import peasy.*;
    import saito.objloader.*;
    import SimpleOpenNI.*;
    import spout.*;
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    Spout spout;
    
    PeasyCam cam;
    
    SimpleOpenNI kinect;
    
    
    float z=0;
    float easing = 0.005;
    float r;
    float k;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector Mouse;
    PVector Mouse2;
    PVector rightHand;
    PVector convertedRightHand;
    PVector leftHand;
    PVector convertedLeftHand;
    PVector rightShoulder;
    PVector convertedRightShoulder;
    PVector leftShoulder;
    PVector convertedleftShoulder;
    float rightHandZ;
    float ConrightHandZ;
    float leftHandZ;
    float ConleftHandZ;
    
    boolean Kin = false;
    
    void setup()
    {
      size(640*3, 480*3, P3D);
      frameRate(30);
      noStroke();
    
      kinect = new SimpleOpenNI(this);
    
      kinect.enableDepth();
      kinect.enableUser();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(200);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(200);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(200);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 2300);
    
    
      spout = new Spout(this);
    
      spout.createSender("Self kinect");
    }
    
    
    
    void draw()
    {
      background(0);
      lights();
    
      kinect.update();
      IntVector userList = new IntVector();
      kinect.getUsers(userList);
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      r =300;
      //k = k + 0.01;
    
    
    
    
      cam.setMouseControlled(false);
    
    
    
    
    
    
    
      if (userList.size() > 0) {
    
        textSize(300);
        text("Start1", width/2-150, height/2-150); 
        fill(0, 102, 153);
    
        int userId = userList.get(0);
    
        if ( kinect.isTrackingSkeleton(userId)) {
          Kin=true;
          textSize(300);
          text("Start2", width/2-150, height/2-150); 
          fill(0, 102, 153);
    
          rightHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, rightHand);
    
          convertedRightHand = new PVector();
          kinect.convertRealWorldToProjective(rightHand, convertedRightHand);
    
          leftHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, leftHand);
    
          convertedLeftHand = new PVector();
          kinect.convertRealWorldToProjective(leftHand, convertedLeftHand);
    
    
          rightShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, rightShoulder);
    
          convertedRightShoulder = new PVector();
          kinect.convertRealWorldToProjective(rightShoulder, convertedRightShoulder);
    
    
          leftShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, leftShoulder);
    
          convertedleftShoulder = new PVector();
          kinect.convertRealWorldToProjective(leftShoulder, convertedleftShoulder);
    
    
          //output.println(" This is the firstPose "+"rightHand "+rightHand+" leftHand "+leftHand);
    
    
    
          rightHandZ =  map(rightHand.z, 5500, 7500, 1100, 1500);
          ConrightHandZ = map(rightHandZ, 1100, 1500, 0, 1440);
    
          leftHandZ =map(leftHand.z, 5500, 7500, 1100, 1500);
          ConleftHandZ = map(leftHandZ, 1100, 1500, 0, 1440);
    
          Mouse = new PVector(rightHand.x, -rightHand.y, z);
          Mouse2 = new PVector(leftHand.x, -leftHand.y, z);
    
          pushMatrix();
          translate(width/2, height/2, 0);
          pushMatrix();
          rotateY(-k); //-----------------HERE
          translate(Mouse.x, Mouse.y, Mouse.z);
          rotateY(k); //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 1920);
          popMatrix();
    
    
          pushMatrix();
          rotateY(-k); //-----------------HERE
          translate(Mouse2.x, Mouse2.y, Mouse2.z);
          rotateY(k); //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 1920);
          popMatrix();
          popMatrix();
        }
      }
    
    
      //println("rightHand "+rightHand.z+"leftHand "+leftHand.z);
      //println(frameCount);
    
    
    
    
      pushMatrix();
    
    
    
    
      translate(width/2, height/2, 0);
      rotateY(k);
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
    
        float randX = noise(randomGaussian());
        float randY = noise(randomGaussian());
        float randZ = noise(randomGaussian());
    
        PVector Ran = new PVector(randX, randY, randZ);
    
        Verts[i].x+=Ran.x;
        Verts[i].y+=Ran.y;
        Verts[i].z+=Ran.z;
    
        if (Verts[i].x > width/2 ) {
          Verts[i].x=-width/2;
        } else if (Verts[i].x < -width/2) {
          Verts[i].x=width/2;
        }
        if (Verts[i].y > height/2 ) {
          Verts[i].y=-height/2;
        } else if (Verts[i].y < -height/2) {
          Verts[i].y=height/2;
        }
    
        if (Verts[i].z < -720 ) {  
          Verts[i].z=800/2;
        } else if ( Verts[i].z > 720) {
          Verts[i].z=-800/2;
        }
        tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
    
    
    
    
        //float norX = abs(cos(k)) * randX;
        //float norY = abs(cos(k)) * randY;
        //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
        if (Kin==true) {
          if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
          }
        }    
    
    
    
    
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
    
    
    
      noStroke();
    
      tmpmodel.draw();
    
      popMatrix();
    
    
    
      pushMatrix();
      translate(width/2, height/2, 0);
      rotateY(k);
      noFill();
      stroke(255);
      strokeWeight(7);
      box(width, height, 1920);
      popMatrix();
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame();
      //println(z);
      if (userList.size() < 0) {
        Kin=false;
      }
    
      spout.sendTexture();
      println(Kin);
    }
    
    
    void onNewUser(SimpleOpenNI kinect, int userID) {
    
    
      kinect.startTrackingSkeleton(userID);
    }
    
    //startTracking is alterd 
    void onEndCalibration(int userId, boolean successful) {
      if (successful) {
        println(" User calibrated !!!");
        kinect.startTrackingSkeleton(userId);
      } else {
        println("  Failed to calibrate user !!!");
        kinect.startTrackingSkeleton(userId);
      }
    }
    
    //There is aproblem here,deleted the pose
    
    
    
    void keyPressed() {
      if (keyCode == UP) {
        z++;
      }
      if (keyCode == DOWN) {
        z--;
      }
    }
    
  • Kinect,RotateY,PopMatrix,PushMatrix

    Here is the final example i couldnt put it in the question because of length

    Final Example:Here is the example without the kinect,but with one poin that is static and one that is controlled by the mouse.The problem is that i made several PushMatrix() Popmatrix() each inside an other.the bigg pushMatrix that it includes all other is rotateY by (k).The problem is that to have the cubes that transform the models dont rotate i had inside their pushMatrix to rotate them by -k,so to be static in front the screen and to not confuse the user.The problem is that while the cubes are not rotating, their infuence is rotated because it is in the larger popmatrix.

     import peasy.*;
    import saito.objloader.*;
    import spout.*;
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    Spout spout;
    
    
    PeasyCam cam;
    
    float z=0;
    float easing = 0.005;
    float r;
    float k;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector[] Bez;
    PVector[] Bez2;
    PVector Mouse;
    PVector Mouse2;
    
    int VECS = 800;
    
    
    void setup()
    {
      size(800, 800, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(200);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(200);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(200);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 1600);
    
      spout = new Spout(this);
    
      spout.createSender("Self");
    }
    
    
    
    void draw()
    {
      background(0);
      pointLight(255, 255, 255, 
      width/2, height/2, 1600);
    
    
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      Bez = new PVector[VertCount];
      Bez2 = new PVector[VertCount];
      r =100;
      k = k + 0.01;
    
    
      PVector psVerts[] = new PVector[VECS];
      PVector psVerts2[]= new PVector[VECS];
    
    
      cam.setMouseControlled(false);
    
    
      Mouse = new PVector(mouseX-width/2, mouseY-height/2, z);
      Mouse2 = new PVector(width/2 -height/2, z);
    
    
    
    
    
      //println(frameCount);
     ` pushMatrix();`
    
    
    
    
      translate(width/2, height/2, 0);
      `rotateY(k);`
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
        if (frameCount> 100) {
    
    
    
          float randX = noise(randomGaussian());
          float randY = noise(randomGaussian());
          float randZ = noise(randomGaussian());
    
          PVector Ran = new PVector(randX, randY, randZ);
    
          //float norX = abs(cos(k)) * randX;
          //float norY = abs(cos(k)) * randY;
          //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
    
         ` if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {`
    
    
    
    
            pushMatrix();
            pushStyle();
            strokeWeight(0.1);
            stroke(255, 255, 255);
            noFill();
            bezier(locas[i].x, locas[i].y, locas[i].z, -100, -100, -100, -100, -100, -100, Verts[i].x, Verts[i].y, Verts[i].z);
            popStyle();
            popMatrix();
    
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
          } else {   
    
    
    
            Verts[i].x+=Ran.x;
            Verts[i].y+=Ran.y;
            Verts[i].z+=Ran.z;
    
            if (Verts[i].x > width/2 ) {
              Verts[i].x=-width/2;
            } else if (Verts[i].x < -width/2) {
              Verts[i].x=width/2;
            }
            if (Verts[i].y > height/2 ) {
              Verts[i].y=-height/2;
            } else if (Verts[i].y < -height/2) {
              Verts[i].y=height/2;
            }
    
            if (Verts[i].z < -800/2 ) {  
              Verts[i].z=800/2;
            } else if ( Verts[i].z > 800/2) {
              Verts[i].z=-800/2;
            }
            tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
          }
        }
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
      /*pushMatrix();
       `rotateY(-k);` //-----------------HERE
       translate(0, 0, 0);
    
       //rotateY(k);
       noFill();
       strokeWeight(3);
       stroke(255, 10, 10);
    
       /* beginShape();
    
       for (int i=0; i < VECS; i+=30 ) {
    
       psVerts[i] = new PVector (Mouse.x, Mouse.y, (Mouse.z+400));
       psVerts2[i] = new PVector(Mouse2.x, Mouse2.y, (Mouse2.z-400));
    
    
    
       vertex(psVerts[i].x, psVerts[i].y, psVerts[i].z);
       vertex(psVerts2[i].x, psVerts2[i].y, width/2-i);
       vertex(noise(-width/2, +width/2), noise(-height/2, +height/2), noise(-width/2, +width/2));
       vertex(random(-width/2, +width/2), random(-height/2, +height/2), random(-width/2, +width/2));
       vertex(psVerts[i].x, psVerts[i].y, psVerts[i].z);
       vertex(psVerts2[i].x, psVerts2[i].y, width/2-i);
       vertex(noise(-width/2, +width/2), noise(-height/2, +height/2), noise(-width/2, +width/2));
       vertex(random(-width/2, +width/2), random(-height/2, +height/2), random(-width/2, +width/2));
       }
       endShape();
       popMatrix();*/
    
    
      pushMatrix();
      pushStyle();
      noLights();
      `rotateY(-k);` //-----------------HERE
      translate(Mouse.x, Mouse.y, Mouse2.z+width/2);
      //rotateY(k); //-------------AND HERE
      fill(255, 0, 0);
      ellipse(0, 0, 10, 10);
      popStyle();
      popMatrix();
    
    
    
    
      pushMatrix();
      pushStyle();
      rotateY(-k); //-----------------HERE
      translate(Mouse2.x, Mouse2.y, Mouse2.z+width/2);
      //rotateY(k); //-------------AND HERE
      noFill();
      stroke(255);
      strokeWeight(3);
      box(r, r, 800);
      popStyle();
      popMatrix();
    
    
      noStroke();
      tmpmodel.draw();
      popMatrix();
    
    
    
      /*pushMatrix();
       translate(width/2, height/2, 0);
       rotateY(k);
       noFill();
       stroke(255);
       strokeWeight(7);
       box(width, height, 800);
       popMatrix();*/
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame();
      //println(z);
    
      spout.sendTexture();
    }
    
    void keyPressed() {
      if (keyCode == UP) {
        z++;
      }
      if (keyCode == DOWN) {
        z--;
      }
    }
    

    It will be very helpfull if you had any solution,Thank you very much.I have only 3 days for my degree and i have to solve it

  • Kinect,RotateY,PopMatrix,PushMatrix

    hello guys,here i have 3 examples of the same code,the two of them is with kinect and the other with a static point and the mouse.The final installation will be with the two hands of the kinect.I have one problem with the kinect and one with pushMatrix popMatrix and rotate().I will explain in the code below.What are the problems and the what i want to achieve

    First example:here the examples are not rotating(the cubes,the models and the area that influence the models)It works perfect except that for the model to be shown,it has to calibrate first with the kinect because the if statements.

    import peasy.*;
    import saito.objloader.*;
    import SimpleOpenNI.*;
    import spout.*;
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    Spout spout;
    
    PeasyCam cam;
    
    SimpleOpenNI kinect;
    
    
    float z=0;
    float easing = 0.005;
    float r;
    float k;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector Mouse;
    PVector Mouse2;
    
    void setup()
    {
      size(640*3, 480*3, P3D);
      frameRate(30);
      noStroke();
    
      kinect = new SimpleOpenNI(this);
    
      kinect.enableDepth();
      kinect.enableUser();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(200);
      model.translateToCenter();
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(200);
      Smodel.translateToCenter();
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(200);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 2300);
    
      spout = new Spout(this);
    
      spout.createSender("Self kinect");
    }
    
    
    void draw()
    {
      background(0);
      lights();
    
      kinect.update();
      IntVector userList = new IntVector();
      kinect.getUsers(userList);
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      r =300;
      //k = k + 0.01;
    
      cam.setMouseControlled(false);
    
    
      if (userList.size() > 0) {
    
        textSize(300);
        text("Start1", width/2-150, height/2-150); 
        fill(0, 102, 153);
    
        int userId = userList.get(0);
    
        if ( kinect.isTrackingSkeleton(userId)) {
    
          textSize(300);
          text("Start2", width/2-150, height/2-150); 
          fill(0, 102, 153);
    
          PVector rightHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, rightHand);
    
          PVector convertedRightHand = new PVector();
          kinect.convertRealWorldToProjective(rightHand, convertedRightHand);
    
          PVector leftHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, leftHand);
    
          PVector convertedLeftHand = new PVector();
          kinect.convertRealWorldToProjective(leftHand, convertedLeftHand);
    
    
          PVector rightShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, rightShoulder);
    
          PVector convertedRightShoulder = new PVector();
          kinect.convertRealWorldToProjective(rightShoulder, convertedRightShoulder);
    
    
          PVector leftShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, leftShoulder);
    
          PVector convertedleftShoulder = new PVector();
          kinect.convertRealWorldToProjective(leftShoulder, convertedleftShoulder);
    
    
          //output.println(" This is the firstPose "+"rightHand "+rightHand+" leftHand "+leftHand);
    
    
    
          float rightHandZ =  map(rightHand.z, 5500, 7500, 1100, 1500);
          float ConrightHandZ = map(rightHandZ, 1100, 1500, 0, 1440);
    
          float leftHandZ =map(leftHand.z, 5500, 7500, 1100, 1500);
          float ConleftHandZ = map(leftHandZ, 1100, 1500, 0, 1440);
    
          Mouse = new PVector(rightHand.x, -rightHand.y, z);
          Mouse2 = new PVector(leftHand.x, -leftHand.y, z);
    
    
          println("rightHand "+rightHand.z+"leftHand "+leftHand.z);
          //println(frameCount);
    
          pushMatrix();
    
          translate(width/2, height/2, 0);
          rotateY(k);
    
    
          for (int i = 0; i < VertCount; i++) {
            //PVector orgv = model.getVertex(i);
    
            locas[i]= model.getVertex(i);
            Verts[i]= Smodel.getVertex(i);
    
    
            //PVector tmpv = new PVector();
    
    
            if (frameCount> 100) {
    
    
    
              float randX = noise(randomGaussian());
              float randY = noise(randomGaussian());
              float randZ = noise(randomGaussian());
    
              PVector Ran = new PVector(randX, randY, randZ);
    
              //float norX = abs(cos(k)) * randX;
              //float norY = abs(cos(k)) * randY;
              //float norZ = abs(cos(k)) * randZ;
    
              if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {
                tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
              } else {   
    
                Verts[i].x+=Ran.x;
                Verts[i].y+=Ran.y;
                Verts[i].z+=Ran.z;
    
                if (Verts[i].x > width/2 ) {
                  Verts[i].x=-width/2;
                } else if (Verts[i].x < -width/2) {
                  Verts[i].x=width/2;
                }
                if (Verts[i].y > height/2 ) {
                  Verts[i].y=-height/2;
                } else if (Verts[i].y < -height/2) {
                  Verts[i].y=height/2;
                }
    
                if (Verts[i].z < -720 ) {  
                  Verts[i].z=800/2;
                } else if ( Verts[i].z > 720) {
                  Verts[i].z=-800/2;
                }
                tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
              }
            }
            // output.println("Verts " + Verts[i] + " locas " +locas[i]);
          }
    
          pushMatrix();
          rotateY(-k); //-----------------HERE
          translate(Mouse.x, Mouse.y, Mouse.z);
          rotateY(k); //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 1920);
          popMatrix();
    
    
          pushMatrix();
          rotateY(-k); //-----------------HERE
          translate(Mouse2.x, Mouse2.y, Mouse2.z);
          rotateY(k); //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 1920);
          popMatrix();
    
    
          noStroke();
    
          tmpmodel.draw();
    
          popMatrix();
    
    
    
          pushMatrix();
          translate(width/2, height/2, 0);
          rotateY(k);
          noFill();
          stroke(255);
          strokeWeight(7);
          box(width, height, 1920);
          popMatrix();
          //output.flush(); // Writes the remaining data to the file
          //output.close(); // Finishes the file
          //saveFrame();
          //println(z);
        }
      }
    
      spout.sendTexture();
    }
    
    
    void onNewUser(SimpleOpenNI kinect, int userID) {
    
    
      kinect.startTrackingSkeleton(userID);
    }
    
    //startTracking is alterd 
    void onEndCalibration(int userId, boolean successful) {
      if (successful) {
        println(" User calibrated !!!");
        kinect.startTrackingSkeleton(userId);
      } else {
        println("  Failed to calibrate user !!!");
        kinect.startTrackingSkeleton(userId);
      }
    }
    
    //There is aproblem here,deleted the pose
    
    
    
    void keyPressed() {
      if (keyCode == UP) {
        z++;
      }
      if (keyCode == DOWN) {
        z--;
      }
    }
    

    Second Example: Here is the same example with above,but i tried to move out the kinect calibration from the general animation of the model,which is difined by RanX,RanY,RanZ and Nor.I tried to solve the problem with a boolean.The problem is that when the Kinect calibrates the user the animation stops.

    import peasy.*;
    import saito.objloader.*;
    import SimpleOpenNI.*;
    import spout.*;
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    Spout spout;
    
    PeasyCam cam;
    
    SimpleOpenNI kinect;
    
    
    float z=0;
    float easing = 0.005;
    float r;
    float k;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector Mouse;
    PVector Mouse2;
    PVector rightHand;
    PVector convertedRightHand;
    PVector leftHand;
    PVector convertedLeftHand;
    PVector rightShoulder;
    PVector convertedRightShoulder;
    PVector leftShoulder;
    PVector convertedleftShoulder;
    float rightHandZ;
    float ConrightHandZ;
    float leftHandZ;
    float ConleftHandZ;
    
    `boolean Kin = false;`
    
    void setup()
    {
      size(640*3, 480*3, P3D);
      frameRate(30);
      noStroke();
    
      kinect = new SimpleOpenNI(this);
    
      kinect.enableDepth();
      kinect.enableUser();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(200);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(200);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(200);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 2300);
    
    
      spout = new Spout(this);
    
      spout.createSender("Self kinect");
    }
    
    
    
    void draw()
    {
      background(0);
      lights();
    
      kinect.update();
      IntVector userList = new IntVector();
      kinect.getUsers(userList);
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      r =300;
      //k = k + 0.01;
    
    
    
    
      cam.setMouseControlled(false);
    
    
    
    
    
    
    
      if (userList.size() > 0) {
    
        textSize(300);
        text("Start1", width/2-150, height/2-150); 
        fill(0, 102, 153);
    
        int userId = userList.get(0);
    
        if ( kinect.isTrackingSkeleton(userId)) {
          `Kin=true;`
          textSize(300);
          text("Start2", width/2-150, height/2-150); 
          fill(0, 102, 153);
    
          rightHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, rightHand);
    
          convertedRightHand = new PVector();
          kinect.convertRealWorldToProjective(rightHand, convertedRightHand);
    
          leftHand = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, leftHand);
    
          convertedLeftHand = new PVector();
          kinect.convertRealWorldToProjective(leftHand, convertedLeftHand);
    
    
          rightShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, rightShoulder);
    
          convertedRightShoulder = new PVector();
          kinect.convertRealWorldToProjective(rightShoulder, convertedRightShoulder);
    
    
          leftShoulder = new PVector();
          kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, leftShoulder);
    
          convertedleftShoulder = new PVector();
          kinect.convertRealWorldToProjective(leftShoulder, convertedleftShoulder);
    
    
          //output.println(" This is the firstPose "+"rightHand "+rightHand+" leftHand "+leftHand);
    
    
    
          rightHandZ =  map(rightHand.z, 5500, 7500, 1100, 1500);
          ConrightHandZ = map(rightHandZ, 1100, 1500, 0, 1440);
    
          leftHandZ =map(leftHand.z, 5500, 7500, 1100, 1500);
          ConleftHandZ = map(leftHandZ, 1100, 1500, 0, 1440);
    
          Mouse = new PVector(rightHand.x, -rightHand.y, z);
          Mouse2 = new PVector(leftHand.x, -leftHand.y, z);
    
          pushMatrix();
          translate(width/2, height/2, 0);
          pushMatrix();
          rotateY(-k); //-----------------HERE
          translate(Mouse.x, Mouse.y, Mouse.z);
          rotateY(k); //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 1920);
          popMatrix();
    
    
          pushMatrix();
          rotateY(-k); //-----------------HERE
          translate(Mouse2.x, Mouse2.y, Mouse2.z);
          rotateY(k); //-------------AND HERE
          noFill();
          stroke(255);
          strokeWeight(3);
          box(r, r, 1920);
          popMatrix();
          popMatrix();
        }
      }
    
    
      //println("rightHand "+rightHand.z+"leftHand "+leftHand.z);
      //println(frameCount);
    
    
    
    
      pushMatrix();
    
    
    
    
      translate(width/2, height/2, 0);
      rotateY(k);
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
        if (frameCount> 10) {
    
    
    
          float randX = noise(randomGaussian());
          float randY = noise(randomGaussian());
          float randZ = noise(randomGaussian());
    
          PVector Ran = new PVector(randX, randY, randZ);
    
          //float norX = abs(cos(k)) * randX;
          //float norY = abs(cos(k)) * randY;
          //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
         ` if (Kin==true) {`
            if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {
              tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
            }
         ` } else if (Kin==true||Kin==false) {   `
    
    
    
            Verts[i].x+=Ran.x;
            Verts[i].y+=Ran.y;
            Verts[i].z+=Ran.z;
    
            if (Verts[i].x > width/2 ) {
              Verts[i].x=-width/2;
            } else if (Verts[i].x < -width/2) {
              Verts[i].x=width/2;
            }
            if (Verts[i].y > height/2 ) {
              Verts[i].y=-height/2;
            } else if (Verts[i].y < -height/2) {
              Verts[i].y=height/2;
            }
    
            if (Verts[i].z < -720 ) {  
              Verts[i].z=800/2;
            } else if ( Verts[i].z > 720) {
              Verts[i].z=-800/2;
            }
            tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
          }
        }
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
    
    
    
      noStroke();
    
      tmpmodel.draw();
    
      popMatrix();
    
    
    
      pushMatrix();
      translate(width/2, height/2, 0);
      rotateY(k);
      noFill();
      stroke(255);
      strokeWeight(7);
      box(width, height, 1920);
      popMatrix();
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame();
      //println(z);
      if (userList.size() < 0) {
        Kin=false;
      }
    
      spout.sendTexture();
      println(Kin);
    }
    
    
    void onNewUser(SimpleOpenNI kinect, int userID) {
    
    
      kinect.startTrackingSkeleton(userID);
    }
    
    //startTracking is alterd 
    void onEndCalibration(int userId, boolean successful) {
      if (successful) {
        println(" User calibrated !!!");
        kinect.startTrackingSkeleton(userId);
      } else {
        println("  Failed to calibrate user !!!");
        kinect.startTrackingSkeleton(userId);
      }
    }
    
    //There is aproblem here,deleted the pose
    
    
    
    void keyPressed() {
      if (keyCode == UP) {
        z++;
      }
      if (keyCode == DOWN) {
        z--;
      }
    }
    
  • AR project : Saito OBJLoader + NyARToolkit

    Hi !

    I've learned processing (thanks to the wonderful Daniel Shiffman) few days ago to help in a student project based on AR. First, I did the three examples in the tutorial of Amnon Owed ( creativeapplications.net/processing/augmented-reality-with-processing-tutorial-processing/ ) and after a lot of fails, it finally worked.

    Now, I try to do the same as the third example (cube) but instead of using beginshape/endshape, I want to input my own CAO model. The only thing I found is the library Saito OBJLoader which allows me to load a .obj file into Processing. But I meet always the same problem : "Material"MTLO" is not defined", each time the marker enter in the camera field (sorry about my English).

    I actually selected a material for my model in my CAO software (PTCCreo Parametric) and saved it as a .obj file.

    I'm sorry, i let the "mountain growth" and the loops because it doesn't work without and i actually don't know how to change it.

        // Augmented Reality Dynamic Example by Amnon Owed (21/12/11)
        // Processing 1.5.1 + NyARToolkit 1.1.6 + GSVideo 1.0
    
        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 saito.objloader.*;
    
        // a central location is used for the camera_para.dat and pattern files, so you don't have to copy them to each individual sketch
        // Make sure to change both the camPara and the patternPath String to where the files are on YOUR computer
        // the full path to the camera_para.dat file
        String camPara = "C:/Users/layatlu/Documents/Processing/libraries/nyar4psg/data/camera_para.dat";
        // the full path to the .patt pattern files
        String patternPath = "C:/Users/layatlu/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 = 800;
        int arHeight = 600;
        // 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;
    
        // the resolution at which the mountains will be displayed
        int resX = 60;
        int resY = 60;
        // this is a 2 dimensional float array that all the displayed mountains use during their update-to-draw routine
        float[][] val = new float[resX][resY];
    
        GSCapture cam;
        MultiMarker nya;
        float[] scaler = new float[numMarkers];
        float[] noiseScale = new float[numMarkers];
        float[] mountainHeight = new float[numMarkers];
        float[] mountainGrowth = new float[numMarkers];
    
        OBJModel model;
    
        void setup() {
          size(1280, 720, P3D); // the sketch will resize correctly, so for example setting it to 1920 x 1080 will work as well
          cam = new GSCapture(this, 800, 600); // initializing the webcam capture at a specific resolution (correct/possible settings depends on YOUR webcam)
          cam.start(); // start capturing
          //model H
          model = new OBJModel(this, "h.obj");
          model.scale(80); //because model is too small
          model.translateToCenter();
          noStroke(); // turn off stroke for the rest of this sketch :-)
          // create a new MultiMarker at a specific resolution (arWidth x arHeight), with the default camera calibration and coordinate system
          nya = new MultiMarker(this, arWidth, arHeight, camPara, NyAR4PsgConfig.CONFIG_PSG);
          // 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);
          String[] patterns = loadPatternFilenames(patternPath);
          // for the selected number of markers, add the marker for detection
          // create an individual scale, noiseScale and maximum mountainHeight for that marker (= mountain)
          for (int i=0; i<numMarkers; i++) {
            nya.addARMarker(patternPath + "/" + patterns[i], 80);
            scaler[i] = random(0.8, 1.9); // scaled a little smaller or bigger
            // noiseScale[i] = random(0.02, 0.075); // the perlin noise scale to make it look nicely mountainy
            // mountainHeight[i] = random(75, 150); // the maximum height of a mountain
          }
        }
    
        void draw() {
          // if there is a cam image coming in...
          if (cam.available()== true) {
            cam.read(); // read the cam image
            background(0); // 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
            println(MultiMarker.VERSION);
            drawMountains(); // draw dynamically flowing mountains on the detected markers (3D)
          }
        }
    
        // this function draws correctly placed 3D 'mountains' on top of detected markers
        // while the mountains are displayed they grow (up to a certain point), while not displayed they return to the zero-state
        void drawMountains() {
          // set the AR perspective uniformly, this general point-of-view is the same for all markers
          nya.setARPerspective();
          // turn on some general lights (without lights it also looks pretty cool, try commenting it out!)
          //lights();
          // for all the markers...
          for (int i=0; i<numMarkers; i++) {  // if the mountainGrowth is higher than zero, decrease by 0.05 (return to the zero-state), then continue to the next marker
            if ((!nya.isExistMarker(i))) {
              if (mountainGrowth[i] > 0) { 
                mountainGrowth[i] -= 0.05;
              }
              continue;
            }
            // the following code is only reached and run if the marker DOES EXIST
            // if the mountainGrowth is lower than 1, increase by 0.03
            if (mountainGrowth[i] < 1) { 
              mountainGrowth[i] += 0.03;
            }
            // the double for loop below sets the values in the 2 dimensional float array for this mountain, based on it's noiseScale, mountainHeight and index (i).
            float xoff = 0.0;
            for (int x=0; x<resX; x++) {
              xoff += noiseScale[i];
              float yoff = 0;
              for (int y=0; y<resY; y++) {
                yoff += noiseScale[i];
                val[x][y] = noise(i*10+xoff+frameCount*0.05, yoff) * mountainHeight[i]; // this sets the value
                float distance = dist(x, y, resX/2, resY/2);
                distance = map(distance, 0, resX/2, 1, 0);
                if (distance < 0) { 
                  distance = -distance;
                } // this line causing the four corners to flap upwards (try commenting it out or setting it to zero)
                val[x][y] *= distance; // in the default case this makes the value approach zero towards the outer ends (try commenting it out to see the difference)
              }
            }
            PMatrix syst3D;
    
            // get the Matrix for this marker and use it (through setMatrix)
            syst3D = nya.getMarkerMatrix(i);
            setMatrix(syst3D);
            scale(1, -1); // turn things upside down to work intuitively for Processing users
            scale(scaler[i]); // scale the mountain by it's individual scaler
            translate(-resX/2, -resY/2); // translate to center the mountain on the marker
            // for the full resolution...
            for (int x=0; x<resX-1; x++) {
              for (int y=0; y<resY-1; y++) {
                // each face is a Shape with a fill color, together they make a colored mountain
                model.disableMaterial();
                fill(255, 0, 0);
                model.draw();
              }
            }
          }
    
          // reset to the default perspective
          perspective();
        }
    
    
    
        // this function loads .patt filenames into a list of Strings based on a full path to a directory (relies on java.io)
        String[] loadPatternFilenames(String patternPath) {
          File folder = new File(patternPath);
          FilenameFilter pattFilter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
              return name.toLowerCase().endsWith(".patt");
            }
          };
          return folder.list(pattFilter);
        }
    
  • Fill() and Transform

    Hi,why the fill and transform and rotate goes to next shape,although i used popMatrix and pushMatrix?

    import peasy.*;
    import saito.objloader.*;
    import spout.*;
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    Spout spout;
    
    
    PeasyCam cam;
    
    float z=0;
    float easing = 0.005;
    float r;
    float k;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector Mouse;
    PVector Mouse2;
    
    int VECS = 600;
    
    
    void setup()
    {
      size(800, 800, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(200);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(200);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(200);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 1600);
    
      spout = new Spout(this);
    
      spout.createSender("Self");
    }
    
    
    
    void draw()
    {
      background(0);
      lights();
    
    
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      r =100;
      k = k + 0.01;
    
    
    PVector psVerts[] = new PVector[VECS];
    PVector psVerts2[]= new PVector[VECS];
    
    
      cam.setMouseControlled(false);
    
    
      Mouse = new PVector(mouseX-width/2, mouseY-height/2, z);
      Mouse2 = new PVector(width/2 -height/2, z);
    
    
    
    
    
      //println(frameCount);
      pushMatrix();
    
    
    
    
      translate(width/2, height/2, 0);
      rotateY(k);
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
        if (frameCount> 100) {
    
    
    
          float randX = noise(randomGaussian());
          float randY = noise(randomGaussian());
          float randZ = noise(randomGaussian());
    
          PVector Ran = new PVector(randX, randY, randZ);
    
          //float norX = abs(cos(k)) * randX;
          //float norY = abs(cos(k)) * randY;
          //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
    
          if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
          } else {   
    
    
    
            Verts[i].x+=Ran.x;
            Verts[i].y+=Ran.y;
            Verts[i].z+=Ran.z;
    
            if (Verts[i].x > width/2 ) {
              Verts[i].x=-width/2;
            } else if (Verts[i].x < -width/2) {
              Verts[i].x=width/2;
            }
            if (Verts[i].y > height/2 ) {
              Verts[i].y=-height/2;
            } else if (Verts[i].y < -height/2) {
              Verts[i].y=height/2;
            }
    
            if (Verts[i].z < -800/2 ) {  
              Verts[i].z=800/2;
            } else if ( Verts[i].z > 800/2) {
              Verts[i].z=-800/2;
            }
            tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
          }
        }
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
      pushMatrix();
      rotateY(-k); //-----------------HERE
      //translate(0, 0, 0);
      //rotateY(k); //
      fill(26, 59, 45);
      noStroke();
      beginShape();
    
      for (int i=0; i < VECS; i+=30 ) {
    
        psVerts[i] = new PVector (Mouse.x, Mouse.y,Mouse.z);
       psVerts2[i] = new PVector(Mouse2.x, Mouse2.y,Mouse2.z);
    
    
    
      vertex(psVerts[i].x, psVerts[i].y, psVerts[i].z);
      vertex(psVerts2[i].x, psVerts2[i].y, psVerts2[i].z);
      vertex(noise(-width/2,+width/2),noise(-height/2,+height/2),noise(-width/2,+width/2));
      }
      endShape();
      popMatrix();
    
    
      pushMatrix();
      rotateY(-k); //-----------------HERE
    
      translate(Mouse.x, Mouse.y, Mouse2.z+width/2);
      rotateY(k); //-------------AND HERE
    
      fill(255, 0, 0);
    
      ellipse(0, 0, 10, 10);
      popMatrix();
    
    
    
    
      pushMatrix();
      rotateY(-k); //-----------------HERE
      fill(255, 0, 0);
      translate(Mouse2.x, Mouse2.y, Mouse2.z+width/2);
      rotateY(k); //-------------AND HERE
    
    
      ellipse(0, 0, 10, 10);
      popMatrix();
    
    
      noStroke();
    
      tmpmodel.draw();
    
      popMatrix();
    
    
    
      pushMatrix();
      translate(width/2, height/2, 0);
      rotateY(k);
      noFill();
    
      stroke(255);
      strokeWeight(7);
      box(width, height, 800);
      popMatrix();
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame();
      println(z);
    
      spout.sendTexture();
    }
    
    void keyPressed() {
      if (keyCode == UP) {
        z++;
      }
      if (keyCode == DOWN) {
        z--;
      }
    }
    
  • Rotating mouseX,mouseY

    i make it.Here is all the code,because i use pushMatrix,i had to cancel the first rotation and then put an other rotation after translation

     import peasy.*;
    import saito.objloader.*;
    
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    PeasyCam cam;
    
    float z=0;
    float easing = 0.005;
    float r;
    float k =0.00001;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector Mouse;
    
    void setup()
    {
      size(800, 800, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(150);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(150);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(150);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 1200);
    }
    
    
    
    void draw()
    {
      background(129);
      lights();
    
    
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      float r =200;
    
    
    
    
    
      cam.setMouseControlled(false);
    
    
      Mouse = new PVector(mouseX-width/2, mouseY-height/2, z);
    
    
    
    
    
    
      //println(frameCount);
      pushMatrix();
    
    
    
    
      translate(width/2, height/2, 0);
      rotateY(k);
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
        if (frameCount> 100) {
    
    
    
          float randX = noise(randomGaussian());
          float randY = noise(randomGaussian());
          float randZ = noise(randomGaussian());
    
          PVector Ran = new PVector(randX, randY, randZ);
    
          //float norX = abs(cos(k)) * randX;
          //float norY = abs(cos(k)) * randY;
          //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
    
          if (Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - r/2 && Verts[i].z <  Mouse.z  + r/2) {
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
          } else {   
    
    
    
            Verts[i].x+=Ran.x;
            Verts[i].y+=Ran.y;
            Verts[i].z+=Ran.z;
    
            if (Verts[i].x > width/2 ) {
              Verts[i].x=-width/2;
            } else if (Verts[i].x < -width/2) {
              Verts[i].x=width/2;
            }
            if (Verts[i].y > height/2 ) {
              Verts[i].y=-height/2;
            } else if (Verts[i].y < -height/2) {
              Verts[i].y=height/2;
            }
    
            if (Verts[i].z < -800/2 ) {  
              Verts[i].z=800/2;
            } else if ( Verts[i].z > 800/2) {
              Verts[i].z=-800/2;
            }
            tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
          }
          k+=0.000001;
        }
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
      pushMatrix();
      rotateY(-k); //-----------------HERE
      translate(Mouse.x, Mouse.y, Mouse.z);
      rotateY(k); //-------------AND HERE
      noFill();
      stroke(255);
      box(r);
      popMatrix();
    
    
      noStroke();
    
      tmpmodel.draw();
    
      popMatrix();
    
    
    
      pushMatrix();
      translate(width/2, height/2, 0);
      rotateY(k);
      noFill();
      stroke(255);
      box(width, height, 600);
      popMatrix();
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame();
      println(z);
    }
    
    void keyPressed() {
      if (keyCode == UP) {
        z++;
      }
      if (keyCode == DOWN) {
        z--;
      }
    }
    
  • for loop add atribute,to every 3

    hey,i dont understand it complete,maybe you can help me I have this code,I take the vertices,in a PVector array.I assume that the PVectors are in such a row that correspond to faces.The faces are triangles,that is 3 Pvectors each face.I want to put the same movement to every 3 Pvectors,so[0,1,2] one movement,[3,4,5] an other movement.

     import peasy.*;
    import saito.objloader.*;
    
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    PeasyCam cam;
    
    float easing = 0.005;
    float r;
    float k =0.00001;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector Mouse;
    
    void setup()
    {
      size(800, 800, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(150);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(150);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(150);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 994);
    }
    
    
    
    void draw()
    {
      background(129);
      lights();
    
      int VertCount = model.getVertexCount ();
       Verts = new PVector[VertCount];
       locas = new PVector[VertCount];
      float r =500;
      PVector Mouse = new PVector(mouseX-width/2, mouseY-height/2, 0);
    
    
      cam.setMouseControlled(false);
    
    
    
    
    
    
    
    
    
    
      //println(frameCount);
      pushMatrix();
      translate(width/2, height/2, 0);
    
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
        if (frameCount> 100) {
    
    
    
          float randX = randomGaussian();
          float randY = randomGaussian();
          float randZ = randomGaussian();
    
          PVector Ran = new PVector(randX, randY, randZ);
    
          //float norX = abs(cos(k)) * randX;
          //float norY = abs(cos(k)) * randY;
          //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
    
          if (Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - r/2 && Verts[i].z <  Mouse.z  + r/2) {
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
          } else {   
    
    
    
            Verts[i].x+=Ran.x;
            Verts[i].y+=Ran.y;
            Verts[i].z+=Ran.z;
    
            if (Verts[i].x > width/2 || Verts[i].x < -width/2) {
              Verts[i].x+=-Ran.x;
            }
            if (Verts[i].y > height/2 || Verts[i].y < -height/2) {
              Verts[i].y+=-Ran.y;
            }
            if (Verts[i].z < -800/2 || Verts[i].z > 800/2) {  
              Verts[i].z+=-Ran.z;
            }
            tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
          }
          k+=0.0001;
        }
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
      pushMatrix();
      translate(Mouse.x, Mouse.y, Mouse.z);
      noFill();
      stroke(255);
      box(r);
      popMatrix();
    
    
      noStroke();
    
      tmpmodel.draw();
    
      popMatrix();
    
    
    
      pushMatrix();
      translate(width/2, height/2, 0);
      noFill();
      stroke(255);
      box(width, height, 600);
      popMatrix();
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame(); 
    }
    
    void keyPressed() {
      if (keyCode == UP) {
        setup();
      }
      if (keyCode == LEFT) {
        r+=10;
      }
      if (keyCode == RIGHT) {
        r-=10;
      }
    }
    
  • reset position if inside shape

    I found the solution,i created an extra model(The same),and take the coordinates from it.Here is the code

    import peasy.*;
    import saito.objloader.*;
    
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    PeasyCam cam;
    
    float easing = 0.005;
    float r;
    float k =0.00001;
    int VertCount;
    PVector[] Verts;
    PVector Mouse;
    
    void setup()
    {
      size(800, 800, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(100);
      model.translateToCenter();
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(100);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(100);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 994);
    }
    
    
    
    void draw()
    {
      background(129);
      lights();
    
      int VertCount = model.getVertexCount ();
      PVector[] Verts = new PVector[VertCount];
      PVector[] locas = new PVector[VertCount];
      float r =200;
      PVector Mouse = new PVector(mouseX-width/2, mouseY-height/2, 0);
    
    
      cam.setMouseControlled(true);
    
    
    
    
    
    
    
    
    
    
      //println(frameCount);
      pushMatrix();
      translate(width/2, height/2, 0);
    
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        locas[i]= model.getVertex(i);
        Verts[i]= Smodel.getVertex(i);
    
    
        //PVector tmpv = new PVector();
    
    
        if (frameCount> 100) {
    
    
    
          float randX = random(-5, 5);
          float randY = random(-5, 5);
          float randZ = random(-5, 5);
    
          PVector Ran = new PVector(randX, randY, randZ);
    
          //float norX = abs(cos(k)) * randX;
          //float norY = abs(cos(k)) * randY;
          //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
    
          if (Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - r/2 && Verts[i].z <  Mouse.z  + r/2) {
            tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
          } else {   
    
    
    
            Verts[i].x+=Ran.x;
            Verts[i].y+=Ran.y;
            Verts[i].z+=Ran.z;
    
            if (Verts[i].x > width/2 || Verts[i].x < -width/2) {
              Verts[i].x+=-Ran.x;
            }
            if (Verts[i].y > height/2 || Verts[i].y < -height/2) {
              Verts[i].y+=-Ran.y;
            }
            if (Verts[i].z < -800/2 || Verts[i].z > 800/2) {  
              Verts[i].z+=-Ran.z;
            }
            tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
          }
          k+=0.0001;
        }
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
      pushMatrix();
      translate(Mouse.x, Mouse.y, Mouse.z);
      noFill();
      stroke(255);
      box(r);
      popMatrix();
    
    
      noStroke();
    
      tmpmodel.draw();
    
      popMatrix();
    
    
    
      pushMatrix();
      translate(width/2, height/2, 0);
      noFill();
      stroke(255);
      box(width, height, 600);
      popMatrix();
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
    }
    
    void keyPressed() {
      if (keyCode == UP) {
        setup();
      }
    }
    
  • reset position if inside shape

    hello,again,i have made this code,with a 3d model,the model starts dismorph after 100 frames.I have a box shape that is moved with mouse,i want when ever the vertices be inside the box,to reset their position to the original position,and reconstruct the model,while the others dismorph. Always resetting the position when they are in the box,and move when they are not.Can anyone help me.Until now what it happens,is that when the vertices are inside the box they stop moving.

    Thanks in Advance

    import peasy.*;
    import saito.objloader.*;
    
    
    OBJModel model ;
    OBJModel tmpmodel ;
    
    PeasyCam cam;
    
    float easing = 0.005;
    float r;
    float k =0.00001;
    int VertCount;
    PVector[] Verts;
    PVector Mouse;
    
    void setup()
    {
      size(800, 800, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(100);
      model.translateToCenter();
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(100);
      tmpmodel.translateToCenter();
    
    
    
      cam = new PeasyCam(this, width/2, height/2, 0, 994);
    }
    
    
    
    void draw()
    {
      background(129);
      lights();
    
      int VertCount = model.getVertexCount ();
      PVector[] Verts = new PVector[VertCount];
      PVector[] locas = new PVector[VertCount];
      float r =80;
      PVector Mouse = new PVector(mouseX-width/2, mouseY-height/2, 0);
    
    
      cam.setMouseControlled(true);
    
    
    
    
    
    
    
    
    
    
      //println(frameCount);
      pushMatrix();
      translate(width/2, height/2, 0);
    
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
    
        Verts[i]= model.getVertex(i);
        arrayCopy(Verts, locas);
        //PVector tmpv = new PVector();
        if (frameCount> 100) {
    
    
    
          float randX = random(-5, 5);
          float randY = random(-5, 5);
          float randZ = random(-5, 5);
    
          PVector Ran = new PVector(randX, randY, randZ);
    
          //float norX = abs(cos(k)) * randX;
          //float norY = abs(cos(k)) * randY;
          //float norZ = abs(cos(k)) * randZ;
    
    
    
    
    
    
    
    
    
          if (Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2) {
            if (Verts[i].x > Mouse.y  - r/2 && Verts[i].x < Mouse.y  + r/2) {
              if (Verts[i].x > Mouse.z  - r/2 && Verts[i].x <  Mouse.z  + r/2) {
    
    
                arrayCopy(locas, Verts);
              }
            }
          } else {
    
    
            Verts[i].x+=Ran.x;
            Verts[i].y+=Ran.y;
            Verts[i].z+=Ran.z;
    
            if (Verts[i].x > width/2 || Verts[i].x < -width/2) {
              Verts[i].x+=-Ran.x;
            }
            if (Verts[i].y > height/2 || Verts[i].y < -height/2) {
              Verts[i].y+=-Ran.y;
            }
            if (Verts[i].z < -800/2 || Verts[i].z > 800/2) {  
              Verts[i].z+=-Ran.z;
            }
          }
          tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
        }
        k+=0.0001;
      }
    
      pushMatrix();
      translate(Mouse.x, Mouse.y, Mouse.z);
      noFill();
      stroke(255);
      box(r);
      popMatrix();
    
    
      noStroke();
    
      tmpmodel.draw();
    
      popMatrix();
    
    
    
      pushMatrix();
      translate(width/2, height/2, 0);
      noFill();
      stroke(255);
      box(width, height, 600);
      popMatrix();
    }
    
  • Framecount*i

    Can someone explain this framecount*i,and how it is used in the sketch.Because when i put out i,from the equation the vertices dont move independently.Thanks in advance

    import peasy.*;
    import saito.objloader.*; 
    
    OBJModel model ;
    OBJModel tmpmodel ;
    
    PeasyCam cam;
    float easing = 0.005;
    
    int VertCount;
    PVector[] Verts;
    
    void setup()
    {
      size(800, 600, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(100);
      model.translateToCenter();
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(100);
      tmpmodel.translateToCenter();
    
      cam = new PeasyCam(this, width/2, height/2, 0, 500);
    }
    
    void draw()
    {
      background(129);
      lights();
    
      int VertCount = model.getVertexCount ();
      PVector[] Verts = new PVector[VertCount];
    
      //cam.rotateY(0.05);
      cam.setMouseControlled(true);
    
      //println(frameCount);
      pushMatrix();
      translate(width/2, height/2, 0);
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
        Verts[i]= model.getVertex(i);
    
        //PVector tmpv = new PVector();
        if (frameCount> 100) {
    
          float randX = random(-0.05, 0.05);
          float randY = random(0, 0.05);
          float randZ = random(0, 0.05);
    
          ////HERE
    
          float norX = abs(cos((frameCount+i))) * randX;
          float norY = abs(cos((frameCount+i)) * randY);
          float norZ = abs(cos((frameCount+i)) * randZ);
    
          Verts[i].x+=Verts[i].x*norX;
          Verts[i].y+=Verts[i].y*norY;
          Verts[i].z+=Verts[i].z*norZ;
    
          if (Verts[i].x > width/2|| Verts[i].x < -width/2) {
            Verts[i].x+=Verts[i].x*-0.05;
          }
          if (Verts[i].y > height/2|| Verts[i].y < -height/2) {
            Verts[i].y+=Verts[i].y*-0.05;
          }
    
          if (Verts[i].z < -600/2 || Verts[i].z > 600/2) {  //note that Zaxis goes 'into' the screen
            Verts[i].z+=Verts[i].z*-0.05;
          }
        }
    
        PVector locas = new PVector(Verts[i].x, Verts[i].y, Verts[i].z);
        tmpmodel.setVertex(i, locas.x, locas.y, locas.z);
      }
    
      noStroke();
      tmpmodel.draw();
      popMatrix();
    
      translate(width/2, height/2, 0);
      noFill();
      stroke(255);
      box(width, height, 600);
    }
    
  • Saito OBJLoader Array

    hello,again i proceed the sketch to this.Is any way to irritate through the array of PVectors and make them have autonomous movement,because now it moves only the whole object.I want to make the vertices act like particles.

    import peasy.*;
    import saito.objloader.*;
    
    
    OBJModel model ;
    OBJModel tmpmodel ;
    
    PeasyCam cam;
    
    float easing = 0.005;
    
    
    int VertCount;
    PVector[] Verts;
    
    void setup()
    {
      size(800, 600, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(100);
      model.translateToCenter();
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(100);
      tmpmodel.translateToCenter();
    
    
    
      cam = new PeasyCam(this, width/2, height/2, 0, 500);
    }
    
    
    
    void draw()
    {
      background(129);
      lights();
    
      int VertCount = model.getVertexCount ();
      PVector[] Verts = new PVector[VertCount];
    
    
      //cam.rotateY(0.05);
      cam.setMouseControlled(true);
    
    
    
    
    
    
    
    
    
    
      //println(frameCount);
      pushMatrix();
      translate(width/2, height/2, 0);
    
    
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
    
        Verts[i]= model.getVertex(i);
    
        //PVector tmpv = new PVector();
        if (frameCount> 100) {
    
          float rand = random(0, 0.05);
    
          float nor = abs(noise(sin(radians((frameCount+i)))) * rand);
    
          Verts[i].x+=Verts[i].x*nor;
          Verts[i].y+=Verts[i].y*nor;
          Verts[i].z+=Verts[i].z*nor;
    
    
          if (Verts[i].x > width/2|| Verts[i].x < -width/2) {
            Verts[i].x+=Verts[i].x*-nor;
          }
          if (Verts[i].y > height/2|| Verts[i].y < -height/2) {
            Verts[i].y+=Verts[i].y*-nor;
          }
    
          if (Verts[i].z < -600/2 || Verts[i].z > 600/2) {  //note that Zaxis goes 'into' the screen
            Verts[i].z+=Verts[i].z*-nor;
          }
        }
    
        PVector locas = new PVector(Verts[i].x, Verts[i].y, Verts[i].z);
        tmpmodel.setVertex(i, locas.x, locas.y, locas.z);
      }
    
    
    
    
    
    
      noStroke();
      tmpmodel.draw();
      popMatrix();
    
      translate(width/2, height/2, 0);
      noFill();
      stroke(255);
      box(width, height, 600);
    }
    
  • Saito OBJLoader Array

    hello again,i did this.The array works,but when i printArray(Verts) it returns null,when i println(model.getVertex(i)),i get the Pvectors.

    import peasy.*;
    import saito.objloader.*;
    
    
    OBJModel model ;
    OBJModel tmpmodel ;
    
    PeasyCam cam;
    
    
    PVector velocity;
    float topspeed = 5;
    
    
    void setup()
    {
      size(800, 600, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(100);
      model.translateToCenter();
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(100);
      tmpmodel.translateToCenter();
    
    
      cam = new PeasyCam(this, width/2, height/2, 0, 500);
    }
    
    
    
    void draw()
    {
      background(129);
      lights();
    
      cam.rotateY(0.05);
      cam.setMouseControlled(false);
      translate(width/2, height/2, 0);
      noFill();
      stroke(255);
      box(width, height, 600);
    
    
    
    
    
    
    
    
      //println(frameCount);
      pushMatrix();
    
      int VertCount = model.getVertexCount ();
      PVector[] Verts = new PVector[VertCount];
    
      for (int i = 0; i < VertCount; i++) {
        //PVector orgv = model.getVertex(i);
    
    
        Verts[i]= model.getVertex(i);
    
        //PVector tmpv = new PVector();
        println(model.getVertex(i));
        printArray(Verts);
        for (int j = 0; j< Verts.length; j++) {
    
          if (frameCount > 100) {
    
    
    
    
    
            /*PVector locs = Arr.get(j);
    
             for (PVector locas : Arr) {
    
             locas = new PVector(0, 0, 0);
    
             velocity = new PVector(random(0, 10), random(0, 10), 0);
             PVector mouse = new PVector(screenX(mouseX, mouseY), screenY(mouseX, mouseY), 0);
    
             PVector accel = PVector.sub(mouse, locas);
    
             accel.setMag(0.8);
    
             velocity.add(accel);
    
             velocity.limit(topspeed);
    
             locas.add(velocity);
             mpv.x = mouseY;
             tmpv.y = mouseY;
             tmpv.x += orgv.x;
             tmpv.y += orgv.y;
             tmpv.z = orgv.z;
    
    
             */
            // tmpmodel.setVertex(i, locas);
          }
        }
      }
      //}
    
    
    
    
      popMatrix();
      noStroke();
      tmpmodel.draw();
    }
    
  • Saito OBJLoader Array

    hello again,i made the sketch with arraylist,but it keeps storing the varible i as one element of the arraylist that pass all the vertices.Any Help please.

    import peasy.*;
    import saito.objloader.*;
    
    
    OBJModel model ;
    OBJModel tmpmodel ;
    
    PeasyCam cam;
    
    
    PVector velocity;
    float topspeed = 5;
    
    
    void setup()
    {
      size(800, 600, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(100);
      model.translateToCenter();
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(100);
      tmpmodel.translateToCenter();
    
    
      cam = new PeasyCam(this, width/2, height/2, 0, 500);
    }
    
    
    
    void draw()
    {
      background(129);
      lights();
    
      cam.rotateY(0.05);
      cam.setMouseControlled(false);
      translate(width/2, height/2, 0);
      noFill();
      stroke(255);
      box(width, height, 600);
    
    
    
    
    
    
    
    
      println(frameCount);
      pushMatrix();
    
    
    
      for (int i = 0; i < model.getVertexCount (); i++) {
        //PVector orgv = model.getVertex(i);
    
    
        ArrayList<PVector> Arr = new ArrayList<PVector>();
        Arr.add(model.getVertex(i));
        //println(Arr);
        PVector tmpv = new PVector();
    
        for (int j = 0; j< Arr.size (); j++) {
    
          if (frameCount > 800) {
    
    
    
    
    
            PVector locs = Arr.get(j);
    
            for (PVector locas : Arr) {
    
              locas = new PVector(0, 0, 0);
    
              velocity = new PVector(random(0, 10), random(0, 10), 0);
              PVector mouse = new PVector(screenX(mouseX, mouseY), screenY(mouseX, mouseY), 0);
    
              PVector accel = PVector.sub(mouse, locas);
    
              accel.setMag(0.8);
    
              velocity.add(accel);
    
              velocity.limit(topspeed);
    
              locas.add(velocity);
              /*mpv.x = mouseY;
               tmpv.y = mouseY;
               tmpv.x += orgv.x;
               tmpv.y += orgv.y;
               tmpv.z = orgv.z;
    
               */
    
              tmpmodel.setVertex(i, locas);
            }
          }
        }
      }
    
    
    
    
      popMatrix();
      noStroke();
      tmpmodel.draw();
    }
    
  • Saito OBJLoader Array

    Hello,i have this code

    import saito.objloader.*;
    
    OBJModel model ;
    OBJModel tmpmodel ;
    
    
    PVector[] PVArray;
    float rotX, rotY;
    float k = 0.0;
    
    void setup()
    {
      size(800, 600, P3D);
      frameRate(30);
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
    
      model.scale(100);
      model.translateToCenter();
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
    
      tmpmodel.enableDebug();
    
      tmpmodel.scale(100);
    
      tmpmodel.translateToCenter();
    
    
      frameRate(100);
      stroke(255);
      noStroke();
    }
    
    
    
    void draw()
    {
      background(129);
      lights();
      translate(width/2, height/2, 0);
      //rotX+=0.1;
      rotY+=0.01;
      //rotateX(rotX);
      //rotateY(rotY);
    
    
      pushMatrix();
    
    
      for (int i = 0; i < model.getVertexCount (); i++) {
        PVector orgv = model.getVertex(i);
        PVector tmpv = new PVector();
        PVArray[i] = new PVector();
        //tmpv.x = mouseY;
        //tmpv.y = mouseY;
        println(orgv);
        tmpv.x = orgv.x *(i*mouseX);
        tmpv.y = orgv.y+ (i*0.01) ;
        tmpv.z = orgv.z;
        tmpmodel.setVertex(i, tmpv);
      }
      k+=0.01;
    
    
    
      popMatrix();
    
      tmpmodel.draw();
    }
    

    I have problem with the model.getVertex(i) function,I want to make an array of the PVectors that it gets,so i can manipulate them individualy,with custom functions.and no as a whole object.Do you have any idea?Or u think its better to use PShapeObj?

    Thanks in advance