-
Notifications
You must be signed in to change notification settings - Fork 22
/
__init__.py
162 lines (139 loc) · 4.5 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
bl_info = {
"name" : "libsm64-blender",
"author" : "libsm64",
"description" : "Add a playble Mario to your Blender Scene",
"blender" : (2, 80, 0),
"version" : (1, 0, 6),
"location" : "View3D",
"warning" : "",
"category" : "Generic"
}
import bpy
import platform
from . mario import insert_mario
class LibSm64Properties(bpy.types.PropertyGroup):
camera_follow : bpy.props.BoolProperty (
name="Follow Mario with 3D cursor + camera",
default=True
)
camera_shift : bpy.props.FloatVectorProperty (
name='Camera Offset',
description='Camera Offset from Mario Origin.',
default=(0.0, 0.0, 1.0),
soft_min =-10.0,
soft_max=10.0,
step=10,
precision=3,
subtype='XYZ',
unit='LENGTH',
size=3
)
mario_scale : bpy.props.FloatProperty(
name="Blender to SM64 Scale",
default=100
)
class LibSm64Preferences(bpy.types.AddonPreferences):
bl_idname = __name__
rom_path : bpy.props.StringProperty(
name="Path",
description="Path to an unmodified US SM64 ROM",
subtype='FILE_PATH',
default=('c:\\sm64.us.z64' if platform.system() == 'Windows' else '~/sm64.us.z64')
)
def draw(self, context):
layout = self.layout
col = layout.column()
col.label(text="SM64 US ROM (Unmodified, 8 MB, z64)")
col.prop(self, 'rom_path')
class Main_PT_Panel(bpy.types.Panel):
bl_idname = "LIBSM64_PT_main_panel"
bl_label = "Insert Mario"
bl_category = "LibSM64"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
scene = context.scene
col = layout.column()
prop_split(col, scene.libsm64, "mario_scale", "Blender to SM64 Scale")
col.prop(scene.libsm64, "rom_path")
col.prop(scene.libsm64, "camera_follow")
col.operator(InsertMario_OT_Operator.bl_idname, text='Insert Mario')
col.prop(scene.libsm64, "camera_shift")
col.operator(ControlMario_OT_Operator.bl_idname, text='Control Mario with keyboard')
col.label(text="WASD + JKL to move. ESC to stop.")
class InsertMario_OT_Operator(bpy.types.Operator):
bl_idname = "view3d.libsm64_insert_mario"
bl_label = "Insert Mario"
bl_description = "Inserts a Mario into the scene"
def execute(self, context):
scene = context.scene
preferences = context.preferences.addons[__package__].preferences
err = insert_mario(preferences.rom_path, scene.libsm64.mario_scale, scene.libsm64.camera_follow)
if err != None:
self.report({"ERROR"}, err)
return {'FINISHED'}
class ControlMario_OT_Operator(bpy.types.Operator):
bl_idname = "view3d.libsm64_control_mario"
bl_label = "Control with keyboard"
bl_description = "Control Mario with keyboard"
def invoke(self, context, event):
global config
config["keyboard_control"] = True
if 'LibSM64 Mario' not in bpy.data.objects:
return self.report({"ERROR"}, 'Insert Mario first.')
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
def modal(self, context, event):
if not config["keyboard_control"]:
return {'FINISHED'}
if event.type == 'ESC':
config["keyboard_control"] = False
return {'FINISHED'}
process_input(event)
return {'RUNNING_MODAL'}
config = {
'keyboard_control': False
}
input_value = {
'UP': False,
'DOWN': False,
'LEFT': False,
'RIGHT': False,
'A': False,
'B': False,
'C': False,
}
input_config = {
'UP': 'W',
'DOWN': 'S',
'LEFT': 'A',
'RIGHT': 'D',
'A': 'J',
'B': 'K',
'C': 'L',
}
def process_input(event):
for k, v in input_config.items():
if event.type == v:
if event.value == 'PRESS':
input_value[k] = True
else:
input_value[k] = False
register_classes, unregister_classes = bpy.utils.register_classes_factory((
LibSm64Properties,
LibSm64Preferences,
Main_PT_Panel,
InsertMario_OT_Operator,
ControlMario_OT_Operator
))
def register():
register_classes()
bpy.types.Scene.libsm64 = bpy.props.PointerProperty(type=LibSm64Properties)
def unregister():
unregister_classes()
del bpy.types.Scene.libsm64
def prop_split(layout, data, field, name):
split = layout.split(factor = 0.5)
split.label(text = name)
split.prop(data, field, text = '')