2014-12-19 1 views
1

내가 selectinput의 사용과 관련하여이 스레드처리 2 selectInput() P3D 충돌

Processing 2.0 - Open file dialog 을 공부했습니다(). 일부 3D 플롯을 만들기 위해 점 데이터를 가져 오려고합니다. 데이터를 가져오고 플롯을 만들 수 있지만 selectinput()을 사용하여 파일을 선택하려고하면 문제가 발생합니다. 내가 겪고있는 어려움은 selectinput()이 P3D 창과 호환되지 않는 것 같습니다. 예를 들어,이 코드는 OS의 X10.10

사용

void setup() { 

    size(400, 400,P3D); //3Dgraphics specified 
    background(0); 
    stroke(255); 
    frameRate(20); 
} 

void draw() { 
    noFill(); 
    ellipse(mouseX, mouseY, 90, 90); 

작동 이것은

String [] myInputFileContents ; 
String myFilePath; 

void setup() { 
    selectInput("Select a file : ", "fileSelected"); 
    while (myInputFileContents == null) {//wait 
     // println("wait"); //If there is nothing inside the curly brackets 
     //delay(3000);   //this doesn't work 
     size(400, 400);/// If P3D is added it won't work 
     background(0); 
     //smooth(); 
     stroke(255); 
     frameRate(25); 
    } 
} 

void draw() { 
    box(mouseX, mouseY, 150); 
    println("Selected at this point " + myFilePath); 
} 

void mousePressed() { 
    selectInput("Select a file : ", "fileSelected"); 
} 

void fileSelected(File selection) { 
    if (selection == null) { 
     println("no selection so far..."); 
    } 
    else { 
     myFilePath   = selection.getAbsolutePath(); 
     myInputFileContents = loadStrings(myFilePath) ;// this moves here... 

     println("User selected " + myFilePath); 
    } 
} 

하지만

size(400, 400); 

경우

0 변경된 작품
size(400,400,P3D); 

프레임은 표시되지만 그릴 수는 없습니다.

누군가 나를 대답 할 수 있습니까?

답변

0

이 문제는 일종의 프레임로드 문제 인 것으로 보입니다. 이 "hackish"접근 방식은 OS X 10.10 Yoesemite에서 나를 위해 일했습니다. 창 아래에서도 작동해야합니다. 당신이 selectInput를 사용할 때마다 함수가 한 번만 호출되는, 그래서 아, 그리고()의 mouseReleased을 사용하시기 바랍니다 :) 두 번 어떤 이유에서 호출되는

  1. 설정(), 이것은 우리가 didPreSelect 부울을 이유.
  2. mouseReleased 대신 mousePressed를 호출합니다.
  3. 루프에 이미 화면 선택이 있었기 때문에 이것이 루프를 변경 한 이유입니다.
  4. 지연에도 문제가 있습니다. 이것이 내가 while 루프 내부에 지연을 추가 한 이유입니다.

사람이 질문에 +1했습니다.

추신 : 내가 처음 응용 프로그램을 열 때 취소를 누르면 더 편리 할 것입니다. exit()를 추가했습니다.

String [] myInputFileContents ; 
String myFilePath; 

boolean didPreSelect = false; 
boolean secondPress = false; 
void setup() { 
    if (didPreSelect == false) 
    { 
    didPreSelect = true; 
    selectInput("Select a file : ", "fileSelected"); 
    } 
    //frame = null; 
    while (myInputFileContents == null || myInputFileContents.length < 2) {//wait 
    delay(1000); 
    } 
    //this doesn't work 
    size(400, 400, P3D); 
    background(0); 
    //smooth(); 
    stroke(255); 
    frameRate(25); 
} 
void draw() { 
    box(mouseX, mouseY, 150); 
    //println("Selected at this point " + myFilePath); 
} 

void mouseReleased() { 
    if(secondPress == false) secondPress = true; 
    selectInput("Select a file : ", "fileSelected"); 
} 

void fileSelected(File selection) { 
    if (frameCount < 50) 
    { 
    if (selection == null) { 
     println("no selection so far..."); 
     if(secondPress == false) exit(); 
    } else { 

     myFilePath   = selection.getAbsolutePath(); 
     myInputFileContents = loadStrings(myFilePath) ;// this moves here.. 
     println("User selected " + myFilePath); 
    } 
    } 
}