问题描述
我正在尝试使用 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,1,0);
// pointLight(0,102,255,0);
// directionalLight(255,-1);
// pointLight(0,mouseX,mouseY,0);
backgroundShape();
push();
translate(-260,0);
for (let x = 0; x<10; x++){
bodyFunction(x+spacing,0);
rotateX(50);
}
pop();
}
function bodyFunction(x,y,z,rotation){
specularMaterial(255);
translate(x,z);
rotateX(HALF_PI);
model(bodyShape);
}
function backgroundShape(){
push();
translate(0,-130);
plane(600,600);
texture(bgTexture)
pop();
}
这是草图的链接,以防万一:https://editor.p5js.org/rociorey/sketches/4H1eFQpKh
谢谢!
解决方法
您必须在绘制几何图形之前为几何图形指定纹理(请参阅 texture()
):
isnan