Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #20 from ejeinc/simplify-scene-loader
Browse files Browse the repository at this point in the history
Simplify scene loaders
  • Loading branch information
junpluse authored Apr 26, 2017
2 parents 086c6f6 + 975e942 commit e4df515
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
14 changes: 5 additions & 9 deletions Sources/ImageLoadable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Target: SceneLoadable>: 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 {
Expand All @@ -38,6 +34,6 @@ public struct ImageSceneLoader<Target: SceneLoadable>: ImageLoadable {

scene.image = image

target.scene = (scene as? SCNScene)
return scene as! SCNScene
}
}
18 changes: 5 additions & 13 deletions Sources/VideoLoadable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Target: SceneLoadable>: 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 {
Expand All @@ -44,13 +42,7 @@ public struct VideoSceneLoader<Target: SceneLoadable>: 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
}
}

Expand Down

0 comments on commit e4df515

Please sign in to comment.