diff options
Diffstat (limited to 'basic_settings.py')
-rw-r--r-- | basic_settings.py | 167 |
1 files changed, 85 insertions, 82 deletions
diff --git a/basic_settings.py b/basic_settings.py index 8f41ec5..49df15f 100644 --- a/basic_settings.py +++ b/basic_settings.py @@ -1,93 +1,96 @@ import bpy # SMG was made under the centimeter unit -# SuperBMD assumes everything is in meters so I will scale down the models when being imported +# SuperBMD assumes everything is in meters so +# I will scale down the models when being imported -# the holy variable -scene = bpy.context.scene +# I could add global variables to be sure all is reset +# but I will only reset in unregister what I can see that needs to be reset -print("Setting length/rotation units...") -scene.unit_settings.system = "METRIC" -scene.unit_settings.scale_length = 0.01 -bpy.ops.scene.units_length_preset_add(name = "Galaxy Unit") -scene.unit_settings.system_rotation = 'DEGREES' -scene.unit_settings.use_separate = False +# register func +@bpy.app.handlers.persistent +def register(dummy): + # the holy variable + scene = bpy.context.scene + print("Setting length/rotation units...") + scene.unit_settings.system = "METRIC" + scene.unit_settings.scale_length = 0.01 + bpy.ops.scene.units_length_preset_add(name = "Galaxy Unit") + scene.unit_settings.system_rotation = "DEGREES" + scene.unit_settings.use_separate = False -# scale grid to fit new length unit -# Reference used: -# https://blender.stackexchange.com/a/210749 + # scale grid to fit new length unit + # Reference used: + # https://blender.stackexchange.com/a/210749 + print("Scaling 3D View grid...") + for area in bpy.context.screen.areas: + if (area.type == "VIEW_3D"): + view_3d_area = area.spaces.active + view_3d_area.grid_scale = 0.01 + view_3d_area.grid_lines = 400 + view_3d_area.show_axis_x = True + view_3d_area.show_axis_y = True + view_3d_area.show_axis_z = True + view_3d_area.clip_start = 0.001 + view_3d_area.clip_end = 1000000 + break -print("Scaling 3D View grid...") + # import Mario's model from DAE file included in the template + # get blenxy template location for that and select it + # but first delete all objects in scene so it is clean + bpy.ops.object.select_all(action = "SELECT") + bpy.ops.object.delete() + print("Importing Mario's Model...") + blenxy_path = bpy.utils.user_resource("SCRIPTS", "startup/bl_app_templates_user/blenxy/") + bpy.ops.wm.collada_import(filepath = blenxy_path + "Mario.dae") + Mario = bpy.data.objects.get("Mario") + Mario.select = True -for area in bpy.context.screen.areas: - if (area.type == "VIEW_3D"): - view_3d_area = area.spaces.active - view_3d_area.grid_scale = 0.01 - view_3d_area.grid_lines = 400 - view_3d_area.show_axis_x = True - view_3d_area.show_axis_y = True - view_3d_area.show_axis_z = True - view_3d_area.clip_start = 0.001 - view_3d_area.clip_end = 1000000 - break + # set a SMG axis for reference when doing models + # it is just a visual queue to get how the model will appear on game + # select a model --> create transform orientation --> modify its matrix + # References used: + # https://blenderartists.org/t/how-to-set-transform-orientation-in-code/542536/4 + # for context incorrect bypass: + # https://blender.stackexchange.com/a/6105 + print("Setting SMG Axis Reference...") + Mario.select = True + override = bpy.context.copy() + override['area'] = area + bpy.ops.transform.create_orientation(override, name = "SMG Axis", use = True) + scene.orientations[-1].matrix = [[ 1.0, 0.0, 0.0], + [ 0.0, 0.0, 1.0], + [ 0.0, -1.0, 0.0]] -# import Mario's model from DAE file included in the template -# get blenxy template location for that and select it -# but first delete all objects in scene so it is clean + # set initial 3d viewport camera location + # just a rotation and a camera view distance change + print("Adjusting 3D Viewport camera location...") + # set rotation (quaternions) + view_3d_area.region_3d.view_rotation = (0.8001, 0.4619, 0.1913, 0.3314) + # set camera distance to origin + view_3d_area.region_3d.view_distance = 4 -bpy.ops.object.select_all(action = "SELECT") -bpy.ops.object.delete() + # extra stuff to set >:] -print("Importing Mario's Model...") -blenxy_path = bpy.utils.user_resource("SCRIPTS", "startup/bl_app_templates_user/blenxy/") -bpy.ops.wm.collada_import(filepath = blenxy_path + "Mario.dae") -Mario = bpy.data.objects.get("Mario") -Mario.select = True - -# set a SMG axis for reference when doing models -# it is just a visual queue to get how the model will appear on game -# select a model --> create transform orientation --> modify its matrix - -# References used: -# https://blenderartists.org/t/how-to-set-transform-orientation-in-code/542536/4 -# for context incorrect bypass: -# https://blender.stackexchange.com/a/6105 - -print("Setting SMG Axis Reference...") - -Mario.select = True -override = bpy.context.copy() -override['area'] = area -bpy.ops.transform.create_orientation(override, name = "SMG Axis", use = True) -scene.orientations[-1].matrix = [[ 1.0, 0.0, 0.0], - [ 0.0, 0.0, 1.0], - [ 0.0, -1.0, 0.0]] - - -# set initial 3d viewport camera location -# just a rotation and a camera view distance change - -print("Adjusting 3D Viewport camera location...") -# set rotation (quaternions) -view_3d_area.region_3d.view_rotation = (0.8001, 0.4619, 0.1913, 0.3314) -# set camera distance to origin -view_3d_area.region_3d.view_distance = 4 - -# extra stuff to set >:] - -print("Extra stuff to set...") -# set environment lightnning (material display suggestion) -scene.world.light_settings.use_environment_light = True -# set framerate (SMG runs at 59.94 fps in THP videos) -scene.render.fps = 60 -scene.render.fps_base = 1.001 -# set frames to be able to go negative and allow them to be shown in scene -bpy.context.user_preferences.edit.use_negative_frames = True -scene.use_preview_range = True -scene.frame_preview_start = 0 -scene.frame_current = 0 -scene.frame_preview_end = 100 -bpy.context.user_preferences.view.use_mouse_depth_navigate = True -# ~ bpy.context.user_preferences.view.use_zoom_to_mouse = True - -print("Done with the basic settings!\n") + print("Extra stuff to set...") + # set environment lightnning (material display suggestion) + scene.world.light_settings.use_environment_light = True + # set framerate (SMG runs at 59.94 fps in THP videos) + scene.render.fps = 60 + scene.render.fps_base = 1.001 + # set frames to be able to go negative and allow them to be shown in scene + bpy.context.user_preferences.edit.use_negative_frames = True + scene.use_preview_range = True + scene.frame_preview_start = 0 + scene.frame_current = 0 + scene.frame_preview_end = 100 + bpy.context.user_preferences.view.use_mouse_depth_navigate = True + # ~ bpy.context.user_preferences.view.use_zoom_to_mouse = True + print("Done with the basic settings!\n") + +# unregister func +def unregister(): + # the holy variable again + scene = bpy.context.scene + # remove the galaxy unit + bpy.ops.scene.units_length_preset_add(remove_active = True) |