selectInput for a 3D... beginner
in
Programming Questions
•
9 months ago
Hellooooooo everyone
I'm trying to make a selectInput() for a PShape in my code (to load a 3D).. and that's not working :(
I've got a first 3D, (MTECH.obj) to make a demo of the software, and i need it when the software open, and i want the selectInput() to change it.
Can you help me just a little bit :D
It's the only thing i need to finish it ^^
Thank to everyone!! (and sorry for english, i'm french)
I'm trying to make a selectInput() for a PShape in my code (to load a 3D).. and that's not working :(
I've got a first 3D, (MTECH.obj) to make a demo of the software, and i need it when the software open, and i want the selectInput() to change it.
Can you help me just a little bit :D
It's the only thing i need to finish it ^^
Thank to everyone!! (and sorry for english, i'm french)
- import java.lang.reflect.*;
- import java.awt.Frame;
- import java.awt.BorderLayout;
- import java.awt.event.*;
- import controlP5.*;
- float rotX;
- float rotY;
- public int DeplacerX = 0;
- public int DeplacerY = 0;
- public int RotationX = 0;
- public int RotationY = 0;
- public int RotationZ = 0;
- public int Importer = 0;
- int CIBLE;
- public int Presentation_Mode = 0 ;
- public int Mouse = 1;
- public float Echelle = 1.00;
- PVector A, B, C, D, CENTRE;
- PShape s;
- private ControlP5 cp5;
- ControlFrame cf;
- Renderer renderers[];
- void setup() {
- size(displayHeight, displayHeight, P3D);
- //size(800,600,P3D);
- background(0);
- // Description des points de l'écran
- A = new PVector(0, 0, 0);
- B = new PVector(width, 0, 0);
- C = new PVector(width, height, 0);
- D = new PVector(0, height, 0);
- CENTRE = new PVector(width/2, height/2, 0);
- ///DECLARATION MODEL ICI
- s = loadShape("MTECH.obj");
- cp5 = new ControlP5(this);
- cf = addControlFrame("AGRANDIR= plus d'options", 280, 220);
- renderers = new Renderer[4];
- renderers[0] = new Renderer(this, width, height/2, D, C, CENTRE);
- renderers[1] = new Renderer(this, width, height/2, A, B, CENTRE);
- renderers[2] = new Renderer(this, width/2, height, A, D, CENTRE);
- renderers[3] = new Renderer(this, width/2, height, B, C, CENTRE);
- // Set views
- // VIEW ROTATION WARNING
- renderers[0].setRotation( -180, -180, 0);
- renderers[1].setRotation( 0, 180, 0); /// PRESQUE OK
- renderers[2].setRotation( -90, -90, 90);
- renderers[3].setRotation( 90, 90, -90);
- addMouseWheelListener(new MouseWheelListener() {
- public void mouseWheelMoved(MouseWheelEvent mwe) {
- mouseWheel(mwe.getWheelRotation());
- }
- }
- );
- }
- void mouseWheel(int delta) {
- Mouse = delta;
- println("scroll "+ delta);
- }
- void draw() {
- for (int i=0;i<renderers.length;i++) {
- renderers[i].draw();
- }
- drawRenderer(0);
- drawRenderer(1);
- drawRenderer(2);
- drawRenderer(3);
- }
- void drawRenderer(int which) {
- Renderer r = renderers[which];
- noStroke();
- fill(255, 255);
- beginShape(TRIANGLES);
- textureMode(NORMAL);
- texture(r.pg);
- if (which == 0) {
- vertex(r.A.x, r.A.y, 0, 1);
- vertex(r.B.x, r.B.y, 1, 1);
- vertex(r.C.x, r.C.y, 0.5, 0);
- }
- else if (which == 1) {
- vertex(r.A.x, r.A.y, 0, 0);
- vertex(r.B.x, r.B.y, 1, 0);
- vertex(r.C.x, r.C.y, 0.5, 1);
- }
- else if (which == 2) {
- vertex(r.A.x, r.A.y, 0, 0);
- vertex(r.B.x, r.B.y, 0, 1);
- vertex(r.C.x, r.C.y, 1, 0.5);
- }
- else if (which == 3) {
- vertex(r.A.x, r.A.y, 1, 0);
- vertex(r.B.x, r.B.y, 1, 1);
- vertex(r.C.x, r.C.y, 0, 0.5);
- }
- endShape();
- noFill();
- stroke(c2);
- triangle(r.A.x, r.A.y, r.B.x, r.B.y, r.C.x, r.C.y);
- }
- ///// IMPORTATEUR LE PROBLEME ICI
- public void Importer(int theValue) {
- selectInput("Select a file to process:", "fileselected");
- }
- void fileSelected(File selection) {
- if (selection == null) {
- println("Window was closed or the user hit cancel.");
- }
- else {
- println("User selected " + selection.getAbsolutePath());
- s = loadShape(selection.getAbsolutePath());
- s = s;
- }
- }
- //*/
- void drawRendererObject(Renderer r)
- //METTRE 3D A LA PLACE?
- {
- float time = (millis()*0.1)* Presentation_Mode;
- float fov = PI/4.0;
- float cameraZ = (height/2.0) / tan(fov/2.0);
- r.graphics().rotateX( map((RotationX+rotX)*5, 0, width, 0, PI) );
- r.graphics().rotateY( map((RotationY+rotY)*5 + time, 0, width, 0, PI) );
- r.graphics().rotateZ( map(RotationZ*5, 0, width, 0, PI) );
- r.graphics().translate(DeplacerX, 0, DeplacerY);
- r.graphics().scale(Echelle);
- r.graphics().lights();
- r.graphics().shape(s, 0, 0);
- ///// LOAD SHAPE LA
- //dessin de repérage :
- /*
- r.graphics().fill(255);
- r.graphics().strokeWeight(0);
- r.graphics().box(60);
- r.graphics().translate(0, 60, 0);
- r.graphics().fill(#74E9FF);
- r.graphics().sphere(30);
- r.graphics().sphereDetail(20);
- // */
- }
- void mouseDragged() {
- rotY += (mouseX - pmouseX) ;
- rotX -= (mouseY - pmouseY) ;
- }
1