forked from Fast-64/fast64
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgeneral.py
More file actions
291 lines (230 loc) · 9.99 KB
/
Copy pathgeneral.py
File metadata and controls
291 lines (230 loc) · 9.99 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
from dataclasses import dataclass
from bpy.types import Object
from ....utility import PluginError, CData, exportColor, ootGetBaseOrCustomLight, indent
from ...scene.properties import OOTSceneHeaderProperty, OOTLightProperty
from ..utility import Utility
@dataclass
class EnvLightSettings:
"""This class defines the information of one environment light setting"""
envLightMode: str
ambientColor: tuple[int, int, int]
light1Color: tuple[int, int, int]
light1Dir: tuple[int, int, int]
light2Color: tuple[int, int, int]
light2Dir: tuple[int, int, int]
fogColor: tuple[int, int, int]
fogNear: int
zFar: int
blendRate: int
def getBlendFogNear(self):
"""Returns the packed blend rate and fog near values"""
return f"(({self.blendRate} << 10) | {self.fogNear})"
def getColorValues(self, vector: tuple[int, int, int]):
"""Returns and formats color values"""
return ", ".join(f"{v:5}" for v in vector)
def getDirectionValues(self, vector: tuple[int, int, int]):
"""Returns and formats direction values"""
return ", ".join(f"{v - 0x100 if v > 0x7F else v:5}" for v in vector)
def getEntryC(self, index: int):
"""Returns an environment light entry"""
isLightingCustom = self.envLightMode == "Custom"
vectors = [
(self.ambientColor, "Ambient Color", self.getColorValues),
(self.light1Dir, "Diffuse0 Direction", self.getDirectionValues),
(self.light1Color, "Diffuse0 Color", self.getColorValues),
(self.light2Dir, "Diffuse1 Direction", self.getDirectionValues),
(self.light2Color, "Diffuse1 Color", self.getColorValues),
(self.fogColor, "Fog Color", self.getColorValues),
]
fogData = [
(self.getBlendFogNear(), "Blend Rate & Fog Near"),
(f"{self.zFar}", "Fog Far"),
]
lightDescs = ["Dawn", "Day", "Dusk", "Night"]
if not isLightingCustom and self.envLightMode == "LIGHT_MODE_TIME":
# TODO: Improve the lighting system.
# Currently Fast64 assumes there's only 4 possible settings for "Time of Day" lighting.
# This is not accurate and more complicated,
# for now we are doing ``index % 4`` to avoid having an OoB read in the list
# but this will need to be changed the day the lighting system is updated.
lightDesc = f"// {lightDescs[index % 4]} Lighting\n"
else:
isIndoor = not isLightingCustom and self.envLightMode == "LIGHT_MODE_SETTINGS"
lightDesc = f"// {'Indoor' if isIndoor else 'Custom'} No. {index + 1} Lighting\n"
lightData = (
(indent + lightDesc)
+ (indent + "{\n")
+ "".join(
indent * 2 + f"{'{ ' + vecToC(vector) + ' },':26} // {desc}\n" for (vector, desc, vecToC) in vectors
)
+ "".join(indent * 2 + f"{fogValue + ',':26} // {fogDesc}\n" for fogValue, fogDesc in fogData)
+ (indent + "},\n")
)
return lightData
@dataclass
class SceneLighting:
"""This class hosts lighting data"""
name: str
envLightMode: str
settings: list[EnvLightSettings]
@staticmethod
def new(name: str, props: OOTSceneHeaderProperty):
envLightMode = Utility.getPropValue(props, "skyboxLighting")
lightList: list[OOTLightProperty] = []
settings: list[EnvLightSettings] = []
if envLightMode == "LIGHT_MODE_TIME":
todLights = props.timeOfDayLights
lightList = [todLights.dawn, todLights.day, todLights.dusk, todLights.night]
else:
lightList = props.lightList
for lightProp in lightList:
light1 = ootGetBaseOrCustomLight(lightProp, 0, True, True)
light2 = ootGetBaseOrCustomLight(lightProp, 1, True, True)
settings.append(
EnvLightSettings(
envLightMode,
exportColor(lightProp.ambient),
light1[0],
light1[1],
light2[0],
light2[1],
exportColor(lightProp.fogColor),
lightProp.fogNear,
lightProp.z_far,
lightProp.transitionSpeed,
)
)
return SceneLighting(name, envLightMode, settings)
def getCmd(self):
"""Returns the env light settings scene command"""
return (
indent + "SCENE_CMD_ENV_LIGHT_SETTINGS("
) + f"{len(self.settings)}, {self.name if len(self.settings) > 0 else 'NULL'}),\n"
def getC(self):
"""Returns a ``CData`` containing the C data of env. light settings"""
lightSettingsC = CData()
lightName = f"EnvLightSettings {self.name}[{len(self.settings)}]"
# .h
lightSettingsC.header = f"extern {lightName};\n"
# .c
lightSettingsC.source = (
(lightName + " = {\n") + "".join(light.getEntryC(i) for i, light in enumerate(self.settings)) + "};\n\n"
)
return lightSettingsC
def getXML(self):
"""Returns a ``str`` containing the XML data of env. light settings"""
data = "<LightingSettings>\n"
for i, light in enumerate(self.settings):
data += indent *1 + "<LightingSetting "
data += f"AmbientColorR='{light.ambientColor[0]}' "
data += f"AmbientColorG='{light.ambientColor[1]}' "
data += f"AmbientColorB='{light.ambientColor[2]}' "
data += f"Light1DirX='{light.light1Dir[0]}' "
data += f"Light1DirY='{light.light1Dir[1]}' "
data += f"Light1DirZ='{light.light1Dir[2]}' "
data += f"Light1ColorR='{light.light1Color[0]}' "
data += f"Light1ColorG='{light.light1Color[1]}' "
data += f"Light1ColorB='{light.light1Color[2]}' "
data += f"Light2DirX='{light.light2Dir[0]}' "
data += f"Light2DirY='{light.light2Dir[1]}' "
data += f"Light2DirZ='{light.light2Dir[2]}' "
data += f"Light2ColorR='{light.light2Color[0]}' "
data += f"Light2ColorG='{light.light2Color[1]}' "
data += f"Light2ColorB='{light.light2Color[2]}' "
data += f"FogColorR='{light.fogColor[0]}' "
data += f"FogColorG='{light.fogColor[1]}' "
data += f"FogColorB='{light.fogColor[2]}' "
data += f"FogNear='{light.fogNear}' "
data += f"FogFar='{light.zFar}'/>\n"
data += "</LightingSettings>\n"
return data
@dataclass
class SceneInfos:
"""This class stores various scene header informations"""
### General ###
keepObjectID: str
naviHintType: str
drawConfig: str
appendNullEntrance: bool
useDummyRoomList: bool
### Skybox And Sound ###
# Skybox
skyboxID: str
skyboxConfig: str
# Sound
sequenceID: str
ambienceID: str
specID: str
### Camera And World Map ###
# World Map
worldMapLocation: str
# Camera
sceneCamType: str
@staticmethod
def new(props: OOTSceneHeaderProperty, sceneObj: Object):
return SceneInfos(
Utility.getPropValue(props, "globalObject"),
Utility.getPropValue(props, "naviCup"),
Utility.getPropValue(props.sceneTableEntry, "drawConfig"),
props.appendNullEntrance,
sceneObj.fast64.oot.scene.write_dummy_room_list,
Utility.getPropValue(props, "skyboxID"),
Utility.getPropValue(props, "skyboxCloudiness"),
Utility.getPropValue(props, "musicSeq"),
Utility.getPropValue(props, "nightSeq"),
Utility.getPropValue(props, "audioSessionPreset"),
Utility.getPropValue(props, "mapLocation"),
Utility.getPropValue(props, "cameraMode"),
)
def getCmds(self, lights: SceneLighting):
"""Returns the sound settings, misc settings, special files and skybox settings scene commands"""
return (
indent
+ f",\n{indent}".join(
[
f"SCENE_CMD_SOUND_SETTINGS({self.specID}, {self.ambienceID}, {self.sequenceID})",
f"SCENE_CMD_MISC_SETTINGS({self.sceneCamType}, {self.worldMapLocation})",
f"SCENE_CMD_SPECIAL_FILES({self.naviHintType}, {self.keepObjectID})",
f"SCENE_CMD_SKYBOX_SETTINGS({self.skyboxID}, {self.skyboxConfig}, {lights.envLightMode})",
]
)
+ ",\n"
)
@dataclass
class SceneExits(Utility):
"""This class hosts exit data"""
name: str
exitList: list[tuple[int, str]]
@staticmethod
def new(name: str, props: OOTSceneHeaderProperty):
# TODO: proper implementation of exits
exitList: list[tuple[int, str]] = []
for i, exitProp in enumerate(props.exitList):
if exitProp.exitIndex != "Custom":
raise PluginError("ERROR: Exits are unfinished, please use 'Custom'.")
exitList.append((i, exitProp.exitIndexCustom))
return SceneExits(name, exitList)
def getCmd(self):
"""Returns the exit list scene command"""
return indent + f"SCENE_CMD_EXIT_LIST({self.name}),\n"
def getC(self):
"""Returns a ``CData`` containing the C data of the exit array"""
exitListC = CData()
listName = f"u16 {self.name}[{len(self.exitList)}]"
# .h
exitListC.header = f"extern {listName};\n"
# .c
exitListC.source = (
(listName + " = {\n")
# @TODO: use the enum name instead of the raw index
+ "\n".join(indent + f"{value}," for (_, value) in self.exitList)
+ "\n};\n\n"
)
return exitListC
def getXML(self):
"""Returns a ``str`` containing the XML data of the exit array"""
data = "<ExitList>\n"
for (exitId, name) in self.exitList:
data += indent * 1 + "<ExitEntry Id='{exitId}' Name='{name}' />\n"
data += "</ExitList>\n"
return data