Last active
July 26, 2021 02:28
-
-
Save raganmd/9a3adc738803682789eb653d42c0c962 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bezier | |
import numpy as np | |
# press 'Setup Parameters' in the OP to call this function to re-create the parameters | |
def onSetupParameters(scriptOp): | |
page = scriptOp.appendCustomPage('Custom') | |
p = page.appendFloat('Val1', label='P1', size=3) | |
page = scriptOp.appendCustomPage('Custom') | |
p = page.appendFloat('Val2', label='P2', size=3) | |
p = page.appendInt('Valpoints', label='Points') | |
scriptOp.par.Valpoints.normMax = 1000 | |
scriptOp.par.Valpoints.normMin = 2 | |
return | |
# called on cook | |
def onCook(scriptOp): | |
scriptOp.clear() | |
# pars | |
val1 = scriptOp.par.Val11.tuplet | |
val2 = scriptOp.par.Val21.tuplet | |
u_valPoints = scriptOp.par.Valpoints.eval() | |
# we can move the point calculation step into another function | |
points_array = calc_points_list(val1, val2, u_valPoints) | |
# we only need to create the poly once | |
poly = scriptOp.appendPoly(u_valPoints, closed=0, addPoints=True) | |
# When then update the positions of the points on the poly | |
for each_point in range(u_valPoints): | |
poly[each_point].point.P = (points_array[0][each_point], points_array[1][each_point], 0) | |
return | |
def calc_points_list(val1, val2, u_valPoints): | |
# function from bezier_library | |
nodes = np.asfortranarray([ | |
[val1[0].eval(), val1[1].eval(), val1[2].eval()], | |
[val2[0].eval(), val2[1].eval(), val2[2].eval()], | |
]) | |
curve = bezier.Curve(nodes, degree=2) | |
s_vals = np.linspace(0.0, 1.0, u_valPoints) | |
points_array = curve.evaluate_multi(s_vals) | |
return points_array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks a lot