Notifications
Clear all

[Closed] help needed – link to vertex script

I quickly mocked this up (excuse my removing some of your UI). There are some little things I have learned over the years in here (like changing the button text in favor of a label, closing the window if open already, etc). I think Bobo did something like this his maxscript DVD, you could grab this if you were serious about making maxscript tools.

Caveats:

  • polyop doesn’t work on some geometry types, you should get the geo type before and use the appropriate method.
  • as the faces deform i am not orienting the objects to the face, only positioning them, i think yo ucan see from this how you would orient them to the normal
  • if you have any qs just ask as i didnt comment really, and i really don’t know what i am doing (self taught), anyone feel free to school me on things below; I have a lot to learn about maxscript


 if MainFloater != undefined then (closerolloutfloater mainfloater)
 
 MainFloater = newRolloutFloater "Link Tools" 180 182
    
 rollout face_linker "Link to Face"
 (
    Group "Link to Faces"
    (
 	   button getFaceBtn "Get Selected Face(s)"
 	   edittext dummyTxt "Name: " fieldWidth:100 text:"attDummy_"
 	   button createDummiesBtn "Create attachDummies"
 	   checkbox alignDummies "Align to face normal" checked:true
 	)
    Group "Link to Vertices"
 	(
 		--we do this next
 	)
 
 --locals
 	local theNode
 	local theFaces
 	
 --ui
 	on getFaceBtn pressed do
 	(
 		if selection.count != 1 then (return undefined)
 		theNode = $
 		theFaces = polyop.getFaceSelection theNode
 		getFaceBtn.text = ((theFaces as array).count as string + " Faces on " + theNode.name)
 	)
 	   
 	on createDummiesBtn pressed do
 	(
 		undo "createDummies" on
 		(
 			i=1
 			for face in theFaces do
 			(
 				theFace = ((polyop.getFaceSelection theNode as array)[i])
 				local new
 				if alignDummies.checked == true then
 				(
 					new = dummy name:(dummyTxt.text + i as string) position:(polyop.getFaceCenter theNode theFace) dir:(polyop.getFaceNormal theNode theFace)
 				)
 				else
 				(
 					new = dummy name:(dummyTxt.text + i as string) position:(polyop.getFaceCenter theNode theFace)
 				)
 					new.position.controller = position_script()
 				new.position.controller.script = ("polyop.getFaceCenter $'" + theNode.name +"' " + theFace as string)
 				i += 1
 			)
 		)
 	)
 )
 addrollout face_linker MainFloater

anubis: thank you, i have heard that game engines do no like basic deformers like bend and twist, but for now i’m not restricted by those conventions. is there any way to force the user to select one face in particular without the need of applying a mesh select modifier to the stack? all i need is the number of one face to use for the attach constraint.

Well, you can shoot a ray from the mouse cursor to the first polygon it hits, but wouldn’t you want to be able to use multiple polygons? The only way to select polygons in max to my knowledge is in a subobj level or like meshselect.

Maybe someone here can show you an example of firing a ray perpendicular to the viewport from the mouse position and doing a ray/scene intersect on a polygon. I can’t do this off the top of my head, but if no one chimes in can maybe do this tomorrow. Max has a lot of things like get node from hit, and pickpoint, and the like, but to my knowledge none return the polygon hit.

I used to live in Gainesville, and I am originally from Florida.

I’ve solved my problem about selecting a face, the script temporarily adds the mesh select modifier to the modify stack, and removes the modifier after the face is obtained. The only part now is to set up the attach constraint to the new dummy object by using the parentOBJ and the paretnFace variables that have the object and face sorted in them.

 My only problem now is that the maxscript listener doesn’t give me any clue as to how to add or manipulate the attach constraint, anyone know how?

