Notifications
Clear all

[Closed] help needed – link to vertex script

I’ll start off by saying I’m new to Maxscripting, but I do have years of experience as an actionscript developer. I’ve come across a good tutorial online about how to build a scrip to automate the linking of an object to a vertex of another object at http://www.3dluvr.com/content/article/51

 Unfortunately the script didn’t work, it was unable to get the vertex number nor does the enable of the Link_Me_button work correctly, one any button in the scrip is pressed the link me button enables, it does not wait for both of the true statements that It should wait for.

 I’ve edited the scrip by searching around online and through no easy feat of trial and error I’ve got it working to a degree.  The version I have can now get the selected vertex of an object that has a mesh select modifier.  The label underneath the button fully functions and changes accordingly,

 Here is the real problem I’m having; the link_me_button creates the position script just fine, and however I can’t get the vertex number by itself. 

 Child_Obj.position.controller.script = ("pos = getvert $" + (parentOBJ.name) + " " + (vertex))

 I am either given an error stating it can not convert to string, number, text, or float no matter how I try.  I can get it down to a number with surrounded by brackets and a # in front of it. Can anyone help?

MainFloater = NewRolloutFloater “Link To Vertex” 300 315 –creates the main floater

Rollout Vert_Linker “Vertex Linker” ( –defines the Rollout with all the settings

 group "Pick Vert" (                            --defines a group of settings (optional)
 
     Label getvert1L "Select a vertex to be parent"            --labels create text on the rollout
     Label getvert2L "then hit 'Get Selected Vert'"
     Button GetVert_Button "Get Selected Vert"            --defines the get vert button
     Label vertnumL "Vertex Number: (none selected)"
 
 )
 
 group "Pick Child" (    

     Label childL "Select Child Object"
     PickButton GetChild_PB "Get Child"                --defines a button that puts you in to a selection mode
     Label childnameL "Child Object: (none)"

 )    
     
 group "Link ME Plz!" (
 
     Button LinkME_Button "Link ME!"    enabled:off        --defines the button to press to link
 )
 -----------------------------------------------------------------------------
 on GetVert_Button pressed do (
 
 
     parentOBJ = $
     if classof parentOBJ == Editable_Mesh do (
         vertnum = (getvertselection parentOBJ) as array
         if vertnum.count>0 do (
             vert = getVert parentOBJ vertnum[1]
             vertex = (vertnum as string)
             vertnumL.text = "Vertex Number: " + vertex
             VertPicked = true
         )
     )
     if ChildPicked == true do LinkME_Button.enabled = on
 )
 -----------------------------------------------------------------------------    
 on GetChild_PB picked obj do (
     
     Child_Obj = obj
     childnameL.text = "Child Object: " + Child_Obj.name
     ChildPicked = true
     if ChildPicked == true do LinkME_Button.enabled = on
 )
 -----------------------------------------------------------------------------
 on LinkME_Button pressed do (
     
     Child_Obj.position.controller = position_script()
     Child_Obj.position.controller.script = ("pos = getvert $" + (parentOBJ.name) + " " + (vert.text))
 )

) – Close Rollout

addRollout Vert_Linker MainFloater – Add Rollout to the main floater

the POS scrip in on the object just need to read:
pos = getvert $object.name number
i get eveerything but a number

20 Replies
 S-S

HI lemasterjg

If i got it right (didn’t read your script), you want to “link something to vertex” you mean you want to attach something to a vertex, and then even if the object itself deforms, linked object should follow?

If this is the case, you need to use attachment constaint, which works with faces, not vertices. Look into barycentric coordinates, and if i remember correctly, how to part of max script help has good tutorials on this subject.

Hope this helps.

yes that is exactly what i want to do, but its only one part of the script i plan on making. I also plan on adding a parralel to normals option to the script, somtimes you want an object to stay parralell and other time you don’t as well as a pick vertex mode to the script. right now you have to add a select mesh modifier to the top of the stack witht he vertex desired. I want to make teh prosess more audomated by having a button that changes the parent mesh into a vertex select form without having to add a mesh modifier, if that makes any since.

thank you i will look into barycentric coordinates and how to understand it further.

 S-S

Maybe these can help you too:

myMesh = $.mesh – Mesh property of object
myMesh.verts[1].pos – Vert N position in object space

