Skip to content

Commit

Permalink
Fixed distortion issues, removed compile as curve option
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkj1 committed Jul 15, 2023
1 parent 6b4c3c8 commit 3f2da66
Showing 1 changed file with 12 additions and 46 deletions.
58 changes: 12 additions & 46 deletions latex2blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "latex2blender",
"description": "Enables user to write LaTeX in Blender.",
"author": "Peter K. Johnson and George H. Seelinger",
"version": (1, 0, 6),
"version": (1, 0, 7),
"blender": (2, 80, 0),
"location": "View3D > Sidebar",
"warning": "",
Expand Down Expand Up @@ -264,7 +264,7 @@ def import_latex(self, context, latex_code, custom_latex_path,

if len(svg_file_list) == 0:
self.report({"ERROR"},
"Please check your LaTeX code for errors and that LaTeX and dvisvgm are properly "
"Please check your LaTeX code for errors and that LaTeX and dvisvgm are properly "
"installed and their paths are specified correctly. Also, if using a custom preamble, check that it is formatted correctly. \n"
"Tex return code " + str(tex_process.returncode) + "\n"
"dvi2svgm return code " + str(dvisvgm_process.returncode) + "\n"
Expand All @@ -285,15 +285,21 @@ def import_latex(self, context, latex_code, custom_latex_path,
context.view_layer.objects.active = active_obj
for x in imported_curve:
x.select_set(True)

# Convert to mesh
bpy.ops.object.convert(target='MESH')

# Adjust scale, location, and rotation.
# Join components to merge into single object
bpy.ops.object.join()

# Adjust scale, location, and rotation.
bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='MEDIAN')
active_obj.scale = (600*text_scale, 600*text_scale, 600*text_scale)
bpy.ops.object.transform_apply(location = False, scale = True, rotation = False)
active_obj.location = (x_loc, y_loc, z_loc)
active_obj.rotation_euler = (math.radians(x_rot), math.radians(y_rot), math.radians(z_rot))
# Move curve to scene collection and delete the temp.svg collection. Then rename curve.

# Move mesh to scene collection and delete the temp.svg collection. Then rename mesh.
temp_svg_collection = active_obj.users_collection[0]
bpy.ops.object.move_to_collection(collection_index=0)
bpy.data.collections.remove(temp_svg_collection)
Expand All @@ -302,16 +308,10 @@ def import_latex(self, context, latex_code, custom_latex_path,
if custom_material_bool:
active_obj.material_slots[0].material = custom_material_value

if compile_mode == "mesh":
# Convert to mesh
bpy.ops.object.convert(target='MESH')


if compile_mode == "grease pencil":
# Convert to mesh
bpy.ops.object.convert(target='MESH')
# Then convert to grease pencil
# Convert to grease pencil
bpy.ops.object.convert(target='GPENCIL', angle=0, thickness=1, seams=True, faces=True, offset=0)

# Moves to scene collection, fixes name.
bpy.ops.object.move_to_collection(collection_index=0)
bpy.context.selected_objects[0].name = "LaTeX Figure"
Expand Down Expand Up @@ -368,7 +368,6 @@ class OBJECT_OT_add_latex_preset(AddPresetBase, Operator):

preset_subdir = 'latex2blender_presets'


# Display into an existing panel
def panel_func(self, context):
layout = self.layout
Expand All @@ -378,36 +377,6 @@ def panel_func(self, context):
row.operator(OBJECT_OT_add_latex_preset.bl_idname, text="", icon='ADD')
row.operator(OBJECT_OT_add_latex_preset.bl_idname, text="", icon='REMOVE').remove_active = True

# Compile latex as curve.
class WM_OT_compile_as_curve(Operator):
bl_idname = "wm.compile_as_curve"
bl_label = "Compile as Curve"

def execute(self, context):
scene = context.scene
t = scene.my_tool
if t.latex_code == '' and t.custom_preamble_bool \
and t.preamble_path == '':
ErrorMessageBox("No LaTeX code has been entered and no preamble file has been chosen. Please enter some "
"LaTeX code and choose a .tex file for the preamble", "Multiple Errors")
elif t.custom_material_bool and t.custom_material_value is None:
ErrorMessageBox("No material has been chosen. Please choose a material.", "Custom Material Error")
elif t.latex_code == '':
ErrorMessageBox("No LaTeX code has been entered. Please enter some LaTeX code.", "LaTeX Code Error")
elif t.custom_preamble_bool and t.preamble_path == '':
ErrorMessageBox("No preamble file has been chosen. Please choose a file.", "Custom Preamble Error")
else:
with tempfile.TemporaryDirectory() as temp_dir:
import_latex(self, context, t.latex_code, t.custom_latex_path,
t.custom_pdflatex_path, t.custom_xelatex_path,
t.custom_lualatex_path, t.custom_dvisvgm_path,
t.command_selection, t.text_scale, t.x_loc,
t.y_loc, t.z_loc, t.x_rot, t.y_rot, t.z_rot,
t.custom_preamble_bool, temp_dir,
t.custom_material_bool, t.custom_material_value,
'curve', t.preamble_path)
return {'FINISHED'}

# Compile latex as mesh.
class WM_OT_compile_as_mesh(Operator):
bl_idname = "wm.compile_as_mesh"
Expand Down Expand Up @@ -533,8 +502,6 @@ def draw(self, context):

box = layout.box()
row = box.row()
row.operator("wm.compile_as_curve")
row = box.row()
row.operator("wm.compile_as_mesh")
row = box.row()
row.operator("wm.compile_as_grease_pencil")
Expand All @@ -543,7 +510,6 @@ def draw(self, context):
Settings,
LATEX2BLENDER_MT_Presets,
OBJECT_OT_add_latex_preset,
WM_OT_compile_as_curve,
WM_OT_compile_as_mesh,
WM_OT_compile_as_grease_pencil,
OBJECT_PT_latex2blender_panel
Expand Down

0 comments on commit 3f2da66

Please sign in to comment.