Skip to content

Commit

Permalink
feat: add interpolation mode to lattice operator and default to linear
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-hm committed Jun 24, 2022
1 parent 539f413 commit 9fdd252
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions deform/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def modal(self, context, event):

self.dirty = True

elif pressed(event, {'M'}):
self.interpolation_mode = (self.interpolation_mode + 1) % len(self.interpolation_modes)
self.dirty = True

elif self.key_step_up:
if no_stream(self.lattice_points_u_input_stream) and self.uniform:
self.lattice_points_u += 1
Expand Down Expand Up @@ -171,6 +175,11 @@ def invoke(self, context, event):
self.dirty = False

self.uniform = True

self.interpolation_mode = 0
self.interpolation_modes = ['KEY_LINEAR', 'KEY_CARDINAL', 'KEY_CATMULL_ROM', 'KEY_BSPLINE']
self.interpolation_labels = {'KEY_LINEAR': 'Linear', 'KEY_CARDINAL': 'Cardinal', 'KEY_CATMULL_ROM': 'Catmull-Rom', 'KEY_BSPLINE': 'B-Spline'}

self.lattice_points_u = 2
self.lattice_points_v = 2
self.lattice_points_w = 2
Expand Down Expand Up @@ -233,6 +242,7 @@ def summon_old_operator(self, context, mods):
self.lattice_points_u = self.lattice_points_u_prev = self.lattice_obj.data.points_u
self.lattice_points_v = self.lattice_points_v_prev = self.lattice_obj.data.points_v
self.lattice_points_w = self.lattice_points_w_prev = self.lattice_obj.data.points_w
self.interpolation_mode = self.interpolation_mode_prev = self.interpolation_modes.index(self.lattice_obj.data.interpolation_type_u)


def add_lattice_object(self, context):
Expand Down Expand Up @@ -292,6 +302,11 @@ def operate(self, context):
self.lattice_obj.data.points_u = self.lattice_points_u
self.lattice_obj.data.points_v = self.lattice_points_v
self.lattice_obj.data.points_w = self.lattice_points_w

interpolation_mode = self.interpolation_modes[self.interpolation_mode]
self.lattice_obj.data.interpolation_type_u = interpolation_mode
self.lattice_obj.data.interpolation_type_v = interpolation_mode
self.lattice_obj.data.interpolation_type_w = interpolation_mode

self.dirty = False

Expand All @@ -310,6 +325,11 @@ def revert(self, context):
self.lattice_obj.data.points_v = self.lattice_points_v_prev
self.lattice_obj.data.points_w = self.lattice_points_w_prev

interpolation_mode = self.interpolation_modes[self.interpolation_mode_prev]
self.lattice_obj.data.interpolation_type_u = interpolation_mode
self.lattice_obj.data.interpolation_type_v = interpolation_mode
self.lattice_obj.data.interpolation_type_w = interpolation_mode

hide_utils_collection(True)

if not self.summoned:
Expand Down Expand Up @@ -351,6 +371,12 @@ def draw_text_callback(self):
"Uniform [U]: {}".format("Yes" if self.uniform else "No"),
"Adjust all points uniformly")

interpolation_mode = self.interpolation_modes[self.interpolation_mode]
draw_hint(
self,
"Interpolation Mode [M]: {}".format(self.interpolation_labels[interpolation_mode]),
"Linear, Cardinal, Catmull-Rom, B-Spline")


def register():
bpy.utils.register_class(ND_OT_lattice)
Expand Down

0 comments on commit 9fdd252

Please sign in to comment.