[Closed] Mass attach objects to closest vertices
Hi,
I am just about to attach 70 eyelashes to the vertices around an eye. But before I do it by hand, I guess I should check here and see if anyone knows of a maxscript that does the job. I couldn’t find anything on scriptspot.com, so I guess I am out of luck?
Anybody else know a quick solution for a mass attachment job? I’m restricted to max5 on this. The eyelashes must rotate and behave like they are linked, so I think the attachment controller is the best way to go – shame it’s so terribly cumbersome to set up…
Thanks,
Rune
worth a try.
Hi I did something quite similar some days ago but used faces instead of vertices. I just copied this using an example that comes with maxscript references so basically is the same but it is deleting objects that ended up at the same positions. Try and see if it helps, I am a newba in maxscript
eye = $nameOfEye -- [b][i]replace with the name of your mesh[/i][/b]
nFe = eye.mesh.numfaces
arrayOfPositions = #()
illBeDeleted = #()
for i = 1 to nFe do
(
actrl = Attachment() --create an Attachment controller
eyeSlash = copy $nameOfEyeSlash -- the source to be placed along the eye
-- [b][i]replace with the name of your mesh to be copied[/i][/b]
eyeSlash.position.controller = actrl --assign to the position of the eyeslash
actrl.node = eye --set the eye as the node to attach to
addNewKey actrl 0f --add a key at frame 0
theAKey = AttachCtrl.getKey actrl 1 --get the first key
--Set the face index (0-based) by reading the number of faces in the mesh
theAKey.face = i
for po in arrayOfPositions do
(
test = findItem arrayOfPositions eyeSlash.pos
if test != 0 do append illBeDeleted eyeSlash
)
append arrayOfPositions eyeSlash.pos
)
delete illBeDeleted
I hope it helps and remember, it is working with faces not vertices.
regards
Guimas
Thanks, I will see if your script contains something to help me out. I’ve written something on my own, but there is one thing missing to make this work: To place something using the attachment constraint, you need a two point value of sorts. It kind of looks like a UV value when looking at it. I am looking for a way to convert the barycentric coordinates that intersectRayEx returns into these UV values, if anybody knows how I could sure use some help
Here’s my script so far:
function superPlacer sourceObj targetObj = (
-- Clear some variables
dirRay = dirVec = intersectArr = undefined
-- Our target object must have a temporary normal modifier to turn it into a mesh
meshMod = ( addmodifier targetObj (normalModifier()) )
-- We need a direction vector, it will start a couple of units away from the object being placed pointing towards it
in coordsys sourceObj (
dirStart = point pos:[ 0, 0, 2 ] size:1 cross:true box:false
dirEnd = point pos:[ 0, 0, 1 ] size:1 cross:true box:false
)
-- Now we can figure out the direction vector thanks to some simple arithmetic
dirVec = ( dirEnd.pos - dirStart.pos )
print ("-- Direction vector for " + sourceObj.name + " is " + dirVec as string + "
")
-- Now it's time to calculate our intersection
dirRay = (ray dirStart.pos dirVec)
intersectArr = (intersectRayEx targetObj dirRay)
if intersectArr == undefined then (
dirRay = (ray sourceObj.pos -dirVec)
intersectArr = (intersectRayEx targetObj dirRay)
)
if intersectArr == undefined then (
print ("-- Could not find intersection point for object " + sourceObj.name + "
")
) else (
-- We have found a hit point! Let's place our object there
hitPoint = point pos:(intersectArr[1].pos) size:1 cross:true box:false
-- Temp! Using a copy at the moment...
newNode = copy sourceObj
newNode.name = "placeMento"
newNode.pos.controller = Attachment node:targetObj
attachKey = attachCtrl.addNewKey newNode.pos.controller 0
attachKey.face = intersectArr[2]
attachKey.coord = intersectArr[3] -- I need a 2 point something, not a barycentric 3 point!
-- We must re-orient the attached object to match its previous orientation
delete hitPoint
)
-- Cleanup, removing helpers and normal modifier
delete dirStart
delete dirEnd
deleteModifier targetObj 1
) -- End superPlacer() function definition
Ah, seems like I did something wrong with the face index. This takes care of the object position:
From this…
attachKey.face = intersectArr[2]
attachKey.coord = intersectArr[3] – I need a 2 point something, not a barycentric 3 point!
To this…
attachKey.face = intersectArr[2]-1
attachKey.coord = intersectArr[3]
That takes care of things
Now I just need to orient the damn thing. Looking at the world rotation values in the maxscript listener and in the GUI gives me two completely different orientations (one matches up, one doesnt), but I hope I can find what I am looking for with a quick search around here… I wish the max align had a maxscript equivalent…
Rune
attach all peaces of eyelashes togather and use modifier: PathDeform
to put them on a spline.
Thanks MerlinEl, but I think I am going for attachment controllers. The underlying surface is deforming quite a lot, so I think direct face attachments are the most direct way of aligning the objects to that deformation…
Rune
Yess!
I finally got my method working OK. I need to be very strict on the target surface being a mesh, and nothing else. And by attaching helpers and then parenting the attachment objects to the helpers, everything works out beautifully. Check out this little test animation:
http://www.superrune.com/offsite/2007/eyelash_test.mov
I love the way you can see the eyelashes crossing eachother, something you couldn’t get by combining all of them to a single mesh. Also, since their kept with their stack intact, I could go back and change the radii and curvature of them after the attachment (they’re bent cones).
If someone is interested, I could make an UI and put the script up on my website/scriptspot for downloading.
Rune