Geometry/Surface constraint


#1

Hello,

I’m looking for a way to do exactly the same in MAX as ShaderOp coded for SoftImage. He called it Geometry constraint:

http://shaderop.com/softimage/geometry-constraint/

Anyone any ideas? Much appreciated!


#2

Attachment Constraint does just this.


#3

No, it does not. Attachment Constraint allows to attach one piece of geometry to the surface of another. you can set which face of the host’s geometry you want it attached to and to some degree its place upon that face.

It does not allow one to animate the attached object easily over the surface of the host. The Surface Constraint does a better job as you can set the x and y coordinates of the attached object with sliders, but that’s not what I’m looking for either.

What I need is the space of movement of the attached object to be constraint to the surface of the host object. Please take a look at the vimeo movie hosted on the link I posted, to see exactly what I mean:


#4

sorry my mistake


#5

You may try a little scripting using the intersectRay command which allows you to shoot a ray from any point and calculate the intersection coordinates with a surface.

Maybe someone even posted such thing on scriptspot.


#6

another workaround is using Peter Watje’s ConformMod plugin (available on maxplugins.de) on a single-poly plane, to constrain it to the surface object, and attaching your target object to this plane with an attachment constraint.

It might not work for all cases, and will probably need specific tweaking for most, but generally it works.


#7

Float Script on the z pos controller


theray = ray ($Sphere01.pos + [0,0,50]) [0,0,-1]		--switch sphere01 with the object you're putting this on
intersection = intersectRay $Plane01 theray  -- Plane01 or the object you want to constrain to
if intersection != undefined then
(
	intersection.pos.z
)
else(0)

On the rotation controller a float script:


theray = ray ($Sphere01.pos + [0,0,50]) [0,0,-1] -- shooting from higher above, so we get a hit
intersection = intersectRay $Plane01 theray 
if intersection != undefined then
(
	newmatrix = matrixFromNormal intersection.dir
	newmatrix.rotation
)
else
( quat 0 0 0 1)

This contstrains the position and matches the z rotation of the object to the normal of the conform object --only works from a top down thing like a plane, would be easy enough to modify to work on another object, but this is just a quick way of doing it.


#8

Ian, that’s pretty awesome. Do you have any ideas about what would be the best strategy of modifying this script to work with any polygonal object regardless of axis?


#9

I sure do… instead of shooting the ray on the z axis down, you’d shoot it towards an object instead… I got it working really quick with a “helper” object to generate the ray from… not sure how to override the position while still being able to manipulate it in the viewport … I can see how this wouldn’t work for most objects, as it is shooting a ray towards the pivot… you’d need to constantly get the nearest face / barycentric coord on the surface, but I’m not sure how to do that, though it wouldn’t take me too long, I’m at work :smiley:


  
  --applied to "Torus01" position controller
  dependson $Cone01 --my helper object --so it updates when you move your helper
  thedirection = normalize($Sphere01.pos - $Cone01.pos)  --conforming to the sphere
  theray = ray $Cone01.pos thedirection
  intersection = intersectRay $Sphere01 theray 
  if intersection != undefined then
  (
  	intersection.pos
  )
  else([0,0,0])
  

and the code for the rotation controller:


 --applied to "Torus01" rot controller
 dependson $Cone01 --my helper object --so it updates when you move your helper
 thedirection = normalize($Sphere01.pos - $Cone01.pos)  --conforming to the sphere
 theray = ray $Cone01.pos thedirection
 intersection = intersectRay $Sphere01 theray
 if intersection != undefined then
 (
 	newmatrix = matrixFromNormal intersection.dir
 	newmatrix.rotation
 )
 else(quat 0 0 0 1)
 
 

#10

you could always cycle through all the faces and figure which one is the nearest, but that would probably stop being so quick :slight_smile:


#11

Yes, but then I think it’d pop to the face position when it gets to the next nearest face, probably wouldn’t be smooth…


#12

Thank you so much for your help, SoLiTuDe!! I just can’t quite get your script to work. Could you maybe post your scene?

Thanks again!


#13

File is done with Max2009


#14

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.