Browse Source

prompt warning and error message to GUI

Jason0214 7 years ago
parent
commit
7aa88957b9

+ 33 - 28
io_scene_godot/converters/animation.py

@@ -3,11 +3,11 @@ import collections
 import re
 import math
 import copy
+import logging
 from functools import partial
 import bpy
 import bpy_extras.anim_utils
 import mathutils
-from . import armature
 from ..structures import (NodeTemplate, NodePath, fix_directional_transform,
                           InternalResource, Array, Map, fix_matrix)
 
@@ -461,9 +461,6 @@ def export_transform_action(godot_node, animation_player,
 
     first_frame, last_frame = get_action_frame_range(action)
 
-    # if no skeleton node exist, it will be None
-    skeleton_node = armature.find_skeletion_node(godot_node)
-
     transform_frame_values_map = collections.OrderedDict()
     for fcurve in action.fcurves:
         # fcurve data are seperated into different channels,
@@ -472,37 +469,45 @@ def export_transform_action(godot_node, animation_player,
         # are aggregated to object while being evaluted
         object_path, attribute = split_fcurve_data_path(fcurve.data_path)
 
-        if object_path not in transform_frame_values_map:
-            if attribute in TransformFrame.ATTRIBUTES:
+        if (object_path not in transform_frame_values_map and
+                attribute in TransformFrame.ATTRIBUTES):
 
-                default_frame = None
+            default_frame = None
 
-                # the fcurve location is matrix_basis.to_translation()
-                default_frame = TransformFrame(
-                    blender_object.matrix_basis,
-                    blender_object.rotation_mode
-                )
+            # the fcurve location is matrix_basis.to_translation()
+            default_frame = TransformFrame(
+                blender_object.matrix_basis,
+                blender_object.rotation_mode
+            )
 
-                if object_path.startswith('pose'):
-                    bone_name = blender_path_to_bone_name(object_path)
+            if object_path.startswith('pose'):
+                bone_name = blender_path_to_bone_name(object_path)
 
-                    # if the correspond bone of this track not exported, skip
-                    if (skeleton_node is None or
-                            skeleton_node.find_bone_id(bone_name) == -1):
-                        continue
-
-                    pose_bone = blender_object.pose.bones[
-                        blender_object.pose.bones.find(bone_name)
-                    ]
-                    default_frame = TransformFrame(
-                        pose_bone.matrix_basis,
-                        pose_bone.rotation_mode
+                # bone fcurve in a non armature object
+                if godot_node.get_type() != 'Skeleton':
+                    logging.warning(
+                        "Skip a bone fcurve in a non-armature "
+                        "object '%s'",
+                        blender_object.name
                     )
+                    continue
 
-                transform_frame_values_map[object_path] = [
-                    copy.deepcopy(default_frame)
-                    for _ in range(last_frame - first_frame)
+                    # if the correspond bone of this track not exported, skip
+                if godot_node.find_bone_id(bone_name) == -1:
+                    continue
+
+                pose_bone = blender_object.pose.bones[
+                    blender_object.pose.bones.find(bone_name)
                 ]
+                default_frame = TransformFrame(
+                    pose_bone.matrix_basis,
+                    pose_bone.rotation_mode
+                )
+
+            transform_frame_values_map[object_path] = [
+                copy.deepcopy(default_frame)
+                for _ in range(last_frame - first_frame)
+            ]
 
         if attribute in TransformFrame.ATTRIBUTES:
 

+ 15 - 17
io_scene_godot/converters/mesh.py

@@ -1,11 +1,12 @@
 """Exports a normal triangle mesh"""
+import logging
 import bpy
 import bmesh
 import mathutils
 
 from .material import export_material
 from ..structures import (Array, NodeTemplate, InternalResource, NodePath,
-                          ValidationError, Map)
+                          Map)
 from . import physics
 from . import armature
 from . import animation
@@ -119,14 +120,10 @@ class MeshResourceExporter:
 
         self.mesh_resource = InternalResource('ArrayMesh')
 
-        try:
-            self.make_arrays(
-                escn_file,
-                export_settings,
-            )
-        except ValidationError as exception:
-            exception.args += (mesh.name, )
-            raise
+        self.make_arrays(
+            escn_file,
+            export_settings,
+        )
 
         mesh_id = escn_file.add_internal_resource(self.mesh_resource, mesh)
         assert mesh_id is not None
@@ -223,9 +220,10 @@ class MeshResourceExporter:
         if export_settings['use_mesh_modifiers']:
             if not self.validate_morph_mesh_modifiers(
                     self.object):
-                raise ValidationError(
-                    "Mesh object '{}' has modifiers "
-                    "incompatible with shape key".format(self.object.name)
+                logging.warning(
+                    "Mesh object '%s' has modifiers "
+                    "incompatible with shape key",
+                    self.object.name
                 )
 
         self.mesh_resource["blend_shape/names"] = Array(
@@ -589,11 +587,11 @@ class Vertex:
 
         if gid_to_bid_map and not new_vert.weights:
             # vertex not assign to any bones
-            raise ValidationError(
-                "No bone assigned vertex detected, "
-                "vertex with local position {} ".format(
-                    mesh.vertices[loop.vertex_index].co
-                )
+            logging.warning(
+                "No bone assigned vertex detected in mesh '%s' "
+                "at local position %s.",
+                mesh.name,
+                str(mesh.vertices[loop.vertex_index].co)
             )
 
         return new_vert

+ 22 - 0
io_scene_godot/export_godot.py

@@ -57,6 +57,23 @@ def find_godot_project_dir(export_path):
     return project_dir
 
 
+class ExporterLogHandler(logging.Handler):
+    """Custom handler for exporter, would report logging message
+    to GUI"""
+    def __init__(self, operator):
+        super().__init__()
+        self.setLevel(logging.WARNING)
+        self.setFormatter(logging.Formatter("%(message)s"))
+
+        self.blender_op = operator
+
+    def emit(self, record):
+        if record.levelno == logging.WARNING:
+            self.blender_op.report({'WARNING'}, record.message)
+        else:
+            self.blender_op.report({'ERROR'}, record.message)
+
+
 class GodotExporter:
     """Handles picking what nodes to export and kicks off the export process"""
 
@@ -194,7 +211,12 @@ class GodotExporter:
 
 def save(operator, context, filepath="", **kwargs):
     """Begin the export"""
+    exporter_log_handler = ExporterLogHandler(operator)
+    logging.getLogger().addHandler(exporter_log_handler)
+
     with GodotExporter(filepath, kwargs, operator) as exp:
         exp.export()
 
+    logging.getLogger().removeHandler(exporter_log_handler)
+
     return {"FINISHED"}