-
-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathGLTFSceneSource.swift
More file actions
79 lines (65 loc) · 2.69 KB
/
GLTFSceneSource.swift
File metadata and controls
79 lines (65 loc) · 2.69 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// GLTFSceneSource.swift
// GLTFSceneKit
//
// Created by magicien on 2017/08/17.
// Copyright © 2017 DarkHorse. All rights reserved.
//
import SceneKit
@objcMembers
public class GLTFSceneSource : SCNSceneSource {
private var loader: GLTFUnarchiver! = nil
public override init() {
super.init()
}
public convenience init(path: String, options: [SCNSceneSource.LoadingOption : Any]? = nil, extensions: [String:Codable.Type]? = nil, embedExternalImages: Bool = true) throws {
self.init()
let loader = try GLTFUnarchiver(path: path, extensions: extensions, embedExternalImages: embedExternalImages)
self.loader = loader
}
public override convenience init(url: URL, options: [SCNSceneSource.LoadingOption : Any]? = nil) {
self.init(url: url, options: options, extensions: nil, embedExternalImages: true)
}
public convenience init(url: URL, options: [SCNSceneSource.LoadingOption : Any]?, extensions: [String:Codable.Type]?, embedExternalImages: Bool = true) {
self.init()
do {
self.loader = try GLTFUnarchiver(url: url, extensions: extensions, embedExternalImages: embedExternalImages)
} catch {
print("\(error.localizedDescription)")
}
}
public override convenience init(data: Data, options: [SCNSceneSource.LoadingOption : Any]? = nil) {
self.init()
do {
self.loader = try GLTFUnarchiver(data: data)
} catch {
print("\(error.localizedDescription)")
}
}
public convenience init(named name: String, options: [SCNSceneSource.LoadingOption : Any]? = nil, extensions: [String:Codable.Type]? = nil) throws {
let filePath = Bundle.main.path(forResource: name, ofType: nil)
guard let path = filePath else {
throw URLError(.fileDoesNotExist)
}
try self.init(path: path, options: options, extensions: extensions)
}
public override func scene(options: [SCNSceneSource.LoadingOption : Any]? = nil) throws -> SCNScene {
let scene = try self.loader.loadScene()
#if SEEMS_TO_HAVE_SKINNER_VECTOR_TYPE_BUG
let sceneData = NSKeyedArchiver.archivedData(withRootObject: scene)
let source = SCNSceneSource(data: sceneData, options: nil)!
let newScene = source.scene(options: nil)!
return newScene
#else
return scene
#endif
}
/*
public func cameraNodes() -> [SCNNode] {
var cameraNodes = [SCNNode]()
let scene = try self.loader.loadScene()
scene.rootNode.childNodes
return cameraNodes
}
*/
}