Hey,
I am loading stl object from directory(which is totally fine 'cause I can add it to the scene and everything works fine) but when I want to play with that mesh in csg.js (in my case making a intersect with another object and union doesn’t work either) and then the final object return to the three scene the object is not appearing and leaving me with the empty scene.
CSG library I am using is - GitHub - manthrax/THREE-CSGMesh: Conversion of a CSG library for use with modern THREE.js
My project - GitHub - Ondurur/Three: Using three.js library to work with scenes, csg library to cut objects STLLoader to load files
Just to be clear I am trying to make it work in CSGDemo.html
Console error is on this part of code:
CSG.fromGeometry=function(geom){ if(geom.isBufferGeometry) geom = new THREE.Geometry().fromBufferGeometry(geom) var fs = geom.faces; var vs = geom.vertices; var polys=[] var fm=['a','b','c'] //console.log(geom) for(var i=0;i<fs.length;i++){ var f = fs[i]; var vertices=[] for(var j=0;j<3;j++) vertices.push(new Vertex(vs[f[fm[j]]],f.vertexNormals[j],geom.faceVertexUvs[0][i][j])) //Console told that right there is a problem with geometry faceVertexUvs polys.push(new Polygon(vertices)) } return CSG.fromPolygons(polys) } CSG._tmpm3 = new THREE.Matrix3(); CSG.fromMesh=function(mesh){ var csg = CSG.fromGeometry(mesh.geometry) CSG._tmpm3.getNormalMatrix(mesh.matrix); for(var i=0;i<csg.polygons.length;i++){ var p = csg.polygons[i] for(var j=0;j<p.vertices.length;j++){ var v=p.vertices[j] v.pos.applyMatrix4(mesh.matrix); v.normal.applyMatrix3(CSG._tmpm3); } } return csg; }
My code which calls the MeshCSG functions:
function doCSG(a,b,op,mat,ax,ay,az,bx,by,bz){
var bspA = CSG.fromMesh( a ); var bspB = CSG.fromMesh( b ); bspA.c = [ax,ay,az]; bspB.c = [bx,by,bz]; var bspC = bspA[op]( bspB ); var result = CSG.toMesh( bspC, a.matrix ); result.material = mat; result.castShadow = result.receiveShadow = true; return result; }
function splitGetA(objMesh) {
//get objMesh bounding objMesh.geometry.computeBoundingBox(); let bounding = objMesh.geometry.boundingBox.clone(); let size = new THREE.Vector3(); scene.updateMatrixWorld(); objMesh.updateMatrixWorld(true); bounding.copy( objMesh.geometry.boundingBox ).applyMatrix4( objMesh.matrixWorld ); //create cut obj let cut = new THREE.Mesh(new THREE.BoxGeometry(bounding.min,bounding.max/2,bounding.getSize(size) ),mkMat('grey')) console.log(bounding.min) console.log(bounding.max) console.log(bounding.getSize(size)) cut.parent = scene return doCSG(objMesh,cut,'intersect', mkMat('red'), 0,0,0,0,0,0); };
If my problem is not clear enough then feel free to ask. Afterall it is my problem to deal with.