質問編集履歴
3
プログラムの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,3 +9,153 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
どのようなプログラムの追加が必要になりますか?
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
```C#
|
16
|
+
|
17
|
+
using System;
|
18
|
+
|
19
|
+
using System.Runtime.InteropServices;
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
namespace UnityEngine.XR.iOS
|
24
|
+
|
25
|
+
{
|
26
|
+
|
27
|
+
public class UnityARUtility
|
28
|
+
|
29
|
+
{
|
30
|
+
|
31
|
+
private MeshCollider meshCollider; //declared to avoid code stripping of class
|
32
|
+
|
33
|
+
private MeshFilter meshFilter; //declared to avoid code stripping of class
|
34
|
+
|
35
|
+
private static GameObject planePrefab = null;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
public static void InitializePlanePrefab(GameObject go)
|
40
|
+
|
41
|
+
{
|
42
|
+
|
43
|
+
planePrefab = go;
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
public static GameObject CreatePlaneInScene(ARPlaneAnchor arPlaneAnchor)
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
GameObject plane;
|
54
|
+
|
55
|
+
if (planePrefab != null) {
|
56
|
+
|
57
|
+
plane = GameObject.Instantiate(planePrefab);
|
58
|
+
|
59
|
+
} else {
|
60
|
+
|
61
|
+
plane = new GameObject ();
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
plane.name = arPlaneAnchor.identifier;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
ARKitPlaneMeshRender apmr = plane.GetComponent<ARKitPlaneMeshRender> ();
|
72
|
+
|
73
|
+
if (apmr != null) {
|
74
|
+
|
75
|
+
apmr.InitiliazeMesh (arPlaneAnchor);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
// 平面の向きによって平面オブジェクトの色を変える
|
82
|
+
|
83
|
+
if(arPlaneAnchor.alignment == ARPlaneAnchorAlignment.ARPlaneAnchorAlignmentVertical)
|
84
|
+
|
85
|
+
{
|
86
|
+
|
87
|
+
plane.transform.Find("Plane").GetComponent<MeshRenderer>().material.color = new Color(1,1,0);
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
return UpdatePlaneWithAnchorTransform(plane, arPlaneAnchor);
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor)
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
//do coordinate conversion from ARKit to Unity
|
104
|
+
|
105
|
+
plane.transform.position = UnityARMatrixOps.GetPosition (arPlaneAnchor.transform);
|
106
|
+
|
107
|
+
plane.transform.rotation = UnityARMatrixOps.GetRotation (arPlaneAnchor.transform);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
ARKitPlaneMeshRender apmr = plane.GetComponent<ARKitPlaneMeshRender> ();
|
112
|
+
|
113
|
+
if (apmr != null) {
|
114
|
+
|
115
|
+
apmr.UpdateMesh (arPlaneAnchor);
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
MeshFilter mf = plane.GetComponentInChildren<MeshFilter> ();
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
if (mf != null) {
|
128
|
+
|
129
|
+
if (apmr == null) {
|
130
|
+
|
131
|
+
//since our plane mesh is actually 10mx10m in the world, we scale it here by 0.1f
|
132
|
+
|
133
|
+
mf.gameObject.transform.localScale = new Vector3 (arPlaneAnchor.extent.x * 0.1f, arPlaneAnchor.extent.y * 0.1f, arPlaneAnchor.extent.z * 0.1f);
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
//convert our center position to unity coords
|
138
|
+
|
139
|
+
mf.gameObject.transform.localPosition = new Vector3(arPlaneAnchor.center.x,arPlaneAnchor.center.y, -arPlaneAnchor.center.z);
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
return plane;
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
```
|
2
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
平面別にオブジェクト配置
|
test
CHANGED
File without changes
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
初心者です。
|
1
|
+
ARkit初心者です。
|
2
2
|
|
3
3
|
現在UnityとXcodeを使い、水平面の他に垂直面の認識が出来ています。
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
そこで、表示させる3Dオブジェクトを水平面と垂直面それぞれ別々のものを表示させたいと考えています。
|
7
|
+
そこで、タップして表示させる3Dオブジェクトを水平面と垂直面それぞれ別々のものを表示させたいと考えています。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
どのようなプログラムの追加が必要になりますか?
|