I'm attempting to use a boolean operation on a loaded STL mesh file with ThreeCSG.js. Here is the code snippet:
function openFile() {
filePath = document.form.selectedFile.value;
var loader = new THREE.STLLoader();
loader.addEventListener('load', function(event) {
// A simple cube geometry loaded from the STL file.
var geometry = event.content;
var cube_mesh = new THREE.Mesh(geometry);
cube_mesh.position.x = -7;
var cube_bsp = new ThreeBSP(cube_mesh);
// Creating a sphere
var sphere_geometry = new THREE.SphereGeometry(1.8, 32, 32);
var sphere_mesh = new THREE.Mesh(sphere_geometry);
sphere_mesh.position.x = -7;
var sphere_bsp = new ThreeBSP(sphere_mesh);
// Subtracting cube from sphere
var subtract_bsp = cube_bsp.subtract(sphere_bsp);
var result = subtract_bsp.toMesh(new THREE.MeshLambertMaterial({shading: THREE.SmoothShading, map: THREE.ImageUtils.loadTexture('texture.png')}));
result.geometry.computeVertexNormals();
scene.add(result);
});
loader.load(filePath);
}
Unfortunately, the code doesn't seem to be working as expected. I am using three.js R62 and loading an STL file with STLLoader.js.
As a beginner in Three.js, I am uncertain if the imported mesh files are compatible with ThreeCSG.js. Nevertheless, theoretically, the CSG operations should function on the loaded mesh files similar to how they operate on manually created mesh geometries within the program.
If you have any suggestions, please feel free to share them. Thank you!