Notifications
Clear all

[Closed] Create vertex in spline segment in defined position

Hi
Is there any way to create vertex at a defined position
or i have to use “splineOps.startInsert ” or “splineOps.startRefine “

delete objects
sp = splineshape adaptive:on wirecolor:yellow
addnewspline sp
addknot sp 1 #beziercorner #curve [0,50,100] [0,50,100] [250,0,50]
addknot sp 1 #beziercorner #curve [0,-50,0] [-250,0,50] [0,-50,0] 	
updateshape sp
thePosition=point pos:(lengthInterp  sp 1 .4)
6 Replies

From MaxScript Help:
refineSegment <spline_index_integer> <seg_index_integer> <seg_interp_param_float>
“Adds a new knot to the indexed segment of the indexed curve at a place along the indexed segment corresponding to the given segment interpolation parameter.

This value is a float in the range of 0.0 to 1.0 specifying a proportion along the segment.

The new knot coordinates, and in-vector and out-vector are automatically computed to maintain the segment’s existing curvature.

This is the primitive used by the refine() function in the Edit Spline modifier.

You can use the MAXScript spline path interpolation functions to derive segment parameters given that a curve’s path interpolation parameter is divided evenly among the segments in a curve.

Given a path interpolation parameter u in a spline of m segments, the target segment is:

n = (m*u) as integer + 1

The segment parameter is:

f = (u-(n-1)/m) * m

This can be refactored to the following which will reduce roundoff error in the calculation:

f = u*m-n+1

The refineSegment() function returns the index of the newly inserted knot. “

The only additional thing you should need is to convert from lengthParam to pathParam.

Thanks for the reply
aaandres I knew the refineSegment
but I just have the position or the value between 0.0 and 1.0 and I don’t want to use segment number.
You may show the full answer
But unfortunately I didn’t understand
Would you please give me an example

Comvert your 0.0 to 1.0 lengthParam value to pathParam value through maxscript command ‘lengthToParam’ (or something similar, I’m not with my PC).
This value is u.

Then, use the formulas above to find the segment n and the segment param f to use the ‘refineSegment’ command.



Imagine this is your path. Three segments. You want to insert a vertex at lengthParam = 0.60 (dot in red).
Then you convert your lengthParam to pathParam:
lengthToPathParam < shape > [ <curve_num> ] [steps:< integer > ]
u = lengthToPathParam sp 1 0.60 steps:10000

Imagine you get u=0.47
Then, you get the segment number:
n = (3 * 0.47) as integer +1 – You get n = 2
Then, you get the segmentParam:
f = 0.47 * 3 – 2 + 1 – You get f = 0.41

Now, you use the refineSegment command:
newVertNumber = refineSegment sp 1 n f

And that is!

This is a pro Maxscript forum
thanks for taking your time for a beginner like me
I really appreciate it

1 Reply
(@aaandres)
Joined: 10 months ago

Posts: 0

I don’t think this is a pro Maxscript forum. It’s just a forum where some users are absolutely ‘pro’ and give their knowledge for free to everyone who ask for help with education and with an interest in learning. I’m not at all one of them. Of course I’m not a beginner either. But we all were one day.
Once again, thanks to all of them for all the help and advice they give us.