updated Code:


 rollout face_linker "Link to Face"(
 	
 	Group "Pick Parent Face" (
 		pickButton parent_PkBtn "Pick Parent Object"
 		label Parent_lbl "Parent Object: (none selected)"
 		label getface_lbl "" 
 		Button parentFace_Btn "Grab 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: off
 		)
 	Group "About"(
 		button help_btn "Help" pos:[70,275] width: 50
 		button about_btn "About" pos:[130,275] witdh: 50
 		)
 	
 --Button comamnds:
 			
 	on parent_PkBtn picked obj do (
 		parentOBJ = obj
 		Parent_lbl.text = "Parent Object: " + parentOBJ.name
 		select = parentOBJ
 		modPanel.addModToSelection (mesh_select ()) ui:off
 		subobjectLevel = 3
 		getface_lbl.text = "select a face, then press 'Grab Face'"
 		parentpicked = true
 		if parentpicked == true do parentFace_Btn.enabled = on
 		)
 		
 	on parentFace_Btn pressed do (
 		select = parentOBJ
 		parentFace = (getFaceSelection $) as array
 		if parentFace.count > 0 do (
 			facenum = (parentFace)[1]
 			parentFace = (facenum as string)
 			parentFace_lbl.text = "Face Number: "+ parentFace
 		)
 		subobjectLevel = 0
 		deleteModifier $ 1
 		facepicked = true
 		if facepicked == true do createDummy_btn.enabled = on
 		)
 		
 	on createDummy_btn pressed do(
 		if dummy_txt != "" do (
 			new_obj = dummy ()
 			
 			dummyname = dummy_txt.text + "_"
 			new_obj.name = (uniquename dummyname)
 		)
 		)
 )
 if MainFloater != undefined do(
 			closerolloutfloater MainFloater
 		)	
 MainFloater = newRolloutFloater "Link to Face" 250 350
 addrollout face_linker MainFloater
 

lol thanks Anubis, i actually went the rout of mesh select, but i also remove the mesh select after the script is done, i posed up an update like 2 minutes after your last coment

Have you used an attachment constraint? I have always felt they were hard to get right; took manual setup. Did you see how that position script was setup in the example above, or is there a reason you would want to use an attachment over that route?

the reason i would like to use the attach constraint VS a position script is the feed back. a position script just updates when the time line is being played where as the attach constraint updates continually. the fact the the attach constraint it a little hassle to deal with makes this script even more useful.

the values that need to change are:

the changes to A and B center the pivot point to the selected face of the parent object. by turning Position XYZ from 100 to 0 stops teh child object form averaging between the two and uses only the attached constrain as its position and orientation.

but really the main reason is the updating of the position, i’d prefer it to be updated on the fly VS during timeline playback only.

lemasterjg…
sorry for taking so long to answer…been kind of busy…
i think i did not explain the problem correctly…
what i would like to do is to attach a mesh to a target surface in 4 points…
my guess is that the mesh should be inside a cage, so the base of the cage is attached to the target surfaces polygon.
so when the surface is deformed the mesh components is deformed too…this is something paracloud or generative components is able to do…the thing is that i would like to do it in max…
thanks for you reply

 JHN

Maybe I understand it wrong, but couldn’t you do it with a skinwrap modifier?

-Johan

FINISHED!!

thanks to the discreet forums and the following web links i was able to finish my first script, some people have suggested intersect ray but i still do not have a good grasp of how to use it. if someone knows of a tutorial or an example script that uses intersect ray to select a face, please let me know.

http://www.kxcad.net/autodesk/Autodesk_MAXScript_Reference_9/Attachment_PositionController.htm
http://www.kxcad.net/autodesk/Autodesk_MAXScript_Reference_9/Attachment_Controller_Keys.htm

I still need to update my website and add a download and script section but I’m also working on a new Flash version which i hope to have a beta up within the next month, until then there is no direct link besides this one

finished Linked to Face script

Right now this scrip just creates a dummy that is attached to a surface and you simply link what you want to follow to the dummy.

mariovergara1: the original link that you gave really didn’t give too much of an example of what you were saying, is there another example of what you are looking for?

Page 2 / 3