Vertex Keyframe Trasfer

Friends need help with this script.

This script creates boxes at each vertex of the object pick and trasnfiere keyframes of each vertex to each box set. (eye, the script is not mine, I copy a page of examples)

I need help to make some changes, please:

1-select only the vertices I want to use and save it in an array.
2-create a copy of a selected object in each vertex that is in the array and transfer your keyframes.

rollout A1 "Animated Vertex"
( 
 button B3 "Pick Object"
	on B3 pressed do
(	 
 local boxSize = 1 
 local frameStepping = 2 
 ------------------------------------------------------- 
 local obj = selection[1] 
 if isValidNode obj do 
 ( 
  local tMesh = obj.mesh 
  local boxes = for i=1 to tMesh.numVerts collect box width:boxSize height:boxSize length:boxSize 
  with animate true for t=animationRange.start.frame to animationRange.end.frame by frameStepping do at time t for i=1 to tMesh.numVerts do boxes[i].pos=((getVert obj.mesh i)*obj.transform)  
 )
 )  
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

At least you can bake transform animation. You need different aproch if you want .fbx or .obj sequence export, but KeyShot probably not support that.

bga

barigazy's picture

*.ms :{

Or just download script
Cheers!

edit:
I edited the code and now if you select verts (just add mesh_select modifier over cloth modifier and select some verts) boxes will be created only on selected verts
or if nothing is selected then all verts are counted.

AttachmentSize
bga_boxbaker.ms 2.31 KB

bga

THE's picture

barigazy sorry to bother you

barigazy

sorry to bother you again.
you could do that instead of creating a box at each vertex, another object is created,pick of the scene.

example
pickbutton (pick animated object)
pickbutton (pick object to create)

and deleting box creating in the the code , please

no more...

barigazy's picture

Here is part2 :)

Now u can pick target object.

AttachmentSize
bga_boxbaker_v2.ms 2.13 KB

bga

THE's picture

Infinite thanks is exactly

Infinite thanks
is exactly what I wanted,
you are a master

barigazy's picture

my pleasure.

my pleasure.

bga

THE's picture

barigazy sorry to bother you

barigazy

sorry to bother you again.
you could do that instead of creating a box at each vertex, another object is created,pick of the scene.

example
pickbutton (pick animated object)
pickbutton (pick object to create)

and deleting box creating in the the code , please

no more...

barigazy's picture

This is your script

try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "BoxBaker by barigazy"
(
	local sourceObj
	fn bakeBoxes sourcePlane: boxSize: start: end: step: = if isvalidNode sourcePlane do
	(
		local b
		local verts = if (sourcePlane.selectedverts).count != 0 then (sourcePlane.selectedverts as bitarray) else (#{1..(sourcePlane.verts.count)})
		verts = verts as array
		local bArr = for v = 1 to verts.count collect
		(
			if v == 1 then (b = box width:boxSize[1] length:boxSize[2] height:boxSize[3])
			else instance b
		)
		animate on
		(
			for i = start to end by step do
			(
				at time i
				(
					for n = 1 to bArr.count do
					(
						bArr[n].pos = getVert sourcePlane verts[n]
						bArr[n].dir = getNormal sourcePlane verts[n]
					)
				)
			)
		)
	)
	group "Source Object:"
	(
		pickbutton pb_source "Pick Animated Object" offset:[0,0] width:140 height:20
	)
	group "Animation Range:"
	(
		spinner spn_start "Anim. Start:" offset:[-5,0] width:140 height:20 type:#integer range:[0,(1e5-1),0]
		spinner spn_end "Anim. End:  " offset:[-5,-5] width:140 height:20 type:#integer range:[1,1e5,100]
		spinner spn_step "Anim. Step:" offset:[-6,-5] width:140 height:20 type:#integer range:[1,1e5,2]
	)
	group "Target Object (BOX) :"
	(
		spinner spn_width "Box Width:" offset:[-5,0] width:140 height:20 type:#float range:[.1,1e5-1,5]
		spinner spn_length "Box Length:  " offset:[0,-5] width:140 height:20 type:#float range:[.1,1e5,5]
		spinner spn_height "Box Leight:" offset:[-5,-5] width:140 height:20 type:#float range:[.1,1e5,5]
	)
	button btn_bake "Bake Box Animation" pos:[4,231] width:152 height:30
	on pb_source picked obj do
	(
		if not isValidNode obj then (sourceObj = null ; pb_source.text = "Pick Animated Object") else
		(
			pb_source.text = obj.name
			sourceObj = obj
		)
	)
	on btn_bake pressed do 
	(
		if isValidNode sourceObj do
		(
			bakeBoxes sourcePlane:sourceObj \
			boxSize:#((spn_width.value),(spn_length.value),(spn_height.value)) \
			start:(spn_start.value) end:(spn_end.value)  step:(spn_step.value)
		)
	)
)
createDialog bgaRoll 160 263 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

bga

barigazy's picture

solution

You may want to consider this approach. After this u can bake boxes animations

delete objects
gc light:on
sph = convertToMesh (Sphere radius:100 segs:32 wirecolor:[10,10,10])
b = Box length:5 width:5 height:5
for v in 1 to sph.numVerts do
(
	insB = instance b ; insB.wirecolor = random black white
	ctrl = insB[3].track = transform_script()
	ctrl.AddObject "master" sph
	txt = "nrm = getNormal master "+(v as string)+"\n"
	txt += "_x = normalize (cross nrm master.dir)\n"
	txt += "_y = normalize (cross nrm _x)\n"
	txt += "matrix3 _x _y nrm (getVert master "+ v as string +")"
	ctrl.setExpression txt
)
addmodifier sph (Noisemodifier strength:[50,50,50] scale:50 animate:on)
sliderTime = 0f
max time play

bga

THE's picture

Excuse my ignorance

Excuse my ignorance if not understood.
Your script creates a crazy ball automatically :), but I want it to an object in the scene with cloth modifier, I do not understand how I can do what I want with it.

example:
If I have a plane with the cloth modifier and bake animation (vertex with keyframe) and an object.

As I can do to duplicate the object at each vertex of the plane and take your keyframe.

The problem is that I have only one week learning maxscript and I have no idea how to make changes, help :(

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.