Skip to content

Commit

Permalink
sort object lists by name
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanis002 committed Jan 8, 2024
1 parent 5c2db65 commit bff524f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 31 deletions.
10 changes: 3 additions & 7 deletions fast64_internal/oot/exporter/collision/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from mathutils import Quaternion, Matrix
from bpy.types import Object
from ....utility import PluginError, CData, indent
from ...oot_utility import getObjectList
from ...oot_collision_classes import decomp_compat_map_CameraSType
from ...collision.properties import OOTCameraPositionProperty
from ..base import Base
Expand Down Expand Up @@ -89,12 +90,7 @@ class BgCamInformations(Base):
def initCrawlspaceList(self):
"""Returns a list of crawlspace data from every splines objects with the type 'Crawlspace'"""

crawlspaceObjList: list[Object] = [
obj
for obj in self.sceneObj.children_recursive
if obj.type == "CURVE" and obj.ootSplineProperty.splineType == "Crawlspace"
]

crawlspaceObjList = getObjectList(self.sceneObj.children_recursive, "CURVE", splineType="Crawlspace")
for obj in crawlspaceObjList:
if self.validateCurveData(obj):
self.crawlspacePosList.append(
Expand All @@ -110,7 +106,7 @@ def initCrawlspaceList(self):
def initBgCamInfoList(self):
"""Returns a list of camera informations from camera objects"""

camObjList: list[Object] = [obj for obj in self.sceneObj.children_recursive if obj.type == "CAMERA"]
camObjList = getObjectList(self.sceneObj.children_recursive, "CAMERA")
camPosData: dict[int, CameraData] = {}
camInfoData: dict[int, CameraInfo] = {}

Expand Down
6 changes: 2 additions & 4 deletions fast64_internal/oot/exporter/collision/waterbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional
from mathutils import Matrix
from bpy.types import Object
from ...oot_utility import getObjectList
from ....utility import CData, checkIdentityRotation, indent
from ..base import Base

Expand Down Expand Up @@ -88,10 +89,7 @@ class WaterBoxes(Base):
waterboxList: list[WaterBox] = field(default_factory=list)

def __post_init__(self):
waterboxObjList: list[Object] = [
obj for obj in self.sceneObj.children_recursive if obj.type == "EMPTY" and obj.ootEmptyType == "Water Box"
]

waterboxObjList = getObjectList(self.sceneObj.children_recursive, "EMPTY", "Water Box")
for waterboxObj in waterboxObjList:
emptyScale = waterboxObj.empty_display_size
pos, _, scale, orientedRot = self.getConvertedTransform(self.transform, self.sceneObj, waterboxObj, True)
Expand Down
5 changes: 2 additions & 3 deletions fast64_internal/oot/exporter/room/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mathutils import Matrix
from bpy.types import Object
from ....utility import CData, indent
from ...oot_utility import getObjectList
from ...oot_constants import ootData
from ...room.properties import OOTRoomHeaderProperty
from ..base import Base, Actor
Expand Down Expand Up @@ -139,9 +140,7 @@ class RoomActors(HeaderBase):
actorList: list[Actor] = field(default_factory=list)

def __post_init__(self):
actorObjList: list[Object] = [
obj for obj in self.roomObj.children_recursive if obj.type == "EMPTY" and obj.ootEmptyType == "Actor"
]
actorObjList = getObjectList(self.sceneObj.children_recursive, "EMPTY", "Actor")
for obj in actorObjList:
actorProp = obj.ootActorProperty
if not self.isCurrentHeaderValid(actorProp.headerSettings, self.headerIndex):
Expand Down
11 changes: 3 additions & 8 deletions fast64_internal/oot/exporter/scene/actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mathutils import Matrix
from bpy.types import Object
from ....utility import PluginError, CData, indent
from ...oot_utility import getObjectList
from ...oot_constants import ootData
from ...scene.properties import OOTSceneHeaderProperty
from ..base import Base, Actor
Expand Down Expand Up @@ -47,11 +48,7 @@ class SceneTransitionActors(Base):
entries: list[TransitionActor] = field(default_factory=list)

def __post_init__(self):
actorObjList: list[Object] = [
obj
for obj in self.sceneObj.children_recursive
if obj.type == "EMPTY" and obj.ootEmptyType == "Transition Actor"
]
actorObjList = getObjectList(self.sceneObj.children_recursive, "EMPTY", "Transition Actor")
for obj in actorObjList:
roomObj = self.getRoomObjectFromChild(obj)
if roomObj is None:
Expand Down Expand Up @@ -146,9 +143,7 @@ def __post_init__(self):
"""Returns the entrance actor list based on empty objects with the type 'Entrance'"""

entranceActorFromIndex: dict[int, EntranceActor] = {}
actorObjList: list[Object] = [
obj for obj in self.sceneObj.children_recursive if obj.type == "EMPTY" and obj.ootEmptyType == "Entrance"
]
actorObjList = getObjectList(self.sceneObj.children_recursive, "EMPTY", "Entrance")
for obj in actorObjList:
roomObj = self.getRoomObjectFromChild(obj)
if roomObj is None:
Expand Down
7 changes: 2 additions & 5 deletions fast64_internal/oot/exporter/scene/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from mathutils import Matrix
from bpy.types import Object
from ....utility import PluginError, CData, indent
from ...oot_utility import getObjectList
from ...scene.properties import OOTSceneHeaderProperty
from ..base import Base

Expand Down Expand Up @@ -49,11 +50,7 @@ class ScenePathways(Base):

def __post_init__(self):
pathFromIndex: dict[int, Path] = {}
pathObjList: list[Object] = [
obj
for obj in self.sceneObj.children_recursive
if obj.type == "CURVE" and obj.ootSplineProperty.splineType == "Path"
]
pathObjList = getObjectList(self.sceneObj.children_recursive, "CURVE", splineType="Path")

for obj in pathObjList:
relativeTransform = self.transform @ self.sceneObj.matrix_world.inverted() @ obj.matrix_world
Expand Down
5 changes: 2 additions & 3 deletions fast64_internal/oot/exporter/scene/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mathutils import Matrix
from bpy.types import Object
from ....utility import PluginError, CData, indent
from ...oot_utility import getObjectList
from ...oot_model_classes import OOTModel
from ..room import Room

Expand All @@ -25,9 +26,7 @@ def __post_init__(self):

sceneName = self.scene.name.removesuffix("_scene")
roomDict: dict[int, Room] = {}
roomObjs: list[Object] = [
obj for obj in self.sceneObj.children_recursive if obj.type == "EMPTY" and obj.ootEmptyType == "Room"
]
roomObjs = getObjectList(self.sceneObj.children_recursive, "EMPTY", "Room")

if len(roomObjs) == 0:
raise PluginError("ERROR: The scene has no child empties with the 'Room' empty type.")
Expand Down
30 changes: 29 additions & 1 deletion fast64_internal/oot/oot_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from bpy.types import Object
from bpy.utils import register_class, unregister_class
from bpy.types import Object
from typing import Callable
from typing import Callable, Optional
from .oot_constants import ootSceneIDToName

from ..utility import (
Expand Down Expand Up @@ -940,3 +940,31 @@ def getNewPath(type: str, isClosedShape: bool):
bpy.context.view_layer.active_layer_collection.collection.objects.link(newPath)

return newPath


def getObjectList(
objList: list[Object], objType: str, emptyType: Optional[str] = None, splineType: Optional[str] = None
):
"""
Returns a list containing objects matching ``objType``. Sorts by object name.
Parameters:
- ``objList``: the list of objects to iterate through, usually ``obj.children_recursive``
- ``objType``: the object's type (``EMPTY``, ``CURVE``, etc.)
- ``emptyType``: optional, filters the object by the given empty type
- ``splineType``: optional, filters the object by the given spline type
"""

ret: list[Object] = []
for obj in objList:
cond = True

if emptyType is not None:
cond = obj.ootEmptyType == emptyType
elif splineType is not None:
cond = obj.ootSplineProperty.splineType == splineType

if obj.type == objType and cond:
ret.append(obj)
ret.sort(key=lambda o: o.name)
return ret

0 comments on commit bff524f

Please sign in to comment.