Notifications
Clear all

[Closed] CgTalk Maxscript Challenge 004: "Zipper Up"

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:  

[ul]
[li]You can set up scenes and textures for this one as you see fit. If you can code it all, even better![/li][li]Code from scratch. Try not to use pre-exisitng functions or plugins.[/li][li]Show your script references, if any (eg. Looking at another script to assist you).[/li][li]You are encouraged to ask for help where needed, but try to do it on your own. The maxscript reference is an invaluable resource.[/li][li]Post your final script inside [/li]“`
tags (located on your posting toolbar).
[li]Post all code into THIS thread.[/li][li]Post the max version you coded in, plus any maxscript extensions you used. (Thanks galagast!)[/li][li]Try to finish the challenge in a week. There is no definite time limit.[/li][li]Voting will occur at the end of each ‘month’ (every 4 challenges). [/li][/ul] 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!

21 Replies

Sure Erilaz… Give us something easy :rolleyes:

I’ll give it a shot tonight.

1 Reply
(@erilaz)
Joined: 1 year ago

Posts: 0

Hey, I just think of ’em, I don’t know how hard they’ll be!
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!

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

No wonder you don’t have time ivanisavich! I just saw your kickass FX Wars entry!:eek:

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!

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

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

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

  • Martijn

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!

Ok…got a script done

Thanks for your help in solving my animateVertex problem!

Here’s the script: zipper

Here’s an animation showing it in action: zipper animation

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 = #()
 
Page 1 / 3