-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmengersponge.py
36 lines (30 loc) · 1.14 KB
/
mengersponge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# mengersponge.py
#---------------------------------------------
#
# Simple menger sponge generator
import c4d
def CreateCubes(p, size, scale, depth):
end = False
if depth-1==0: end = True
null = c4d.BaseObject(c4d.Onull)
null.SetRelPos(p-size)
for x in xrange(3):
for y in xrange(3):
for z in xrange(3):
if x%2!=0 and y%2!=0: continue
if z%2!=0 and y%2!=0: continue
if x%2!=0 and z%2!=0: continue
sx = sy = sz = size
position = c4d.Vector(x*sx,y*sy, z*sz)
if end:
cube = c4d.BaseObject(c4d.Oinstance)
cube[c4d.INSTANCEOBJECT_RENDERINSTANCE] = True
cube[c4d.INSTANCEOBJECT_LINK] = op[c4d.ID_USERDATA, 1]
cube.SetRelPos(position)
cube.SetRelScale(c4d.Vector(scale))
else:
cube = CreateCubes(position, size/3.0, scale/3.0, depth-1)
cube.InsertUnder(null)
return null
def main():
return CreateCubes(p=c4d.Vector(0), size=200, scale=1, depth=op[c4d.ID_USERDATA, 2])