Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further Performance improvements #12

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
21 changes: 9 additions & 12 deletions tensionmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ def tm_update(obj, context):

# create vertex color list for faster access only if vertex color is activated
if obj.data.tm_enable_vertex_colors:
vertex_colors = [0.0] * (number_of_tm_channels * num_vertices)
vertex_colors = [[0.0]*number_of_tm_channels]* num_vertices
ScottishCyclops marked this conversation as resolved.
Show resolved Hide resolved

#lambda for clamping between min and max
ScottishCyclops marked this conversation as resolved.
Show resolved Hide resolved
clamp = lambda value, lower, upper: lower if value < lower else upper if value > upper else value

# calculate the new values
# store them in the vertex_colors array if the feature is active
Expand All @@ -164,24 +167,20 @@ def tm_update(obj, context):

if weights[i] >= 0:
# positive: stretched
stretch_value = max(obj.data.tm_minimum, min(
obj.data.tm_maximum, weights[i]))
stretch_value = clamp(weights[i], obj.data.tm_minimum, obj.data.tm_maximum)
else:
# negative: squeezed
# invert weights to keep only positive values
squeeze_value = max(obj.data.tm_minimum, min(
obj.data.tm_maximum, -weights[i]))
squeeze_value = clamp(-weights[i], obj.data.tm_minimum, obj.data.tm_maximum)

if obj.data.tm_enable_vertex_groups:
add_index = [i]
group_squeeze.add(add_index, squeeze_value, "REPLACE")
group_stretch.add(add_index, stretch_value, "REPLACE")

if obj.data.tm_enable_vertex_colors:
# red
vertex_colors[i * number_of_tm_channels] = stretch_value
# green
vertex_colors[i * number_of_tm_channels + 1] = squeeze_value
# red, green, blue, alpha
vertex_colors[i] = (stretch_value,squeeze_value, 0.0, 1.0)
ScottishCyclops marked this conversation as resolved.
Show resolved Hide resolved

# store the calculated vertex colors if the feature is active
if obj.data.tm_enable_vertex_colors:
Expand All @@ -193,9 +192,7 @@ def tm_update(obj, context):
for loop_vertex_idx, loop_idx in enumerate(polygon.loop_indices):
vertex_color = colors_tension.data[loop_idx]
vertex_idx = polygon.vertices[loop_vertex_idx]
# replace the color by a 4D vector, using 0 for blue and 1 for alpha
vertex_color.color = (vertex_colors[vertex_idx * number_of_tm_channels],
vertex_colors[vertex_idx * number_of_tm_channels + 1], 0, 1)
vertex_color.color = vertex_colors[vertex_idx]


def tm_update_handler(scene):
Expand Down