Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OoT] New Exporter #256

Merged
merged 104 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
9c6354d
new exporter base
Yanis42 Sep 23, 2023
017f091
cleanup
Yanis42 Sep 23, 2023
c7c3314
format
Yanis42 Sep 23, 2023
8236329
more cleanup + split classes
Yanis42 Sep 23, 2023
8efbad4
moar cleanup
Yanis42 Sep 23, 2023
9a4b029
improvements
Yanis42 Sep 24, 2023
7616a11
implement paths
Yanis42 Sep 24, 2023
b5a6eef
moved lightsettings out of getNewSceneHeader
Yanis42 Sep 24, 2023
3d31756
cs stuff
Yanis42 Sep 24, 2023
f28b313
split header data
Yanis42 Sep 24, 2023
2d7a09e
collision start
Yanis42 Sep 24, 2023
35dd430
collision part 2
Yanis42 Sep 24, 2023
a269260
export stuff
Yanis42 Sep 25, 2023
90dd75b
collision cleanup/fixes
Yanis42 Sep 25, 2023
f34b03f
more cleanup
Yanis42 Sep 25, 2023
86966ae
textures & room shape
Yanis42 Sep 25, 2023
0a5347e
fix missing things
Yanis42 Sep 25, 2023
1a2e982
fixes and additional things
Yanis42 Sep 26, 2023
87a0c08
final "fixes" (?)
Yanis42 Sep 26, 2023
3d28d0f
improvements
Yanis42 Sep 26, 2023
85af15f
format
Yanis42 Sep 26, 2023
c657e18
fixed collision issues
Yanis42 Sep 26, 2023
0d66264
cam pos data fixes
Yanis42 Sep 27, 2023
7edf792
campos output improvements
Yanis42 Sep 27, 2023
c7d5803
fixed extra collision issues
Yanis42 Sep 27, 2023
dfed942
format + docs part 1
Yanis42 Sep 27, 2023
478c2ce
docs part 2
Yanis42 Sep 27, 2023
858b269
docs part 3
Yanis42 Sep 27, 2023
fa5734c
docs part 4
Yanis42 Sep 27, 2023
15990e1
format + docs part 5
Yanis42 Sep 27, 2023
98fa3c0
minor reorg
Yanis42 Sep 27, 2023
92cbe0e
fixed issues related to recent collision export changes
Yanis42 Sep 27, 2023
df4a4ad
add safeguard in header
Yanis42 Sep 27, 2023
7c2b472
exporter.py cleanup
Yanis42 Sep 28, 2023
fb1b2c5
fix part 1
Yanis42 Oct 2, 2023
693139e
fixes part 2
Yanis42 Oct 3, 2023
969102d
camera improvements
Yanis42 Oct 3, 2023
5df9652
fixed entrance actors order
Yanis42 Oct 3, 2023
2a1cb5b
macro toggle
Yanis42 Oct 3, 2023
155df9d
fixed include duplicate
Yanis42 Oct 4, 2023
aece358
"fix" includes (using z64.h for now)
Yanis42 Oct 4, 2023
6e5bb0b
re-organised the files, fixed imports
Yanis42 Oct 4, 2023
ddcdce5
class rename
Yanis42 Oct 5, 2023
306a0e7
renamed more files
Yanis42 Oct 5, 2023
51c7e94
renamed exporter folder
Yanis42 Oct 5, 2023
7ccffb2
code reorganisation part 1
Yanis42 Oct 6, 2023
a0987eb
deleted useless file
Yanis42 Oct 6, 2023
1863a9b
more code reorganisation
Yanis42 Oct 6, 2023
ccbd225
improvements part 3
Yanis42 Oct 6, 2023
2efe6c0
improvements part 4
Yanis42 Oct 6, 2023
a05b165
import cleanup
Yanis42 Oct 6, 2023
d2ae64f
fixed DL entry issue
Yanis42 Oct 9, 2023
b692236
include fix
Yanis42 Oct 9, 2023
3abdf59
path indices
Yanis42 Oct 11, 2023
fb98e8c
single file fixes
Yanis42 Oct 20, 2023
a0d0f8c
Merge remote-tracking branch 'upstream/main' into oot_exporter_experi…
Yanis42 Oct 20, 2023
96aabc1
Merge remote-tracking branch 'upstream/main' into oot_exporter_experi…
Yanis42 Jan 7, 2024
cdbc8a9
remove hwv1 & f3d_type + ``Optional`` when needed
Yanis42 Jan 7, 2024
7e93da1
not x in y -> x not in y
Yanis42 Jan 7, 2024
0bc1c93
fixes and cutscene support
Yanis42 Jan 7, 2024
251ecf7
descriptions
Yanis42 Jan 8, 2024
5c2db65
cutscene enhancements/reorg
Yanis42 Jan 8, 2024
bff524f
sort object lists by name
Yanis42 Jan 8, 2024
72fd5fa
added safety checks to cutscene export
Yanis42 Jan 9, 2024
db272b5
bugfixes (actors, objects, headers none)
Yanis42 Jan 9, 2024
8497ae3
autoset cs name, moved cs export bools to file settings
Yanis42 Jan 10, 2024
7903fde
more bugfixes
Yanis42 Jan 10, 2024
d6e851e
fixed collision issues
Yanis42 Jan 11, 2024
efdee23
removed useless check
Yanis42 Jan 12, 2024
2f2bba8
fixes and minor improvements
Yanis42 Jan 12, 2024
f5d20a9
minor change
Yanis42 Jan 12, 2024
3e891d2
implemented cutscenes
Yanis42 Jan 12, 2024
16df442
collision exporter
Yanis42 Jan 15, 2024
bab124b
"disable" old/new toggle
Yanis42 Jan 16, 2024
836faef
review part 1
Yanis42 Jan 29, 2024
69b9b7d
Merge remote-tracking branch 'upstream/main' into oot_exporter_experi…
Yanis42 Feb 9, 2024
78efdd2
use ``field(init=False)`` for unused class members when calling one
Yanis42 Feb 9, 2024
9189064
fix issues
Yanis42 Feb 9, 2024
730ed98
review part 2
Yanis42 Feb 9, 2024
dc7f175
bugfixes
Yanis42 Feb 10, 2024
8101336
Merge remote-tracking branch 'upstream/main' into oot_exporter_experi…
Yanis42 Apr 22, 2024
cda94ac
review changes part 1
Yanis42 Apr 22, 2024
d506e82
format
Yanis42 Apr 22, 2024
72a52a0
fixed cs_light_setting missing 3 parameters
Yanis42 Apr 22, 2024
cdf031b
review changes part 2
Yanis42 Apr 22, 2024
47aa1b9
format
Yanis42 Apr 22, 2024
d16bc9f
review changes part 3
Yanis42 Jul 18, 2024
1e2d930
format
Yanis42 Jul 18, 2024
c6a828e
fix issues
Yanis42 Jul 18, 2024
3ebda98
Refactor spec.py
kurethedead Jul 21, 2024
0796e3d
Black formatting spec.py
kurethedead Jul 21, 2024
179f234
review changes part 4 + fixed scene table issues
Yanis42 Jul 21, 2024
5f934d5
raise an error if the insertion index was not found
Yanis42 Jul 21, 2024
16d9d8b
Refactor scene_table.py
kurethedead Jul 23, 2024
4a1ad5d
Removed uncecessary includes
kurethedead Jul 23, 2024
f9ec52d
Converted scene removal to new exporter
kurethedead Jul 23, 2024
519205f
Refactored SceneExport, separated export from export params (ExportInfo)
kurethedead Jul 23, 2024
e28069d
Minor edits
kurethedead Jul 23, 2024
bb9d953
Merge pull request #3 from kurethedead/oot_exporter_edits
Yanis42 Jul 23, 2024
ff970e4
Merge remote-tracking branch 'upstream/main' into oot_exporter_experi…
Yanis42 Jul 23, 2024
a780c22
Delete Old Exporter Code (#4)
kurethedead Jul 24, 2024
c95f72c
Refactor Room Shape (#5)
kurethedead Jul 25, 2024
0dbad53
Added occlusion plane system to new exporter (#6)
kurethedead Jul 25, 2024
1181cb4
import cleanup
Yanis42 Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions fast64_internal/oot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ class OOT_Properties(bpy.types.PropertyGroup):
animImportSettings: bpy.props.PointerProperty(type=OOTAnimImportSettingsProperty)
collisionExportSettings: bpy.props.PointerProperty(type=OOTCollisionExportSettings)

useDecompFeatures: bpy.props.BoolProperty(
name="Use decomp for export", description="Use names and macros from decomp when exporting", default=True
)

exportMotionOnly: bpy.props.BoolProperty(
name="Export CS Motion Data Only",
description=(
"Export everything or only the camera and actor motion data.\n"
+ "This will insert the data into the cutscene."
),
default=False,
)


oot_classes = (OOT_Properties,)

Expand Down
53 changes: 30 additions & 23 deletions fast64_internal/oot/collision/exporter/to_c/collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ...exporter import OOTCollision, OOTCameraData
from ...properties import OOTCollisionExportSettings
from ..classes import OOTCameraData, OOTCameraPosData, OOTCrawlspaceData
from ..functions import exportCollisionCommon
from ....exporter.collision import CollisionHeader

from .....utility import (
PluginError,
Expand Down Expand Up @@ -270,7 +270,6 @@ def ootCollisionToC(collision):
def exportCollisionToC(
originalObj: bpy.types.Object, transformMatrix: mathutils.Matrix, exportSettings: OOTCollisionExportSettings
):
includeChildren = exportSettings.includeChildren
name = toAlnum(originalObj.name)
isCustomExport = exportSettings.customExport
folderName = exportSettings.folder
Expand All @@ -289,26 +288,34 @@ def exportCollisionToC(
restoreHiddenState(hiddenState)

try:
exportCollisionCommon(collision, obj, transformMatrix, includeChildren, name)
ootCleanupScene(originalObj, allObjs)
if not obj.ignore_collision:
# get C data
colData = CData()
colData.source = '#include "ultra64.h"\n#include "z64.h"\n#include "macros.h"\n'
if not isCustomExport:
colData.source += f'#include "{folderName}.h"\n\n'
else:
colData.source += "\n"
colData.append(
CollisionHeader.new(
f"{name}_collisionHeader",
name,
obj,
transformMatrix,
bpy.context.scene.fast64.oot.useDecompFeatures,
exportSettings.includeChildren,
).getC()
)

# write file
path = ootGetPath(exportPath, isCustomExport, "assets/objects/", folderName, False, True)
filename = exportSettings.filename if exportSettings.isCustomFilename else f"{name}_collision"
writeCData(colData, os.path.join(path, f"{filename}.h"), os.path.join(path, f"{filename}.c"))
if not isCustomExport:
addIncludeFiles(folderName, path, name)
else:
raise PluginError("ERROR: The selected mesh object ignores collision!")
except Exception as e:
ootCleanupScene(originalObj, allObjs)
raise Exception(str(e))

collisionC = ootCollisionToC(collision)

data = CData()
data.source += '#include "ultra64.h"\n#include "z64.h"\n#include "macros.h"\n'
if not isCustomExport:
data.source += '#include "' + folderName + '.h"\n\n'
else:
data.source += "\n"

data.append(collisionC)

path = ootGetPath(exportPath, isCustomExport, "assets/objects/", folderName, False, True)
filename = exportSettings.filename if exportSettings.isCustomFilename else f"{name}_collision"
writeCData(data, os.path.join(path, f"{filename}.h"), os.path.join(path, f"{filename}.c"))

if not isCustomExport:
addIncludeFiles(folderName, path, name)
finally:
ootCleanupScene(originalObj, allObjs)
2 changes: 1 addition & 1 deletion fast64_internal/oot/collision/operators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from bpy.types import Operator, Mesh
from bpy.types import Operator
from bpy.utils import register_class, unregister_class
from bpy.ops import object
from mathutils import Matrix
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/oot/cutscene/exporter/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ def getNewCutsceneExport(csName: str, motionOnly: bool):
# this allows us to change the exporter's variables to get what we need
return CutsceneExport(
getCutsceneObjects(csName),
bpy.context.scene.fast64.oot.hackerFeaturesEnabled or bpy.context.scene.useDecompFeatures,
bpy.context.scene.fast64.oot.hackerFeaturesEnabled or bpy.context.scene.fast64.oot.useDecompFeatures,
motionOnly,
)
13 changes: 7 additions & 6 deletions fast64_internal/oot/cutscene/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from bpy.types import Scene, Operator, Context
from bpy.utils import register_class, unregister_class
from ...utility import CData, PluginError, writeCData, raisePluginError
from ..oot_utility import getCollection, getCutsceneName
from ..oot_utility import getCollection
from ..oot_constants import ootData
from ..scene.exporter.to_c import getCutsceneC
from .constants import ootEnumCSTextboxType, ootEnumCSListType
from .importer import importCutsceneData
from .exporter import getNewCutsceneExport
from ..exporter.cutscene import Cutscene


def checkGetFilePaths(context: Context):
Expand Down Expand Up @@ -180,10 +180,11 @@ def execute(self, context):
cpath, hpath, headerfilename = checkGetFilePaths(context)
csdata = ootCutsceneIncludes(headerfilename)

if context.scene.exportMotionOnly:
if context.scene.fast64.oot.exportMotionOnly:
# TODO: improve this
csdata.append(insertCutsceneData(cpath, activeObj.name.removeprefix("Cutscene.")))
else:
csdata.append(getCutsceneC(getCutsceneName(activeObj)))
csdata.append(Cutscene(activeObj, context.scene.fast64.oot.useDecompFeatures).getC())
writeCData(csdata, hpath, cpath)

self.report({"INFO"}, "Successfully exported cutscene")
Expand Down Expand Up @@ -213,10 +214,10 @@ def execute(self, context):
print(f"Parent: {obj.parent.name}, Object: {obj.name}")
raise PluginError("Cutscene object must not be parented to anything")

if context.scene.exportMotionOnly:
if context.scene.fast64.oot.exportMotionOnly:
raise PluginError("ERROR: Not implemented yet.")
else:
csdata.append(getCutsceneC(getCutsceneName(obj)))
csdata.append(Cutscene(obj, context.scene.fast64.oot.useDecompFeatures).getC())
count += 1

if count == 0:
Expand Down
20 changes: 0 additions & 20 deletions fast64_internal/oot/cutscene/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ def draw(self, context):
exportBox = layout.box()
exportBox.label(text="Cutscene Exporter")

col = exportBox.column()
if not context.scene.fast64.oot.hackerFeaturesEnabled:
col.prop(context.scene, "useDecompFeatures")
col.prop(context.scene, "exportMotionOnly")

prop_split(exportBox, context.scene, "ootCutsceneExportPath", "Export To")

activeObj = context.view_layer.objects.active
Expand Down Expand Up @@ -66,25 +61,10 @@ def draw(self, context):


def cutscene_panels_register():
Scene.useDecompFeatures = BoolProperty(
name="Use Decomp for Export", description="Use names and macros from decomp when exporting", default=True
)

Scene.exportMotionOnly = BoolProperty(
name="Export Motion Data Only",
description=(
"Export everything or only the camera and actor motion data.\n"
+ "This will insert the data into the cutscene."
),
)

for cls in oot_cutscene_panel_classes:
register_class(cls)


def cutscene_panels_unregister():
del Scene.exportMotionOnly
del Scene.useDecompFeatures

for cls in oot_cutscene_panel_classes:
unregister_class(cls)
137 changes: 137 additions & 0 deletions fast64_internal/oot/exporter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import bpy
import os

from mathutils import Matrix
from bpy.types import Object
from ...f3d.f3d_gbi import DLFormat, TextureExportSettings
from ..oot_model_classes import OOTModel
from ..oot_f3d_writer import writeTextureArraysNew, writeTextureArraysExisting1D
from .scene import Scene
from .decomp_edit import Files

from ...utility import (
PluginError,
checkObjectReference,
unhideAllAndGetHiddenState,
restoreHiddenState,
toAlnum,
readFile,
writeFile,
)

from ..oot_utility import (
ExportInfo,
OOTObjectCategorizer,
ootDuplicateHierarchy,
ootCleanupScene,
getSceneDirFromLevelName,
ootGetPath,
)


def writeTextureArraysExistingScene(fModel: OOTModel, exportPath: str, sceneInclude: str):
drawConfigPath = os.path.join(exportPath, "src/code/z_scene_table.c")
drawConfigData = readFile(drawConfigPath)
newData = drawConfigData

if f'#include "{sceneInclude}"' not in newData:
additionalIncludes = f'#include "{sceneInclude}"\n'
else:
additionalIncludes = ""

for flipbook in fModel.flipbooks:
if flipbook.exportMode == "Array":
newData = writeTextureArraysExisting1D(newData, flipbook, additionalIncludes)
else:
raise PluginError("Scenes can only use array flipbooks.")

if newData != drawConfigData:
writeFile(drawConfigPath, newData)


class SceneExport:
"""This class is the main exporter class, it handles generating the C data and writing the files"""

@staticmethod
def create_scene(originalSceneObj: Object, transform: Matrix, exportInfo: ExportInfo) -> Scene:
"""Returns and creates scene data"""
# init
if originalSceneObj.type != "EMPTY" or originalSceneObj.ootEmptyType != "Scene":
raise PluginError(f'{originalSceneObj.name} is not an empty with the "Scene" empty type.')

if bpy.context.scene.exportHiddenGeometry:
hiddenState = unhideAllAndGetHiddenState(bpy.context.scene)

# Don't remove ignore_render, as we want to reuse this for collision
sceneObj, allObjs = ootDuplicateHierarchy(originalSceneObj, None, True, OOTObjectCategorizer())

if bpy.context.scene.exportHiddenGeometry:
restoreHiddenState(hiddenState)

try:
sceneName = f"{toAlnum(exportInfo.name)}_scene"
newScene = Scene.new(
sceneName,
sceneObj,
transform,
exportInfo.useMacros,
exportInfo.saveTexturesAsPNG,
OOTModel(f"{sceneName}_dl", DLFormat.Static, False),
)
newScene.validateScene()

except Exception as e:
raise Exception(str(e))
finally:
ootCleanupScene(originalSceneObj, allObjs)

return newScene

@staticmethod
def export(originalSceneObj: Object, transform: Matrix, exportInfo: ExportInfo):
"""Main function"""
# circular import fixes
from .decomp_edit.config import Config

checkObjectReference(originalSceneObj, "Scene object")
scene = SceneExport.create_scene(originalSceneObj, transform, exportInfo)

isCustomExport = exportInfo.isCustomExportPath
exportPath = exportInfo.exportPath
sceneName = exportInfo.name

exportSubdir = ""
if exportInfo.customSubPath is not None:
exportSubdir = exportInfo.customSubPath
if not isCustomExport and exportInfo.customSubPath is None:
exportSubdir = os.path.dirname(getSceneDirFromLevelName(sceneName))

sceneInclude = exportSubdir + "/" + sceneName + "/"
path = ootGetPath(exportPath, isCustomExport, exportSubdir, sceneName, True, True)
textureExportSettings = TextureExportSettings(False, exportInfo.saveTexturesAsPNG, sceneInclude, path)

sceneFile = scene.getNewSceneFile(path, exportInfo.isSingleFile, textureExportSettings)

if not isCustomExport:
writeTextureArraysExistingScene(scene.model, exportPath, sceneInclude + sceneName + "_scene.h")
else:
textureArrayData = writeTextureArraysNew(scene.model, None)
sceneFile.sceneTextures += textureArrayData.source
sceneFile.header += textureArrayData.header

sceneFile.write()
for room in scene.rooms.entries:
room.roomShape.copy_bg_images(path)

if not isCustomExport:
Files.add_scene_edits(exportInfo, scene, sceneFile)

hackerootBootOption = exportInfo.hackerootBootOption
if hackerootBootOption is not None and hackerootBootOption.bootToScene:
Config.setBootupScene(
os.path.join(exportPath, "include/config/config_debug.h")
if not isCustomExport
else os.path.join(path, "config_bootup.h"),
f"ENTR_{sceneName.upper()}_{hackerootBootOption.spawnIndex}",
hackerootBootOption,
)
31 changes: 31 additions & 0 deletions fast64_internal/oot/exporter/actor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from ...utility import indent

# this file is not inside the room folder since the scene data can have actors too


class Actor:
"""Defines an Actor"""

def __init__(self):
self.name = str()
self.id = str()
self.pos: list[int] = []
self.rot = str()
self.params = str()

def getActorEntry(self):
"""Returns a single actor entry"""

posData = "{ " + ", ".join(f"{round(p)}" for p in self.pos) + " }"
rotData = "{ " + self.rot + " }"

actorInfos = [self.id, posData, rotData, self.params]
infoDescs = ["Actor ID", "Position", "Rotation", "Parameters"]

return (
indent
+ (f"// {self.name}\n" + indent if self.name != "" else "")
+ "{\n"
+ ",\n".join((indent * 2) + f"/* {desc:10} */ {info}" for desc, info in zip(infoDescs, actorInfos))
+ ("\n" + indent + "},\n")
)
Loading
Loading