forked from morse-simulator/morse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[builder] add setup replacing basics.blend (logic part)
- Loading branch information
1 parent
fe00be2
commit 8cbaa72
Showing
2 changed files
with
287 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,285 @@ | ||
# usage: blender -P {file} | ||
import os, sys, subprocess | ||
|
||
def ext_exec(cmd, python=None): | ||
if not python: | ||
python = 'python%i.%i'%(sys.version_info.major, sys.version_info.minor) | ||
|
||
return subprocess.getoutput('%s -c"%s"' % (python, cmd) ) | ||
|
||
def fix_python_path(python=None): | ||
pythonpath = ext_exec("import os,sys;print(os.pathsep.join(sys.path))") | ||
sys.path.extend(pythonpath.split(os.pathsep)) | ||
|
||
fix_python_path() | ||
|
||
import bpy | ||
from morse.builder.bpymorse import * | ||
from mathutils import Vector, Euler | ||
|
||
def init_morse(): | ||
setup_init() | ||
setup_basics() | ||
finalize() | ||
|
||
def finalize(): | ||
camera = bpy.data.objects['CameraFP'] | ||
camera.data.clip_end = 1000 | ||
bpy.context.scene.camera = camera | ||
|
||
def setup_init(): | ||
""" Setup the scene """ | ||
# Set Game mode | ||
bpy.context.scene.render.engine = 'BLENDER_GAME' | ||
# make sure OpenGL shading language shaders (GLSL) is the | ||
# material mode to use for rendering | ||
bpy.context.scene.game_settings.material_mode = 'GLSL' | ||
# Set the unit system to use for button display (in edit mode) to metric | ||
bpy.context.scene.unit_settings.system = 'METRIC' | ||
# Select the type of Framing to Extend, | ||
# Show the entire viewport in the display window, | ||
# viewing more horizontally or vertically. | ||
bpy.context.scene.game_settings.frame_type = 'EXTEND' | ||
# see the texture in realtime (in the 3D viewport) | ||
set_viewport('TEXTURED', 10000) | ||
# Set the color at the horizon to dark azure | ||
bpy.context.scene.world.horizon_color = (0.05, 0.22, 0.4) | ||
# Display framerate and profile information of the simulation | ||
bpy.context.scene.game_settings.show_framerate_profile = True | ||
bpy.context.scene.render.resolution_x = 800 | ||
bpy.context.scene.render.resolution_y = 600 | ||
# TODO camera issue, see: bpy.ops.scene.new(type='NEW') | ||
# http://www.blender.org/documentation/blender_python_api_2_67b_release/bpy.ops.scene.html#bpy.ops.scene.new | ||
|
||
def setup_basics(): | ||
# warning: not an empty TODO AbstractComponent.append_meshes() | ||
# select_only(bpy.data.objects['CameraFP']) | ||
bpy.ops.object.add(type='CAMERA', location=Vector((6, 0, 4.0)), rotation=Euler((1.57, 0, 1.57), 'XYZ')) | ||
bpy.context.object.name = 'CameraFP' | ||
bpy.context.object.game.physics_type = 'STATIC' | ||
game = bpy.context.object.game | ||
add_controller(type='PYTHON', name='Store degfault') | ||
game.controllers['Store degfault'].mode = "MODULE" | ||
game.controllers['Store degfault'].module = "view_camera.store_default" | ||
add_controller(type='PYTHON', name='MouseLook') | ||
game.controllers['MouseLook'].mode = "MODULE" | ||
game.controllers['MouseLook'].module = "view_camera.rotate" | ||
add_controller(type='PYTHON', name='KeyboardMove') | ||
game.controllers['KeyboardMove'].mode = "MODULE" | ||
game.controllers['KeyboardMove'].module = "view_camera.move" | ||
add_sensor(type='ALWAYS', name='onLoad') | ||
game.sensors['onLoad'].link(game.controllers['Store degfault']) | ||
add_sensor(type='MOUSE', name='Mouse') | ||
game.sensors['Mouse'].mouse_event = "MOVEMENT" | ||
game.sensors['Mouse'].use_pulse = False | ||
game.sensors['Mouse'].link(game.controllers['MouseLook']) | ||
add_sensor(type='KEYBOARD', name='All_Keys') | ||
game.sensors['All_Keys'].key = "NONE" | ||
game.sensors['All_Keys'].use_all_keys = True | ||
game.sensors['All_Keys'].use_pulse_true_level = True | ||
game.sensors['All_Keys'].link(game.controllers['KeyboardMove']) | ||
game.sensors['All_Keys'].link(game.controllers['MouseLook']) | ||
properties(bpy.context.object, Sensitivity=0.001, Speed=0.1) | ||
# warning: not an empty TODO AbstractComponent.append_meshes() | ||
# select_only(bpy.data.objects['CameraID_text']) | ||
bpy.ops.object.add(type='MESH', location=Vector((5, 0.338, 4.151)), rotation=Euler((1.57, 0, 1.57), 'XYZ')) | ||
bpy.context.object.name = 'CameraID_text' | ||
bpy.context.object.game.physics_type = 'NO_COLLISION' | ||
game = bpy.context.object.game | ||
properties(bpy.context.object, Text="No camera selected") | ||
# warning: not an empty TODO AbstractComponent.append_meshes() | ||
# select_only(bpy.data.objects['Compass']) | ||
bpy.ops.object.add(type='MESH', location=Vector((-0.471, -0.312, 18.977)), rotation=Euler((0.0, 0.0, 0.0), 'XYZ')) | ||
bpy.context.object.name = 'Compass' | ||
bpy.context.object.game.physics_type = 'NO_COLLISION' | ||
game = bpy.context.object.game | ||
add_controller(type='PYTHON', name='Billboard') | ||
game.controllers['Billboard'].mode = "MODULE" | ||
game.controllers['Billboard'].module = "billboard.reset_rotation" | ||
add_controller(type='PYTHON', name='Display') | ||
game.controllers['Display'].mode = "MODULE" | ||
game.controllers['Display'].module = "billboard.display" | ||
add_sensor(type='ALWAYS', name='Always') | ||
game.sensors['Always'].use_pulse_true_level = True | ||
game.sensors['Always'].link(game.controllers['Billboard']) | ||
add_sensor(type='KEYBOARD', name='1') | ||
game.sensors['1'].key = "ONE" | ||
game.sensors['1'].modifier_key_1 = "LEFT_SHIFT" | ||
game.sensors['1'].link(game.controllers['Display']) | ||
properties(bpy.context.object, Display=True) | ||
# warning: not an empty TODO AbstractComponent.append_meshes() | ||
# select_only(bpy.data.objects['HUD_plane']) | ||
bpy.ops.object.add(type='MESH', location=Vector((0.0, 0.0, 0.0)), rotation=Euler((0.0, 0.0, 0.0), 'XYZ')) | ||
bpy.context.object.name = 'HUD_plane' | ||
bpy.context.object.game.physics_type = 'NO_COLLISION' | ||
game = bpy.context.object.game | ||
add_actuator(type='PROPERTY', name='Toggle') | ||
game.actuators['Toggle'].mode = "TOGGLE" | ||
game.actuators['Toggle'].object_property = "" | ||
game.actuators['Toggle'].property = "Visible" | ||
game.actuators['Toggle'].value = "" | ||
add_actuator(type='VISIBILITY', name='Show') | ||
game.actuators['Show'].apply_to_children = True | ||
game.actuators['Show'].use_visible = True | ||
add_actuator(type='VISIBILITY', name='Hide') | ||
game.actuators['Hide'].apply_to_children = True | ||
add_controller(type='LOGIC_AND', name='And') | ||
game.controllers['And'].link(actuator=game.actuators['Toggle']) | ||
add_controller(type='LOGIC_AND', name='And1') | ||
game.controllers['And1'].link(actuator=game.actuators['Show']) | ||
add_controller(type='LOGIC_NAND', name='Nand') | ||
game.controllers['Nand'].link(actuator=game.actuators['Hide']) | ||
add_sensor(type='KEYBOARD', name='H_KEY') | ||
game.sensors['H_KEY'].key = "H" | ||
game.sensors['H_KEY'].link(game.controllers['And']) | ||
add_sensor(type='PROPERTY', name='Visible') | ||
game.sensors['Visible'].property = "Visible" | ||
game.sensors['Visible'].value = "True" | ||
game.sensors['Visible'].value_min = "True" | ||
game.sensors['Visible'].link(game.controllers['And1']) | ||
game.sensors['Visible'].link(game.controllers['Nand']) | ||
properties(bpy.context.object, Visible=False) | ||
# warning: not an empty TODO AbstractComponent.append_meshes() | ||
# select_only(bpy.data.objects['Keys_text']) | ||
bpy.ops.object.add(type='MESH', location=Vector((-0.81, 0.3, 0.0)), rotation=Euler((0.0, 0.0, 0.0), 'XYZ')) | ||
bpy.context.object.name = 'Keys_text' | ||
bpy.context.object.game.physics_type = 'NO_COLLISION' | ||
game = bpy.context.object.game | ||
add_controller(type='PYTHON', name='And') | ||
game.controllers['And'].mode = "MODULE" | ||
game.controllers['And'].module = "hud_text.change_text" | ||
add_sensor(type='ALWAYS', name='Keyboard') | ||
game.sensors['Keyboard'].link(game.controllers['And']) | ||
properties(bpy.context.object, Text="HUD text") | ||
# warning: not an empty TODO AbstractComponent.append_meshes() | ||
# select_only(bpy.data.objects['Scene_Script_Holder']) | ||
bpy.ops.object.add(type='EMPTY', location=Vector((0.0, 0.0, 10.828)), rotation=Euler((0.0, 0.0, 0.0), 'XYZ')) | ||
bpy.context.object.name = 'Scene_Script_Holder' | ||
bpy.context.object.game.physics_type = 'NO_COLLISION' | ||
game = bpy.context.object.game | ||
add_actuator(type='SCENE', name='Set_Camera') | ||
game.actuators['Set_Camera'].mode = "CAMERA" | ||
add_actuator(type='GAME', name='Quit_sim') | ||
game.actuators['Quit_sim'].filename = "" | ||
game.actuators['Quit_sim'].mode = "QUIT" | ||
add_actuator(type='GAME', name='Restart_sim') | ||
game.actuators['Restart_sim'].filename = "" | ||
game.actuators['Restart_sim'].mode = "RESTART" | ||
add_controller(type='LOGIC_AND', name='cont') | ||
game.controllers['cont'].link(actuator=game.actuators['Set_Camera']) | ||
add_controller(type='PYTHON', name='Path') | ||
game.controllers['Path'].mode = "MODULE" | ||
game.controllers['Path'].module = "setup_path.test" | ||
game.controllers['Path'].use_priority = True | ||
game.controllers['Path'].link(actuator=game.actuators['Quit_sim']) | ||
add_controller(type='PYTHON', name='Initialize') | ||
game.controllers['Initialize'].mode = "MODULE" | ||
game.controllers['Initialize'].module = "main.init" | ||
game.controllers['Initialize'].link(actuator=game.actuators['Quit_sim']) | ||
add_controller(type='PYTHON', name='Finalize') | ||
game.controllers['Finalize'].mode = "MODULE" | ||
game.controllers['Finalize'].module = "main.finish" | ||
game.controllers['Finalize'].link(actuator=game.actuators['Quit_sim']) | ||
add_controller(type='PYTHON', name='Switch_Camera') | ||
game.controllers['Switch_Camera'].mode = "MODULE" | ||
game.controllers['Switch_Camera'].module = "main.switch_camera" | ||
add_controller(type='LOGIC_AND', name='Fast_quit') | ||
game.controllers['Fast_quit'].link(actuator=game.actuators['Quit_sim']) | ||
add_controller(type='PYTHON', name='Admin') | ||
game.controllers['Admin'].mode = "MODULE" | ||
game.controllers['Admin'].module = "main.simulation_main" | ||
game.controllers['Admin'].link(actuator=game.actuators['Quit_sim']) | ||
add_controller(type='PYTHON', name='Restart') | ||
game.controllers['Restart'].mode = "MODULE" | ||
game.controllers['Restart'].module = "main.restart" | ||
game.controllers['Restart'].link(actuator=game.actuators['Restart_sim']) | ||
add_controller(type='PYTHON', name='Import_path_script') | ||
add_sensor(type='ALWAYS', name='onLoad') | ||
game.sensors['onLoad'].link(game.controllers['cont']) | ||
game.sensors['onLoad'].link(game.controllers['Path']) | ||
add_sensor(type='PROPERTY', name='paths_ok') | ||
game.sensors['paths_ok'].property = "paths_ok" | ||
game.sensors['paths_ok'].value = "True" | ||
game.sensors['paths_ok'].value_min = "True" | ||
game.sensors['paths_ok'].link(game.controllers['Initialize']) | ||
add_sensor(type='KEYBOARD', name='ESC_KEY') | ||
game.sensors['ESC_KEY'].key = "ESC" | ||
game.sensors['ESC_KEY'].link(game.controllers['Finalize']) | ||
add_sensor(type='KEYBOARD', name='F9_KEY') | ||
game.sensors['F9_KEY'].key = "F9" | ||
game.sensors['F9_KEY'].link(game.controllers['Switch_Camera']) | ||
add_sensor(type='KEYBOARD', name='F12_KEY') | ||
game.sensors['F12_KEY'].key = "F12" | ||
game.sensors['F12_KEY'].link(game.controllers['Fast_quit']) | ||
add_sensor(type='ALWAYS', name='Constant') | ||
game.sensors['Constant'].use_pulse_true_level = True | ||
game.sensors['Constant'].link(game.controllers['Admin']) | ||
add_sensor(type='KEYBOARD', name='F11_KEY') | ||
game.sensors['F11_KEY'].key = "F11" | ||
game.sensors['F11_KEY'].link(game.controllers['Restart']) | ||
properties(bpy.context.object, UTMZOffset=0.0, UTMXOffset=0.0, paths_ok=True, Temperature="15.0", environment_file="", UTMYOffset=0.0) | ||
# warning: not an empty TODO AbstractComponent.append_meshes() | ||
# select_only(bpy.data.objects['Screen']) | ||
bpy.ops.object.add(type='MESH', location=Vector((4.8, 0.5, 4.3)), rotation=Euler((1.57, 0, 1.57), 'XYZ')) | ||
bpy.context.object.name = 'Screen' | ||
bpy.context.object.game.physics_type = 'NO_COLLISION' | ||
game = bpy.context.object.game | ||
add_actuator(type='PROPERTY', name='Toggle') | ||
game.actuators['Toggle'].mode = "TOGGLE" | ||
game.actuators['Toggle'].object_property = "" | ||
game.actuators['Toggle'].property = "Visible" | ||
game.actuators['Toggle'].value = "" | ||
add_actuator(type='VISIBILITY', name='Show') | ||
game.actuators['Show'].apply_to_children = True | ||
game.actuators['Show'].use_visible = True | ||
add_actuator(type='VISIBILITY', name='Hide') | ||
game.actuators['Hide'].apply_to_children = True | ||
add_controller(type='LOGIC_AND', name='And') | ||
game.controllers['And'].link(actuator=game.actuators['Toggle']) | ||
add_controller(type='LOGIC_AND', name='And1') | ||
game.controllers['And1'].link(actuator=game.actuators['Show']) | ||
add_controller(type='LOGIC_NAND', name='Nand') | ||
game.controllers['Nand'].link(actuator=game.actuators['Hide']) | ||
add_sensor(type='KEYBOARD', name='V_KEY') | ||
game.sensors['V_KEY'].key = "V" | ||
game.sensors['V_KEY'].link(game.controllers['And']) | ||
add_sensor(type='PROPERTY', name='Visible') | ||
game.sensors['Visible'].property = "Visible" | ||
game.sensors['Visible'].value = "True" | ||
game.sensors['Visible'].value_min = "True" | ||
game.sensors['Visible'].link(game.controllers['And1']) | ||
game.sensors['Visible'].link(game.controllers['Nand']) | ||
properties(bpy.context.object, DisplayCamera="CameraMain", Visible=False) | ||
# warning: not an empty TODO AbstractComponent.append_meshes() | ||
# select_only(bpy.data.objects['Screen_frame']) | ||
bpy.ops.object.add(type='MESH', location=Vector((4.799, 0.5, 4.299)), rotation=Euler((1.57, 0, 1.57), 'XYZ')) | ||
bpy.context.object.name = 'Screen_frame' | ||
bpy.context.object.game.physics_type = 'NO_COLLISION' | ||
game = bpy.context.object.game | ||
# warning: not an empty TODO AbstractComponent.append_meshes() | ||
# select_only(bpy.data.objects['Title_text']) | ||
bpy.ops.object.add(type='MESH', location=Vector((-0.6, 0.43, 0.0)), rotation=Euler((0.0, 0.0, 0.0), 'XYZ')) | ||
bpy.context.object.name = 'Title_text' | ||
bpy.context.object.game.physics_type = 'NO_COLLISION' | ||
game = bpy.context.object.game | ||
properties(bpy.context.object, Text="MORSE keyboard shortcuts") | ||
bpy.data.objects['Compass'].parent = bpy.data.objects['CameraFP'] | ||
bpy.data.objects['HUD_plane'].parent = bpy.data.objects['CameraFP'] | ||
bpy.data.objects['Screen'].parent = bpy.data.objects['CameraFP'] | ||
bpy.data.objects['Keys_text'].parent = bpy.data.objects['HUD_plane'] | ||
bpy.data.objects['Title_text'].parent = bpy.data.objects['HUD_plane'] | ||
bpy.data.objects['CameraID_text'].parent = bpy.data.objects['Screen'] | ||
bpy.data.objects['Screen_frame'].parent = bpy.data.objects['Screen'] | ||
new_text() | ||
text = get_last_text() | ||
text.name = 'Info.txt' | ||
text.write("###########################################\n# Multi Open Robots Simulation Engine #\n###########################################\n\n\nCamera Control\n--------------\n\t\n\tDisplay help: Press the H key\n\tToggle screen on/off: Press the V key\n\t\n\tCamera controls:\n\t\tHold left CTRL + Mouse -> Look around\n\t\tW/Z, S keys -> Move forward, backward\n\t\tA/Q, D keys -> Move to the sides\n\t\tR, F keys -> Move up, down\n\t\t\n\tThe speed and sensitivity of movement can be changed by editing the Logic Properties of the CameraFP object\n\t\n\t\n\nDefault props file\n-----------------\n\nIncludes:\n\t- the Scene_Script_Holder object\n\t- the CameraFP object\n\t- the Compass object\n\t- HUD help messages\n\t- the basic scripts:\n\t\t- to initialize PYTHONPATH\n\t\t- to configure components") | ||
new_text() | ||
text = get_last_text() | ||
text.name = 'setup_path.py' | ||
text.write("import sys, os\n\n\"\"\" Check that MORSE libraries are correctly installed\n\nSearches the PYTHONPATH variable for the required directories: $ORS_ROOT and $ORS_ROOT/morse/blender\n\"\"\"\n\ndef test(contr):\n print (\"==============================\")\n print (\"Welcome to the MORSE simulator\")\n print (\"==============================\")\n #print (\"\\nUsing path: {0}\\n\".format(sys.path))\n\n blender_dir = 'morse/blender'\n\n for dir in sys.path:\n if os.path.exists(os.path.join(dir, \"morse/blender/main.py\")):\n sys.path.append(os.path.join(dir, \"morse/blender\"))\n sys.path.append(os.path.join(dir, \"morse/blender/human_interaction\"))\n return\n \n print (\"MORSE ERROR: could not find the MORSE libraries. Please run 'morse check' from the command line to solve this issue.\")\n print (\"Exiting the simulation!\")\n quitActuator = contr.actuators['Quit_sim']\n contr.activate(quitActuator)") | ||
|
||
|
||
# to test with: blender -P {file} | ||
if __name__ == '__main__': | ||
init_morse() |