Is there a concise way to make a material that draws nothing (nodraw/skip/invisible material)?
I want to use the multi-material feature with BoxGeometry to hide the top and bottom of the box, like something from the examples below.
Things I’ve tried
Passing undefined somehow works, even though a quick glance through WebGLRenderer seems like it shouldn’t. Typescript also doesn’t like it and this isn’t documented anywhere so I’m hesitant on using it
const duct = new THREE.Mesh(ductGeometry, [
baseMaterial,
baseMaterial,
undefined as any, // no material for these faces (+Y/-Y)
undefined as any,
baseMaterial,
baseMaterial,
]);
I could also set colorWrite, depthWrite, and stencilWrite to false, but not sure if this is better/worse
.visible = false would skip the draw call entirely, and will be cheaper than alpha blending, discard, colorWrite=false, etc… Alternatively you could use the geometry.groups API to remove those groups from the geometry entirely. But if it’s just the one cube, not a big difference performance-wise anyway.
class LidlessBox extends THREE.Mesh{
constructor(w, h, d, color){
let r = Math.cos(Math.PI * 0.25);
let g = new THREE.CylinderGeometry(r, r, 1, 4, 1, true)
.rotateY(Math.PI * 0.25)
.scale(w, h, d)
.toNonIndexed();
g.computeVertexNormals();
let m = new THREE.MeshLambertMaterial({color: color, side: THREE.DoubleSide});
super(g, m);
}
}
...
let lidlessBox = new LidlessBox(2, 2, 2, "#fff");
scene.add(lidlessBox);