Hi,
I’m trying to use the THREE-CSGMesh library from @manthrax.
(https://github.com/manthrax) to make a subtraction from a mesh imported with objloader with a cube.
The tool is a kind of editor where i move things around after i add them to a scene
If I import the obj mesh and don’t change its position or scale before i call the CSG with :
var subtraction = CSG.fromMesh( scene.getObjectByName("cropCube"));
mesh.geometry.verticesNeedUpdate = true;
mesh.geometry.elementsNeedUpdate = true;
mesh.geometry.uvsNeedUpdate = true;
mesh.geometry.normalsNeedUpdate = true;
mesh.geometry.colorsNeedUpdate = true;
mesh.geometry.groupsNeedUpdate = true;
mesh.geometry.lineDistancesNeedUpdate = true;
mesh.updateMatrix();
mesh.updateMatrixWorld();
mesh.geometry.vertices.forEach(function(vertex) {
vertex = mesh.localToWorld( vertex );
});
var keep = CSG.fromMesh(mesh);
var subtracted = keep['subtract']( subtraction );
var result = CSG.toMesh( subtracted, mesh.matrix );
var newGeometry = result.geometry;
mesh.geometry.dispose();
mesh.geometry = newGeometry;
Everything works if i have added the mesh to the scene and the cropcube .
However if i have moved or scaled the mesh using the transform helper tool the CSG step ignores the positioning and scaling changes to the mesh.
before I add the mesh to the scene i use :
mesh.geometry.verticesNeedUpdate = true;
mesh.geometry.dynamic = true;
when i click the subtract function i’m calling:
mesh.geometry.verticesNeedUpdate = true;
mesh.geometry.elementsNeedUpdate = true;
mesh.geometry.uvsNeedUpdate = true;
mesh.geometry.normalsNeedUpdate = true;
mesh.geometry.colorsNeedUpdate = true;
mesh.geometry.groupsNeedUpdate = true;
mesh.geometry.lineDistancesNeedUpdate = true;
mesh.updateMatrix();
mesh.updateMatrixWorld();
mesh.geometry.vertices.forEach(function(vertex) {
vertex = mesh.localToWorld( vertex );
});
But It does not work
I assume the mesh geometry, the vertexes need to be updated somehow…or it is a cache problem?
Is there a way for the geometry of a mesh to be updated so the vertices use the world coordinates in the scene so the csg can take into account the fact I’ve moved the mesh after placing it at 0,0,0 ??
any help would be great.