puxiao
1
I want to create a box with code, the box like this:

The cuboid satisfies the following conditions:
- the border width is 2
- the transparency of the back faces is 0.8, and that of the other faces is 0.2;
I tried to use LineSegments
, but it didn’t meet my requirements.
I guess I may need to use ShaderMaterial
, but I don’t know how to write it at the moment.
puxiao
2
Well, my question is wrong.
The second parameter of Mesh
can be an array of Material
.
const normal_face_material = new MeshBasicMaterial({
color: 'red',
transparent: true,
opacity: 0.2,
})
const special_face_material = normal_face_material.clone()
special_face_material.opacity = 0.8
special_face_material.side = DoubleSide
const box = new Mesh(
new BoxGeometry(width, height, depth),
[special_face_material, normal_face_material, normal_face_material, normal_face_material, normal_face_material, normal_face_material]
)
It can also simplify the code
- [special_face_material, normal_face_material, normal_face_material, normal_face_material, normal_face_material, normal_face_material]
+ [special_face_material].concat( new Array(5).fill(normal_face_material) )