From 975e942ad15c7bf6a2fec21fed68267ba396c7bc Mon Sep 17 00:00:00 2001 From: Jun Tanaka Date: Wed, 26 Apr 2017 23:29:11 +0900 Subject: [PATCH] Simplify scene loaders --- Sources/ImageLoadable.swift | 14 +++++--------- Sources/VideoLoadable.swift | 18 +++++------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Sources/ImageLoadable.swift b/Sources/ImageLoadable.swift index b8c195a..2814eca 100644 --- a/Sources/ImageLoadable.swift +++ b/Sources/ImageLoadable.swift @@ -15,18 +15,14 @@ public protocol ImageLoadable { extension ImageLoadable where Self: SceneLoadable { public func load(_ image: UIImage, format: MediaFormat) { - ImageSceneLoader(target: self).load(image, format: format) + scene = ImageSceneLoader().load(image, format: format) } } -public struct ImageSceneLoader: ImageLoadable { - public let target: Target +public struct ImageSceneLoader { + public init() {} - public init(target: Target) { - self.target = target - } - - public func load(_ image: UIImage, format: MediaFormat) { + public func load(_ image: UIImage, format: MediaFormat) -> SCNScene { let scene: ImageScene switch format { @@ -38,6 +34,6 @@ public struct ImageSceneLoader: ImageLoadable { scene.image = image - target.scene = (scene as? SCNScene) + return scene as! SCNScene } } diff --git a/Sources/VideoLoadable.swift b/Sources/VideoLoadable.swift index bfd6446..309daf0 100644 --- a/Sources/VideoLoadable.swift +++ b/Sources/VideoLoadable.swift @@ -19,20 +19,18 @@ public protocol VideoLoadable { extension VideoLoadable where Self: SceneLoadable { public func load(_ player: AVPlayer, format: MediaFormat) { - VideoSceneLoader(target: self).load(player, format: format) + scene = VideoSceneLoader(device: device).load(player, format: format) } } -public struct VideoSceneLoader: VideoLoadable { - public let target: Target +public struct VideoSceneLoader { public let device: MTLDevice - public init(target: Target, device: MTLDevice) { - self.target = target + public init(device: MTLDevice) { self.device = device } - public func load(_ player: AVPlayer, format: MediaFormat) { + public func load(_ player: AVPlayer, format: MediaFormat) -> SCNScene { let scene: VideoScene switch format { @@ -44,13 +42,7 @@ public struct VideoSceneLoader: VideoLoadable { scene.player = player - target.scene = (scene as? SCNScene) - } -} - -extension VideoSceneLoader where Target: VideoLoadable { - public init(target: Target) { - self.init(target: target, device: target.device) + return scene as! SCNScene } }