Skip to content

Commit

Permalink
[builder] setup cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickKoch committed Oct 6, 2013
1 parent 8c0c51e commit a262f6c
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 172 deletions.
81 changes: 30 additions & 51 deletions src/morse/builder/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@ def select_only(obj):
obj.select = True
bpy.context.scene.objects.active = obj

def roundv(v,r=3):
return tuple([round(e, r) for e in v])

def do_all():
print("base = AbstractComponent(category='props', filename='basics_wo_logic')")
meshes = [o.name for o in bpy.data.objects if o.type == 'MESH']
print("base.append_meshes(%s)"%repr(meshes))
for obj in bpy.data.objects:
if not obj.type is 'EMPTY':
print("# warning: not an empty TODO AbstractComponent.append_meshes()")
print("# select_only(bpy.data.objects['%s'])"%obj.name)
#else:
print("bpy.ops.object.add(type='%s', location=%s, rotation=%s)" % \
(obj.type, repr(obj.location), repr(obj.rotation_euler)))

print("bpy.context.object.name = '%s'" % obj.name)
print("# %s : %s"%(obj.type, obj.name))
if obj.type == 'MESH':
print("select_only(bpy.data.objects['%s'])"%obj.name)
else:
print("bpy.ops.object.add(type='%s', location=%s, rotation=%s)" % \
(obj.type, repr(obj.location), repr(obj.rotation_euler)))
print("bpy.context.object.name = '%s'" % obj.name)
if obj.scale != (1,1,1):
print("bpy.context.object.scale = %s" % repr(obj.scale))

print("bpy.context.object.game.physics_type = '%s'" % obj.game.physics_type)
print("bpy.context.object.hide_render = %s" % obj.hide_render)
if obj.scale != (1,1,1):
print("bpy.context.object.scale = %s" % repr(obj.scale))
print_all_logic(obj)
print_properties(obj)
print_all_logic(obj)

# set children - parent relationship
for obj in bpy.data.objects:
Expand All @@ -34,10 +40,12 @@ def do_all():

# set children - parent relationship
for text in bpy.data.texts:
print("# text : %s"%text.name)
print("new_text()")
print("text = get_last_text()")
print("text.name = '%s'" % text.name)
print("text.write(%s)" % json.dumps(text.as_string()) )
print("text_str = %s" % json.dumps(text.as_string()) )
print("text.write(text_str)")


def get_properties(obj):
Expand Down Expand Up @@ -76,6 +84,7 @@ def print_all_logic(obj):
print("game.sensors['%s'].link(game.controllers['%s'])" % \
(brick.name, ctr.name) )

# map the default values of game logic bricks to filter the output
map_attr_default = {
'default': {
'__module__': '',
Expand All @@ -93,7 +102,6 @@ def print_all_logic(obj):
'use_tap': False,
'pin': False,
},
# other attributes of sensor sub-classes...
'PROPERTY': {
'evaluation_type': 'PROPEQUAL',
'property': '',
Expand All @@ -114,7 +122,6 @@ def print_all_logic(obj):
'use_priority': False,
'states': 1,
},
# other attributes of controller sub-classes...
'PYTHON': {
'mode': 'SCRIPT',
'module': '',
Expand All @@ -125,11 +132,9 @@ def print_all_logic(obj):
'default': {
'pin': False,
},
# other attributes of actuator sub-classes...
'VISIBILITY': {
'apply_to_children': False,
'use_occlusion': False,
'use_visible': False,
},
},
}
Expand All @@ -149,30 +154,11 @@ def print_logic(brick, sca):
value == map_attr_default[sca][brick.type][attr]:
continue # skip default to save readibility
if type(value).__name__ in ['int', 'float', 'bool']:
print("game.%ss['%s'].%s = %s" % \
(sca, brick.name, attr, str(value)) )
print("game.%ss[-1].%s = %s" % (sca, attr, str(value)) )
if type(value).__name__ == 'str':
print("game.%ss['%s'].%s = %s" % \
(sca, brick.name, attr, json.dumps(value)) )
#else:
# print("# game.%ss['%s'].%s = %s" % \
# (sca, brick.name, attr, repr(value)) )

# TODO cleanup

"""
for sca_type in ['default', brick.type]:
for attr in map_attr_default[sca][sca_type].keys():
value = getattr(brick, attr)
if value != map_attr_default[sca][attr]:
print("game.%ss['%s'].%s = %s" % \
(sca, brick.name, attr, str(value)) )
"""
print("game.%ss[-1].%s = %s" % (sca, attr, json.dumps(value)) )


# if __name__ == '__main__':

print("""# usage: blender -P {file}
_header = """# usage: blender -P {file}
import os, sys, subprocess
def ext_exec(cmd, python=None):
Expand All @@ -188,18 +174,11 @@ def fix_python_path(python=None):
fix_python_path()
from morse.builder.bpymorse import *
from morse.builder import AbstractComponent
from mathutils import Vector, Euler
""")

do_all()

print("""
# over
""")
"""

import os, sys
# _stdout = sys.stdout
sys.stdout.flush()
sys.stdout = open(os.devnull, 'wb')
if __name__ == '__main__':
print(_header)
do_all()
print("\n\n# TODO remove the following lines (Blender output messages)\n\n")

0 comments on commit a262f6c

Please sign in to comment.