Skip to content

Instantly share code, notes, and snippets.

@darkvertex
Created March 26, 2013 21:34
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 darkvertex/5249517 to your computer and use it in GitHub Desktop.
Save darkvertex/5249517 to your computer and use it in GitHub Desktop.
Evenly distributed points on a Softimage curve
si = Application
def frange(x, y, jump):
'''
Like range() but with float values.
'''
while x < y:
yield x
x += jump
def evenPositions(crv, quantity):
'''
Get an amount of evenly spaced positions on a given curve.
'''
subcrv = crv.ActivePrimitive.Geometry.Curves(0)
percs = [num for num in frange(0.0, 100.0, 100.0 / quantity)]
percs.append(100)
ppos = [ subcrv.EvaluatePosition( subcrv.GetUFromPercentage(percs[i]) )[0] for i in xrange(len(percs)) ]
return ppos
def main():
size = float( Application.XSIInputBox("What particle size do you plan on using?", "So I know the spacing...", 1) )
newCurves = []
si.OpenUndo("Make evenly spread linear curves")
for crv in si.Selection:
quantity = int(crv.ActivePrimitive.Geometry.Curves(0).Length / (size*2.0))
positions = evenPositions(crv, quantity)
positions = ["(%s,%s,%s)" % (a.X,a.Y,a.Z) for a in positions]
newCurve = si.CreateCurve( 1, 0, ",".join(positions), False)('Value')
newCurve.Name = crv.Name+'_evenlySpaced'
newCurves.append(newCurve)
si.SelectObj(newCurves)
si.CloseUndo()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment