ScriptSpot

Forum topic · General Scripting

Vertex Keyframe Trasfer

By THE · 2013-02-25

Description

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 (22)

alternative baking options

skaale · 2013-09-02

Hey Nice Script,
But is it possible to modify the script, so it bakes the vertex animation from the original mesh to transform keys? without assigning any meshes to the vertex(Plain and simple bake all the vertex animations to transforms key frames on the original mesh?)

Best Regards
Daniel

barigazy · 2013-09-02

I thiks for that is better to use skin wrap modifier

update on vertex animation to transform keys

skaale · 2013-09-02

HI again,
Thanks for your reply, is because I want to export a FBX file to keyshot render(http://keyshot.com/) and there is no support for modifiers and skin and bones right now only position,rotation and scale keys so I have been experimented with vertex animation and i works fine but I want to translate it back to transforms keys so I can export meshes with baked modifiers etc.. maybe I could make a video to explain my experiment and I found this nice script but it copy the vertex animation to an array of instances And I just want the transforms keys to the original mesh.

workflow right now:

1) mesh with edit poly.
2) apply vol selection modifier
3) ex. FFD modifiers
4) the a use http://www.scriptspot.com/3ds-max/scripts/volume-select-vertex-baker
5) ?

Best
Daniel

barigazy · 2013-09-03

Try this one:
Example
Create sphere, assigne FFD modifier and animate control points.
Next use this code which will create copy of original mesh with baked verts animation.

fn bakeVertsAnim obj = if isvalidnode obj and canConvertTo obj Editable_mesh do
(
slidertime = animationRange.start
targObj = snapShot obj
local gv = meshop.getVert, sv = meshop.setVert
animateVertex targObj #all

for a in animationRange.start to animationRange.end do
(
at time a animate on with redraw off
(
arr = for v in 1 to obj.verts.count collect gv obj v
sv targObj #{1..targObj.numverts} arr
)
)
select targObj
)
bakeVertsAnim $Sphere001

error in max with the code

skaale · 2013-09-03

Big thanks Barigazy,

Get this error in the array Unable to convert: undefined to type: Point3
I have a screen shot

https://dl.dropboxusercontent.com/u/6776363/test.jpg

thanks for helping me out Keyshort has become a very powerful path raytrace rendering engine
best
Daniel

barigazy · 2013-09-03

I fix some lines. Try now and tell me how it works for you

fn bakeVertsAnim obj = if isvalidnode obj and canConvertTo obj Editable_mesh do
(
slidertime = animationRange.start
if getCommandPanelTaskMode() != #create do setCommandPanelTaskMode #create
targObj = snapShot obj
addModifier obj (Turn_to_Mesh ())
local gv = meshop.getVert, sv = meshop.setVert
animateVertex targObj #all
with undo off with redraw off
(
for a in animationRange.start to animationRange.end do
(
with animate on at time a
(
arr = for v in 1 to obj.numverts collect gv obj v
sv targObj #{1..targObj.numverts} arr
)
)
deletemodifier obj 1
)
select targObj
)
bakeVertsAnim $Sphere001

barigazy · 2013-09-03

maybe this :)

fn bakeVertsAnim obj = if isvalidnode obj and canConvertTo obj Editable_mesh do
(
slidertime = animationRange.start
if getCommandPanelTaskMode() != #create do setCommandPanelTaskMode #create
targObj = snapShot obj
addModifier obj (Turn_to_Mesh ())
local gv = meshop.getVert, sv = meshop.setVert
animateVertex targObj #all
with undo off with redraw off
(
for a in animationRange.start to animationRange.end do
(
with animate on at time a
(
targObj.transform = obj.transform
arr = for v in 1 to obj.numverts collect gv obj v
sv targObj #{1..targObj.numverts} arr
)
)
deletemodifier obj 1
)
select targObj
)
bakeVertsAnim $Sphere001

:-)

skaale · 2013-09-03

hey,
Thanks again!, but It was a crazy idea. I can see now it is not possible to convert vertex animation to animated transform keys because it only works with XYZ position. But Thanks again Barigazy:-)

https://dl.dropboxusercontent.com/u/6776363/3.jpg

Best
Daniel
Email : daniel@simulacrum.dk

barigazy · 2013-09-03

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.

*.ms :{

barigazy · 2013-02-26

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.

Attachments

THE · 2013-02-26

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...

THE · 2013-02-26

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...

Here is part2 :)

barigazy · 2013-02-26

Now u can pick target object.

Attachments

THE · 2013-02-26

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

barigazy · 2013-02-26

my pleasure.

This is your script

barigazy · 2013-02-26


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)

solution

barigazy · 2013-02-25

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

THE · 2013-02-25

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 :(

barigazy · 2013-02-25

Attach simple test scene for testing

THE · 2013-02-26

I need to create the bone at the vertexes of the fabric, but only the selected vertices (not all) and transfer framekeys of vertices to bones created at each vertex.

If it is difficult for you, then duplicate the bone at all vertices.

thanks

cloth.max is the fabric with the cloth modifier

cloth_baked_without_clothmodifier.max without cloth modifier

Attachments