aboutsummaryrefslogtreecommitdiffstats
path: root/generat3d/scene.py
diff options
context:
space:
mode:
Diffstat (limited to 'generat3d/scene.py')
-rw-r--r--generat3d/scene.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/generat3d/scene.py b/generat3d/scene.py
index 25e4b61..28dc00c 100644
--- a/generat3d/scene.py
+++ b/generat3d/scene.py
@@ -62,9 +62,17 @@ class Scene:
graph: Graph
+def _finite(v):
+ return (not isinstance(v, bool) and isinstance(v, (int, float))
+ and math.isfinite(v))
+
+
def _channel(node, name):
comps = {c["id"]: c.get("current_value", c.get("value", 0.0)) for c in node.get(name, [])}
- return [comps.get(a, 0.0) for a in AXES]
+ out = [comps.get(a, 0.0) for a in AXES]
+ if not all(_finite(v) for v in out):
+ raise Error(f"{node['id']}: {name} is not a finite number")
+ return out
def _lookup(library, doc, url, section):
@@ -147,9 +155,12 @@ class _Loader:
self.graph.add_prop(key(n["id"], n["id"], f"{ch}/{a}"), v)
for f in n.get("formulas", []):
self.pending.append((f, fpath))
+ verts = np.array(geom["vertices"]["values"], dtype=float)
+ if verts.ndim != 2 or verts.shape[1] != 3 or not np.isfinite(verts).all():
+ raise Error(f"{fpath}: bad vertices")
return Figure(asset["id"], inst.get("name", asset.get("name", asset["id"])),
inst.get("label", asset.get("label", asset["id"])),
- np.array(geom["vertices"]["values"], dtype=float),
+ verts,
list(geom.get("polygon_material_groups", {}).get("values", [])),
nodes)
@@ -179,6 +190,9 @@ class _Loader:
if parent and parent != self.figure.id:
continue
ch = mod.get("channel", {})
+ for name in ("value", "min", "max"):
+ if name in ch and not _finite(ch[name]):
+ raise Error(f"{path}#{mod['id']}: {name} is not a finite number")
k = key(self.figure.id, mod["id"], "value")
self.graph.add_prop(k, ch.get("value", 0.0), ch.get("min", -math.inf),
ch.get("max", math.inf), ch.get("clamped", False))
@@ -206,7 +220,7 @@ class _Loader:
doc = self.library.load(path)
try:
self._modifiers(path, doc)
- except (KeyError, TypeError, ValueError, IndexError, AttributeError) as e:
+ except (KeyError, TypeError, ValueError, IndexError, AttributeError, OverflowError) as e:
raise Error(f"{path}: malformed morph data: {e!r}") from None
def _morphs(self, fpath):
@@ -263,5 +277,5 @@ def load(path, library):
"""Load a .duf scene and everything its figure needs."""
try:
return _Loader(path, library).run()
- except (KeyError, TypeError, IndexError, ValueError, AttributeError) as e:
+ except (KeyError, TypeError, IndexError, ValueError, AttributeError, OverflowError) as e:
raise Error(f"{path}: malformed scene data: {e!r}") from None