PDA

View Full Version : CgTalk Maxscript Challenge 004: "Zipper Up"


erilaz
07-04-2005, 02:12 PM
CgTalk Maxscript Challenge 004: "Zipper Up"

DESCRIPTION: Create a slider-controlled zipper that functions as realistically as possible. (Just the zip: No cloth necessary). The zip has to pass over the open locks and appear to pull them shut.

INTERMEDIATE SCRIPTERS: Add the zipper to a cloth simulation (either an actual scripted method of seperation or a scripted cloth simulation), so it pulls together the cloth.

ADVANCED SCRIPTERS: Create a tool that draws the zipper onto a selected line of edges, splits the edges at the appopriate point, and operates with the slider. Essentially a functional "zip inserter".

RULES:


You can set up scenes and textures for this one as you see fit. If you can code it all, even better!
Code from scratch. Try not to use pre-exisitng functions or plugins.
Show your script references, if any (eg. Looking at another script to assist you).
You are encouraged to ask for help where needed, but try to do it on your own. The maxscript reference is an invaluable resource.
Post your final script inside [CODE] tags (located on your posting toolbar).
Post all code into THIS thread.
Post the max version you coded in, plus any maxscript extensions you used. (Thanks galagast!)
Try to finish the challenge in a week. There is no definite time limit.
Voting will occur at the end of each 'month' (every 4 challenges).
NOTES: A little bit simpler than the last one (that was a little daunting, but with some amazing results!). I'm after a simple lock and close method here, but take the complexity as far as you like. You may need to look up how a zip works, or better yet, just look at your own zips for reference!
By the way, I haven't forgotten the suggestions you guys are making! Thanks for the support!

Wahooney
07-04-2005, 02:51 PM
Sure Erilaz... Give us something easy :rolleyes:

:p

I'll give it a shot tonight.

erilaz
07-05-2005, 12:49 AM
Sure Erilaz... Give us something easy :rolleyes:


Hey, I just think of 'em, I don't know how hard they'll be! :D
But yeah, in retrospect, this may be slightly difficult! I guess that's why it's a challenge!

Incidently, you guys need to tell me if these are beyond your scripting abilities (and I mean that across the board... beginners to advanced). I don't have a lot of time to fully try these ideas myself, so I may be asking too much of you for a week's challenge. If what I'm putting up is too much for a week's work, I'll simplify the normal challenges and put smaller elevations of difficuly in the intermediate and advanced sections.
Remember, you don't have to get it to work completely, the whole idea is to try ideas out!

ivanisavich
07-05-2005, 04:58 PM
Hey Erilaz,

Thanks for holding these challenges! I like them a lot! Even if I don't get a chance to enter...my brain is ticking all week long trying to think of ways of implementing the proposed script in maxscript.

As for the difficulty of these challenges, I think that as long as they're focused on only ONE thing (ie....make a table, make a zipper, make footprints) they'll be fine. The number of entries that get submitted will differ for sure (some lots, some none)....but I don't think it's too "hard"....it's just that all of our schedules differ from week to week :)

What WOULD be too hard imo, were some of the challenges suggested in the suggestions thread. Ie...make an image viewer complete with preview window. Lol...that would take me 6 months ;)

erilaz
07-06-2005, 01:02 AM
No wonder you don't have time ivanisavich! I just saw your kickass FX Wars entry!:eek:

ivanisavich
07-06-2005, 08:06 PM
Ok....My script is coming along...but I'm having some trouble animating the zipper-splines...ie...getting them to zip up into place is no problem....but setting keys so that they are animated to move (over time) into place isa problem. Make sense?

Basically, here's what's happening:

Using the setknotpoint function (even combined with "animate on") will move the spline vertex.....but no keys will be set for that movement....no matter what I've tried....the vertex will just move...but no positional keys are created.

However, calling this method on a spline vertex:

$Line01.Spline_1___Vertex_1 = [(insert point 3 value)]

