Skip to content

Instantly share code, notes, and snippets.

@raganmd
Last active July 26, 2021 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raganmd/9a3adc738803682789eb653d42c0c962 to your computer and use it in GitHub Desktop.
Save raganmd/9a3adc738803682789eb653d42c0c962 to your computer and use it in GitHub Desktop.
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
@haraldpliessnig
Copy link

thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment