首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Processing2 selectInput() P3D clash

Processing2 selectInput() P3D clash
EN

Stack Overflow用户
提问于 2014-12-20 01:03:31
回答 1查看 92关注 0票数 1

我一直在研究这个帖子

关于Processing 2.0 - Open file dialog ()的用法。我希望导入点数据来构建一些3d图。我可以导入数据并构建绘图,但在尝试使用selectinput()选择文件时,我遇到了麻烦。我遇到的困难是selectinput()似乎与P3D窗口不兼容。

使用OS X10.10

例如,下面的代码可以工作

代码语言:javascript
复制
void setup() {

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

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

这是可行的

代码语言:javascript
复制
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);
   }
}

但是如果

代码语言:javascript
复制
size(400, 400); 

被更改为

代码语言:javascript
复制
size(400,400,P3D);

框架将显示,但不会绘制。

谁能告诉我答案是什么?

EN

回答 1

Stack Overflow用户

发布于 2014-12-24 20:12:50

这个问题似乎是某种帧加载问题。在OSX10.10Yoesemite上,这种“黑客”的方法对我很有效。它应该也可以在windows下工作。哦,当你使用selectInput()的时候,请使用mouseReleased,这样这个函数只会被调用一次:)

  1. ()被调用了两次,这就是为什么我们有didPreSelect布尔值。
  2. 你调用mousePressed而不是while循环已经有了屏幕选择,这就是为什么我改变了循环。
  3. 延迟也有问题,这就是为什么我在while-循环中添加了延迟。

伙计,这是一个相当大的挑战,+1的问题。

PS:如果您第一次打开应用程序时按取消,我添加了一个exit(),这应该会更方便。

代码语言:javascript
复制
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);
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27570651

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档