diff options
author | Max Schlecht <Bobbe> | 2022-03-29 10:56:43 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-03-29 10:56:43 +0300 |
commit | ff99cb3cf86ff2824262541b1e6d981be76ea2ac (patch) | |
tree | bd6121a1d3fef460d879e7e4e10b1a2204b571fa /io_scene_x3d | |
parent | 1d45d7e10631bc57f563f3e6702592c7a8565416 (diff) |
Fix .X3D/.WRL importer crashing with empty IndexedFaceSets
When importing a .x3d file containing an empty IndexedFaceSet, like this for example:
```
Shape {
geometry IndexedFaceSet {
coord Coordinate {
point [
]
}
coordIndex [
]
}
}
```
`import_x3d.py` throws an exception, because `x_min`, `x_max`, ... are not initialized/still set to `None`.
This fixes the issue by initializing the mentioned variables to `inf`/`-inf` respectively and also further simplifies the code by utlizing the `min` and `max` builtins.
Reviewed By: mont29
Differential Revision: https://developer.blender.org/D14470
Diffstat (limited to 'io_scene_x3d')
-rw-r--r-- | io_scene_x3d/import_x3d.py | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/io_scene_x3d/import_x3d.py b/io_scene_x3d/import_x3d.py index 8299faf1..fbde81ad 100644 --- a/io_scene_x3d/import_x3d.py +++ b/io_scene_x3d/import_x3d.py @@ -2007,23 +2007,18 @@ def importMesh_IndexedFaceSet(geom, ancestry): for v in f for co in tex_coord_points[v]] else: - x_min = x_max = y_min = y_max = z_min = z_max = None + x_min = y_min = z_min = math.inf + x_max = y_max = z_max = -math.inf for f in faces: # Unused vertices don't participate in size; X3DOM does so for v in f: (x, y, z) = points[v] - if x_min is None or x < x_min: - x_min = x - if x_max is None or x > x_max: - x_max = x - if y_min is None or y < y_min: - y_min = y - if y_max is None or y > y_max: - y_max = y - if z_min is None or z < z_min: - z_min = z - if z_max is None or z > z_max: - z_max = z + x_min = min(x_min, x) + x_max = max(x_max, x) + y_min = min(y_min, y) + y_max = max(y_max, y) + z_min = min(z_min, z) + z_max = max(z_max, z) mins = (x_min, y_min, z_min) deltas = (x_max - x_min, y_max - y_min, z_max - z_min) |