Notifications
Clear all

[Closed] how to make script work at all time?

how to make the script run at all time?
first,i creat a box in sense,and animated it.then i want to write a script to carry out that another box follow the first one.i created the script,but it only run at 1 frame.i wonder that when i drag the timeslider,the second box will follow the first box at all time.can some one how to do that?

this is the script:
rollout pick_box_test “Pick Box Test”
(
–Pickbutton to select a Box from the scene
pickbutton chooseit “Select Box” width:140
–If the user picked an object, then
on chooseit picked obj do
(
–see if the user did not cancel the picking…
if obj != undefined do
(
–if he did not, make the box’s wireframe red:
obj.wirecolor =blue
obj.name=“test”
–and display the name of the object on the button:
chooseit.text = obj.name
obj2 = box() –create a Sphere
obj2.wirecolor=red
convertToMesh obj
convertToMesh obj2 –collapse to EditableMesh
for v = 1 to getNumVerts obj do –loop through all vertices
(
vert2=getvert obj v
vert = getVert obj2 v –get the v-th vertex
vert.z =vert2.z –change the Z coordinate to 0.0
vert.x =vert2.x
vert.y =vert2.y
setVert obj2 v vert –assign back to the v-th vertex
)
update obj2
)
)
)
createDialog pick_box_test

i’m sorry for my poor english.thx

10 Replies

You can use a script controller to do what you want. But, just out of curiosity, why are you moving the verts and not the box itself, which you could do very easily a number of different ways? It seems like you’re making it more complicated than it needs to be.

1 Reply
(@supermouse)
Joined: 11 months ago

Posts: 0

ok,cite a case.there is a 3X3 plan(it means plan have 9faces),i animated the plan by reactor next,now i copy the plan at frame “0”,then i detach 9 face from the plan.i want the 9 face to hold the same positon as the plan’s face.it means that the plan and the 9 face will be overlapped with in the next 100 frames.

It seems like i’m making it more complicated than it needs to be.i want to expot a vertex animation to a game engine,this is only way that the animation can be supported by the engine.so my only recourse is maxscript.

Can you suggest how i might tackle the problem? thx again

Animating vertex when time changes?
If you really want to make this happen,I suggest you looking over the following section on maxscript reference:
“Change Handlers and Callbacks”;
“Time Change Callback Mechanism”
And maybe,if you want,we can talk about it on QQ.My QQ:2633625.

i am so glad to see my countrymen here,i just sent a message to you with QQ.

Which game engine are you trying to export to? If the engine supports vertex animation then it should be up to the engineers of that engine to write an exporter for Max that will save the vertex information at each frame of your animation.

Another option that some older engines use is to save the model at each frame as a seperate .3ds file. That will create a snapshot of the object at each frame, and the engine should be able to read the series of .3ds files to get the vertex animation. Something like that would be very easy to script.

1 Reply
(@supermouse)
Joined: 11 months ago

Posts: 0

《warcraft3》

i used arttools to export model,the wc3 engine can’t support vertex animation.so i must transform the animation to adapt the wc3engine.so i want to detach every face from a vertex animated obj. then the every face can control by TCB controller and the wc3 engine will weld them altogether in game. do u know what i mean?

Anyway,I know more about what you want now:Split a source to many single triangle face mesh,than simulate some dynamic animaiton on the source mesh.after that,Make all the triangle face mesh’s transform(TCB) follow the source mesh’s vertex animation.

So finally you would get these keys and export to your engine.Am I right?

I do some experiments:

(1)Make a plane object and convert it to mesh,clone one of it’s triangle face to an mesh object.
(2)Tweak triangle mesh object’s pivot to one of it’s vertex.
(3)Triangle mesh attachment constraint to the plane mesh,tweak it’s position matching where it was in controller dialog.
(4)I make a cloth simulation on the plane mesh,Now the Triangle mesh follow the plane mesh.(5)Next,just thinking a way to bake the Triangle mesh’s attachment constraint controller’s animation to PRS transform.I found the following script on www.scriptspot.com
http://www.scriptspot.com/start.asp?p=download&ID=3117

It work’s quite well except that it doesn’t use tcb controller.

Still,it has a lot of works to do,but it does have a solution now.

ok.i will try that script.special thx again.

oh,that way can’t solve my problem.
my problem is on step 1,2,3,4 what is said above,and the step 5,i can use a plugin which named “snapshot”.that plugin even have a ability to bake the animation of character studio skeleton.so i want the step1,2,3,4 that they are worling in script automatically,u know the plan may have a lots of triangle mesh,and i can’t do that manually.

i improve my script.some function can realize now.but it can’t set key,can’t record the animation.guys,do u have any suggestion?
script here:
obj=box()
obj.wirecolor =blue
obj.name=“test”
animate on
(
at time 0 (obj.pos = [-100, 0, 0]; obj.scale = [1, 1, 0.25])
at time 100 (obj.pos = [100, 0, 0]; obj.scale = [1, 1, 3])
)
obj2=box() –create a Sphere
obj2.wirecolor=red
obj2.name=“test2”
convertToMesh obj
convertToMesh obj2 –collapse to EditableMesh
fn ss =
(
for v = 1 to getNumVerts obj do –loop through all vertices
(
vert2=getvert obj v
vert = getVert obj2 v –get the v-th vertex
vert.z =vert2.z –change the Z coordinate to 0.0
vert.x =vert2.x
vert.y =vert2.y
setVert obj2 v vert –assign back to the v-th vertex
)
update obj2
)
registerTimeCallback ss