View Full Version : Wire parameters and scripting :)
postreal 10-25-2007, 11:46 AM Hi.
I was told to ask following question from scripting forum, so I did. Here is my question and some answer I got:
I have a interesting problem on wiring parameters. Im making an animation of a Pop-Up book. I have lots of planes raising from opening pages. I have wired almost everything I need to wire, but I ran into the trouble when trying to do next; I have branches (plants) raising from the page and every branch has 10-15 berries. I need to make a slider that controls the scale of all berries despite which branch their attach to. I also need a random factory on birth - when I slide the slider, berries will grow to their predefined sizes with offset on birth. I have several hundreds of berries so animating by hand is not an option. Berries are planes attached to branch planes. Please check out the viewport sample.
http://www.verseproductions.fi/cgta...port_sample.jpg (http://www.verseproductions.fi/cgtalk/viewport_sample.jpg)
..and some answers I got:
Hi,
I think your approach will depend on how you are placing the berries on the branches. If you're using pflow for example, you could instance all the berries from one master berry. The slider would control the scale of your master berry and the randomness would come from a scale operator within your pflow event (with some scale variation applied).
If you're placing actual berry geometry on the branches without the use of a particle system, you could parent each berry to a dummy - the slider would control the scale of the parent dummies from 0 - 100 and the berries could then be scaled randomly in relation to their parent dummy.
Hope some of that makes sense!
...my answer :
Thanks for your answer
It did make sense, but I cannot use particles since I have placed all my berries to specific places. Problem is wiring scale; Since scale is a component of three scalars (x,y,z.....and I need a random offset for birth), it needs somekind of a script to work.
..another answer for me (a good one, i think..)
You can use a little scripting in the wire dialog.. so you could take the x,y and z coord of the berry in world space and use them to drive a function for the size..
size=slidervalue+ sin(x)*sin(y)*sin(z)*5 will give a +-5 deviation on slidersize depending on where it's at in world space. you have to clamp it not to be negative.. can all be done but dont know exactly how to do it form the top of my head.. but ask around in th scripting department..
..and my answer:
Thanks!! This is what I´m on to ! Actually the position is not important. I just need some randomness to birth. When I pull the slider instead of getting all the berries scaled to 100% at the same time I need a offset to get more random look. This is definatily the way I´m trying to resolve this, I posted this thread to scripting forum, mayby somebody can help me there :) Thanks for this :)
..ok :) I hope you got the idea. If anybody could point me a way or donate me a script for this I would be greatfull !
Thanks in advance !!
|
|
jonadb
10-25-2007, 12:03 PM
Followed you from the other thread :)
There is this script function called 'at time'. It looks at values at a different place in the time line then the current time.
At scriptspot.com there's a script that can randomize the seed values of random operators (use the search). So if you use a noise modifier on al the berries, use that script to give them all a rondom seed.
So now all berries have a different random number available tot them by using that seed value. (the rest of the noise modifier values can be set to 0 )
pseudo script:
berry_size=slidervalue at time (current time+sin(random_seed)*10 )
The berrysize will be the slidervalue but at all the berries look at with a different time offset so they'll grow out of sync.. you can even stretch/shrink the time flow so some can grow faster then others bu multiplying the current_time value. (You'll have to start the slider animation @time=0 for that to work tho.. and add an offset to the 'at time' if you want the berries to grow later)
postreal
10-25-2007, 12:29 PM
nice that you followed :) I do understand this concept, but I cannot turn it to a working script..my scripting skills are zero. Argh..my head explodes as I try to figure out this :)
this is how I understand this problem:
1. I need a slider controlling the transformations (scales).
2. I need a random seed to offset start time of each individual "berrie scales".
3. I dont want to get negative values.
4. I dont want to get random scales for berries, just random starting time for scale.
..when slider is 100 % full, then all the berries are scaled to full size (at the predefined scales).
but how to turn this into a script... :(
Ok i understand, run this on a selection. Test is with some spheres:
(
disableSceneRedraw()
local randomTime = 0f
local randomScale = 0.0
local t = 0.0
local interval = 10f
for i = 1 to selection.count do
(
randomTime = (random animationRange.start (animationRange.end-interval)) as integer
randomScale = random 0.5 2.5
with animate on
(
for f = randomTime to (randomTime + interval) do
(
slidertime = f
t = ((slidertime as integer/160) - randomTime)/(interval as integer/160) as float
t/= 1.0
t = (-1.0 * t * (t-2) + 0.0 )
--selection[i].scale.x = (1-t)*0.0 + (1.0 + randomScale) * t
--selection[i].scale.y = (1-t)*0.0 + (1.0 + randomScale) * t
--selection[i].scale.z = (1-t)*0.0 + (1.0 + randomScale) * t
selection[i].scale.x = ((1-t)^3 *0.0 + 3*t*(1-t)^2*1.35 + 3*t^3*(1-t)* -0.65 + t^3*1.0)* randomScale
selection[i].scale.y = ((1-t)^3 *0.0 + 3*t*(1-t)^2*1.35 + 3*t^3*(1-t)* -0.65 + t^3*1.0)* randomScale
selection[i].scale.z = ((1-t)^3 *0.0 + 3*t*(1-t)^2*1.35 + 3*t^3*(1-t)* -0.65 + t^3*1.0)* randomScale
)
)
selectKeys selection[i].scale.controller 0f
deleteKeys selection[i].scale.controller #selection
gc()
)
slidertime = animationRange.start
enableSceneRedraw()
)
edit: i cleaned this up. The lines commented out are basic growing. Ive added polynormials to give a sence of bouncyness to the growing. And made 't' have an ease out, so they shoot out when they grow. If you make randomScale to one value e.g 3.0 they wont have variation in there size. You could randomize the interval too.
MoonDoggie
10-25-2007, 04:52 PM
polywhat? polynomials? Explain :)
cubic polynormial is the base function of a bezier curve.
postreal
10-26-2007, 07:32 AM
Ok i understand, run this on a selection. Test is with some spheres:
(
disableSceneRedraw()
local randomTime = 0f
local randomScale = 0.0
local t = 0.0
local interval = 10f
for i = 1 to selection.count do
(
randomTime = (random animationRange.start (animationRange.end-interval)) as integer/160randomScale = random -0.5 0.5
randomScale = random 0.5 2.5
with animate on
(
for f = randomTime to (randomTime + interval) do
(
slidertime = f
t = ((slidertime as integer/160) - randomTime)/(interval as integer/160) as float
t/= 1.0
t = (-1.0 * t * (t-2) + 0.0 )
--selection[i].scale.x = (1-t)*0.0 + (1.0 + randomScale) * t
--selection[i].scale.y = (1-t)*0.0 + (1.0 + randomScale) * t
--selection[i].scale.z = (1-t)*0.0 + (1.0 + randomScale) * t
selection[i].scale.x = ((1-t)^3 *0.0 + 3*t*(1-t)^2*1.35 + 3*t^3*(1-t)* -0.65 + t^3*1.0)* randomScale
selection[i].scale.y = ((1-t)^3 *0.0 + 3*t*(1-t)^2*1.35 + 3*t^3*(1-t)* -0.65 + t^3*1.0)* randomScale
selection[i].scale.z = ((1-t)^3 *0.0 + 3*t*(1-t)^2*1.35 + 3*t^3*(1-t)* -0.65 + t^3*1.0)* randomScale
)
)
selectKeys selection[i].scale.controller 0f
deleteKeys selection[i].scale.controller #selection
gc()
)
slidertime = animationRange.start
enableSceneRedraw()
)
edit: i cleaned this up. The lines commented out are basic growing. Ive added polynormials to give a sence of bouncyness to the growing. And made 't' have an ease out, so they shoot out when they grow. If you make randomScale to one value e.g 3.0 they wont have variation in there size. You could randomize the interval too.
Hi there.
Thank you very much for writing this code for me. But it seems I´m doing something wrong. I made some planes on top view, then I ran the script on selection (planes). I get an error saying next:
-- Compile error: Bad number or time syntax
-- In line: randomTime = (random animationRange.start (animationRange.end-interval)) as integer/160randomScale = random -0.5 0.5
By the way I´m using Max 7.0. Thank you very much for helping me on this. I have totally no understanding on max script and you are a big help !
Sorry it was a typo on my end, try this:
(
local randomTime = 0f
local randomScale = 0.0
local t = 0.0
local interval = 10f
local advancedGrow = 1
disableSceneRedraw()
for i = 1 to selection.count do
(
randomTime = (random animationRange.start (animationRange.end-interval)) as integer/160
randomScale = random 1.0 1.0 -- this is the minimum it should be set at!
with animate on
(
for f = randomTime to (randomTime + interval) do
(
slidertime = f
t = ((slidertime as integer/160) - randomTime)/(interval as integer/160) as float
if (advancedGrow == 0) then
(
------------------------------------
-- basic growing
------------------------------------
selection[i].scale.x = (1-t)*0.0 + (randomScale) * t
selection[i].scale.y = (1-t)*0.0 + (randomScale) * t
selection[i].scale.z = (1-t)*0.0 + (randomScale) * t
)
else
(
----------------------------------------
-- Advanced growing with bounce & ramp
----------------------------------------
t/= 1.0
t = (-1.0 * t * (t-2) + 0.0 )
selection[i].scale.x = ((1-t)^3 *0.0 + 3*t*(1-t)^2*1.35 + 3*t^3*(1-t)* -0.65 + t^3*1.0) * randomScale
selection[i].scale.y = ((1-t)^3 *0.0 + 3*t*(1-t)^2*1.35 + 3*t^3*(1-t)* -0.65 + t^3*1.0) * randomScale
selection[i].scale.z = ((1-t)^3 *0.0 + 3*t*(1-t)^2*1.35 + 3*t^3*(1-t)* -0.65 + t^3*1.0) * randomScale
)
)
)
selectKeys selection[i].scale.controller 0f
deleteKeys selection[i].scale.controller #selection
gc()
)
slidertime = animationRange.start
enableSceneRedraw()
)
currently 'randomScale = random 1 1' which means the scale of the objects your running it on will be random from 1 to 1 so no change - They will grow to there original size you made them at. Virtually every setting can be changed:
The growth time, can be random or fixed
The scale of the object can be random or fixed
The interpolation of t can change so you can make it ease in/out, linear, ease out or ease in
The bouncyness of the objects can be changed via 4 variables. I use a cubic polynormial for this.
There's a ton of things you can do ontop of this, just depends on the style of the animation/design.
edit: i add a statement clause for the advanced grow option, so if you declare 'advancedGrow = 0' you'll get simple growing, if 1 you'll get advanced.
postreal
10-29-2007, 08:24 AM
eh..I´m doing something wrong again. What I get is random sized objects that just scale to huge (over my scene limits). How should I use this script ? First I made ramdom sized objects; then I selected them and the I ran the script..it didn´t complain anything, but what I got was just random scale animations on timeline and objects scaled to huge size. My test manipulator slider (slider01) did not affect anyway on the scales. Could you save me an example (max7), I´m totally lost :)
Thanks for being helpfull !
Mikko
eh..I´m doing something wrong again. What I get is random sized objects that just scale to huge (over my scene limits). How should I use this script ? First I made ramdom sized objects; then I selected them and the I ran the script..it didn´t complain anything, but what I got was just random scale animations on timeline and objects scaled to huge size. My test manipulator slider (slider01) did not affect anyway on the scales. Could you save me an example (max7), I´m totally lost :)
Thanks for being helpfull !
Mikko
Err.. well it doesnt have any control of your slider at all. You would have to change i guess the randomScale 1 1 to 'randomScale 1 $.slider01.value' or something i dont know. Hmm.. the objects didnt finish at there original size? thats odd. did you scale them after you made them? I would model say 1 plane, edit it with a editpoly/mesh modifier to get the right scale (dont use the transform scale gizmo or type-in) and duplicate that. Then run the script on them.
For a test, make a bunch of spheres (dont scale them, keep them at there original created size) and run the script. If you set advancedGrow = 0 in the script your'll get just basic growing. (linear)
postreal
11-05-2007, 09:33 AM
uhh...I must be stupid :D I came up with very simple solution :) I have seven different berrie textures..so I only animated those textures to scale from 0 to 100 % and there it was, a perfect random look. Sometimes its hard to see the most simple solution :D Sorry for taking your time !
CGTalk Moderation
11-05-2007, 09:33 AM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.