blenxy_settings_stuff.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import bpy
  2. # SMG1/2 was made with Autodesk Maya
  3. # and Maya uses centimeters as default unit
  4. # so supposedly SMG1/2 original units are in centimeters
  5. # however...
  6. # SuperBMD assumes everything is in meters so
  7. # using the Mario.dae obtained from the Mario.bdl file
  8. # in the template I will set 1 Galaxy Unit as 100 Meters
  9. # this can be easily modified in the future in case
  10. # I get how this unit thing works fully
  11. # might open an issue on the SuperBMD repo to ask about it
  12. scene = bpy.context.scene
  13. print("Setting Galaxy Unit...")
  14. scene.unit_settings.scale_length = 100
  15. scene.unit_settings.system = 'METRIC'
  16. bpy.ops.scene.units_length_preset_add(name="Galaxy Unit")
  17. scene.unit_settings.system_rotation = 'DEGREES'
  18. scene.unit_settings.use_separate = False
  19. # scale grid to fit new length unit
  20. # Reference used:
  21. # https://blender.stackexchange.com/a/210749
  22. print("\nScaling 3D View grid...")
  23. for area in bpy.context.screen.areas:
  24. if (area.type == 'VIEW_3D'):
  25. view_3d_area = area.spaces.active # declare to use later
  26. area.spaces.active.grid_scale = 100
  27. area.spaces.active.grid_lines = 300
  28. area.spaces.active.show_axis_x = False
  29. area.spaces.active.show_axis_y = False
  30. area.spaces.active.show_axis_z = False
  31. area.spaces.active.clip_start = 0.1
  32. area.spaces.active.clip_end = 10000
  33. break
  34. # import Mario's model from DAE file included in the template
  35. # get blenxy template location for that and select it
  36. # but first delete all objects in scene so it is clean
  37. bpy.ops.object.select_all(action='SELECT')
  38. bpy.ops.object.delete()
  39. print("\nImporting Mario's Model...")
  40. blenxy_path = bpy.utils.user_resource('SCRIPTS', "startup/bl_app_templates_user/blenxy/")
  41. bpy.ops.wm.collada_import(filepath = blenxy_path + "Mario.dae")
  42. Mario = bpy.data.objects.get("Mario")
  43. Mario.select = True
  44. # set a SMG axis for reference when doing models
  45. # it is just a visual queue to get how the model will appear on game
  46. # select a model --> create transform orientation --> modify its matrix
  47. # References used:
  48. # https://blenderartists.org/t/how-to-set-transform-orientation-in-code/542536/4
  49. # for context incorrect bypass:
  50. # https://blender.stackexchange.com/a/6105
  51. print("\nSetting SMG Axis Reference...")
  52. Mario.select = True
  53. override = bpy.context.copy()
  54. override['area'] = area
  55. bpy.ops.transform.create_orientation(override, name = "SMG Axis", use = True)
  56. bpy.context.scene.orientations[-1].matrix = [ [1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0] ]
  57. # set initial 3d viewport camera location
  58. # just a rotation and a camera view distance change
  59. print("\nAdjusting 3D Viewport camera location...")
  60. # set rotation (quaternions)
  61. view_3d_area.region_3d.view_rotation = (0.8001, 0.4619, 0.1913, 0.3314)
  62. # set camera distance to origin
  63. view_3d_area.region_3d.view_distance = 4
  64. # extra stuff to set >:]
  65. print("\nExtra stuff to set...")
  66. # set environment lightnning (material display suggestion)
  67. bpy.context.scene.world.light_settings.use_environment_light = True
  68. # set framerate (SMG runs at 59.94 fps in THP videos)
  69. # need to check if it is the same for BCK animations
  70. bpy.context.scene.render.fps = 60
  71. bpy.context.scene.render.fps_base = 1.001
  72. # set start frame at 0
  73. bpy.data.scenes["Scene"].frame_start = 0
  74. bpy.data.scenes["Scene"].frame_current = 0
  75. print("\nDone with the main settings!\n")