trimesh
trimesh copied to clipboard
trimesh.boolean.difference causes subprocess.CalledProcessError
I'm running the following code in a for loop, just to test it:
slice1 = trimesh.intersections.slice_mesh_plane(cubo, plane_normal=triRandomVector(True), plane_origin=triRandomOrigin(cube), cap=True, cached_dots=None)
slice2 = trimesh.intersections.slice_mesh_plane(cubo, plane_normal=triRandomVector(True), plane_origin=triRandomOrigin(cube), cap=True, cached_dots=None)
union = trimesh.boolean.union([slice2, slice1], 'scad')
differenza = trimesh.boolean.difference([cube, union], 'scad')
Where cube is the mesh of a watertight cube and the functions are to randomly generate a plane_normal and a plane_origin:
def triRandomVector(returnInt):
d = [0.0, 0.0, 0.0]
if returnInt == False:
a = random.uniform(-1, 1)
b = random.uniform(-1, 1)
c = random.uniform(-1, 1)
s = abs(a) + abs(b) + abs(c)
d = [a/s, b/s, c/s]
if returnInt == True:
t = random.randint(0, 2)
s = random.randint(1, 2)
d[t] = 1.0*pow(-1, s)
return d
def triRandomOrigin(mesh):
a = random.uniform(mesh.bounds[0][0], mesh.bounds[1][0])
b = random.uniform(mesh.bounds[0][1], mesh.bounds[1][1])
c = random.uniform(mesh.bounds[0][2], mesh.bounds[1][2])
d = [a, b, c]
return d
The error I get at a random point in the for-cycle is the following:
Traceback (most recent call last):
File "/home/alessandro/ProgettoIacca/log-carving-approximator/multiCuts.py", line 191, in <module>
differenza = trimesh.boolean.difference([cube, union], 'scad')
File "/home/alessandro/miniconda3/envs/tensorflow/lib/python3.7/site-packages/trimesh/boolean.py", line 25, in difference
result = _engines[engine](meshes, operation='difference', **kwargs)
File "/home/alessandro/miniconda3/envs/tensorflow/lib/python3.7/site-packages/trimesh/interfaces/scad.py", line 65, in boolean
return interface_scad(meshes, script, debug=debug, **kwargs)
File "/home/alessandro/miniconda3/envs/tensorflow/lib/python3.7/site-packages/trimesh/interfaces/scad.py", line 53, in interface_scad
result = scad.run(_scad_executable + ' $SCRIPT -o $MESH_POST')
File "/home/alessandro/miniconda3/envs/tensorflow/lib/python3.7/site-packages/trimesh/interfaces/generic.py", line 93, in run
startupinfo=startupinfo)
File "/home/alessandro/miniconda3/envs/tensorflow/lib/python3.7/subprocess.py", line 363, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/openscad', '/tmp/tmpya1afsl4', '-o', '/tmp/tmpm8nk03gg.off']' returned non-zero exit status 1.
Do somebody know why does this happen?
Hey, can you try running the failing operation in debug mode, which should print the output from scad:
differenza = trimesh.boolean.difference([cube, union], engine='scad', debug=True)
It may be mad at the geometry not intersecting or perhaps not being watertight.
Did you solve it? I have a similar issue with boolean.intersection and setting debug=True returns the same Error message as not having the parameter..