''' Fractalize Blender script Copyright (c) 2006, Gabor Papp (gabor.papp at mndl hu) All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. usage: Each transformation between parent and children will be iterated a number of times set by the variable FRACTAL_LEVELS. Select the parent before running the script. ''' from Blender import * FRACTAL_LEVELS = 2 def getChildren(obj): return filter(lambda x: x.parent==obj, Object.Get()) def duplicate_linked(orig): scene = Scene.getCurrent() type = orig.getType() dup = Object.New(type) dup.shareFrom(orig) scene.link(dup) dup.setMatrix(orig.getMatrix()) scene.update(1) return dup def add_level(obj_list, level): if level <= 0: return for o in obj_list: o_invmat = o.getInverseMatrix() o_size = o.getSize() children = getChildren(o) for base in children: i = 1 base_mat = base.getMatrix() base_size = base.getSize() base_name = base.getName() for c in children: d = duplicate_linked(o) d.setName(base_name + '.%03d' % i) i += 1 c_mat = c.getMatrix() c_size = c.getSize() r = o_invmat*c_mat s_size = (c_size[0]/o_size[0], c_size[1]/o_size[1], c_size[2]/o_size[2]) d.setMatrix(base_mat*r) d.setSize(base_size[0]*s_size[0], base_size[1]*s_size[1], base_size[2]*s_size[2]) c.makeParent([d], 0, 1) add_level(children, level-1) def fractalize(): obj_list = Object.GetSelected() if not obj_list: raise ValueError, 'no selected object' add_level(obj_list, FRACTAL_LEVELS) print 'fractalize' fractalize()