案例
描述
在THREE.MeshDepthMaterial案例中MeshDepthMaterial使用联合材质方法,给方块添加颜色
结果
部分代码
this.addCube = function () {
//随机大小
var cubeSize = Math.ceil(3+(Math.random()*3));
//定义立方体几何
var cubeGeometry = new THREE.BoxGeometry(cubeSize,cubeSize,cubeSize);
//定义一种材质MeshDepthMaterial
var cubeMaterial = new THREE.MeshDepthMaterial();
//定义第二种材质MeshBasicMaterial
var colorMaterial = new THREE.MeshBasicMaterial({
// 颜色
color: MDM.color,
// 是否透明
transparent: true,
// 融合模式THREE.MultiplyBlending模式会把前景色和背景色融合
blending: THREE.MultiplyBlending
});
var cube = new THREE.SceneUtils.createMultiMaterialObject(cubeGeometry,[colorMaterial,cubeMaterial]);
cube.children[1].scale.set(0.99,0.99,0.99);
cube.castShadow = true;
cube.position.x = -60+Math.round((Math.random()*100));
cube.position.y = Math.round((Math.random()*10));
cube.position.z = -100+Math.round((Math.random()*150));
scene.add(cube);
}
这些方块从MeshDepthMaterial对象获得了亮度,从MeshBasicMaterial对象获得了颜色