我一直在研究这个帖子
关于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); 被更改为
size(400,400,P3D);框架将显示,但不会绘制。
谁能告诉我答案是什么?
发布于 2014-12-24 20:12:50
这个问题似乎是某种帧加载问题。在OSX10.10Yoesemite上,这种“黑客”的方法对我很有效。它应该也可以在windows下工作。哦,当你使用selectInput()的时候,请使用mouseReleased,这样这个函数只会被调用一次:)
伙计,这是一个相当大的挑战,+1的问题。
PS:如果您第一次打开应用程序时按取消,我添加了一个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);
}
}
}https://stackoverflow.com/questions/27570651
复制相似问题