#!/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] shape = ['BOX','CONE'] size = [40,4] nlevel = 1 def make_tabs(level): s = "" for i in range(0,level): s = s + '\t' return s def make_obbox(x,y,z,sz): s = "" hsz = sz*.5 #half size s = s+ "{} {} {}, {} {} {}, {} {} {}, {} {} {}".format(x,y,z,hsz,0,0,0,hsz,0,0,0,hsz) return s def make_tile_start(level,shapename,x,y,z): s = make_tabs(level) s = s + """""" s = s + '\n' s = s + make_tabs(level+1) s = s + """\n""".format(x,y,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,y,z): s = make_tile_start(level,shape[level],x,y,z) if level < nlevel: level = level + 1 sz = size[level] for i in range(-10,11,2): for j in range(-10,11,2): for k in range(-10,11,2): xx = x + i*sz*.5 yy = y + j*sz*.5 zz = z + k*sz*.5 s = s + make_tile(level,xx,yy,zz) level = level -1 s = s + make_tile_end(level) return s def make_grid(): s = "" s = s + make_tile(0,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_scene2.x3d" f = open(fname,"w+") f.write(outstr) f.close()