Three.js - multiple material plane

被刻印的时光 ゝ 提交于 2019-11-28 22:05:28

To get a checkerboard pattern with three colors do this:

// geometry
var geometry = new THREE.PlaneGeometry( 500, 500, 10, 10 );

// materials
var materials = []; 
materials.push( new THREE.MeshBasicMaterial( { color: 0xff0000 }) );
materials.push( new THREE.MeshBasicMaterial( { color: 0x00ff00 }) );
materials.push( new THREE.MeshBasicMaterial( { color: 0x0000ff }) );

// assign a material to each face (each face is 2 triangles)
var l = geometry.faces.length / 2;
for( var i = 0; i < l; i ++ ) {
    var j = 2 * i;
    geometry.faces[ j ].materialIndex = i % 3;
    geometry.faces[ j + 1 ].materialIndex = i % 3;
}

// mesh
mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
scene.add( mesh );

EDIT: Updated for three.js r.60

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!