参考代码:
//透明度测试,利用透明度,可以方便的进行复杂建模,从而看到内部结构,透明物体一样可以打印!
function main () {
var o = [];
for (var i = 7; i >= 0; i--) { // reverse order for seeing through all cylinders (see http://www.opengl.org/wiki/Transparency_Sorting)
// hsl to rgb, creating rainbow [r,g,b]
o.push(
cylinder({r: 3, h: 20}).setColor(
hsl2rgb(i / 8, 1, 0.5).concat(1 / 8 + i / 8) // and add to alpha to make it [r,g,b,a]
).translate([(i - 3) * 7.5, 0, 0])
);
}
o.push(color('red', cube(5)).translate([-4, -10, 0]));
o.push(color('red', 0.5, cube(5)).translate([4, -10, 0]));
return o;
}
其中,o.push 是将对象推入数组;
color('red',0.5,cube(5)); 就是透明度;
而setColor 里的, 数组: [r,g,b,a] 分别代表:红,绿,蓝,透明度,值都是 0-1 之间;
|