Notifications
Clear all

[Closed] Patch Deform

Goad: to make a spline conform to deformed mesh
Uses: to make a road on a “noisy” (plane with noise modifier on it ) terrain
idea01 : the dumb way

i made a spline path in the top view then i applied the normalize spline modifier so that i get more points on the spline while maintaining the shape of the curve (i used a setting of 5.0) next i applied a “Spline I.K. Control” modifier (my settings : link types = no linking ; press create helpers ) and that gives me a set of point helpers that can be used to deform the shape of the spline (similar to a linked xform modifier applied to each vert in the spline)
next i made a plane and gave it 32 length and width segments and applied a noise modifier that gave the ground surface to place my road spline on
next i shot rays from each of the point helpers in the road spline in the direction of the ground surface ([0,0,-1]) – my road spline is exactly above the ground surface – and where the ray intersected the ground surface i placed the point helper controlling the spline onto the intersecting point heres the maxscript for it :

for p in helpers do
(
	myray = ray p.pos [0,0,-1]
	col = intersectray $plane01 myray
	p.pos = col.pos
)

this deformed the confoms the spline to the deformed plane
the problem with this technique is that if i modify the plane the spline doesnt change and if i loft a rectangle on the spline it doesnt stick to the surface

idead02: patch and surface deform

is there any other way of doing this ?? i have tried patch deform and surface deform but they only work for quad patches and nurbs also when i loft my spline after doing patch deform it doesnt loft about the deformed spline instead it lofts on the original spline :S ( i tried to convert to editable spline , group etc… but no use ) so i tried to deform a box with patch deform but i need to first do a path deform on the box so it represents my roads curve after doing path deform on the box … the patch deform modifier gives wierd results if applied to the box … I am in deadlock ! s.o.s

any help is appreciated !!

4 Replies

only one thing that you need to add is Attachment (Position Controller) to your point helpers using terrain surface as “attached to” object.

Ah! i almost forgot the attachment contraint … good 1. so i finally got the spline to conform to my deformed plane.

But i had to use some more maxscript to get the attachment constraint to work because

  1. i cannot go in manually attach the constraint to 41 point helper objects and,
  2. the attachment constraint initially sets the rong face and A, B values (the face index,
    and the bary coords)

so i used the ( intersectrayex <node> <ray> ) function which gives me the face and bary coords of the face at which the ray intersects the <node> and then i added these values to the attachment constrain via maxscript like so :

to better understand the code please have a look at the attached .max files

for p in helpers do 
  (
  	/*i shoot a ray from the point helpers which are on top of the deformed plane */
  	
  	theray = ray p.pos [0,0,-1]
  	
  	/* col = collision it holds the 3 values col[1] = ray , col[2] = the index of the face at 
  	which the ray intersects and col[3] = barrycoords of that face*/
  		
  	col = intersectrayex $Plane01 theray	
  
  	/*i add the attachment constrain to my helper object*/
  	
  	p.position.controller = attachment node:$plane01
  	
  	/*next i add a new key to my controller*/
  	
  	attachCtrl.addnewkey p.position.controller 0
  	
  	/*i fetch this newly added key so i can modify the faceindex and the barycoords*/
  	mykey = attachCtrl.getkey p.position.controller 1
  	
  	/*the next 2 lines make sure that the point object is at the correct position on the 
  	deformed plane*/

  	--mykey.face = col[2] wrong !
	
	mykey.face = ((col[2] as integer) - (1 as integer)) -- returns correct face index    
  	mykey.coord=[col[3].x,col[3].y] --the bary coords
  	
  	attachctrl.update p.position.controller
  )

Note* : in order for the intersectrayex function to work correctly the <node> parameter must have a mesh select modifier on the top of its stack or must be an editable mesh
i think this is because bary coords are calculated for faces which show up only under editable mesh (editable polys donot have faces) … Correct me if i am wrong… thanx

i have also attached the .max file

unfortunately the script works correctly only if the deformed plane is tessalated [a lot!!]
let me see i will do some further research and post if i find something better

PS: i have attached 2 max files the start and the end!

when you attach helpers to the plane calculate intersection with plane’s mesh (snapshotasmesh) and use this returned data (face, bary) in attachment controller

hmm… snapshottomesh function doesnt return the bary coords and the face index it just returns the type of the mesh (tri mesh) ?