Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit fe686cd

Browse files
committed
Added support for blender 2.9
1 parent 41361e0 commit fe686cd

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

helpers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from bpy import context, ops, data
1+
from bpy import context, ops, data, app
22
from typing import List, Tuple
33

44

@@ -43,6 +43,14 @@ def add_object(object, collection=None):
4343
context.scene.objects.link(object)
4444

4545

46+
def apply_modifier(modifier_name: str):
47+
"""Apply the given modifier on the current object (2.8/2.9)"""
48+
if app.version >= (2, 90, 0):
49+
ops.object.modifier_apply(modifier=modifier_name)
50+
else:
51+
ops.object.modifier_apply(apply_as='DATA', modifier=modifier_name)
52+
53+
4654
def hex2rgb(hex: str):
4755
"""Convert HEX color to Blender RGBA"""
4856
hex = hex.lstrip("#")

import_keyboard.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from math import pi
1818
from . import parse_json
1919
from . import labels
20-
from .helpers import hex2rgb, add_object, select_object, unselect_all, set_active_object
20+
from .helpers import *
2121
from .materials import make_key_material, make_led_material
2222
from .key import Label, Key, KeyBase, KeySegment, Profile
2323

@@ -39,7 +39,7 @@ def append_object(obj_name: str):
3939
object = bpy.data.objects[obj_name]
4040
set_active_object(object)
4141
for mod in object.modifiers:
42-
bpy.ops.object.modifier_apply(modifier=mod.name)
42+
apply_modifier(mod.name)
4343

4444
appended_objects.append(obj_name)
4545

@@ -345,7 +345,7 @@ def read(filepath: str):
345345
set_active_object(case)
346346
# bevel the corners
347347
bpy.ops.object.modifier_add(type="BEVEL")
348-
bpy.ops.object.modifier_apply(modifier="Bevel")
348+
apply_modifier("Bevel")
349349

350350
bpy.data.materials["Stem"].node_tree.nodes[
351351
"Diffuse BSDF"].inputs["Color"].default_value = keyboard.stem_color

labels.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
import os
44
from math import pi
5-
from .helpers import select_all, unselect_all, add_object, select_object, set_active_object, in_charset
5+
from .helpers import *
66
from .key import Profile, Label, Key
77
from .char_ranges import CJK_RANGES, DEJAVU_RANGES
88
from typing import Tuple, List
@@ -77,7 +77,7 @@ def add_curve(key: Key, curve, text_length: int, label_material_name: str, label
7777
curve.modifiers["Remesh"].mode = 'SMOOTH'
7878
curve.modifiers["Remesh"].octree_depth = (4 if text_length == 1 else 7)
7979
curve.modifiers["Remesh"].use_remove_disconnected = False
80-
ops.object.modifier_apply(apply_as='DATA', modifier="Remesh")
80+
apply_modifier("Remesh")
8181

8282
unselect_all()
8383
set_active_object(curve)
@@ -90,7 +90,7 @@ def add_curve(key: Key, curve, text_length: int, label_material_name: str, label
9090
context.object.modifiers["Shrinkwrap"].use_positive_direction = True
9191
context.object.modifiers["Shrinkwrap"].use_negative_direction = True
9292
context.object.modifiers["Shrinkwrap"].target = key_object
93-
ops.object.modifier_apply(apply_as='DATA', modifier="Shrinkwrap")
93+
apply_modifier("Shrinkwrap")
9494

9595
# create clipping cube
9696
ops.mesh.primitive_cube_add(location=(box[0] - box[2] * 0.5, box[1] + box[3] * 0.5, key_object.location[2] + key_object.dimensions[2] / 2))
@@ -107,7 +107,7 @@ def add_curve(key: Key, curve, text_length: int, label_material_name: str, label
107107
ops.object.modifier_add(type='BOOLEAN')
108108
context.object.modifiers["Boolean"].operation = 'INTERSECT'
109109
context.object.modifiers["Boolean"].object = cube
110-
ops.object.modifier_apply(apply_as='DATA', modifier="Boolean")
110+
apply_modifier("Boolean")
111111
data.objects.remove(cube)
112112

113113
for edge in context.object.data.edges:
@@ -194,7 +194,8 @@ def add(key: Key, fonts: List, label_position: int, material_name: str, key_obj)
194194
label_length = len(key_label.text)
195195

196196
curve = None
197-
if (match := re.fullmatch(r"<i class=['\"](fa|kb) (fa|kb)-([a-zA-Z0-9\-]+)['\"]><\/i>", key_label.text)) is not None:
197+
match = re.fullmatch(r"<i class=['\"](fa|kb) (fa|kb)-([a-zA-Z0-9\-]+)['\"]><\/i>", key_label.text)
198+
if match is not None:
198199
label_size *= 0.5
199200
curve = add_icon(match[1], match[3], label_size, label_position, box)
200201
label_length = 1

parse_json.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ def load(filePath: str) -> Keyboard:
8686
keyboard.name = row["name"]
8787
if "switchType" in row:
8888
keyboard.switch_type = row["switchType"]
89-
if "notes" in row and (color_match := re.search(r'led_color:\s*#([a-fA-F0-9]{3,6})', row["notes"])) is not None:
90-
keyboard.led_color = '#' + color_match[1]
91-
if (brightness_match := re.search(r'led_brightness:\s*(1|0\.?[0-9]*)', row["notes"])) is not None:
89+
if "notes" in row:
90+
color_match = re.search(r'led_color:\s*#([a-fA-F0-9]{3,6})', row["notes"])
91+
brightness_match = re.search(r'led_brightness:\s*(1|0\.?[0-9]*)', row["notes"])
92+
if color_match is not None:
93+
keyboard.led_color = '#' + color_match[1]
94+
if brightness_match is not None:
9295
keyboard.led_brightness = float(brightness_match[1])
9396
if "css" in row:
9497
keyboard.css = row["css"]

0 commit comments

Comments
 (0)