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:

  1. Create Some objects and scatter them across a xy-plane.
  2. 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?))
  3. 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):

PYTHON:
  1. import Blender, math
  2. from Blender import *
  3.  
  4. curframe = Blender.Get('curframe')
  5.  
  6. ipo = Ipo.Get('cameraipo')
  7. cx = ipo[Ipo.OB_LOCX]
  8. cy = ipo[Ipo.OB_LOCY]
  9. cz = ipo[Ipo.OB_LOCZ]
  10.  
  11. obs = Object.Get()
  12.  
  13. for ob in obs:
  14.     mods = ob.modifiers
  15.     for mod in mods
  16.         if mod.name == 'Decimate':
  17.             sx = ob.LocX
  18.             sy = ob.LocY
  19.             sz = ob.LocZ
  20.             dist = math.sqrt((cx[curframe]-sx)**2 + (cy[curframe]-sy)**2 + (cz[curframe]-sz)**2))
  21.             if dist> 50: dist = 50
  22.             mod[Modifier.Settings.RATIO] = (50-dist)/50 + 0.1
  23.             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:

Verwandte Beiträge

Comments

  • By , 23. April 2007 @ 04:00

    Hey!!! nice use of the animated modifiers. Thanks for sharing.

    Greetings,
    Satish.

Other Links to this Post

RSS-Feed für Kommentare zu diesem Beitrag. TrackBack URI

Einen Kommentar schreiben