Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Linking a bone to a vertex (note: not the other way round!)

4 REPLIES 4
Reply
Message 1 of 5
kungmongie
302 Views, 4 Replies

Linking a bone to a vertex (note: not the other way round!)

Hi all,

I wonder if you can help, I want to run a cloth simulation on a dummy flag mesh, then recreate that animation using bones, then finally throw away the dummy flag so I've just got the skelatal animation.

 

I've done the cloth sim on the flag and now strugling to get the bones to match the flags movement.

 

I found advice that describes a process but it's manually snapping the bones to the mesh every 10 frames. Through Maxscript (see below) I've tried changing the position of each bone to match the mesh but that doesn't work, the position changes but the orientation of each bone stays the same, effectivly no longer joining up to the next bone.

 

Any ideas?

Thanks!

 

boneCnt = ($bone*).count --where the bone count number matches the vertext number of the flag
boneArr = ($bone*) as array
flagObj = $Plane001

animate on
(
  for timeDur = 10 to 100 by 10 do
  (
     for eachBone = 1 to boneCnt do
     (
       at time timeDur boneArr[eachBone].pos = flagObj.verts[eachBone].pos
     )
  )
)

 

 

4 REPLIES 4
Message 2 of 5
bksong
in reply to: kungmongie

3 year old bump but I have the exact same dilemma. I've searched all over for an answer on how to create a flag animation using bones but no success.

 

If by chance, anyone reads this and knows, please share!

Message 3 of 5
denisT.MaxDoctor
in reply to: bksong

use Attachment controller for the bones with Align option ON, and just snapshot their animation (full transform) after your simulation is done

Message 4 of 5

delete objects
redraw off
(
	max create mode
	
	n = plane width:10 length:10 widthsegs:10 lengthsegs:10
	m = n.mesh
	pp = for v=1 to m.numverts collect (point size:2 wirecolor:green)
	done = #{}
	coords = #([1,0],[0,0],[0,1])	
	for f=1 to m.numfaces do
	(
		vv = getface m f
		for k=1 to 3 where not done[vv[k]] do 
		(
			v = vv[k]
			p = pp[v]
			c = p.pos.controller = Attachment node:n align:on
			key = AttachCtrl.addNewKey c 0
			key.face = (f-1)
			b = meshop.getBaryCoords m f (getvert m v)
			--format "% % == % %\n" k v b coords[k]
			key.coord = b --coords[k]
			done[v] = on 
		)
	)
	modi = Bend BendAxis:0
	addModifier n modi
	animate on 
	(
		at time 0 modi.BendAngle = 0
		at time 50 modi.BendAngle = -340
		at time 100 modi.BendAngle = 0
	)
	
	tms = #()
	for t=0 to 100 do at time t
	(
		for k=1 to pp.count do 
		(
			if tms[k] == undefined do tms[k] = #()
			append tms[k] pp[k].transform
		)
	)
	for k=1 to pp.count do pp[k].transform.controller = createinstance prs	
	
	animate on 
	(
		for t=0 to 100 do at time t
		(
			for k=1 to pp.count do pp[k].transform = tms[k][t+1]
		)
	)
	
	deletemodifier n modi
	
	sk = Skin()
	max modify mode
	select n
	modPanel.addModToSelection sk ui:on
	for k=1 to pp.count do skinOps.addbone sk pp[k] (if k == pp.count then 1 else 0) 
	notifydependents sk
)

something like this...

Message 5 of 5


delete objects with redraw off ( max create mode n = plane width:10 length:10 widthsegs:10 lengthsegs:10 m = n.mesh pp = for v=1 to m.numverts collect (point size:2 wirecolor:green) done = #{} coords = #([1,0],[0,0],[0,1]) for f=1 to m.numfaces do ( vv = getface m f for k=1 to 3 where not done[vv[k]] do ( v = vv[k] p = pp[v] c = p.pos.controller = Attachment node:n align:on key = AttachCtrl.addNewKey c 0 key.face = (f-1) b = meshop.getBaryCoords m f (getvert m v) --format "% % == % %\n" k v b coords[k] key.coord = b --coords[k] done[v] = on ) ) modi = Bend BendAxis:0 addModifier n modi animate on ( at time 0 modi.BendAngle = 0 at time 50 modi.BendAngle = -340 at time 100 modi.BendAngle = 0 ) tms = #() for t=0 to 100 do at time t ( for k=1 to pp.count do ( if tms[k] == undefined do tms[k] = #() append tms[k] pp[k].transform ) ) for k=1 to pp.count do pp[k].transform.controller = createinstance prs animate on ( for t=0 to 100 do at time t ( for k=1 to pp.count do pp[k].transform = tms[k][t+1] ) ) deletemodifier n modi sk = Skin() max modify mode select n modPanel.addModToSelection sk ui:on addbone = skinOps.addbone for k=1 to pp.count do addbone sk pp[k] 0 select n replaceVertexWeights = skinOps.replaceVertexWeights for k=1 to m.numverts do replaceVertexWeights sk k k 1 ok )

Couple bugs were fixed

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report