質問編集履歴
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -88,8 +88,6 @@
|
|
88
88
|
|
89
89
|
class ShipNode: SCNNode {
|
90
90
|
|
91
|
-
//class ShipNode: SCNNode {
|
92
|
-
|
93
91
|
required init?(coder aDecoder: NSCoder) {
|
94
92
|
|
95
93
|
fatalError("init(coder:) has not been implemented")
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,6 +25,12 @@
|
|
25
25
|
**ViewController.swift**
|
26
26
|
|
27
27
|
```
|
28
|
+
|
29
|
+
import UIKit
|
30
|
+
|
31
|
+
import SceneKit
|
32
|
+
|
33
|
+
import ARKit
|
28
34
|
|
29
35
|
class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {
|
30
36
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,123 @@
|
|
15
15
|
なぜエラーが消えたのでしょうか?
|
16
16
|
|
17
17
|
![イメージ説明](2b8dcae147fa5c4befa99ec02b0345d3.png)
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
追記 ソースコード一部抜粋
|
24
|
+
|
25
|
+
**ViewController.swift**
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {
|
30
|
+
|
31
|
+
@IBOutlet var sceneView: ARSCNView!
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
override func viewDidLoad() {
|
36
|
+
|
37
|
+
super.viewDidLoad()
|
38
|
+
|
39
|
+
// デリゲートになる
|
40
|
+
|
41
|
+
sceneView.delegate = self // ARSCNViewDelegateデリゲート
|
42
|
+
|
43
|
+
sceneView.session.delegate = self // ARSessionDelegateデリゲート
|
44
|
+
|
45
|
+
// シーンを作る
|
46
|
+
|
47
|
+
let scene = SCNScene()
|
48
|
+
|
49
|
+
sceneView.scene = scene
|
50
|
+
|
51
|
+
// shipNodeを2機作る
|
52
|
+
|
53
|
+
let shipNode1 = ShipNode()
|
54
|
+
|
55
|
+
shipNode1.position = SCNVector3(0.05, 0.05, -0.3)
|
56
|
+
|
57
|
+
let shipNode2 = ShipNode()
|
58
|
+
|
59
|
+
shipNode2.position = SCNVector3(-0.05, -0.15, -0.2)
|
60
|
+
|
61
|
+
// シーンに追加する
|
62
|
+
|
63
|
+
sceneView.scene.rootNode.addChildNode(shipNode1)
|
64
|
+
|
65
|
+
sceneView.scene.rootNode.addChildNode(shipNode2)
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
**ShipNode.swift**
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
import SceneKit
|
80
|
+
|
81
|
+
import ARKit
|
82
|
+
|
83
|
+
class ShipNode: SCNNode {
|
84
|
+
|
85
|
+
//class ShipNode: SCNNode {
|
86
|
+
|
87
|
+
required init?(coder aDecoder: NSCoder) {
|
88
|
+
|
89
|
+
fatalError("init(coder:) has not been implemented")
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
override init() {
|
96
|
+
|
97
|
+
super.init()
|
98
|
+
|
99
|
+
//art.scnassets/ship.scnからshipノードを作る
|
100
|
+
|
101
|
+
let sceneURL = Bundle.main.url(forResource: "ship", withExtension: "scn", subdirectory: "art.scnassets")!
|
102
|
+
|
103
|
+
let ship = SCNReferenceNode(url: sceneURL)! //ノードを作る
|
104
|
+
|
105
|
+
ship.load() //データをノードに読み込む
|
106
|
+
|
107
|
+
//機首をZ軸の正方向に向ける
|
108
|
+
|
109
|
+
ship.eulerAngles.y = -.pi
|
110
|
+
|
111
|
+
self.addChildNode(ship)
|
112
|
+
|
113
|
+
self.scale = SCNVector3Make(0.2, 0.2, 0.2)
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
```
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
**エラー箇所**
|
124
|
+
|
125
|
+
ShipNode()の部分でエラーが出ていました。
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
**ViewController.swift**
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
let shipNode1 = ShipNode()
|
134
|
+
|
135
|
+
let shipNode2 = ShipNode()
|
136
|
+
|
137
|
+
```
|