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 #11 from ejeinc/simulator-support
Browse files Browse the repository at this point in the history
Simulator support
  • Loading branch information
junpluse committed Apr 19, 2017
2 parents a2f788c + 6c4d940 commit 6223b9f
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 80 deletions.
5 changes: 5 additions & 0 deletions Examples/MonoImage/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ final class ViewController: UIViewController {
weak var panoramaView: PanoramaView?

private func loadPanoramaView() {
#if METALSCOPE_ENABLE_METAL
let panoramaView = PanoramaView(frame: view.bounds, device: device)
#else
let panoramaView = PanoramaView(frame: view.bounds) // iOS Simulator
#endif

panoramaView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(panoramaView)

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ present(stereoViewController, animated: true, completion: nil)

Check example apps for more samples.

### Simulator
`PanoramaView`, `StereoView` and `StereoViewController` can also be used on iOS simulator by using alternative initializers.

```swift
#if METALSCOPE_ENABLE_METAL
let panoramaView = PanoramaView(frame: view.bounds, device: device)
#else
let panoramaView = PanoramaView(frame: view.bounds) // on simulator
#endif
```

Please note that these classes are significantly limited in functionality on the simulator. For example, `PanoramaView` can display photos, but cannot display videos. For `StereoView` and `StereoViewController`, it is a placeholder and nothing is displayed.

## Requirements

- Xcode 8.2+
Expand Down
6 changes: 0 additions & 6 deletions Sources/MediaSceneLoader+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
// Copyright © 2017 eje Inc. All rights reserved.
//

#if (arch(i386) || arch(x86_64)) && os(iOS)
// Not available on iOS Simulator
#else

import SceneKit

extension MediaSceneLoader {
Expand All @@ -28,5 +24,3 @@ extension MediaSceneLoader {
self.scene = (scene as? SCNScene)
}
}

#endif
4 changes: 1 addition & 3 deletions Sources/MediaSceneLoader+Video.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// Copyright © 2017 eje Inc. All rights reserved.
//

#if (arch(i386) || arch(x86_64)) && os(iOS)
// Not available on iOS Simulator
#else
#if METALSCOPE_ENABLE_METAL

import SceneKit
import AVFoundation
Expand Down
9 changes: 3 additions & 6 deletions Sources/MediaSceneLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
// Copyright © 2017 eje Inc. All rights reserved.
//

#if (arch(i386) || arch(x86_64)) && os(iOS)
// Not available on iOS Simulator
#else

import SceneKit

public protocol MediaSceneLoader: class {
#if METALSCOPE_ENABLE_METAL
var device: MTLDevice { get }
#endif

var scene: SCNScene? { get set }
}

#endif
2 changes: 2 additions & 0 deletions Sources/MetalScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import <UIKit/UIKit.h>

#define METALSCOPE_ENABLE_METAL (!TARGET_OS_SIMULATOR)

//! Project version number for MetalScope.
FOUNDATION_EXPORT double MetalScopeVersionNumber;

Expand Down
6 changes: 0 additions & 6 deletions Sources/PanoramaView+PanGesture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
// Copyright © 2017 eje Inc. All rights reserved.
//

#if (arch(i386) || arch(x86_64)) && os(iOS)
// Not available on iOS Simulator
#else

import UIKit
import UIKit.UIGestureRecognizerSubclass
import SceneKit
Expand Down Expand Up @@ -157,5 +153,3 @@ extension PanoramaView {
}
}
}

#endif
21 changes: 13 additions & 8 deletions Sources/PanoramaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
// Copyright © 2017 eje Inc. All rights reserved.
//

#if (arch(i386) || arch(x86_64)) && os(iOS)
// Not available on iOS Simulator
#else

import UIKit
import SceneKit

public final class PanoramaView: UIView, MediaSceneLoader {
#if METALSCOPE_ENABLE_METAL
public let device: MTLDevice
#endif

public var scene: SCNScene? {
get {
Expand All @@ -37,10 +35,14 @@ public final class PanoramaView: UIView, MediaSceneLoader {
}()

lazy var scnView: SCNView = {
#if METALSCOPE_ENABLE_METAL
let view = SCNView(frame: self.bounds, options: [
SCNView.Option.preferredRenderingAPI.rawValue: SCNRenderingAPI.metal.rawValue,
SCNView.Option.preferredDevice.rawValue: self.device
])
#else
let view = SCNView(frame: self.bounds)
#endif
view.backgroundColor = .black
view.isUserInteractionEnabled = false
view.delegate = self
Expand All @@ -61,13 +63,18 @@ public final class PanoramaView: UIView, MediaSceneLoader {
return InterfaceOrientationUpdater(orientationNode: self.orientationNode)
}()

#if METALSCOPE_ENABLE_METAL
public init(frame: CGRect, device: MTLDevice) {
self.device = device

super.init(frame: frame)

addGestureRecognizer(self.panGestureManager.gestureRecognizer)
}
#else
public override init(frame: CGRect) {
super.init(frame: frame)
addGestureRecognizer(self.panGestureManager.gestureRecognizer)
}
#endif

public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand Down Expand Up @@ -185,5 +192,3 @@ extension PanoramaView: SCNSceneRendererDelegate {
sceneRendererDelegate?.renderer?(renderer, didRenderScene: scene, atTime: time)
}
}

#endif
4 changes: 1 addition & 3 deletions Sources/PlayerItemRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// Copyright © 2016 eje Inc. All rights reserved.
//

#if (arch(i386) || arch(x86_64)) && os(iOS)
// Not available on iOS Simulator
#else
#if METALSCOPE_ENABLE_METAL

import Metal
import AVFoundation
Expand Down
4 changes: 1 addition & 3 deletions Sources/PlayerRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// Copyright © 2017 eje Inc. All rights reserved.
//

#if (arch(i386) || arch(x86_64)) && os(iOS)
// Not available on iOS Simulator
#else
#if METALSCOPE_ENABLE_METAL

import Metal
import AVFoundation
Expand Down
4 changes: 1 addition & 3 deletions Sources/StereoRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// Copyright © 2017 eje Inc. All rights reserved.
//

#if (arch(i386) || arch(x86_64)) && os(iOS)
// Not available on iOS Simulator
#else
#if METALSCOPE_ENABLE_METAL

import SceneKit
import Metal
Expand Down
4 changes: 1 addition & 3 deletions Sources/StereoScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// Copyright © 2017 eje Inc. All rights reserved.
//

#if (arch(i386) || arch(x86_64)) && os(iOS)
// Not available on iOS Simulator
#else
#if METALSCOPE_ENABLE_METAL

import SceneKit

Expand Down

0 comments on commit 6223b9f

Please sign in to comment.