From: Mikko Rasa Date: Sat, 17 Apr 2021 19:38:43 +0000 (+0300) Subject: Improve error reporting in the Blender exporter X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=160293feec7b0b976856685153cd24c7f1ce9492;p=libs%2Fgl.git Improve error reporting in the Blender exporter Exceptions now include information identifying the thing which could not be processed. --- diff --git a/blender/io_mspgl/export_animation.py b/blender/io_mspgl/export_animation.py index 90d5d412..3f174e54 100644 --- a/blender/io_mspgl/export_animation.py +++ b/blender/io_mspgl/export_animation.py @@ -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) diff --git a/blender/io_mspgl/export_armature.py b/blender/io_mspgl/export_armature.py index 27bf6e0b..42c57b27 100644 --- a/blender/io_mspgl/export_armature.py +++ b/blender/io_mspgl/export_armature.py @@ -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) diff --git a/blender/io_mspgl/export_camera.py b/blender/io_mspgl/export_camera.py index 984ec0da..78afbd12 100644 --- a/blender/io_mspgl/export_camera.py +++ b/blender/io_mspgl/export_camera.py @@ -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") diff --git a/blender/io_mspgl/export_light.py b/blender/io_mspgl/export_light.py index cfa4a19d..43270558 100644 --- a/blender/io_mspgl/export_light.py +++ b/blender/io_mspgl/export_light.py @@ -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 diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 69662218..bf7e2b3f 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -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: diff --git a/blender/io_mspgl/export_object.py b/blender/io_mspgl/export_object.py index 3ee06fc2..177641c8 100644 --- a/blender/io_mspgl/export_object.py +++ b/blender/io_mspgl/export_object.py @@ -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) diff --git a/blender/io_mspgl/export_texture.py b/blender/io_mspgl/export_texture.py index 7661b90b..54b21054 100644 --- a/blender/io_mspgl/export_texture.py +++ b/blender/io_mspgl/export_texture.py @@ -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) diff --git a/blender/io_mspgl/material.py b/blender/io_mspgl/material.py index a24c09e3..ba5fc3e2 100644 --- a/blender/io_mspgl/material.py +++ b/blender/io_mspgl/material.py @@ -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 diff --git a/blender/io_mspgl/mesh.py b/blender/io_mspgl/mesh.py index 3f9ab02e..8009191f 100644 --- a/blender/io_mspgl/mesh.py +++ b/blender/io_mspgl/mesh.py @@ -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)