Saito OBJLoader Array

edited August 2016 in Library Questions

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

Answers

  • 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();
    }
    
  • yeah i know,i did it because sometimes here noone answers

  • i will check it

  • i did this and worked perfect until now,no null pointer exception

    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();
    
        /* for (int j = 0; j< Arr.size (); j+=100) {
    
         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();
    }
    
  • 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();
    }
    
  • if i declare the array as global variable and then populate it in the for loop like this Verts[i]= model.getVertex(i); i get null pointer exception

  • vertCount is 12738

  • 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);
    }
    
Sign In or Register to comment.