0

Processing を使用して 3D 空間のグリッドにテクスチャを適用したいと思います。PImage を宣言し、.jpg ファイルを loadimage で設定しようとしましたが、結果はありませんでした..

    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();  }

何かアドバイスはありますか?ありがとう!

4

2 に答える 2

0

.jpgのようなファイル拡張子が必要なようです。リファレンスページからコードを実行することでトラブルシューティングを行うことができます。

http://www.processing.org/reference/texture_

size(100, 100, P3D);
noStroke();
PImage img = loadImage("laDefense.jpg");
beginShape();
texture(img);
vertex(10, 20, 0, 0);
vertex(80, 5, 100, 0);
vertex(95, 90, 100, 100);
vertex(40, 95, 0, 100);
endShape();

laDefense.jpgを画像名に置き換えます。また、スケッチディレクトリのデータディレクトリに配置する必要があります。それが機能する場合、あなたの問題は他の場所にあります。スケッチにあなたの計画が何であるかはわかりませんが、peasycamが3Dでのトラブルシューティングに役立つ場合があります。

http://mrfeinberg.com/peasycam/

もう1つの手法は、フロートをフレームごとに0.01ずつインクリメントし、draw()メソッド/ループの開始時にRotateX()、Y、Z、または上記のすべてを呼び出すことです。

于 2013-03-04T01:55:24.330 に答える
0

お返事ありがとうございます!コードをこれに変更しました。これで、コードを実行して、何が得られるかを確認できます(まず、https: //www.dropbox.com/s/fsda0tih67q8tll/grass.jpg?mから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();
  }
于 2013-03-05T00:53:16.580 に答える