Animating modifiers
After doing day-long construction job (actually this is something that has been going on for quite a while and I'm looking forward to ending this construction) and since i had to wait to get someone to the airport at 3:15am i decided to have a look at blendernation and found a very interesting article about "Animated Modifiers". The gist of it: The values assigned to a modifier can't be animated right now. While on can't see the point in animating the level of Subsurfacing applied to a mesh, Matt demonstrates a way to change the value of "Decimation" modifier.
For that to work, one has to 'read' the current value of an IPO-Curve (Matt uses an 'Empty') and based on it's value change the "RATIO"-setting for the decimate modifier.
Some comments suggested using this nice trick to decimate objects which are further away from the camera more and let them get less decimated when they get nearer. So this is what i did:
- Create Some objects and scatter them across a xy-plane.
- Have the objects all have a 'decimate' modifier (best copy and paste an object which already has the modifier; by the way, wouldn't it be nice, if we could add modifiers to multiple objects?))
- Set up an IPO for the camera and add some points for camera navigation
Once the basic scene is finished, this is the python-script i used (based on what Matt provided in the example .blend-file):
-
import Blender, math
-
from Blender import *
-
-
curframe = Blender.Get('curframe')
-
-
ipo = Ipo.Get('cameraipo')
-
cx = ipo[Ipo.OB_LOCX]
-
cy = ipo[Ipo.OB_LOCY]
-
cz = ipo[Ipo.OB_LOCZ]
-
-
obs = Object.Get()
-
-
for ob in obs:
-
mods = ob.modifiers
-
for mod in mods
-
if mod.name == 'Decimate':
-
sx = ob.LocX
-
sy = ob.LocY
-
sz = ob.LocZ
-
dist = math.sqrt((cx[curframe]-sx)**2 + (cy[curframe]-sy)**2 + (cz[curframe]-sz)**2))
-
if dist> 50: dist = 50
-
mod[Modifier.Settings.RATIO] = (50-dist)/50 + 0.1
-
ob.makeDisplayList()
The 0.1 that is added to the RATIO is only there to ensure the objects don't disappear. And i guess there is a better way to make the objects regenerate other that .makeDisplayList() inside the for-loop.
Here is the result:
[MEDIA=10]
Python-references
Because this is my first python script here are the references i used:
Comments
Other Links to this Post
RSS-Feed für Kommentare zu diesem Beitrag. TrackBack URI
By , 23. April 2007 @ 04:00
Hey!!! nice use of the animated modifiers. Thanks for sharing.
Greetings,
Satish.