Notifications
Clear all

[Closed] (SDK) what is equivalent to mxs nearestpathparam?

At last, I think I have something consistent to offer!!

It’s been really hard. But now it seems that everything works.
The algorithms failed in the areas where there are very close possible solutions (in the image below, if you check for a very dense object located in the P-1 area for example, or in the maximum of S-1 and near S-6.

In fact, the native Maxscript function fails too in this cases sometimes (if you give the default steps value), giving a “nearpathparam” that is in other segment than the good solution is.
Now, I solved it (at last!)

So, what we have here is:

  • A function to search for the nearestPathParam for a set of nodes at a time, faster and more accurate than the native function.
  • The use is explained in the attached mxs script and in the C# code.
  • For bezier curves, the speed is increased by 10 to 25 in ‘safe mode’ and by 65-100 in ‘screening mode’ comparing with default steps of the native function. For more steps in native function, times are far better.
  • For polygons, the speed is far better too (200 to 500 times).
  • The accuracy is allways better than 1E-05 for the pathParam.

Use it if you want to. It’s free! Let me know please any problems found.
The attached ZIP contains the maxscript file, the native code in C# and a compiled dll (that I hope works in computers different than mine. I’m an absolute rookie in C#)

Note: speed tests made with a 20k vertex sphere.

Sorry. Deleted. Still doesn’t work in some cases. :banghead:

It seems that consider straight segments based just in comparing distance between knots and segment length is not a good idea… The pathParam of “nearly straight segments” doesn’t have an homogeneous distribution.

Well… Here’s the final version, with some improvements:

  • Speeded up by 4 to 6 thanks to Parallel processing (now it’s really very fast).
  • Accepts defaults values for spline number and subsegments
  • Works with arrays of nodes and arrays of Point3 (two different function names)
  • Solved bug with straight segments

Use with MaxScript:

(
	dotNet.loadAssembly @"C:\...\SuperNearestPathParameter.dll"
	
	-------------------------------------------------------------------------
	-- USE WITH ARRAY OF GEOMETRY NODES
	-------------------------------------------------------------------------
	theObjects = selection as array						--	Array with the nodes to search for nearestPathParam of their verts
	theHandles = for o in theObjects collect o.inode.handle		--	Get the nodes handles
	
	thePath = $Line001								-- 	The shape node containing the spline
	thePathHandle = thePath.inode.handle				--	Get the shape handle
	numSpline = 0																-- 	Number of the spline in the shape (zero based) [default to 0]
			
	
	subSegments = 1															--	Number of subsegments for calculation [default to 3]. See note below:
	
--	subSegment = 0: search in every segment of the spline, without segment screening. Gives the best solution in 99% of the cases. (slow)
-- 	             		-n (negative values): search in every segment with n+1 subdivisions. Only needed in very special cases (not need over -2). (slower)
-- 	             		n (positive odd number): prior screening of segments with n subdivisions and n steps per subdivision. (fast)
-- 	             		n (positive even number): prior screening of segments with (n-1) subdivisions and (n+1) steps per subdivision. (fast) 
-- 	            		value 1 is the fastest one. Gives the best solution in 75% of the cases. Value of 3 gives solution in 99% of cases. Not need of values over 9.
--				For linear splines (polygons), this value isn't important for time and calculation.
--				[default to 3]
	
	cc = (dotnetclass "Proin3D.SuperNearestPathParameterMain")
	c = cc.SuperNearestPathParameterNodes   theHandles   thePathHandle   subSegments   numSpline 
--	c = cc.SuperNearestPathParameterNodes   theHandles   thePathHandle   subSegments   	-- Default value for numSpline = 0
--	c = cc.SuperNearestPathParameterNodes   theHandles   thePathHandle      					-- Default value for numSegments = 3

-- 	c variable will contain an array of arrays (one per input node). Each of these arrays contains the nearestPathParam for each vertex of the node
	
	-------------------------------------------------------------------------
	-------------------------------------------------------------------------
	
	-------------------------------------------------------------------------
	-- USE WITH ARRAY OF POINT3
	-------------------------------------------------------------------------
	--	Point3List = #([x1,y1,z1], [x2,y2,z2],...)   -- array of Point3
	--	List_Point3D = for v in Point3List collect (#(v.x, v.y, v.z))   -- Convert Point3 array to float array
	
	List_Point3D = for v in theObjects[1].verts collect (#(v.pos.x, v.pos.y, v.pos.z))
		
	c = cc.SuperNearestPathParameterList3D   List_Point3D   thePathHandle   subSegments   numSpline 
--	c = cc.SuperNearestPathParameterList3D   theHandles   thePathHandle   subSegments   	-- Default value for numSpline = 0
--	c = cc.SuperNearestPathParameterList3D   theHandles   thePathHandle      				-- Default value for numSegments = 3
		
-- 	c variable will contain an array with the nearestPathParam for each vertex in the list array
)

Any comments are wellcome.

File actualized (work with more than one node at a time).

Has any one tested the function?
After three month of work, I’ll be gratefull with any backfeed.
Thanks.

Next step: convert the pathParam to lengthParam.

That is easy (more or less) by integrating through Simpson method the segment length ‘dS’ from 0 to t:
L = SUM(dS/dt) ; L = SUM (sqrt ((dx/dt)^2 + (dy/dt)^2 + (dz/dt)^2))

What I can’t see how to do is the inverse task: how to pass from lengthParam to pathParam in case I need to. The only way I can think of is finding the 3Dpoint for lenghParam and iterate with pathParam to find the same 3Dpoint+Epsilon. But I don’t like this method at all.
Any suggestions?

Where is the DLL for download to test?? Can you share ??

Page 3 / 3