myFacesUsingThisVert = meshop.getFacesUsingVert myMesh 1 – Returns bitarray of faces in object, if it’s using this vert, it will be true

intersectRay – With this you can shoot a ray using vector and a position to surface, and get faces it hit…

im trying to do the same kind of thing but instead of using just one vertex im trying to work with 4 vertexs, something like generative componets or paracloud but done in 3d max.
The idea is to create a component and attack it to a target surface…so if the surface is deformed the componet will adapt to the new configuration, considering it’s base polygon
I first tryied using scatter, but this tool is very limited, since you can only distribute the componet in the target surface’s in one vertex or to do it randomly…
then i tryied attach and then Paul Hormis’s Attach By Local Z script, but still this relationship is based in only one point helper…so the component follows the target surface in its rotation and position parameters, but will not adapt to the surface’s polygons new configuration…
please help!!!..is it possible?
thanks…

mariovargara: if i understand correctly, you want to create a point in the middle of a face that stays in the exact center of the face, based of the relationship of the 4 corners? if thats what you are trying to do you would need to average to locations of all 4 vertices together to get on set of locations that is in the middle of the 4 vertices

S-S: thanks again, i’m looking into all of your suggestions and reading up and researching how they all work, am i correct in assuming the

myMesh = $.mesh – Mesh property of object
myMesh.verts[1].pos – Vert N position in object space

would give me the x,y,z of one particular vert? i also tried the attach function which to my knowledge is relatively new in 2008, I’ve switched over to maya a few years ago and forgot about max all together now i have to return. a position script only seems to update on playback, where as the attach function updates regardless, that I like so I will be using the attach constraint instead of a pos script.

I’ve decided to not attach an object directly, I will be making a dummy object as an intermediate between the vertex and the intended object. This will allow the child object to move freely but stay in the same relationship as the vertex. It just gives an animator a little more freedom and control.

 S-S

“would give me the x,y,z of one particular vert”

Yes

“I’ve decided to not attach an object directly, I will be making a dummy object as an intermediate between the vertex and the intended object”

Yes. That’s what i have done too. It’s definitely the best choice. You have an option to animate position and orientation of “attached” object too.

i’ve desided to rebuld fromt he ground up, and i want to use the attach constrain as the backbone instead of a pos script.

ok here is what i have so far:


   MainFloater = newRolloutFloater "Link to Face" 250 315
   
   rollout face_linker "Link to Face"(
       
       Group "Pick Parent Face" (
           pickButton parent_PkBtn "Pick Parent Object"
           label Parent_lbl "Parent Object: (none selected)"
           pickButton parentFace_PkBtn "Pick Face" enabled: off
           label parentFace_lbl "Face Number: (none selected)"
           )
           
       Group "Creat Dummy-Child"(
           label dummyname_lbl "Name of new Dummy-Child object"
           edittext dummy_txt "" fieldWidth:200
           button createDummy_btn "Create Dummy Child" enabled: on
           )
       Group "About"(
           button help_btn "Help" pos:[70,250] width: 50
           button about_btn "About" pos:[130,250] witdh: 50
       )
   --Button comamnds:
               
       on parent_PkBtn picked obj do (
           parentOBJ = obj
           Parent_lbl.text = "Parent Object: " + parentOBJ.name
           parentpicked = true
           if parentpicked == true do parentFace_PkBtn.enabled = on
           )
           
       on parentFace_PkBtn picked obj do (
  [b]NEED HELP HERE[/b]
           )
           
       on createDummy_btn pressed do(
           if dummy_txt != "" do (
               new_obj = dummy ()
               dummyname = dummy_txt.text + "_"
               new_obj.name = (uniquename dummyname)
           )
       )
   )
       addrollout face_linker MainFloater
 

above where i have the “NEED HELP HERE” is where i’m stuck at, i was reading about the intersectray and i somewhat understand that but i’m suck at how to grab one face of the parent object, which is stored as parentOBJ. any thoughts?

In videogames we cannot use any deformers from DCC apps other than bones and morphs, so sometimes we ‘bake’ arbitrary deformations down to bones. An easy way of doing this is driving the attached object (bone) via a float script that uses getVert to grab the point position, or a ‘when’ (user driven), or a callback on time slider change. Is this kind of what you were referring to?

This is a simple way of getting even things like cloth (prebaked) into a game engine.

Page 1 / 3