Reputation: 69
I am trying to perform a subtraction on 2 mesh files imported from objloader using THREE.js and ThreeCSG but it is not working. Here is a piece of code:
loader= new THREE.OBJLoader ();
loader.load ('../obj/obj/obj/tool.obj', function (object) {
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material = new THREE.MeshLambertMaterial({ color: 0xBBAA84, });
child.geometry.computeFaceNormals();
child.geometry.computeVertexNormals();
//convert to CSG
toolCSG= new ThreeBSP(child.geometry);
}
});
//scene.add (object);
//second object
loader= new THREE.OBJLoader ();
loader.load ('../obj/obj/tool2.obj', function (object) {
object.traverse (function (mesh) {
if (mesh instanceof THREE.Mesh) {
mesh.material = new THREE.MeshPhongMaterial ({ color : 0xBBAA84});
mesh.geometry.computeFaceNormals();
mesh.geometry.computeVertexNormals();
//convert to CSG
tool2CSG= new ThreeBSP(mesh.geometry);
}
});
//scene.add(object);
var subtractedtool = tool2CSG.subtract(toolCSG);
subtractedBone.geomerty.computeFaceNormals();
var materialCSG = new THREE.MeshPhongMaterial( { color: 0x42AFD4 } );
var result = subtractedtool.toMesh(materialCSG);*/
scene.add(result);
});
});
But the Boolean operation is not working. Also, the subtract and the toolCSG and tool2CSG are undefined. I checked the similar examples in stackoverflow this using STLloader or this one using OBJloader. It is working fine with the generic objects such as a cube and a sphere but not working with the loaded compound objects. Besides, I should mention that I am using r.72 and objloader version 68 as I need to get the geometry from the loader and not the buffergeometry. I will be really thankful if you could help me about this issue.
r.72
Upvotes: 0
Views: 587