#!/usr/bin/env python import subprocess import os import glob import sys root = os.path.dirname(sys.argv[0]) platform = sys.platform SHADERS = 'shaders' TEXTURES = 'textures' RES = 2048 # /// ENV SETUP os.environ['DL_SHADERS_PATH'] = os.path.join(root, SHADERS) os.environ['DL_TEXTURES_PATH'] = os.path.join(root, TEXTURES) if platform == 'linux2': print 'running linux' DELIGHT = '/usr/local/3delight-12.0.19/Linux-x86_64' #os.environ['DELIGHT'] = DELIGHT #sys.path.append(os.path.join(DELIGHT, 'bin')) elif platform == 'darwin': DELIGHT = '/Applications/3Delight' os.environ['DELIGHT'] = DELIGHT sys.path.append(os.path.join(DELIGHT, 'bin')) DELIGHT_BIN_FOLDER = os.path.join(DELIGHT, 'bin') DELIGHT_BIN = os.path.join(DELIGHT_BIN_FOLDER, 'renderdl') TDLMAKE_BIN = os.path.join(DELIGHT_BIN_FOLDER, 'tdlmake') def cleanup(): for bakefile in glob.glob(os.path.join(root,'*.bake')): os.remove(bakefile) for tdl in glob.glob(os.path.join(root,'*.tdl')): os.remove(tdl) def gen_includes(heightmap, disp_factor=1): includes = [] disp_bound = disp_factor * 1.05 for file in glob.glob('caster/*'): includes.append(file) for file in glob.glob('receiver/*'): basename = os.path.splitext(os.path.basename(file))[0] dispsettings = '\n\tDisplacement "lm_disp" "float offset" [.01] \n\t"float Km" [{2}] "string texname" ["textures/tweaked_heightmap.tdl"]' include = 'AttributeBegin\ \n\tSurface "lm_bake" "string bakefile" ["{0}"] "string texColName" [""] "string texSpecName" [""] "float Ka" [0.5] "float Kd" [0.4] "float Ks" [0.5] "float roughness" [0.1]\ \n\tAttribute "displacementbound" "sphere" [{3}]\ \n\tReadArchive "{1}"]\ \nAttributeEnd'.format(basename, file, disp_factor, disp_bound) includes.append(include) return includes def bake_post_render(root, res=RES): for bakefile in glob.glob(os.path.join(root, '*.bake')): bake_target = os.path.splitext(bakefile)[0] # tdlmake converts bake files to tdl only cmd = [TDLMAKE_BIN, '-nomipmap', '-progress', '-bakeres', str(res) + 'x' + str(res), bakefile, bake_target + '.tdl'] subprocess.call(cmd) cmd = [TDLMAKE_BIN, '-nomipmap', '-progress', bake_target + '.tdl', bake_target + '.tif'] subprocess.call(cmd) for include in gen_includes('textures/tweaked_heightmap.tdl', 200): print include cleanup() subprocess.call([DELIGHT_BIN, '-res', str(RES), str(RES), '-id', '-progress', 'options.rib']) bake_post_render(root)