-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPreviewViewController.swift
More file actions
36 lines (31 loc) · 1.14 KB
/
PreviewViewController.swift
File metadata and controls
36 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Cocoa
import Quartz
import SceneKit
import GLTFSceneKit
class PreviewViewController: NSViewController, QLPreviewingController {
var sceneView: SCNView!
override func loadView() {
self.sceneView = SCNView(frame: NSRect(x: 0, y: 0, width: 800, height: 600))
self.sceneView.autoresizingMask = [.width, .height]
self.sceneView.backgroundColor = NSColor.windowBackgroundColor
self.sceneView.allowsCameraControl = true
self.sceneView.autoenablesDefaultLighting = true
self.view = self.sceneView
}
func preparePreviewOfFile(at url: URL, completionHandler handler: @escaping (Error?) -> Void) {
DispatchQueue.global(qos: .userInitiated).async {
do {
let source = try GLTFSceneSource(url: url)
let scene = try source.scene()
DispatchQueue.main.async {
self.sceneView.scene = scene
handler(nil)
}
} catch {
DispatchQueue.main.async {
handler(error)
}
}
}
}
}