0

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

Community
  • 1
  • 1
Arezoo Tony
  • 69
  • 1
  • 8
  • 1
    I made a fork of [ThreeCSG](https://github.com/chandlerprall/ThreeCSG) and am working on adding support for buffer geometries to the library. You can find the develop branch of my fork [here on GitHub](https://github.com/Wilt/ThreeCSG/tree/develop). Maybe it will work for you? Maybe not? but worth a try. – Wilt Mar 23 '16 at 16:06
  • Thanks. I will definitely try it but my current issue is to perform the subtraction of the two objects that give me an undefined object. – Arezoo Tony Mar 23 '16 at 16:47
  • It probably returns undefined because it runs into an error while doing the subtraction. Any error messages in your console? – Wilt Mar 23 '16 at 16:52
  • well,sometimes it says that the subtract function is undefined. and also when I log the CSG objects it seems to be undefined aswell. – Arezoo Tony Mar 23 '16 at 17:31

0 Answers0