]> git.tdb.fi Git - libs/gl.git/commitdiff
Improve error reporting in the Blender exporter
authorMikko Rasa <tdb@tdb.fi>
Sat, 17 Apr 2021 19:38:43 +0000 (22:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 17 Apr 2021 22:10:56 +0000 (01:10 +0300)
Exceptions now include information identifying the thing which could not
be processed.

blender/io_mspgl/export_animation.py
blender/io_mspgl/export_armature.py
blender/io_mspgl/export_camera.py
blender/io_mspgl/export_light.py
blender/io_mspgl/export_material.py
blender/io_mspgl/export_object.py
blender/io_mspgl/export_texture.py
blender/io_mspgl/material.py
blender/io_mspgl/mesh.py

index 90d5d4125197d0557741febe92eb75d311181778..3f174e549ba8d616542314e27a7cc36830ebae29 100644 (file)
@@ -40,9 +40,9 @@ class AnimationExporter:
                else:
                        anim_data = context.active_object.animation_data
                        if not anim_data:
-                               raise Exception("Object has no animation data")
+                               raise Exception("Object {} has no animation data".format(context.active_object.name))
                        if not anim_data.action:
-                               raise Exception("No active action")
+                               raise Exception("Object {} has no active action".format(context.active_object.name))
 
                        resource = self.export_animation(context, anim_data.action)
 
index 27bf6e0b05df9341369258b0daefa4aa8d1dad0e..42c57b27016412a9af0549e516f8947bc0ccbf2c 100644 (file)
@@ -1,7 +1,7 @@
 class ArmatureExporter:
        def export_armature(self, obj):
                if obj.type!="ARMATURE":
-                       raise ValueError("Object is not an armature")
+                       raise ValueError("Object {} is not an armature".format(obj))
 
                from .armature import Armature
                armature = Armature(obj.data)
index 984ec0dafa8ecd3fde4d6859abf5cf1f6241c4ef..78afbd1235594f62e9350f2ef684570846149687 100644 (file)
@@ -4,7 +4,7 @@ import mathutils
 class CameraExporter:
        def export_camera(self, obj):
                if obj.type!='CAMERA':
-                       raise ValueError("Object is not a camera")
+                       raise ValueError("Object {} is not a camera".format(obj.name))
 
                from .datafile import Resource, Statement
                resource = Resource(obj.name+".camera", "camera")
index cfa4a19dadef5e2d859233dd1db477b054e46e61..432705589bcd8b972c2684dbc762e7c37e05f424 100644 (file)
@@ -3,7 +3,7 @@ import mathutils
 class LightExporter:
        def export_light(self, obj):
                if obj.type!='LIGHT':
-                       raise ValueError("Object is not a light")
+                       raise ValueError("Object {} is not a light".format(obj.name))
                light = obj.data
 
                from .datafile import Resource, Statement
index 696622183153a5b0d244d0eda3ca64dafdb74159..bf7e2b3f5b8d4824dc3a132b75ff93a93b0cdce8 100644 (file)
@@ -65,7 +65,7 @@ class MaterialExporter:
                mat_res = Resource(material.name+".mat", "material")
 
                if material.type!="pbr" and material.type!="unlit":
-                       raise Exception("Can't export unknown material type "+material.type)
+                       raise Exception("Can't export material {} of unknown type {}".format(material.name, material.type))
 
                mat_res.statements.append(Statement("type", Token(material.type)));
                for p in material.properties:
index 3ee06fc218c3fe1a618826eb22668b4687739e26..177641c83ddf21eecfe7bfd6d9dd4f2659d800b1 100644 (file)
@@ -20,7 +20,7 @@ class ObjectExporter:
                lods += sorted([c for c in obj.children if c.lod_for_parent], key=(lambda l: l.lod_index))
                for i, l in enumerate(lods):
                        if i>0 and l.lod_index!=i:
-                               raise Exception("Inconsistent LOD indices")
+                               raise Exception("Invalid configuration on object {}: Inconsistent LOD indices".format(obj.name))
 
                return lods
 
@@ -62,7 +62,7 @@ class ObjectExporter:
                                material_atlas_key = mmk(l.data.materials[0])
                                key_mismatch = any(mmk(m)!=material_atlas_key for m in l.data.materials)
                                if not all(atlas_flags) or key_mismatch:
-                                       raise Exception("Conflicting settings in object materials")
+                                       raise Exception("Invalid configuration on object {}: Mixed material atlas state")
 
                                if material_atlas_key in material_atlases:
                                        material_atlas = material_atlases[material_atlas_key]
@@ -94,7 +94,7 @@ class ObjectExporter:
 
        def export_object(self, obj, resources, progress):
                if obj.type!='MESH':
-                       raise ValueError("Object is not a mesh")
+                       raise ValueError("Object {} is not a mesh".format(obj.name))
 
                lods = self.collect_object_lods(obj)
 
index 7661b90b2fa5e1d91c5ba0410689904d29681bdb..54b2105492f898e30f8502f936e518b30b983c84 100644 (file)
@@ -36,7 +36,7 @@ class TextureExporter:
 
                colorspace = image.colorspace_settings.name
                if usage=='GRAY' and colorspace=='sRGB':
-                               raise Exception("Grayscale textures with sRGB colorspace are not supported")
+                       raise Exception("Unsupported configuration on texture {}: Grayscale with sRGB".format(image.name))
 
                from .util import basename
                fn = basename(image.filepath)
index a24c09e3b59dd59a05f9c3ba504afd398a1f7fbf..ba5fc3e2c6cb7567b0563b391cf8d4a3c0c21cf2 100644 (file)
@@ -98,9 +98,9 @@ class Material:
                self.shader = material.shader
 
                if self.render_mode=='EXTERNAL' and not self.technique:
-                       raise Exception("Missing technique with external rendering mode")
+                       raise Exception("Invalid configuration on material {}: No technique for external rendering".format(self.name))
                elif self.render_mode=='CUSTOM' and not self.shader:
-                       raise Exception("Missing shader with custom rendering mode")
+                       raise Exception("Invalid configuration on material {}: No shader for custom rendering".format(self.name))
 
                out_node = None
                for n in material.node_tree.nodes:
@@ -109,12 +109,12 @@ class Material:
                                break
 
                if not out_node:
-                       raise Exception("No material output node found")
+                       raise Exception("No output node found on material {}".format(self.name))
 
                surface_node, _ = get_linked_node_and_socket(material.node_tree, out_node.inputs["Surface"])
                if not surface_node:
                        if self.render_mode=='BUILTIN':
-                               raise Exception("Empty material can't use builtin rendering mode")
+                               raise Exception("Invalid configuration on material {}: Empty material with builtin rendering".format(self.name))
                        return
                elif surface_node.type=='BSDF_PRINCIPLED':
                        self.type = "pbr"
@@ -137,7 +137,7 @@ class Material:
 
                        color.set_from_input(material.node_tree, surface_node.inputs["Color"])
                else:
-                       raise Exception("Unsupported surface node type "+surface_node.type)
+                       raise Exception("Unsupported surface node type {} on material {}".format(surface_node.type, self.name))
 
                sampler_settings = None
                for p in self.properties:
@@ -146,7 +146,7 @@ class Material:
                                if sampler_settings is None:
                                        sampler_settings = settings
                                elif settings!=sampler_settings:
-                                       raise Exception("Conflicting sampler settings in material textures")
+                                       raise Exception("Material {} has conflicting texture sampler settings".format(self.name))
 
        def create_property(self, *args):
                prop = None
index 3f9ab02e2bd3dabf8493088b114f398c77983659..8009191f080a045468c36908cee738a988e562e4 100644 (file)
@@ -207,7 +207,7 @@ class Mesh:
                edge_map = {e.key: e for e in self.edges}
                for f in self.faces:
                        if len(f.vertices)>4:
-                               raise ValueError("Ngons are not supported")
+                               raise ValueError("Unsupported face on mesh {}: N-gon".format(self.name))
 
                        f.vertices = [self.vertices[i] for i in f.vertices]
                        for v in f.vertices:
@@ -252,10 +252,10 @@ class Mesh:
 
        def splice(self, other):
                if len(self.uv_layers)!=len(other.uv_layers):
-                       raise ValueError("Meshes have incompatible UV layers")
+                       raise ValueError("Meshes {} and {} have incompatible UV layers".format(self.name, other.name))
                for i, u in enumerate(self.uv_layers):
                        if u.name!=other.uv_layers[i].name:
-                               raise ValueError("Meshes have incompatible UV layers")
+                               raise ValueError("Meshes {} and {} have incompatible UV layers".format(self.name, other.name))
 
                # Merge materials and form a lookup from source material indices to the
                # merged material list
@@ -418,7 +418,7 @@ class Mesh:
        def apply_material_atlas(self, material_atlas):
                for m in self.materials:
                        if m.name not in material_atlas.material_names:
-                               raise Exception("Material atlas is not compatible with Mesh")
+                               raise Exception("Material atlas {} is not compatible with Mesh {}".format(material_atlas.name, self.name))
 
                if self.use_uv=='NONE':
                        return
@@ -480,7 +480,7 @@ class Mesh:
                                progress.pop_task()
                                prog_step = 2
                        else:
-                               raise Exception("Tangent UV layer not found")
+                               raise Exception("Invalid configuration on mesh {}: No tangent UV layer".format(self.name))
 
                # Split by the remaining UV layers
                for i, u in enumerate(self.uv_layers):
@@ -797,7 +797,7 @@ class Mesh:
 
 def create_mesh_from_object(context, obj, material_atlas, progress):
        if obj.type!="MESH":
-               raise Exception("Object is not a mesh")
+               raise Exception("Object {} is not a mesh".format(obj.name))
 
        progress.push_task("Preparing mesh", 0.0, 0.2)