basic_settings.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import bpy
  2. # SMG was made under the centimeter unit
  3. # SuperBMD assumes everything is in meters so I will scale down the models when being imported
  4. scene = bpy.context.scene
  5. print("Setting length/rotation units...")
  6. scene.unit_settings.system = 'METRIC'
  7. scene.unit_settings.scale_length = 0.01
  8. bpy.ops.scene.units_length_preset_add(name="Galaxy Unit")
  9. scene.unit_settings.system_rotation = 'DEGREES'
  10. scene.unit_settings.use_separate = False
  11. # scale grid to fit new length unit
  12. # Reference used:
  13. # https://blender.stackexchange.com/a/210749
  14. print("Scaling 3D View grid...")
  15. for area in bpy.context.screen.areas:
  16. if (area.type == 'VIEW_3D'):
  17. view_3d_area = area.spaces.active
  18. view_3d_area.grid_scale = 0.01
  19. view_3d_area.grid_lines = 400
  20. view_3d_area.show_axis_x = True
  21. view_3d_area.show_axis_y = True
  22. view_3d_area.show_axis_z = True
  23. view_3d_area.clip_start = 0.001
  24. view_3d_area.clip_end = 1000000
  25. break
  26. # import Mario's model from DAE file included in the template
  27. # get blenxy template location for that and select it
  28. # but first delete all objects in scene so it is clean
  29. bpy.ops.object.select_all(action='SELECT')
  30. bpy.ops.object.delete()
  31. print("Importing Mario's Model...")
  32. blenxy_path = bpy.utils.user_resource('SCRIPTS', "startup/bl_app_templates_user/blenxy/")
  33. bpy.ops.wm.collada_import(filepath = blenxy_path + "Mario.dae")
  34. Mario = bpy.data.objects.get("Mario")
  35. Mario.select = True
  36. # set a SMG axis for reference when doing models
  37. # it is just a visual queue to get how the model will appear on game
  38. # select a model --> create transform orientation --> modify its matrix
  39. # References used:
  40. # https://blenderartists.org/t/how-to-set-transform-orientation-in-code/542536/4
  41. # for context incorrect bypass:
  42. # https://blender.stackexchange.com/a/6105
  43. print("Setting SMG Axis Reference...")
  44. Mario.select = True
  45. override = bpy.context.copy()
  46. override['area'] = area
  47. bpy.ops.transform.create_orientation(override, name = "SMG Axis", use = True)
  48. bpy.context.scene.orientations[-1].matrix = [[ 1.0, 0.0, 0.0],
  49. [ 0.0, 0.0, 1.0],
  50. [ 0.0, -1.0, 0.0]]
  51. # set initial 3d viewport camera location
  52. # just a rotation and a camera view distance change
  53. print("Adjusting 3D Viewport camera location...")
  54. # set rotation (quaternions)
  55. view_3d_area.region_3d.view_rotation = (0.8001, 0.4619, 0.1913, 0.3314)
  56. # set camera distance to origin
  57. view_3d_area.region_3d.view_distance = 4
  58. # extra stuff to set >:]
  59. print("Extra stuff to set...")
  60. # set environment lightnning (material display suggestion)
  61. bpy.context.scene.world.light_settings.use_environment_light = True
  62. # set framerate (SMG runs at 59.94 fps in THP videos)
  63. bpy.context.scene.render.fps = 60
  64. bpy.context.scene.render.fps_base = 1.001
  65. # set start frame at 0
  66. bpy.data.scenes["Scene"].frame_start = 0
  67. bpy.data.scenes["Scene"].frame_current = 0
  68. print("Done with the basic settings!\n")