about Data Base .

edited April 2015 in How To...

i want to know the methode to iterate over object 3d located in my data base. please freinds i nead your help and thank you :)

for exemple ===> for (int i = 0; i < "number d'object in my data base "; i = i+1) { ... }

Answers

  • ... located in my data base.

    If it's in a database, you gotta find a library to deal w/ it! (:|

  • You rejected GoToLoop's answer, without adding a comment. Not a way to progress. What is your database, exactly?

  • edited April 2015

    I got the following 3d object in my data base ==> table.obj, canapet.obj, fauteuil.obj. and what i need exactly is all the object pun up when i click one button (one click on the button the first 3d object pun up and when i click another time the first object disappear and the next object pun up ) and like that until i finished all the object on the data base **

    **this my code where there is three button and each button pun up one object but i think it is not a good idea because what i realy wanna do is one button pun up all the object **

    import saito.objloader.*;
    import codeanticode.gsvideo.*;
    import controlP5.*;
    
    ControlP5 controlP5;
    OBJModel model;
    
    GSCapture cam;
    Button btn1, btn2,btn3;
    
    void setup(){
      
      
      btn1 = new Button(580, 80, 40, 40);
      btn2 = new Button(580, 200, 40, 40);
       btn3 = new Button(580, 300, 40, 40);
      size(640, 480, P3D);
      
       model = new OBJModel(this,"");
       model.scale(90);
       model.translateToCenter();
      noStroke();
      cam = new GSCapture(this, 640, 480); // initialize the webcam capture at a specific resolution (correct and/or possible settings depend on YOUR webcam)
      cam.start(); // start capturing
    }
    
    
    void mouseClicked() {
     
     
      if ( btn1.hasClicked())
       // s = loadShape("mankey.obj");
       // s.scale(90);
       // noStroke();
      model = new OBJModel(this,"mankey.obj");
      // model.scale(90);
      model.translateToCenter();
        println("Button 1 clicked");
      noStroke();  
     if ( btn2.hasClicked())
      model = new OBJModel(this,"mankey1.obj");
      model.scale(90);
      model.translateToCenter();
        println("Button 2 clicked");
       noStroke();  
        if ( btn3.hasClicked())
        model = new OBJModel(this,"");
        //model.scale(90);
        model.translateToCenter();
        println("Button 3 clicked");
        noStroke(); 
    }
    
    class Button {
    
      final int COLOR_STATE0 = color(255, 255, 255);
      final int COLOR_STATE1 = color(255, 255, 255);
    
      int buttonX, buttonY, buttonWidth, buttonHeight;
      boolean overButton, buttonOn;
    
      Button(int tempbuttonX, int tempbuttonY, int tempbuttonWidth, int tempbuttonHeight) {
        buttonX = tempbuttonX;
        buttonY = tempbuttonY;
        buttonWidth = tempbuttonWidth;
        buttonHeight = tempbuttonHeight;
      }
    
    
    void buttonDisplay() {
        if (buttonOn)
          fill(COLOR_STATE0);
        else
          fill(COLOR_STATE1);
        if (isOver(mouseX, mouseY)) {
          stroke(0);
          strokeWeight(2);
        } else {
          noStroke();
        }
        rect(buttonX, buttonY, buttonWidth, buttonHeight);
      }
    
      boolean isOver(int x, int y) {
        return x > buttonX && x < buttonX+buttonWidth && y > buttonY && y < buttonY+buttonHeight;
      }
    
    
      boolean hasClicked() {
        boolean changeState = isOver(mouseX, mouseY);
        if (changeState) {
          buttonOn = !buttonOn;
        }
        return changeState;
      }}
    void draw(){
       btn1.buttonDisplay();
        btn2.buttonDisplay();
        btn3.buttonDisplay();
      
      if (cam.available()) {
    cam.read(); // read the cam image
    
    
    background(cam); // a background call is needed for correct display of the marker results
    //image(cam, 0, 0, width, height); // display the image at the width and height of the sketch window
    
    
     fill(180, 0, 0, 127);
      translate(mouseX, mouseY);
      lights();
      rotateX(mouseX*0.02);
      lights();
      rotateY(mouseY*0.02);  
      lights();
      model.draw();
       
      
      
    }}
  • Answer ✓

    Apparently, there is no database involved in your code. Perhaps you meant files in the data folder? You want to list the files there?

  • @Philho==> thank you very much brother ! that's exactly what i talking about . I am very interested with your help

  • Let's be clear here: You are not dealing with a database at all. A database is a collecting of tables, each of which has fields and records, that can be read and updated, usually over a network, by multiple users, atomically.

    What you have is an array of objects, which is much simpler. You load each of your objects from a specific file, and are displaying them one at a time. Now you want one button that, when pressed, displays the next object in your array. Great. Ok. No one is going to write it for you, but here is an example button that displays several colors, one at a time:

    color[] colors = { 
      color(255, 0, 0), color(255, 255, 0), color(0, 255, 0), color(0, 0, 255), color(255, 0, 255)
    };
    int whichColor = 0;
    
    void setup() {
      size(220,220);
      stroke(0);
      strokeWeight(2);
      ellipseMode(CENTER);
    }
    
    void draw(){
      background(colors[whichColor]);
      fill(dist(mouseX,mouseY,110,110)<=10?255:128);
      ellipse(110,110,20,20);
    }
    
    void mousePressed(){
      if(dist(mouseX,mouseY,110,110)<=10){
        whichColor++;
        whichColor%=colors.length;
      }
    }
    
  • @TfGuy44 you are great men thank you very much and this is so helpful ,but you gonna answer finally my question if you give the method haw i make an array of objects like the array you give it to me about the color

    color[] colors = { 
      color(255, 0, 0), color(255, 255, 0), color(0, 255, 0), color(0, 0, 255), color(255, 0, 255)
    };

    for exemple i have this object i wanna put them in an array==> table.obj , tv.obj, chair.obj .. and thank you very much

  • Answer ✓

    Well, first you would create an array to hold the objects. This would be global.

    OBJModel[] models = new OBJModel[3];
    

    Then you would populate it, probably in setup().

    models[0] = new OBJModel(this,"table.obj")
    models[1] = new OBJModel(this,"tv.obj")
    models[2] = new OBJModel(this,"chair.obj")
    

    And so on. And if you don't know how many objects and their names ahead of time, well, you'll need to get a list of .obj files from the directory... And PhiLho is better at that than me.

  • @TfGuy44 thank you brother for your help you are great ! but i realy nead a list of .obj :/ i hope that Philho find us a solution

  • Well, you can Google "list files in folder Processing" and see what you get yourself...

  • edited April 2015

    Check it out my sample below whether it serves ya right: ;;)

    // forum.processing.org/two/discussion/10183/about-data-base
    
    import java.io.FilenameFilter;
    static final FilenameFilter MODELS = new FilenameFilter() {
      @ Override boolean accept(File f, String s) {
        return s.endsWith(".obj");
      }
    };
    
    import saito.objloader.OBJModel;
    OBJModel[] models;
    
    void setup() {
      File dir = dataFile("");
      String[] filenames = dir.list(MODELS);
      int len = filenames.length;
    
      println("Found", len, "object model(s) in folder:\n" + dir + '\n');
      printArray(filenames);
    
      models = new OBJModel[len];
      for (int i = 0; i != len; models[i] = new OBJModel(this, filenames[i++])); 
    
      exit();
    }
    
  • @GoToLoop ==> thank you brother very much for your help , but on my code here and after i fill in the list() dont forget there is a button when i click on one of the .obj pun up (one click on the button the first 3d object pun up and when i click another time the first object disappear and the next object pun up ) and like that until i finished all the object in the liste() ..

    ==> here in the mouseClicked() method (line 28) when i make the condition when i say if ( btn1.hasClicked()) (line 31) on this time i call ** model = new OBJModel(this,"mankey.obj");** (line 35) to pun up the .obj .. but when i change the code with the list() i dont know how i make the code change on this point .

  • edited April 2015

    Sorry, but your description of your current issues isn't exactly helpful. We've shown you how to have a button that displays one thing from an array, and we've shown you how to create an array of objects dynamically based on what's in a folder. It's up to you to understand these examples and merge them together to create the sketch you want.

    If you need more help, post the entire code of your current sketch. Also, tell us what is wrong with it.

  • edited April 2015

    **please friend some help to fixed the code there is an erreur in the line 40 **

    import java.io.FilenameFilter;
    static final FilenameFilter MODELS = new FilenameFilter() {
      boolean accept(File f, String s) {
        return s.endsWith(".obj");
      }
    };
     
    import saito.objloader.OBJModel;
    OBJModel[] models;
    import codeanticode.gsvideo.*;
    GSCapture cam;
    import controlP5.*;
    Button btn1;
    OBJModel model;
    void setup() {
      btn1 = new Button(580, 80, 40, 40);
      size(640, 480, P3D);
      cam = new GSCapture(this, 640, 480); // initialize the webcam capture at a specific resolution (correct and/or possible settings depend on YOUR webcam)
      cam.start(); // start capturing
      File dir = dataFile("");
      String[] filenames = dir.list(MODELS);
      int len = filenames.length;
     
      println("Found", len, "object model(s) in folder:\n" + dir + '\n');
      printArray(filenames);
     
      models = new OBJModel[len];
      for (int i = 0; i != len; models[i] = new OBJModel(this, filenames[i++])); 
     
      //exit();
    }
    
    void mouseClicked() 
    {
      int i =0;
      File dir = dataFile("");
     String[] filenames = dir.list(MODELS);
      if ( btn1.hasClicked())
      models[i] = new OBJModel(this, filenames[i++]);
        model = new OBJModel(this,models[i]);
    }
    
    class Button {
    
      final int COLOR_STATE0 = color(255, 255, 255);
      final int COLOR_STATE1 = color(255, 255, 255);
    
      int buttonX, buttonY, buttonWidth, buttonHeight;
      boolean overButton, buttonOn;
    
      Button(int tempbuttonX, int tempbuttonY, int tempbuttonWidth, int tempbuttonHeight) {
        buttonX = tempbuttonX;
        buttonY = tempbuttonY;
        buttonWidth = tempbuttonWidth;
        buttonHeight = tempbuttonHeight;
      }
    
    
    void buttonDisplay() {
        if (buttonOn)
          fill(COLOR_STATE0);
        else
          fill(COLOR_STATE1);
        if (isOver(mouseX, mouseY)) {
          stroke(0);
          strokeWeight(2);
        } else {
          noStroke();
        }
        rect(buttonX, buttonY, buttonWidth, buttonHeight);
      }
    
      boolean isOver(int x, int y) {
        return x > buttonX && x < buttonX+buttonWidth && y > buttonY && y < buttonY+buttonHeight;
      }
    
    
      boolean hasClicked() {
        boolean changeState = isOver(mouseX, mouseY);
        if (changeState) {
          buttonOn = !buttonOn;
        }
        return changeState;
      }}
      
      void draw(){
       btn1.buttonDisplay();
      if (cam.available()) {
    cam.read(); // read the cam image
    
    
    background(cam); // a background call is needed for correct display of the marker results
     fill(180, 0, 0, 127);
      translate(mouseX, mouseY);
      lights();
      rotateX(mouseX*0.02);
      lights();
      rotateY(mouseY*0.02);  
      lights();
      model.draw();
       
      
      
    }}
Sign In or Register to comment.