Three.js CSG How to change result's material and color?

585 views Asked by At

I'd like to get MeshLambertMaterial on this particular object 'result' which I get after making union of two meshes:

var lathe = new THREE.Mesh(latheGeometry);
var cube_bsp = new ThreeBSP( lathe );

var box = new THREE.BoxGeometry( 2,30,3);

var sub = new THREE.Mesh( box );
sub.position = new THREE.Vector3(0,0,19);
var substract_bsp  = new ThreeBSP( sub );
var subtract_bsp  = cube_bsp.union( substract_bsp );

var result = subtract_bsp.toMesh(); 
    result.rotation.x = Math.PI * -0.5;
    scene.add(result);

Here I have a box and a latheGeometry. After union is done I get random plain color ugly object. Instead I should get LambertMaterial white color object.

Images: https://i.stack.imgur.com/cJzUC.jpg

1

There are 1 answers

3
Falk Thiele On BEST ANSWER

You can apply the material when calling ThreeBSP.toMesh():

subtract_bsp.toMesh( new THREE.MeshLambertMaterial( {color:0xFFFFFF} ) );

or after the creation on the resulting mesh:

result.material = new THREE.MeshLambertMaterial( {color:0xFFFFFF} ) );