will not only move the spline vertex, but also set keys for it.

Now...I could just use the above method to move all the spline vertices (and have them animated too)...but that would mean I've gotta type out 50 lines of that code if there are 50 vertices to be animated (whereas the setknotpoint function can take index integers to define vertices...and would therefore only require a loop to run through all the different points). So that's obviously out of the question.

So does anyone know why that's happening (setknotpoint does not set keys)? I've called the "animateVertex" function on my splines, tried the whole script with the animate button on and off etc etc...but I just can't get those vertices animated!

Thanks!

marktsang
07-06-2005, 08:26 PM
hi ivan,
all the knots must have point master controlers before you attemt to move them (to keep animaiton) moving them with script will not apply this controller - you can use a command to set it (cannot remember off hand) or you can just select them all with animate mode on and move them with the move transform tool.

mark

rdg
07-06-2005, 08:39 PM
hi ivan,
the command mark reffering to is probably:
Controllers can be assigned to vertices using the animateVertex() method described in Scripting Vertex and Control Point Animation (http://Scripting_Vertex_and_Control_Point_Animation.htm)

I cannot take part in this challenges, as I am chicken-hearted.

Good luck

Georg

magicm
07-06-2005, 09:58 PM
Not sure if I'll have time to develop it further, but this is what I got right now (no script yet, just an avi). A fairly simple script to animate the zipper + edges and Reactor Cloth for the secondary motion. A user-drawn spline is used to define the trajectory of the zipper.

See it here (http://magicm.cgcommunity.com/downloads/zipper_01.avi)

- Martijn

ivanisavich
07-07-2005, 03:20 AM
Hey Mark (and rdg),

Yes...I've already called the "animateVertex" function on my splines...but it still doesn't do anything :(

In fact...when I call the list property function it lists all of the animation controllers for the knots...but STILL they won't animate! :P

ivanisavich
07-08-2005, 02:29 AM
Ok...got a script done :)

Thanks for your help in solving my animateVertex problem!

Here's the script: zipper (http://www.theonlyt.com/Main/Scripts/zipper.ms)

Here's an animation showing it in action: zipper animation (http://www.theonlyt.com/Main/Scripts/zipper.avi)

Here's the code [:)]:


--"Spline Zipper" created by Tyson Ibele, 2005.

global startTime = bezier_float()
global endTime = bezier_float()
global zip1
global tread1
global tread2

rollout zipper "Spline Zipper"
(
pickbutton spline1 "Select Spline Tread 1" width:150
pickbutton spline2 "Select Spline Tread 2" width:150
pickbutton zipper1 "Select Zipper" width:150
spinner in1 "Start Time: " type:#integer range:[-100000,100000,0] controller:startTime width:100
spinner out1 "End Time: " type:#integer range:[-100000,100000,100] controller:endTime width:100
checkbox help1 "Create Helpers" pos:[50,124]
button zip "Zip it up!" width:70 height:30

on spline1 picked obj do --get user to pick first spline
(
if canconvertto obj SplineShape then --only splines allowed
(
tread1 = obj
convertto tread1 SplineShape
spline1.text = tread1.name
)
else messagebox "Must be a shape object"
)
on spline2 picked obj do --get user to pick second spline
(
if canconvertto obj SplineShape then
(
convertto obj SplineShape
tread2 = obj
spline2.text = tread2.name
)
else messagebox "Must be a shape object"
)
on zipper1 picked obj do --get user to pick zipper object
(
zip1 = obj
zipper1.text = obj.name
if numkeys zip1.pos.controller == 0 then
(
messagebox "Note: You've selected an object with no positional keyframes, therefore no actual zipping will occur"
)
)
on zip pressed do
(
if (tread1 != undefined and tread2 != undefined and zip1 != undefined) and ((isdeleted tread1) != true and (isdeleted tread2) != true and (isdeleted zip1) != true) then
--the above statement checks to see if all necessary objects have been selected, and are available
(
if help1.checked == true then --if the helper checkbox is checked, make helpers
(
delete $*zip_* --delete previous helpers first
for k in 1 to (numknots tread1 1) do
(
ht1[k] = point name:("zip_l_point"+(k as string))
ht1[k].wireColor = blue
)
for k in 1 to (numknots tread2 1) do
(
ht2[k] = point name:("zip_r_point"+(k as string))
ht2[k].wireColor = green
)
)
count1 = 1 --reset counters
count2 = 1
zipStep = #() --reset zipper position cache
zipStep2 = #()
dumStep = #() --reset helper position cache
dumStep2 = #()

animateVertex tread1 #all --enable both spline's vertices to be animated
animateVertex tread2 #all
sliderTime = startTime.value --reset time slider

deleteKeys tread1 --delete all previous spline keyes, to avoid weird errors due to key overlaps
deleteKeys tread2

div1 = floor ((endTime.value-startTime.value)/(numknots tread1 1)) --calculate keying distance between separate spline vertices
div2 = floor ((endTime.value-startTime.value)/(numknots tread2 1))

for j in startTime.value to endTime.value by div1 do --key vertices of first spline
(
sliderTime = j
in coordsys tread1 (zipStep[count1] = zip1.pos) --cache position of box (using the spline's coordinate system), over time
in coordsys world (dumStep[count1] = zip1.pos)

setknottype tread1 1 count1 #smooth --convert current spline vertice to "smooth"
track = 3*(count1-1)+2 --get necessary controller track *thanks to Bobo for posting how to do this!*
key = addNewKey tread1[4][4][track].controller (j-(div1*2)) --set inital key for vertice
key = addNewKey tread1[4][4][track].controller (j) --set destination key for vertice
key.value = zipStep[count1] --set destination position for vertice (ie...its zipped position)

if help1.checked == true then --if the user wants helpers to be created, create them!
(
at time (j-(div1*2)) (ht1[count1].pos = (in coordsys world (getknotpoint tread1 1 count1)))
addNewKey ht1[count1].pos.controller (j-(div1*2))
with animate on
(
at time j (ht1[count1].pos = dumStep[count1])
)
)
count1 += 1 --increase counter (this counter is used to cycle through vertices, as well as to cycle through the zipper's position cache)
updateshape tread1
if count1 > (numknots tread1 1) then exit --exit when we've cycled through all available vertices
)

for j in startTime.value to endTime.value by div2 do --key vertices of second spline (same as above)
(
sliderTime = j
in coordsys tread2 (zipStep2[count2] = zip1.pos)
in coordsys world (dumStep2[count2] = zip1.pos)

setknottype tread2 1 count2 #smooth
track = 3*(count2-1)+2
key = addNewKey tread2[4][4][track].controller (j-(div2*2))
key = addNewKey tread2[4][4][track].controller (j)
key.value = zipStep2[count2]

if help1.checked == true then
(
at time (j-(div2*2)) (ht2[count2].pos = (in coordsys world (getknotpoint tread2 1 count2)))
addNewKey ht2[count2].pos.controller (j-(div2*2))
with animate on
(
at time j (ht2[count2].pos = dumStep2[count2])
)
)
count2 += 1
updateshape tread2
if count2 > (numknots tread2 1) then exit
)
sliderTime = startTime.value
)
else --the following statements check to see why the above script did not execute
(
if tread1 != undefined and tread2 != undefined and zip1 != undefined then
(
messagebox "One or more of your zipper objects has been deleted. Script cannot continue."
case of
(
(isdeleted tread1 == true): spline1.text = "Select Spline Tread 1"
(isdeleted tread2 == true): spline2.text = "Select Spline Tread 2"
(isdeleted zip1 == true): zipper1.text = "Select Zipper"
)
)
else
(
messagebox "You must select three zipper objects first!"
)
)
)
)
zipit=newrolloutfloater "Spline Zipper" 200 215 650 300
addrollout zipper zipit
endTime.value = 100
tread1 = undefined --clear out all three object variables, each time the script is run
tread2 = undefined
zip1 = undefined
ht1 = #()
ht2 = #()

erilaz
07-08-2005, 04:02 AM
Nice little solution you've got there! I keep geting an error about a controller not being defined after I've selected my objects though.

ivanisavich
07-08-2005, 04:24 AM
Hey Erilaz....

That's odd...I've tried all sorts of combinations of objects etc and never had that problem.

Could you post more info about your error? And/or...did you get past it? I'd like to fix it :)

j-man
07-08-2005, 11:24 AM
Hi Tyler,

I'm having a problem with your script to!

"unknown proerty controller in undefined"

Maybe you could post a sample scene or some instructions how to use it! I've got two splines and an animated box, I'm not really sure what to do.

Don' think I'm gonig to have time for this one either but keep up the good work everyone1

J.

ivanisavich
07-08-2005, 02:56 PM
That's truly weird!

I tried my script again and still it worked without error!

Maybe the formatting code screwed up with the (code) tags? Did you try running it from the .ms file that I provided?

Btw....although my script sort of stops you from being able to do anything else (and provides error messages telling you why)....this is what you have to do:

1) create 2 splines...with any number of knots (the more the better)

2) create a "zipper" object (a box or something), and animate it over a series of frames

3) Run the script

4) Select the 2 splines as the 2 treads, then the box as the zipper.

