Notifications
Clear all

[Closed] Wrap/Conform surface on surface HELP NEEDED

Hello guys, I’m a noob in maxscript.
Now my challenge is to create a script similar to Wrapit or the Conform brush of Max’s Graphite Tool.

So far I came up with this code, which works but it’s very slow even on simple objects, so I was thinking if you guys have suggestion to make this faster, and I’m especially looking for already built in methods to find the closest distance which will run faster for sure.
Or maybe there’s a smarter mathematical solution to speed up the process.
Thank you for your attention.




clearListener();
global source = $Plane001 --Source that will be wrapped SHOULD be Editable Poly object
global target = $Sphere001 --the target
global sourceVN = polyop.getnumVerts source --the vertex count of the source
global vector = tape pos:[0,0,0] target:(targetObject pos: [1,1,1] ) -- a tape helper which will help to measure distances
global beenthere = #() --a temporary array for current vertex which records all the used positions
global omega = 18	
global om = 360/omega --the angle in which rays will be send to find intersection
global v_pos --vertex position
global t_pos --the position when the ray will hit the target
global intR
global shortest --variable for the shortest distance which will be found amound ray intersections
-- for all the vertexes creat a Dom of rays to locate the shortest from the target to vertex
for v =1 to sourceVN do
(
	
	v_pos = polyop.getVert source v
	--first circle
	for i = 1 to omega do
	(
		
		--second circle
		for f = 1 to omega do
		( 
			
			tm = transMatrix v_pos 
			preRotateZ tm (om*i)
			preRotateY tm (om*f)
			preTranslate tm [2,0,0]
			t_pos = tm.pos 
			
			found =  findItem beenthere (t_pos as string) --checking if this position was already tested for this vertex
			vector.pos = v_pos
			vector.target.pos = t_pos
			intR = intersectRay target (vector as ray)
			
			if found == 0 and intR != undefined do
			(				
				
				if shortest == undefined do shortest = intR.pos
				
				if (distance v_pos shortest) > (distance v_pos intR.pos) do shortest = intR.pos --if the new distance is shorter pick it
				append beenthere (t_pos as string)
			
				polyop.setVert source v shortest -- set the current vertex to that position
			)
		)
		
	)
	beenthere = #() -- erase the array to make it ready for the next vertex
	
)
delete vector -- erase the tape





1 Reply

Have you had a look at RayMeshGridIntersect?