[Closed] Simple Math Problem
This is probably a very simple bit of math however it escapes me
I want to make a copy of a mesh every 20 frames say. The actual code to make the copy I am working on so dont need help with, yet I am still learning MScript.
My problem is I cannot figure out how to make this happen say every 20th frame. I know I need to take the current frame and somehow test to see if it is 0 20 40 60 80 then create the snapshot. However I do not want to hand code the frame values in as I dont know the length of the finished piece. Any help would be good. (with an explanation please )
Thanks
Harry
for t = animationrange.start to animationrange.end by 20 do
(
at time t ( ) –do something inside the time context
)–end t loop
You could also set the time slider directly to the time in the loop, like
sliderTime = t
which will cause the scene to update while you are running the loop. In some cases, for example when dealing with Particle Flow, this is the only way to force an update of the object. In most other cases, at time t () context should be enough…
Thanks Bobo. I just figured out the “by 20 bit” and was going to post my finding, but you beat me to it :). The animation range section is very useful however and has simplified the other part of the script a lot.
Thanks
Harry
Ok I am a little further in with my script but have become stuck again…
This is the script so far
[size=1]for t = animationrange.start to animationrange.end by 20 do
(
MyName = (“Slab_” + t as string)
at time t (Snapshot $SlabMover_01 name:myname)
slidertime = t
)
for o in $slab_* do
(
print o.name
o.visibility = Linear_float()
o.visibility.controller.value = 0.0
print currenttime
)
[/size]This is what I had in mind…feel free to point out any errors in my thinking
I havea rolling box that rolls across the screen. At every 20 frames I create a Snapshot of the box and want to set its visibility to 1.0 on the frame it was created and Zero on the previous frame, with a stepped tangent. This basicly allows the rolling box to uncover the slabs as it goes over them…
The first loop I setup to loop through every 20 frames and create a snapshot and name it the same with the name Slab and append the frame on which it was created.
The bit im stuck on is how to go about the second loop. Part of its there however I need to loop through the geometry and read out the frame part of the name. I am baffled by how to do this. I have looked through forum and manual before posting but have come up blank…
Any pointers would be appreciated… I would like more of a hint than a solution as I would like to work this thing out
Thanks
Harry
This seems to work just need to figure out tangents…I would have like it to name the slabs with the prefix Slab though…
for t = animationrange.start to animationrange.end by 20 do
(
MyName = (t as string)
at time t (Snapshot $SlabMover_01 name:myname)
–slidertime = t
)
for o in $*f do
(
o.visibility = Bezier_float()
o.visibility.controller.value = 0
MyName = o.name as integer
animate on
(at time Myname o.visibility.controller.value = 1.0
)
)
Ok I think I have it:
for t = animationrange.start to animationrange.end by 20 do
(
MyName = (t as string)
at time t (Snapshot $SlabMover_01 name:myname)
–slidertime = t
)
for o in $*f do
(
o.visibility = Bezier_float()
o.visibility.controller.value = 0
MyName = o.name as integer
animate on
(at time Myname o.visibility.controller.value = 1.0
)
o.visibility.keys.intangenttype = #step
o.visibility.keys.outtangenttype = #step
)
This seems to work as planned however it still doesnt let me name things with a prefix
Any pointers on this would be great
Harry
There is really no reason for two loops. (And if you wanted two loops, you could have just collected the results of the snapshot operations in an array, the times of their creation in another and looped through them instead).
Try to avoid name dependencies – storing the time in the object’s name and trying to get it back sounds like a bad idea to me.
Here is a single loop version – I created an animated Box here and tested it to see what it does. Seems to work ok…
(
theObj = $Box01
for t = animationrange.start to animationrange.end by 20 do
(
at time t
(
theClone = Snapshot theObj
theClone.name = theObj.name + "_" +t as string
theClone.visibility = bezier_float()
theClone.visibility.controller.value = 0
with animate on theClone.visibility.controller.value = 1
theClone.visibility.keys.intangenttype = #step
theClone.visibility.keys.outtangenttype = #step
)--end time
)--end t loop
)--end script
Just for information, Modulo is what you would use to do this in other languages and basic math, it can do basically the same thing as the ‘by #’ with a little work
Hi Bobo
You certainly simplified the loop I am still early on in the learning process so I dont think that I did too bad. Still finding my feet with the whole coding thing…using your dvd’s has helped no end…thanks
I see what you mean about the name thing I just couldnt figure out how to store the information. I will try your code tomorrow…thanks again.
Vsai
Thanks for that you dont know how long I was trying to find that name
No, you did well. Most functions in MAXScript return values (some return a meaningless OK, but in many cases you will get an actual value to work with).
So in your case, calling the snapshot method returns the new object as result.
Once you get it, you can change its name – snapshot does not allow you to use the name: parameter to rename the clone.
If you wanted (for some technical reason) to go with two loops, you would do the following:
(
theObj = $Box01
theObjects = #() --define an array to collect data
for t = animationrange.start to animationrange.end by 20 do
(
at time t
(
theClone = Snapshot theObj
theClone.name = theObj.name + "_" +t as string
append theObjects #(theClone,t) --add a subarray containing the object and time
)--end time
)--end t loop
for o in theObjects do --loop through all sub-arrays in the data array
(
theObj = o[1] --element 1 is the object, element 2 is the time
theObj.visibility = bezier_float()
theObj.visibility.controller.value = 0
at time o[2] with animate on theObj.visibility.controller.value = 1 --set the time and animate
theObj.visibility.keys.intangenttype = #step
theObj.visibility.keys.outtangenttype = #step
)--end o loop
)--end script