Grid 将纹理应用于栅格

Grid 将纹理应用于栅格,grid,processing,Grid,Processing,我想使用Processing将纹理应用于3d空间中的网格,我已尝试声明一个PImage并使用loadimage设置.jpg文件,但没有结果 PImage tex; void setup() { size(800, 600, P3D); tex=loadImage("ground104"); noCursor(); } void draw() { directionalLight(255, 255, 255, 0, 0, -1);

我想使用Processing将纹理应用于3d空间中的网格,我已尝试声明一个PImage并使用loadimage设置.jpg文件,但没有结果

    PImage tex;

    void setup()  {    
size(800, 600, P3D);   
 tex=loadImage("ground104"); 
noCursor(); 
}  
void draw() 
  {    
directionalLight(255, 255, 255, 0, 0, -1); 
   background(180); 
   drawPlane();  
}    
void drawPlane()
  {  //lights(); 
   int s = 10000;  
        int ss = 500;
         fill(0, 200, 20);   stroke(200);    for(int i = 0; i < s; i += ss)    {
        stroke(0,100,0);
        strokeWeight(3);
        beginShape(QUAD_STRIP);
        for(int j = 0; j <= s; j += ss)
        {
          texture(tex);
          vertex(j, i, 0);
          vertex(j, i + ss, 0);
        }
        endShape();    }    noStroke();  }
PImage-tex;
无效设置(){
尺寸(800600,P3D);
tex=loadImage(“ground104”);
noCursor();
}  
作废提款()
{    
定向光(255,255,255,0,0,-1);
背景(180);
绘图平面();
}    
void drawPlane()
{//lights();
int s=10000;
int-ss=500;
填充(0,200,20);笔划(200);for(inti=0;ifor(int j=0;j看起来您需要一个像.jpg这样的文件扩展名。您可以通过从参考页运行代码来进行故障排除:

并将laDefense.jpg替换为您的图像名称。此外,它需要放在草图目录的数据目录中。如果它起作用,那么您的问题就在别处。我不确定草图中的计划是什么,但您可能会发现peasycam对3d中的疑难解答很有用

另一种方法是每帧增加0.01个浮点,并在draw()方法/循环的开始处调用RotateX()、Y或Z或以上所有函数。

谢谢您的回复! 我已经将我的代码更改为这个,现在您可以运行它并查看我得到了什么(首先从下载grass.jpg)。我很接近,但我想知道为什么网格是绿色的,而它本来应该是一块草地

PImage tex;

void setup()  
{    
size(800, 600, P3D);   
tex=loadImage("grass.jpg"); 
noCursor(); 
}  

void draw() 
{ 
  translate(width/2 , height/2 , 0);  // center of screen
    rotateX(QUARTER_PI * 1.0);            // move camera up
    rotateZ(QUARTER_PI * 1.8);
    //rotateZ(camZ.val + offset);           // rotate around turret

    rotateZ(map(mouseX, mouseY, width, 2.5, -2.5));

    translate(-1000, 0, -1000);
  directionalLight(255, 255, 255, 0, 0, -1); 
  background(180); 
  drawPlane();  
}    
void drawPlane()
  {  //lights(); 
   int s = 10000;  
        int ss = 500;
         fill(0, 200, 20);   stroke(200);    for(int i = 0; i < s; i += ss)    {
        stroke(0,100,0);
        strokeWeight(3);
        beginShape(QUAD_STRIP);
        for(int j = 0; j <= s; j += ss)
        {
          texture(tex);
          vertex(j, i, 0);
          vertex(j, i + ss, 0);
        }
        endShape();
    }    
noStroke();
  }
PImage-tex;
无效设置()
{    
尺寸(800600,P3D);
tex=loadImage(“grass.jpg”);
noCursor();
}  
作废提款()
{ 
平移(宽度/2,高度/2,0);//屏幕中心
rotateX(四分之一_PI*1.0);//向上移动相机
rotateZ(四分之一π*1.8);
//rotateZ(camZ.val+偏移);//围绕炮塔旋转
rotateZ(地图(鼠标,鼠标,宽度,2.5,-2.5));
翻译(-1000,0,-1000);
定向光(255,255,255,0,0,-1);
背景(180);
绘图平面();
}    
void drawPlane()
{//lights();
int s=10000;
int-ss=500;
填充(0,200,20);笔划(200);for(inti=0;ifill(0,200,20);
stroke(0100,0);
如果我要猜测,最有可能是笔划。如果应用纹理,我建议删除所有fill、stroke和strokewweight调用。
PImage tex;

void setup()  
{    
size(800, 600, P3D);   
tex=loadImage("grass.jpg"); 
noCursor(); 
}  

void draw() 
{ 
  translate(width/2 , height/2 , 0);  // center of screen
    rotateX(QUARTER_PI * 1.0);            // move camera up
    rotateZ(QUARTER_PI * 1.8);
    //rotateZ(camZ.val + offset);           // rotate around turret

    rotateZ(map(mouseX, mouseY, width, 2.5, -2.5));

    translate(-1000, 0, -1000);
  directionalLight(255, 255, 255, 0, 0, -1); 
  background(180); 
  drawPlane();  
}    
void drawPlane()
  {  //lights(); 
   int s = 10000;  
        int ss = 500;
         fill(0, 200, 20);   stroke(200);    for(int i = 0; i < s; i += ss)    {
        stroke(0,100,0);
        strokeWeight(3);
        beginShape(QUAD_STRIP);
        for(int j = 0; j <= s; j += ss)
        {
          texture(tex);
          vertex(j, i, 0);
          vertex(j, i + ss, 0);
        }
        endShape();
    }    
noStroke();
  }