From 14308f3383667d8e97e838de1db5189650651a06 Mon Sep 17 00:00:00 2001 From: Rob Stenson Date: Tue, 19 Mar 2024 09:21:21 -0700 Subject: [PATCH] working on more generic export_origin with export_typographic_origin_x/export_typographic_origin_y bools [ref #19] --- ST2/exporting.py | 8 +++++--- ST2/properties.py | 24 +++++++++++++++++++++++- ST2/typesetter.py | 24 +++++++++++++++++++----- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/ST2/exporting.py b/ST2/exporting.py index 0ebbd6b..0cca28c 100644 --- a/ST2/exporting.py +++ b/ST2/exporting.py @@ -242,7 +242,7 @@ def draw(self, context): row = layout.row() row.label(text="Options") - row.prop(data, "export_geometric_origins", icon="TRANSFORM_ORIGINS", icon_only=True) + #row.prop(data, "export_geometric_origins", icon="TRANSFORM_ORIGINS", icon_only=True) row.prop(data, "export_meshes", icon="OUTLINER_OB_MESH", icon_only=True) #row = layout.row() @@ -253,7 +253,10 @@ def draw(self, context): col.enabled = data.export_meshes col.prop(data, "export_rigidbody_active", icon="RIGID_BODY", icon_only=True) - # row = layout.row() + row = layout.row() + #row.label("Origin") + row.prop(data, "export_origin", text="Origin") + # row.label(text="New Objects") # row.prop(data, "export_style", text="", expand=True) @@ -301,7 +304,6 @@ def draw(self, context): row = layout.row() row.label(text="Options") - #row.prop(data, "export_geometric_origins", icon="TRANSFORM_ORIGINS", icon_only=True) row.prop(data, "export_every_x_frame", text="Frame Interval") row.prop(data, "export_meshes", icon="OUTLINER_OB_MESH", icon_only=True) diff --git a/ST2/properties.py b/ST2/properties.py index 33f6a5a..66fdbe1 100644 --- a/ST2/properties.py +++ b/ST2/properties.py @@ -168,7 +168,29 @@ class ST2PropertiesGroup(bpy.types.PropertyGroup): # exporting export_meshes: bpy.props.BoolProperty(name="Export as Meshes", default=True) - export_geometric_origins: bpy.props.BoolProperty(name="Export with Geometric Origins", default=True) + + #export_geometric_origins: bpy.props.BoolProperty(name="Export with Geometric Origins", default=True) + + export_origin: bpy.props.EnumProperty(name="Export Origin", + description="Where should origin be relative to bounding box?", + items=[ + ("EXISTING", "Existing", ""), + ("GEOMETRIC", "Geometric", ""), + ("N", "North", ""), + ("NE", "Northeast", ""), + ("E", "East", ""), + ("SE", "Southeast", ""), + ("S", "South", ""), + ("SW", "Southwest", ""), + ("W", "West", ""), + ("NW", "Northwest", ""), + + ], + default="EXISTING") + + export_typographic_origin_x: bpy.props.BoolProperty(name="Export Typographic Origin X", default=True) + export_typographic_origin_y: bpy.props.BoolProperty(name="Export Typographic Origin Y", default=True) + export_apply_transforms: bpy.props.BoolProperty(name="Export with Applied Transforms", default=True) export_rigidbody_active: bpy.props.BoolProperty(name="Export with Active Rigid Body", default=False) export_every_x_frame: bpy.props.IntProperty(name="Export Every X Frame", default=1, min=1, max=50) diff --git a/ST2/typesetter.py b/ST2/typesetter.py index fef98e7..d86d642 100644 --- a/ST2/typesetter.py +++ b/ST2/typesetter.py @@ -417,6 +417,11 @@ def export(glyph=None, idx=None): txtObj.obj.location = self.obj.location txtObj.obj.rotation_euler = self.obj.rotation_euler + origin_pt = None + origin = self.st2.export_origin + typo_origin_x = self.st2.export_typographic_origin_x + typo_origin_y = self.st2.export_typographic_origin_y + if glyph and idx is not None: if self.st2.export_stagger_y: txtObj.locate_relative(y=idx*self.st2.export_stagger_y) @@ -424,8 +429,10 @@ def export(glyph=None, idx=None): txtObj.locate_relative(z=idx*self.st2.export_stagger_z) if glyph: + amb = glyph.ambit(tx=not typo_origin_x, ty=not typo_origin_y) + if origin not in ["EXISTING", "GEOMETRIC"]: + origin_pt = amb.point(origin) txtObj.draw(glyph, set_origin=False, fill=False) - # TODO option to set typographic origins else: txtObj.draw(p, set_origin=False, fill=False) @@ -453,6 +460,7 @@ def hide(hidden): self.scene.frame_set(frame) txtObj.obj.select_set(True) + if self.st2.export_meshes: bpy.ops.object.convert(target="MESH") if self.st2.export_apply_transforms: @@ -462,8 +470,10 @@ def hide(hidden): txtObj.obj.rigid_body.type = "ACTIVE" #bpy.ops.object.transform_apply(location=0, rotation=1, scale=1, properties=0) pass - if self.st2.export_geometric_origins: + + if origin == "GEOMETRIC": bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY') + txtObj.obj.select_set(False) if parent: @@ -477,7 +487,7 @@ def hide(hidden): if self.st2.export_rotate_y: txtObj.rotate(y=math.degrees(self.st2.export_rotate_y)) - return txtObj + return txtObj, origin_pt if glyphwise: if shapewise: @@ -488,9 +498,13 @@ def hide(hidden): # p.mapv(lambda _p: _p.explode()) for idx, glyph in enumerate(p): - output.append(export(glyph, idx=idx)) + res, origin_pt = export(glyph, idx=idx) + output.append(res) + if origin_pt is not None: + res.set_origin(*origin_pt, 0) else: - output.append(export()) + res, origin_pt = export() + output.append(res) return output