5) Press "Zip it up"

Could one of you getting the errors maybe provide their max file so I could check it out?

j-man
07-11-2005, 09:44 AM
Hi T,

I've tried downloading you script as requested ansd i still get the same error. Attached is a screen grab anda max file.

Josh.

ivanisavich
07-11-2005, 04:41 PM
Thanks for the screengrab j_man...I believe I know what the problem is and will post and updated script this afternoon (if I'm right about what's the matter ;)).

ivanisavich
07-11-2005, 06:57 PM
Hooray! Thanks for your max file j_man...I've fixed the problem! :)

Basically, what was happening was there was an error with the index of the vertice master track in my code.

The line that was having the problem included this:

tread1[4][4][track].controller

The weird part is...when I created a spline in my version of max (max 7)...I had no errors because the master track of my vertices was at an index of "4" in the subcontroller.

But...when I loaded up your .max file j_man, there was an "controller undefined" error, because (as I found out later), the master track of your splines' vertices was 8 (for some reason)....

Anywho....after doing some help-file reading, I discovered that instead of using numbers to define the index of the animation track, you can instead call a variable that will allow max to determine the actual number of the track itself (so it'll work no matter what the index is....be it 4, or 8, or 1000)

So....those areas of the code now look like this:

tread1[#object__line][#master][track].controller

And...now there is no error :) Have fun! And thanks for all your help!

http://www.theonlyt.com/Main/Scripts/zipper.ms

j-man
07-12-2005, 02:58 PM
Hey Tyler,

Well no errors, but I end up with two no length splines! I'm thinking this must be an issue with Max7.5 and spline vertex animation. I can't say for sure but that is my guess. what a hassle!
Anyone else having problems?


J.

rdg
07-12-2005, 03:29 PM
The last script works fine for me with max 7.5.
Took a while to realise, that the spline need more than two vertices.

Georg

ivanisavich
07-12-2005, 03:32 PM
Arg! That's too weird j_man, as I've mentioned before...I've yet to have a single error and I'm on max 7. I really don't understand what's going on!

Ah well....the challenge is over anyways, hopefully my lightning bolt script will work for you! ;)

j-man
07-12-2005, 04:09 PM
ah! got it working! I don't know what was happening before but there it is. and it does work with splines with less than there verts.

Well done!

J.

CGTalk Moderation
07-12-2005, 04:09 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.