@@ -17,7 +17,7 @@ import Foundation
1717 }
1818
1919 @usableFromInline
20- internal var backend : ObjectAnimation3DBackend {
20+ internal var backend : RawObjectAnimation3D {
2121 assert ( state == . ready, " This resource is not ready to be used. Make sure it's state property is .ready before accessing! " )
2222 return Game . unsafeShared. resourceManager. objectAnimation3DCache ( for: cacheKey) !. objectAnimation3DBackend!
2323 }
@@ -445,7 +445,7 @@ extension ObjectAnimation3D {
445445 }
446446}
447447
448- public final class ObjectAnimation3DBackend {
448+ public struct RawObjectAnimation3D {
449449 let name : String
450450 let duration : Float
451451 let animation : ObjectAnimation3D . Animation
@@ -460,9 +460,7 @@ public final class ObjectAnimation3DBackend {
460460// MARK: - Resource Manager
461461
462462public protocol ObjectAnimation3DImporter : ResourceImporter {
463- init ( )
464-
465- func process( data: Data , baseURL: URL , options: ObjectAnimation3DImporterOptions ) async throws -> ObjectAnimation3DBackend
463+ func loadObjectAnimation( options: ObjectAnimation3DImporterOptions ) async throws ( GateEngineError) -> RawObjectAnimation3D
466464}
467465
468466public struct ObjectAnimation3DImporterOptions : Equatable , Hashable , Sendable {
@@ -495,6 +493,13 @@ extension ResourceManager {
495493 }
496494}
497495
496+ extension RawObjectAnimation3D {
497+ init ( path: String , options: ObjectAnimation3DImporterOptions = . none) async throws {
498+ let importer : any ObjectAnimation3DImporter = try await Game . unsafeShared. resourceManager. objectAnimation3DImporterForPath ( path)
499+ self = try await importer. loadObjectAnimation ( options: options)
500+ }
501+ }
502+
498503extension ResourceManager . Cache {
499504 @usableFromInline
500505 struct ObjectAnimation3DKey : Hashable , CustomStringConvertible , Sendable {
@@ -517,7 +522,7 @@ extension ResourceManager.Cache {
517522
518523 @usableFromInline
519524 final class ObjectAnimation3DCache : ResourceCache {
520- @usableFromInline var objectAnimation3DBackend : ObjectAnimation3DBackend ?
525+ @usableFromInline var objectAnimation3DBackend : RawObjectAnimation3D ?
521526 var lastLoaded : Date
522527 var state : ResourceState
523528 var referenceCount : UInt
@@ -565,7 +570,7 @@ extension ResourceManager {
565570 cache. objectAnimation3Ds [ key] = Cache . ObjectAnimation3DCache ( )
566571 Game . unsafeShared. resourceManager. incrementLoading ( path: key. requestedPath)
567572 Task . detached {
568- let backend = ObjectAnimation3DBackend (
573+ let backend = RawObjectAnimation3D (
569574 name: name,
570575 duration: duration,
571576 animation: animation
@@ -618,18 +623,11 @@ extension ResourceManager {
618623 let path = key. requestedPath
619624
620625 do {
621- let importer : any ObjectAnimation3DImporter = try await Game . unsafeShared. resourceManager. objectAnimation3DImporterForPath ( path)
622-
623- let data = try await Platform . current. loadResource ( from: path)
624- let backend = try await importer. process (
625- data: data,
626- baseURL: URL ( string: path) !. deletingLastPathComponent ( ) ,
627- options: key. options
628- )
626+ let rawObjectAnimation = try await RawObjectAnimation3D ( path: key. requestedPath, options: key. options)
629627
630628 Task { @MainActor in
631629 if let cache = cache. objectAnimation3Ds [ key] {
632- cache. objectAnimation3DBackend = backend
630+ cache. objectAnimation3DBackend = rawObjectAnimation
633631 cache. state = . ready
634632 } else {
635633 Log . warn ( " Resource \" \( path) \" was deallocated before being " + ( isFirstLoad ? " loaded. " : " re-loaded. " ) )
0 commit comments