mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
3.02k stars 582 forks source link

When trying to export an imported dxf to gltf error "divide by zero encountered in true_divide" happens #1414

Open autonomobil opened 3 years ago

autonomobil commented 3 years ago

Code

import trimesh

imported = trimesh.load(dxf_path)
trimesh_scene = trimesh.Scene(geometry=imported)
with open(gltf_path, 'wb') as f:
    f.write(trimesh.exchange.gltf.export_glb(trimesh_scene, include_normals=True))

Error:

.../trimesh/path/arc.py:50: RuntimeWarning: divide by zero encountered in true_divide
  edges = np.array([a, b, c]) / scale
../trimesh/path/arc.py:50: RuntimeWarning: invalid value encountered in true_divide
  edges = np.array([a, b, c]) / scale
.../trimesh/path/arc.py:68: RuntimeWarning: invalid value encountered in true_divide
  center = (points.T).dot(ba) / sum(ba)
mikedh commented 3 years ago

Ah, that's probably a degenerate zero-length arc if I had to guess? Probably somewhere in the loader it should be checking and discarding.

autonomobil commented 3 years ago

Yes that could be. For me it's ok if this arc is then just skipped, so I added

if A==B or B==C or A==C:
      return

after https://github.com/mikedh/trimesh/blob/46f48f1df0bbba304b1ef9673417d3ede5256172/trimesh/path/arc.py#L40 This seems to solve the problem.

Is this ok?