@@ -26,7 +26,7 @@ extension GLTF {
2626 case mat4 = " MAT4 "
2727 }
2828}
29- private class GLTF : Decodable {
29+ private struct GLTF : Decodable , Sendable {
3030 var baseURL : URL ? = nil
3131
3232 let scene : Int
@@ -259,7 +259,7 @@ private class GLTF: Decodable {
259259 }
260260
261261 lazy var cachedBuffers : [ Data ? ] = Array ( repeating: nil , count: buffers. count)
262- func buffer( at index: Int ) -> Data ? {
262+ mutating func buffer( at index: Int ) -> Data ? {
263263 // Buffer 0 is pre-cached for glb files
264264 // So `existing` will always be present for index 0 of a glb file
265265 if let existing = cachedBuffers [ index] {
@@ -282,7 +282,7 @@ private class GLTF: Decodable {
282282 return buffer
283283 }
284284
285- func values< T: BinaryInteger > ( forAccessor accessorIndex: Int ) async -> [ T ] ? {
285+ mutating func values< T: BinaryInteger > ( forAccessor accessorIndex: Int ) async -> [ T ] ? {
286286 let accessor = accessors [ accessorIndex]
287287 let bufferView = bufferViews [ accessor. bufferView]
288288 let count = accessor. count * accessor. primitiveCount
@@ -366,7 +366,7 @@ private class GLTF: Decodable {
366366 }
367367 }
368368
369- func values< T: BinaryFloatingPoint > ( forAccessor accessorIndex: Int ) async -> [ T ] ? {
369+ mutating func values< T: BinaryFloatingPoint > ( forAccessor accessorIndex: Int ) async -> [ T ] ? {
370370 let accessor = accessors [ accessorIndex]
371371 let bufferView = bufferViews [ accessor. bufferView]
372372 let count = accessor. count * accessor. primitiveCount
@@ -450,7 +450,7 @@ private class GLTF: Decodable {
450450 }
451451 }
452452
453- func animationValues< T: BinaryFloatingPoint > ( forAccessor accessorIndex: Int ) async -> [ T ] ? {
453+ mutating func animationValues< T: BinaryFloatingPoint > ( forAccessor accessorIndex: Int ) async -> [ T ] ? {
454454 let accessor = accessors [ accessorIndex]
455455 let bufferView = bufferViews [ accessor. bufferView]
456456 let count = accessor. count * accessor. primitiveCount
@@ -693,32 +693,32 @@ public extension GLTransmissionFormat {
693693 }
694694}
695695
696- public final class GLTransmissionFormat : ResourceImporter {
696+ public struct GLTransmissionFormat : ResourceImporter {
697697 fileprivate var gltf : GLTF ! = nil
698- required public init ( ) { }
698+ public init ( ) { }
699699
700- public func synchronousPrepareToImportResourceFrom( path: String ) throws ( GateEngineError) {
700+ public mutating func synchronousPrepareToImportResourceFrom( path: String ) throws ( GateEngineError) {
701701 guard let path = Platform . current. synchronousLocateResource ( from: path) else { throw . failedToLocate( resource: path, nil ) }
702702 let baseURL = URL ( fileURLWithPath: path) . deletingLastPathComponent ( )
703703 do {
704704 let data = try Platform . current. synchronousLoadResource ( from: path)
705- self . gltf = try gltf ( from: data, baseURL: baseURL)
705+ self . gltf = try Self . gltf ( from: data, baseURL: baseURL)
706706 } catch {
707707 throw GateEngineError ( error)
708708 }
709709 }
710- public func prepareToImportResourceFrom( path: String ) async throws ( GateEngineError) {
710+ public mutating func prepareToImportResourceFrom( path: String ) async throws ( GateEngineError) {
711711 guard let path = await Platform . current. locateResource ( from: path) else { throw . failedToLocate( resource: path, nil ) }
712712 let baseURL = URL ( fileURLWithPath: path) . deletingLastPathComponent ( )
713713 do {
714714 let data = try await Platform . current. loadResource ( from: path)
715- self . gltf = try gltf ( from: data, baseURL: baseURL)
715+ self . gltf = try Self . gltf ( from: data, baseURL: baseURL)
716716 } catch {
717717 throw GateEngineError ( error)
718718 }
719719 }
720720
721- fileprivate func gltf( from data: Data , baseURL: URL ) throws -> GLTF {
721+ fileprivate static func gltf( from data: Data , baseURL: URL ) throws -> GLTF {
722722 var jsonData : Data = data
723723 var bufferData : Data ? = nil
724724 if data [ 0 ..< 4 ] == Data ( " glTF " . utf8) {
@@ -728,7 +728,7 @@ public final class GLTransmissionFormat: ResourceImporter {
728728 jsonData = data. advanced ( by: 20 ) [ ..< byteCount]
729729 bufferData = data. advanced ( by: ( byteCount + 28 ) )
730730 }
731- let gltf = try JSONDecoder ( ) . decode ( GLTF . self, from: jsonData)
731+ var gltf = try JSONDecoder ( ) . decode ( GLTF . self, from: jsonData)
732732 gltf. baseURL = baseURL
733733 gltf. cachedBuffers [ 0 ] = bufferData
734734 return gltf
@@ -749,7 +749,7 @@ public final class GLTransmissionFormat: ResourceImporter {
749749}
750750
751751extension GLTransmissionFormat : GeometryImporter {
752- public func loadGeometry( options: GeometryImporterOptions ) async throws ( GateEngineError) -> RawGeometry {
752+ public mutating func loadGeometry( options: GeometryImporterOptions ) async throws ( GateEngineError) -> RawGeometry {
753753 guard gltf. meshes != nil else { throw GateEngineError . failedToDecode ( " File contains no geometry. " ) }
754754
755755 var mesh : GLTF . Mesh ? = nil
@@ -921,7 +921,7 @@ extension GLTransmissionFormat: SkinImporter {
921921 }
922922 return nil
923923 }
924- private func inverseBindMatrices(
924+ private mutating func inverseBindMatrices(
925925 from bufferView: GLTF . BufferView ,
926926 expecting count: Int
927927 ) async -> [ Matrix4x4 ] ? {
@@ -945,7 +945,7 @@ extension GLTransmissionFormat: SkinImporter {
945945 } )
946946 }
947947
948- public func loadSkin( options: SkinImporterOptions ) async throws ( GateEngineError) -> RawSkin {
948+ public mutating func loadSkin( options: SkinImporterOptions ) async throws ( GateEngineError) -> RawSkin {
949949 guard let skins = gltf. skins, skins. isEmpty == false else {
950950 throw GateEngineError . failedToDecode ( " File contains no skins. " )
951951 }
@@ -1055,7 +1055,7 @@ extension GLTransmissionFormat: SkeletonImporter {
10551055 return gltf. scenes [ gltf. scene] . nodes? . first
10561056 }
10571057
1058- public func loadSkeleton( options: SkeletonImporterOptions ) async throws ( GateEngineError) -> RawSkeleton {
1058+ public mutating func loadSkeleton( options: SkeletonImporterOptions ) async throws ( GateEngineError) -> RawSkeleton {
10591059 guard let rootNode = skeletonNode ( named: options. subobjectName) else {
10601060 throw GateEngineError . failedToDecode ( " Couldn't find skeleton root. " )
10611061 }
@@ -1095,7 +1095,7 @@ extension GLTransmissionFormat: SkeletalAnimationImporter {
10951095 return gltf. animations? . first
10961096 }
10971097
1098- public func loadSkeletalAnimation( options: SkeletalAnimationImporterOptions ) async throws ( GateEngineError) -> RawSkeletalAnimation {
1098+ public mutating func loadSkeletalAnimation( options: SkeletalAnimationImporterOptions ) async throws ( GateEngineError) -> RawSkeletalAnimation {
10991099 guard let animation = animation ( named: options. subobjectName) else {
11001100 throw GateEngineError . failedToDecode (
11011101 " Couldn't find animation: \" \( options. subobjectName!) \" . \n Available Animations: \( ( gltf. animations ?? [ ] ) . map ( { $0. name} ) ) "
@@ -1238,7 +1238,7 @@ extension GLTransmissionFormat: SkeletalAnimationImporter {
12381238}
12391239
12401240extension GLTransmissionFormat : ObjectAnimation3DImporter {
1241- public func loadObjectAnimation( options: ObjectAnimation3DImporterOptions ) async throws ( GateEngineError) -> RawObjectAnimation3D {
1241+ public mutating func loadObjectAnimation( options: ObjectAnimation3DImporterOptions ) async throws ( GateEngineError) -> RawObjectAnimation3D {
12421242 guard let animation = animation ( named: options. subobjectName) else {
12431243 throw GateEngineError . failedToDecode (
12441244 " Couldn't find animation: \" \( options. subobjectName!) \" . \n Available Animations: \( ( gltf. animations ?? [ ] ) . map ( { $0. name} ) ) "
@@ -1339,7 +1339,7 @@ extension GLTransmissionFormat: ObjectAnimation3DImporter {
13391339
13401340extension GLTransmissionFormat : TextureImporter {
13411341 // TODO: Supports only PNG. Add other formats (JPEG, WebP, ...)
1342- public func synchronousLoadTexture( options: TextureImporterOptions ) throws ( GateEngineError) -> RawTexture {
1342+ public mutating func synchronousLoadTexture( options: TextureImporterOptions ) throws ( GateEngineError) -> RawTexture {
13431343 let imageData : Data
13441344 func loadImageData( image: GLTF . Image ) throws ( GateEngineError) -> Data {
13451345 if let uri = image. uri {
@@ -1375,13 +1375,13 @@ extension GLTransmissionFormat: TextureImporter {
13751375 return try PNGDecoder ( ) . decode ( imageData)
13761376 }
13771377
1378- public func loadTexture( options: TextureImporterOptions ) async throws ( GateEngineError) -> RawTexture {
1378+ public mutating func loadTexture( options: TextureImporterOptions ) async throws ( GateEngineError) -> RawTexture {
13791379 return try synchronousLoadTexture ( options: options)
13801380 }
13811381}
13821382
13831383extension GLTransmissionFormat : CollisionMeshImporter {
1384- public func loadCollisionMesh( options: CollisionMeshImporterOptions ) async throws ( GateEngineError) -> RawCollisionMesh {
1384+ public mutating func loadCollisionMesh( options: CollisionMeshImporterOptions ) async throws ( GateEngineError) -> RawCollisionMesh {
13851385 guard gltf. meshes != nil else { throw GateEngineError . failedToDecode ( " File contains no geometry. " ) }
13861386
13871387 var mesh : GLTF . Mesh ? = nil
0 commit comments