WEBGL P5js 未将图像显示为纹理

时间:2021-02-21 11:50:53

标签: javascript webgl textures p5.js plane

我正在尝试使用 WEBGL 在 P5js 中使用图像作为平面的纹理,但由于某种原因它不起作用。

我试图摆脱所有的照明,只使用ambientLight(),但它仍然没有显示。我已经尝试在一个只有平面和相同代码的新草图中,它工作正常,所以我不明白这个草图中的问题是什么?

let bodyShape;
let spacing = 50;
let bgTexture;


function preload() {
  bodyShape = loadModel('Human_body_with_net.obj');
  bgTexture = loadImage('assets/gormleyline.jpeg');
}

function setup() {
  createCanvas(600, 600,WEBGL);
  noStroke();
}

function draw() {
  background(0);
  
  debugMode();
  orbitControl();

  ambientLight(255);
  // pointLight(102,0,0,0,1,0);
  // pointLight(0,102,255,1,0,0);
  // directionalLight(255,0,0,0,1,0);
  // directionalLight(255,255,255,0,0,-1);
  // pointLight(0,0,0,mouseX,mouseY,0);
  backgroundShape();

  push();
  translate(-260,0,0); 
  for (let x = 0; x<10; x++){    
  bodyFunction(x+spacing,0,0);
  rotateX(50);
  }
  pop();
}

function bodyFunction(x,y,z,rotation){
  specularMaterial(255);
  translate(x,y,z);
  rotateX(HALF_PI);
  model(bodyShape);

}

function backgroundShape(){
  push();
  translate(0,0,-130);
  plane(600,600);
    texture(bgTexture)
  pop();
}

这是草图的链接,以防万一:https://editor.p5js.org/rociorey/sketches/4H1eFQpKh

谢谢!

1 个答案:

答案 0 :(得分:0)

您必须在绘制几何图形之前为几何图形指定纹理(请参阅 texture()):

isnan
相关问题