[Bf-extensions-cvs] [ff99cb3c] master: Fix .X3D/.WRL importer crashing with empty IndexedFaceSets

Max Schlecht noreply at git.blender.org
Tue Mar 29 09:57:08 CEST 2022


Commit: ff99cb3cf86ff2824262541b1e6d981be76ea2ac
Author: Max Schlecht
Date:   Tue Mar 29 09:56:43 2022 +0200
Branches: master
https://developer.blender.org/rBAff99cb3cf86ff2824262541b1e6d981be76ea2ac

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

===================================================================

M	io_scene_x3d/import_x3d.py

===================================================================

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)



More information about the Bf-extensions-cvs mailing list