#!/usr/bin/env python
# MIT or general permissive
import os, sys
from sys import platform
def pre_amble():
s = """
"""
return s
def post_amble():
s = """
"""
return s
level = 0
error = [5, .5, .05, .01]
shape = ['PLANE','CYLINDER','CONE','SPHERE']
size = [40,20,10,5,2.5]
nlevel = 3
def make_tabs(level):
s = ""
for i in range(0,level):
s = s + '\t'
return s
def make_obbox(x,z,sz):
s = ""
s = s+ "{} {} {}, {} {} {}, {} {} {}, {} {} {}".format(x,0,z,sz,0,0,0,.1,0,0,0,sz)
return s
def make_tile_start(level,shapename,x,z):
s = make_tabs(level)
s = s + """"""
s = s + '\n'
s = s + make_tabs(level+1)
s = s + """\n""".format(x,0,z)
s = s + make_tabs(level+2)
s = s + """\n"""
s = s + make_tabs(level+1)
s = s + """\n"""
return s
def make_tile_end(level):
s = make_tabs(level)
s = s + """\n"""
return s
def make_tile(level,x,z):
s = make_tile_start(level,shape[level],x,z)
if level < nlevel:
level = level + 1
sz = size[level]
for i in range(-1,2,2):
for j in range(-1,2,2):
xx = x + i*sz*.5
zz = z + j*sz*.5
s = s + make_tile(level,xx,zz)
level = level -1
s = s + make_tile_end(level)
return s
def make_grid():
s = ""
s = s + make_tile(0,0,0)
return s
def generate_scene():
scene = pre_amble();
scene = scene + make_grid()
scene = scene + post_amble()
return scene
if __name__ == "__main__":
outstr = generate_scene()
fname = "tile_scene.x3d"
f = open(fname,"w+")
f.write(outstr)
f.close()