From bac5a7127f28e878e27573dd86b98e7bb67787ae Mon Sep 17 00:00:00 2001 From: James Thomas Date: Mon, 7 Sep 2020 16:23:37 -0400 Subject: [PATCH 1/2] Added conversion function for turning font objects into mesh objects that can be exported to Plasma. --- korman/exporter/convert.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/korman/exporter/convert.py b/korman/exporter/convert.py index ffcafe2..60a322c 100644 --- a/korman/exporter/convert.py +++ b/korman/exporter/convert.py @@ -272,6 +272,20 @@ class Exporter: else: self.report.msg("No material(s) on the ObData, so no drawables", indent=1) + def _export_font_blobj(self, so, bo): + self.report.msg("Converting font to mesh for export") + bpy.ops.object.select_all(action='DESELECT') + bpy.context.scene.objects.active = bo + bo.select = True + convertible = bpy.ops.object.convert.poll() + if convertible: + bpy.ops.object.convert(target='MESH', keep_original= True) + convertedFont = bpy.context.active_object + self._export_mesh_blobj(so, convertedFont) + bpy.ops.object.delete() + else: + self.report.msg("not convertible, skipping...") + def _export_referenced_node_trees(self): self.report.progress_advance() self.report.progress_range = len(self.want_node_trees) From e1b95378868205b8f379c02159e33e249ddaec57 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 7 Sep 2020 17:29:54 -0400 Subject: [PATCH 2/2] Avoid using object operators for TextCurve conversions. --- korman/exporter/convert.py | 15 +++------------ korman/exporter/utils.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/korman/exporter/convert.py b/korman/exporter/convert.py index 60a322c..100dcb6 100644 --- a/korman/exporter/convert.py +++ b/korman/exporter/convert.py @@ -273,18 +273,9 @@ class Exporter: self.report.msg("No material(s) on the ObData, so no drawables", indent=1) def _export_font_blobj(self, so, bo): - self.report.msg("Converting font to mesh for export") - bpy.ops.object.select_all(action='DESELECT') - bpy.context.scene.objects.active = bo - bo.select = True - convertible = bpy.ops.object.convert.poll() - if convertible: - bpy.ops.object.convert(target='MESH', keep_original= True) - convertedFont = bpy.context.active_object - self._export_mesh_blobj(so, convertedFont) - bpy.ops.object.delete() - else: - self.report.msg("not convertible, skipping...") + self.animation.convert_object_animations(bo, so) + with utils.temporary_mesh_object(bo) as meshObj: + self._export_mesh_blobj(so, meshObj) def _export_referenced_node_trees(self): self.report.progress_advance() diff --git a/korman/exporter/utils.py b/korman/exporter/utils.py index 9385ecf..87d894b 100644 --- a/korman/exporter/utils.py +++ b/korman/exporter/utils.py @@ -92,3 +92,20 @@ def bmesh_object(name : str): bm.to_mesh(mesh) finally: bm.free() + +@contextmanager +def temporary_mesh_object(source : bpy.types.Object) -> bpy.types.Object: + """Creates a temporary mesh object from a nonmesh object that will only exist for the duration + of the context.""" + assert source.type != "MESH" + + obj = bpy.data.objects.new(source.name, source.to_mesh(bpy.context.scene, True, "RENDER")) + obj.draw_type = "WIRE" + obj.matrix_basis, obj.matrix_world = source.matrix_basis, source.matrix_world + obj.parent = source.parent + + bpy.context.scene.objects.link(obj) + try: + yield obj + finally: + bpy.data.objects.remove(obj)