1
我是新的three.js。基本上我想做一個像棋盤一樣的東西。我得到這個:錯誤設置顏色
for(x=-30; x<=50;x=x+10){
for(y=-30; y<=20;y=y+10){
var TileGeometry = new THREE.PlaneGeometry(5,5);
var TileMaterial = new THREE.MeshBasicMaterial();
var Tile = new THREE.Mesh(TileGeometry,TileMaterial);
//tile.receiveShadow = true
Tile.rotation.x=-0.5*Math.PI;
Tile.position.x = x;
Tile.position.y = 0;
Tile.position.z = y;
Tile.castShadow=true;
scene.add(Tile);
//whiteTile.material.color.setHex(0x000000);
tiles.push(Tile);
}
}
for(var tile in tiles){
if(count%2==0){
tile.material.color.setHex(0x000000);
}
else{
tile.material.color.setHex(0xffffff);
}
count++;
}
瓷磚正確定位。問題是設置顏色時。 我得到:
Uncaught TypeError: Cannot read property 'color' of undefined
你也可以使用着色器http://blog.2pha.com/demos/threejs/shaders/checker.html – 2pha