質問編集履歴

9

意図的に内容を抹消する行為にあたるため

2021/07/12 02:30

投稿

pofinpouty
pofinpouty

スコア20

test CHANGED
@@ -1 +1 @@
1
- teratailで質問。削除予定
1
+ ARFoundation +image tracking 外部にある画像を認識したい
test CHANGED
@@ -1 +1,67 @@
1
+ ARFoundation +ARKitでimage trackingのを試しています。
2
+
3
+ [image trackingサンプル](https://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@4.2/manual/image-tracking.html)
4
+
5
+ サンプルだとこのように「Reference image library」に直接画像を設定することによりマーカー認識できるようになると思うのですが、これを外部から設定できるようにしたいです。
6
+
7
+ [画像読み込み方法の参考](https://qiita.com/k7a/items/df6dd8ea66cbc5a1e21d)
8
+
9
+ こちらを参考にまずはResources.Loadの方法で画像を読み込めるようにAsset > Rerources > sample(画像)としました。
10
+
11
+ Reference image libraryのスクリプトを直接編集することができないため、実行時に参照ライブラリに画像を追加できるという「Dynamic Library」のスクリプトに記述しました。
12
+
13
+ 以下コードです。
14
+
15
+ ```
16
+
17
+ void Start(){
18
+
19
+ ARTrackedImageManager mARTrackedImageManager = gameObject.GetComponent<ARTrackedImageManager>();
20
+
21
+ //MutableRuntimeReferenceImageLibrary myRuntimeReferenceImageLibrary = mARTrackedImageManager.CreateRuntimeLibrary() as MutableRuntimeReferenceImageLibrary;
22
+
23
+ var texture = Resources.Load("sample") as Texture2D;
24
+
25
+ Debug.Log("Texture name:"+ texture.name);
26
+
27
+
28
+
29
+ if (mARTrackedImageManager.referenceLibrary is MutableRuntimeReferenceImageLibrary myRuntimeReferenceImageLibrary)
30
+
31
+ {
32
+
33
+ myRuntimeReferenceImageLibrary.ScheduleAddImageWithValidationJob(texture, "sample", 0.5f);
34
+
35
+ if(myRuntimeReferenceImageLibrary != null)
36
+
37
+ {
38
+
39
+ Debug.Log("myRuntimeReferenceImageLibrary:" + myRuntimeReferenceImageLibrary.count);
40
+
41
+ Debug.Log("supportedTextureFormatCount:" + myRuntimeReferenceImageLibrary.supportedTextureFormatCount);
42
+
43
+ mARTrackedImageManager.referenceLibrary = myRuntimeReferenceImageLibrary;
44
+
45
+ }
46
+
47
+ Debug.Log("入らない");
48
+
49
+ //mARTrackedImageManager.maxNumberOfMovingImages = 1;
50
+
51
+ //mARTrackedImageManager.trackedImagePrefab = m_TrackedImagePrefab;
52
+
53
+ mARTrackedImageManager.enabled = true;
54
+
55
+
56
+
57
+ }
58
+
59
+ }
60
+
61
+ ```
62
+
63
+ エラーは起きていないのですが、「myRuntimeReferenceImageLibrary.count」が0のままで、
64
+
1
- ~~u~~削除予定削除予定削除予定削除予定削除予定削除予定削除予定削除予定
65
+ Resourcesフォルダに格納したsample画像が読み込まれておりません…
66
+
67
+ texture.nameは取れているので読み込みできていると思っていたのですが、どのようにしたら実現できるのでしょうか?

8

2021/07/12 02:30

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- ARFoundation +image tracking 外部にある画像を認識したい
1
+ teratailで質問。削除予定
test CHANGED
@@ -1,73 +1 @@
1
- ARFoundation +ARKitでimage trackingのを試しています。
2
-
3
- [image trackingサンプル](https://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@4.2/manual/image-tracking.html)
4
-
5
- サンプルだとこのように「Reference image library」に直接画像を設定することによりマーカー認識できるようになると思うのですが、これを外部から設定できるようにしたいです。
6
-
7
- [画像読み込み方法の参考](https://qiita.com/k7a/items/df6dd8ea66cbc5a1e21d)
8
-
9
- こちらを参考にまずはResources.Loadの方法で画像を読み込めるようにAsset > Rerources > sample(画像)としました。
10
-
11
- Reference image libraryのスクリプトを直接編集することができないため、実行時に参照ライブラリに画像を追加できるという「Dynamic Library」のスクリプトに記述しました。
12
-
13
- 以下コードです。
14
-
15
- ```
16
-
17
-
18
-
19
- void Start(){
20
-
21
- ARTrackedImageManager mARTrackedImageManager = gameObject.GetComponent<ARTrackedImageManager>();
22
-
23
- //MutableRuntimeReferenceImageLibrary myRuntimeReferenceImageLibrary = mARTrackedImageManager.CreateRuntimeLibrary() as MutableRuntimeReferenceImageLibrary;
24
-
25
- var texture = Resources.Load("sample") as Texture2D;
26
-
27
- Debug.Log("Texture name:"+ texture.name);
28
-
29
-
30
-
31
- if (mARTrackedImageManager.referenceLibrary is MutableRuntimeReferenceImageLibrary myRuntimeReferenceImageLibrary)
32
-
33
- {
34
-
35
- myRuntimeReferenceImageLibrary.ScheduleAddImageWithValidationJob(texture, "sample", 0.5f);
36
-
37
- if(myRuntimeReferenceImageLibrary != null)
38
-
39
- {
40
-
41
- Debug.Log("myRuntimeReferenceImageLibrary:" + myRuntimeReferenceImageLibrary.count);
42
-
43
- Debug.Log("supportedTextureFormatCount:" + myRuntimeReferenceImageLibrary.supportedTextureFormatCount);
44
-
45
- mARTrackedImageManager.referenceLibrary = myRuntimeReferenceImageLibrary;
46
-
47
- }
48
-
49
- Debug.Log("入らない");
50
-
51
- //mARTrackedImageManager.maxNumberOfMovingImages = 1;
52
-
53
- //mARTrackedImageManager.trackedImagePrefab = m_TrackedImagePrefab;
54
-
55
- mARTrackedImageManager.enabled = true;
56
-
57
-
58
-
59
- }
60
-
61
- }
62
-
63
-
64
-
65
- ```
66
-
67
-
68
-
69
- エラーは起きていないのですが、「myRuntimeReferenceImageLibrary.count」が0のままで、
70
-
71
- Resourcesフォルダに格納したsample画像が読み込まれておりません…
1
+ ~~u~~削除予定削除予定削除予定削除予定削除予定削除予定削除予定削除予定
72
-
73
- texture.nameは取れているので読み込みできていると思っていたのですが、どのようにしたら実現できるのでしょうか?

7

2021/07/10 04:52

投稿

pofinpouty
pofinpouty

スコア20

test CHANGED
File without changes
test CHANGED
@@ -6,491 +6,59 @@
6
6
 
7
7
  [画像読み込み方法の参考](https://qiita.com/k7a/items/df6dd8ea66cbc5a1e21d)
8
8
 
9
- こちらを参考にまずはResources.Loadで画像を表示できるようにAsset > Rerources > sample(画像)としたのですがうく動作ません
9
+ こちらを参考にまずはResources.Loadの方法で画像を読み込めるようにAsset > Rerources > sample(画像)としまし
10
-
11
-
12
10
 
13
11
  Reference image libraryのスクリプトを直接編集することができないため、実行時に参照ライブラリに画像を追加できるという「Dynamic Library」のスクリプトに記述しました。
14
12
 
15
- 以下コードです。コメントの内容はサンプルの英語を直訳しただけなので気にしないでください…
13
+ 以下コードです。
16
14
 
17
15
  ```
18
16
 
19
17
 
20
18
 
21
- namespace UnityEngine.XR.ARFoundation.Samples
19
+ void Start(){
22
20
 
23
- {
21
+ ARTrackedImageManager mARTrackedImageManager = gameObject.GetComponent<ARTrackedImageManager>();
24
22
 
25
- /// <summary>
23
+ //MutableRuntimeReferenceImageLibrary myRuntimeReferenceImageLibrary = mARTrackedImageManager.CreateRuntimeLibrary() as MutableRuntimeReferenceImageLibrary;
26
24
 
27
- ///実行時に参照ライブラリに画像を追加します
25
+ var texture = Resources.Load("sample") as Texture2D;
28
26
 
29
- /// Adds images to the reference library at runtime.
30
-
31
- /// </summary>
32
-
33
- [RequireComponent(typeof(ARTrackedImageManager))]
27
+ Debug.Log("Texture name:"+ texture.name);
34
-
35
- public class DynamicLibrary : MonoBehaviour
36
-
37
- {
38
-
39
- public Texture2D value;
40
-
41
-
42
-
43
- void awake(){
44
28
 
45
29
 
46
30
 
47
- value = Resources.Load("sample") as Texture2D;
48
-
49
-
50
-
51
- }
52
-
53
- [Serializable]
54
-
55
- public class ImageData
56
-
57
- {
58
-
59
- //画像のソーステクスチャ。読み取り可能としてマークする必要があります。
60
-
61
- [SerializeField, Tooltip("The source texture for the image. Must be marked as readable.")]
31
+ if (mARTrackedImageManager.referenceLibrary is MutableRuntimeReferenceImageLibrary myRuntimeReferenceImageLibrary)
62
-
63
- //2D画像の変数生成
64
-
65
- Texture2D m_Texture;
66
-
67
-
68
-
69
-
70
-
71
- //2D画像の変数生成
72
-
73
- public Texture2D texture
74
32
 
75
33
  {
76
34
 
77
- get => m_Texture;
35
+ myRuntimeReferenceImageLibrary.ScheduleAddImageWithValidationJob(texture, "sample", 0.5f);
78
36
 
79
- set => m_Texture = value;
37
+ if(myRuntimeReferenceImageLibrary != null)
38
+
39
+ {
40
+
41
+ Debug.Log("myRuntimeReferenceImageLibrary:" + myRuntimeReferenceImageLibrary.count);
42
+
43
+ Debug.Log("supportedTextureFormatCount:" + myRuntimeReferenceImageLibrary.supportedTextureFormatCount);
44
+
45
+ mARTrackedImageManager.referenceLibrary = myRuntimeReferenceImageLibrary;
80
46
 
81
47
  }
82
48
 
49
+ Debug.Log("入らない");
83
50
 
51
+ //mARTrackedImageManager.maxNumberOfMovingImages = 1;
84
52
 
85
- [SerializeField, Tooltip("The name for this image.")]
53
+ //mARTrackedImageManager.trackedImagePrefab = m_TrackedImagePrefab;
86
54
 
87
- //画像の名前
88
-
89
- string m_Name;
90
-
91
-
92
-
93
- public string name
94
-
95
- {
96
-
97
- get => m_Name;
98
-
99
- set => m_Name = value;
100
-
101
- }
102
-
103
-
104
-
105
- [SerializeField, Tooltip("The width, in meters, of the image in the real world.")]
106
-
107
- //実世界での画像の幅(メートル単位)
108
-
109
- float m_Width;
110
-
111
-
112
-
113
- public float width
114
-
115
- {
116
-
117
- get => m_Width;
118
-
119
- set => m_Width = value;
120
-
121
- }
122
-
123
-
124
-
125
- public AddReferenceImageJobState jobState { get; set; }
126
-
127
- }
128
-
129
- //実行時に画像ライブラリに追加する画像のセット
130
-
131
- [SerializeField, Tooltip("The set of images to add to the image library at runtime")]
132
-
133
- ImageData[] m_Images;
134
-
135
-
136
-
137
- /// <summary>
138
-
139
- ///実行時に画像ライブラリに追加する画像のセット
140
-
141
- /// The set of images to add to the image library at runtime
142
-
143
- /// </summary>
144
-
145
- public ImageData[] images
146
-
147
- {
148
-
149
- get => m_Images;
150
-
151
- set => m_Images = value;
152
-
153
- }
154
-
155
-
156
-
157
- enum State
158
-
159
- {
160
-
161
- NoImagesAdded,
162
-
163
- AddImagesRequested,
164
-
165
- AddingImages,
166
-
167
- Done,
168
-
169
- Error
170
-
171
- }
172
-
173
-
174
-
175
- State m_State;
176
-
177
-
178
-
179
- string m_ErrorMessage = "";
180
-
181
-
182
-
183
- StringBuilder m_StringBuilder = new StringBuilder();
184
-
185
-
186
-
187
- void OnGUI()
188
-
189
- {
190
-
191
- //ボタンと文字の大きさ
192
-
193
- var fontSize = 50;
194
-
195
- GUI.skin.button.fontSize = fontSize;
196
-
197
- GUI.skin.label.fontSize = fontSize;
198
-
199
-
200
-
201
- float margin = 100;
202
-
203
-
204
-
205
- //開始エリア
206
-
207
- GUILayout.BeginArea(new Rect(margin, margin, Screen.width - margin * 2, Screen.height - margin * 2));
208
-
209
-
210
-
211
- switch (m_State)
212
-
213
- {
214
-
215
- case State.NoImagesAdded:
216
-
217
- {
218
-
219
- if (GUILayout.Button("Add images"))
220
-
221
- {
222
-
223
- m_State = State.AddImagesRequested;
55
+ mARTrackedImageManager.enabled = true;
224
-
225
- }
226
-
227
-
228
-
229
- break;
230
-
231
- }
232
-
233
- case State.AddingImages:
234
-
235
- {
236
-
237
- m_StringBuilder.Clear();
238
-
239
- //追加行
240
-
241
- m_StringBuilder.AppendLine("Add image status:");
242
-
243
- foreach (var image in m_Images)
244
-
245
- {
246
-
247
- m_StringBuilder.AppendLine($"\t{image.name}: {(image.jobState.status.ToString())}");
248
-
249
- }
250
-
251
- GUILayout.Label(m_StringBuilder.ToString());
252
-
253
- break;
254
-
255
- }
256
-
257
- case State.Done:
258
-
259
- {
260
-
261
- GUILayout.Label("All images added");
262
-
263
- break;
264
-
265
- }
266
-
267
- case State.Error:
268
-
269
- {
270
-
271
- GUILayout.Label(m_ErrorMessage);
272
-
273
- break;
274
-
275
- }
276
-
277
- }
278
-
279
-
280
-
281
- GUILayout.EndArea();
282
-
283
- }
284
-
285
-
286
-
287
- void SetError(string errorMessage)
288
-
289
- {
290
-
291
- m_State = State.Error;
292
-
293
- m_ErrorMessage = $"Error: {errorMessage}";
294
-
295
- }
296
-
297
-
298
-
299
- void Update()
300
-
301
- {
302
-
303
-
304
-
305
- switch (m_State)
306
-
307
- {
308
56
 
309
57
 
310
-
311
- case State.AddImagesRequested:
312
-
313
- {
314
-
315
-
316
-
317
- if (m_Images == null)
318
-
319
- {
320
-
321
-
322
-
323
- SetError("No images to add.");
324
-
325
- break;
326
-
327
- }
328
-
329
-
330
-
331
- var manager = GetComponent<ARTrackedImageManager>();
332
-
333
- if (manager == null)
334
-
335
- {
336
-
337
-
338
-
339
- SetError($"No {nameof(ARTrackedImageManager)} available.");
340
-
341
- break;
342
-
343
- }
344
-
345
-
346
-
347
- //生の画像バイトを追加するか、テクスチャを受け入れる拡張メソッド(以下で使用)を使用できます。ただし、テクスチャを使用するには、そのインポート設定でテクスチャへの読み取り/書き込みアクセスが有効になっている必要があります。
348
-
349
- // You can either add raw image bytes or use the extension method (used below) which accepts
350
-
351
- // a texture. To use a texture, however, its import settings must have enabled read/write
352
-
353
- // access to the texture.
354
-
355
- foreach (var image in m_Images)
356
-
357
- {
358
-
359
- Debug.Log("ここでエラー");
360
-
361
- if (!image.texture.isReadable)//////
362
-
363
- {
364
-
365
-
366
-
367
- SetError($"Image {image.name} must be readable to be added to the image library.");
368
-
369
- break;
370
-
371
- }
372
-
373
-
374
-
375
- }
376
-
377
-
378
-
379
- if (manager.referenceLibrary is MutableRuntimeReferenceImageLibrary mutableLibrary)
380
-
381
- {
382
-
383
-
384
-
385
- try
386
-
387
- {
388
-
389
- foreach (var image in m_Images)
390
-
391
- {
392
-
393
- //注:返されたJobHandleに対して何もする必要はありませんが、画像がライブラリに追加された時期を知りたい
394
-
395
- //場合は、数フレームかかる可能性があるため便利です。
396
-
397
- // Note: You do not need to do anything with the returned JobHandle, but it can be
398
-
399
- // useful if you want to know when the image has been added to the library since it may
400
-
401
- // take several frames.
402
-
403
- image.jobState = mutableLibrary.ScheduleAddImageWithValidationJob(image.texture, image.name, image.width);
404
-
405
-
406
-
407
- }
408
-
409
-
410
-
411
- m_State = State.AddingImages;
412
-
413
- }
414
-
415
- catch (InvalidOperationException e)
416
-
417
- {
418
-
419
-
420
-
421
- SetError($"ScheduleAddImageJob threw exception: {e.Message}");
422
-
423
- }
424
-
425
- }
426
-
427
- else
428
-
429
- {
430
-
431
-
432
-
433
- SetError($"The reference image library is not mutable.");
434
-
435
- }
436
-
437
-
438
-
439
- break;
440
-
441
- }
442
-
443
- case State.AddingImages:
444
-
445
- {
446
-
447
-
448
-
449
- //完了を確認する
450
-
451
- // Check for completion
452
-
453
- var done = true;
454
-
455
- foreach (var image in m_Images)
456
-
457
- {
458
-
459
- if (!image.jobState.jobHandle.IsCompleted)
460
-
461
- {
462
-
463
- done = false;
464
-
465
- break;
466
-
467
- }
468
-
469
- }
470
-
471
-
472
-
473
- if (done)
474
-
475
- {
476
-
477
- m_State = State.Done;
478
-
479
- }
480
-
481
-
482
-
483
- break;
484
-
485
- }
486
58
 
487
59
  }
488
60
 
489
61
  }
490
-
491
-  }
492
-
493
-
494
62
 
495
63
 
496
64
 
@@ -498,16 +66,8 @@
498
66
 
499
67
 
500
68
 
501
- エラーの内容
69
+ エラーは起きていないです、「myRuntimeReferenceImageLibrary.count」が0のままで、
502
70
 
503
- NullReferenceException: Object reference not set to an instance of an object.
71
+ Resourcesフォルダに格納したsample画像が読み込まれておりません…
504
72
 
505
- at UnityEngine.XR.ARFoundation.Samples.DynamicLibrary.Update () [0x00000]
73
+ texture.nameは取れているので読み込みできていると思っていたのですが、どのようにしたら実現できるのでしょうか?
506
-
507
- in <00000000000000000000000000000000>:0
508
-
509
-
510
-
511
- となっており、うまく読み込めていないのかと思っております…
512
-
513
- 通常は何行目がエラーか出るみたいなのですが、私の場合はでておりません。

6

2021/07/08 11:00

投稿

pofinpouty
pofinpouty

スコア20

test CHANGED
File without changes
test CHANGED
@@ -495,3 +495,19 @@
495
495
 
496
496
 
497
497
  ```
498
+
499
+
500
+
501
+ エラーの内容が
502
+
503
+ NullReferenceException: Object reference not set to an instance of an object.
504
+
505
+ at UnityEngine.XR.ARFoundation.Samples.DynamicLibrary.Update () [0x00000]
506
+
507
+ in <00000000000000000000000000000000>:0
508
+
509
+
510
+
511
+ となっており、うまく読み込めていないのかと思っております…
512
+
513
+ 通常は何行目がエラーか出るみたいなのですが、私の場合はでておりません。

5

2021/07/07 22:57

投稿

pofinpouty
pofinpouty

スコア20

test CHANGED
@@ -1 +1 @@
1
- ARFoundation +image tracking 外部にある画像を認識し、テキストを表示したい
1
+ ARFoundation +image tracking 外部にある画像を認識したい
test CHANGED
@@ -1,21 +1,497 @@
1
1
  ARFoundation +ARKitでimage trackingのを試しています。
2
2
 
3
- [ク内容](https://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@4.2/manual/image-tracking.html)
4
-
5
- サンプルだとこのように「reference image library」に直接画像を設定することによりマーカー認識できるようになると思うのですが、これを外部から設定(開発環境がmacなのfinderからできるのが理想です)したいです。
6
-
7
- スクリプト中身(もしかしてreference image libraryのスクリプトではない…?)を確認したのですがどのようにしたら実現できるのかわかりませんでした…
8
-
9
- その辺ちゃん理解ていく必要があるのですが、ご教示願いたいです
10
-
11
-
12
-
13
- **追記**
14
-
15
- したことと
16
-
17
- ![![イメージ説明](133a92a8b8cde8e1191e599d247d9185.png)](e9fab14f3de3923cbc34da70cf1153f9.png)
18
-
19
-
20
-
21
- trackedimagemanagerのスクリプトのupdateinfoメソッドに、finderのパスを記述してテキストの内容を表示しようとしましたがダメでした…
3
+ [image trackingサプル](https://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@4.2/manual/image-tracking.html)
4
+
5
+ サンプルだとこのように「Reference image library」に直接画像を設定することによりマーカー認識できるようになると思うのですが、これを外部から設定できるようにしたいです。
6
+
7
+ [画像読み込み方法参考](https://qiita.com/k7a/items/df6dd8ea66cbc5a1e21d)
8
+
9
+ こちらを参考にまずResources.Loadで画像を表示できるようにAsset > Rerources > sample(画像)としのですがうまく動作しません
10
+
11
+
12
+
13
+ Reference image libraryのスクリプトを直接編集することができないため、実行時に参照ライブラリに画像を加できるという「Dynamic Library」のスクリプトに述しました。
14
+
15
+ 以下コードです。コメントの内容はサンプルの英語を直訳しただけなので気にないでください…
16
+
17
+ ```
18
+
19
+
20
+
21
+ namespace UnityEngine.XR.ARFoundation.Samples
22
+
23
+ {
24
+
25
+ /// <summary>
26
+
27
+ ///実行時に参照ライブラリに画像を追加します
28
+
29
+ /// Adds images to the reference library at runtime.
30
+
31
+ /// </summary>
32
+
33
+ [RequireComponent(typeof(ARTrackedImageManager))]
34
+
35
+ public class DynamicLibrary : MonoBehaviour
36
+
37
+ {
38
+
39
+ public Texture2D value;
40
+
41
+
42
+
43
+ void awake(){
44
+
45
+
46
+
47
+ value = Resources.Load("sample") as Texture2D;
48
+
49
+
50
+
51
+ }
52
+
53
+ [Serializable]
54
+
55
+ public class ImageData
56
+
57
+ {
58
+
59
+ //画像のソーステクスチャ。読み取り可能としてマークする必要があります。
60
+
61
+ [SerializeField, Tooltip("The source texture for the image. Must be marked as readable.")]
62
+
63
+ //2D画像の変数生成
64
+
65
+ Texture2D m_Texture;
66
+
67
+
68
+
69
+
70
+
71
+ //2D画像の変数生成
72
+
73
+ public Texture2D texture
74
+
75
+ {
76
+
77
+ get => m_Texture;
78
+
79
+ set => m_Texture = value;
80
+
81
+ }
82
+
83
+
84
+
85
+ [SerializeField, Tooltip("The name for this image.")]
86
+
87
+ //画像の名前
88
+
89
+ string m_Name;
90
+
91
+
92
+
93
+ public string name
94
+
95
+ {
96
+
97
+ get => m_Name;
98
+
99
+ set => m_Name = value;
100
+
101
+ }
102
+
103
+
104
+
105
+ [SerializeField, Tooltip("The width, in meters, of the image in the real world.")]
106
+
107
+ //実世界での画像の幅(メートル単位)
108
+
109
+ float m_Width;
110
+
111
+
112
+
113
+ public float width
114
+
115
+ {
116
+
117
+ get => m_Width;
118
+
119
+ set => m_Width = value;
120
+
121
+ }
122
+
123
+
124
+
125
+ public AddReferenceImageJobState jobState { get; set; }
126
+
127
+ }
128
+
129
+ //実行時に画像ライブラリに追加する画像のセット
130
+
131
+ [SerializeField, Tooltip("The set of images to add to the image library at runtime")]
132
+
133
+ ImageData[] m_Images;
134
+
135
+
136
+
137
+ /// <summary>
138
+
139
+ ///実行時に画像ライブラリに追加する画像のセット
140
+
141
+ /// The set of images to add to the image library at runtime
142
+
143
+ /// </summary>
144
+
145
+ public ImageData[] images
146
+
147
+ {
148
+
149
+ get => m_Images;
150
+
151
+ set => m_Images = value;
152
+
153
+ }
154
+
155
+
156
+
157
+ enum State
158
+
159
+ {
160
+
161
+ NoImagesAdded,
162
+
163
+ AddImagesRequested,
164
+
165
+ AddingImages,
166
+
167
+ Done,
168
+
169
+ Error
170
+
171
+ }
172
+
173
+
174
+
175
+ State m_State;
176
+
177
+
178
+
179
+ string m_ErrorMessage = "";
180
+
181
+
182
+
183
+ StringBuilder m_StringBuilder = new StringBuilder();
184
+
185
+
186
+
187
+ void OnGUI()
188
+
189
+ {
190
+
191
+ //ボタンと文字の大きさ
192
+
193
+ var fontSize = 50;
194
+
195
+ GUI.skin.button.fontSize = fontSize;
196
+
197
+ GUI.skin.label.fontSize = fontSize;
198
+
199
+
200
+
201
+ float margin = 100;
202
+
203
+
204
+
205
+ //開始エリア
206
+
207
+ GUILayout.BeginArea(new Rect(margin, margin, Screen.width - margin * 2, Screen.height - margin * 2));
208
+
209
+
210
+
211
+ switch (m_State)
212
+
213
+ {
214
+
215
+ case State.NoImagesAdded:
216
+
217
+ {
218
+
219
+ if (GUILayout.Button("Add images"))
220
+
221
+ {
222
+
223
+ m_State = State.AddImagesRequested;
224
+
225
+ }
226
+
227
+
228
+
229
+ break;
230
+
231
+ }
232
+
233
+ case State.AddingImages:
234
+
235
+ {
236
+
237
+ m_StringBuilder.Clear();
238
+
239
+ //追加行
240
+
241
+ m_StringBuilder.AppendLine("Add image status:");
242
+
243
+ foreach (var image in m_Images)
244
+
245
+ {
246
+
247
+ m_StringBuilder.AppendLine($"\t{image.name}: {(image.jobState.status.ToString())}");
248
+
249
+ }
250
+
251
+ GUILayout.Label(m_StringBuilder.ToString());
252
+
253
+ break;
254
+
255
+ }
256
+
257
+ case State.Done:
258
+
259
+ {
260
+
261
+ GUILayout.Label("All images added");
262
+
263
+ break;
264
+
265
+ }
266
+
267
+ case State.Error:
268
+
269
+ {
270
+
271
+ GUILayout.Label(m_ErrorMessage);
272
+
273
+ break;
274
+
275
+ }
276
+
277
+ }
278
+
279
+
280
+
281
+ GUILayout.EndArea();
282
+
283
+ }
284
+
285
+
286
+
287
+ void SetError(string errorMessage)
288
+
289
+ {
290
+
291
+ m_State = State.Error;
292
+
293
+ m_ErrorMessage = $"Error: {errorMessage}";
294
+
295
+ }
296
+
297
+
298
+
299
+ void Update()
300
+
301
+ {
302
+
303
+
304
+
305
+ switch (m_State)
306
+
307
+ {
308
+
309
+
310
+
311
+ case State.AddImagesRequested:
312
+
313
+ {
314
+
315
+
316
+
317
+ if (m_Images == null)
318
+
319
+ {
320
+
321
+
322
+
323
+ SetError("No images to add.");
324
+
325
+ break;
326
+
327
+ }
328
+
329
+
330
+
331
+ var manager = GetComponent<ARTrackedImageManager>();
332
+
333
+ if (manager == null)
334
+
335
+ {
336
+
337
+
338
+
339
+ SetError($"No {nameof(ARTrackedImageManager)} available.");
340
+
341
+ break;
342
+
343
+ }
344
+
345
+
346
+
347
+ //生の画像バイトを追加するか、テクスチャを受け入れる拡張メソッド(以下で使用)を使用できます。ただし、テクスチャを使用するには、そのインポート設定でテクスチャへの読み取り/書き込みアクセスが有効になっている必要があります。
348
+
349
+ // You can either add raw image bytes or use the extension method (used below) which accepts
350
+
351
+ // a texture. To use a texture, however, its import settings must have enabled read/write
352
+
353
+ // access to the texture.
354
+
355
+ foreach (var image in m_Images)
356
+
357
+ {
358
+
359
+ Debug.Log("ここでエラー");
360
+
361
+ if (!image.texture.isReadable)//////
362
+
363
+ {
364
+
365
+
366
+
367
+ SetError($"Image {image.name} must be readable to be added to the image library.");
368
+
369
+ break;
370
+
371
+ }
372
+
373
+
374
+
375
+ }
376
+
377
+
378
+
379
+ if (manager.referenceLibrary is MutableRuntimeReferenceImageLibrary mutableLibrary)
380
+
381
+ {
382
+
383
+
384
+
385
+ try
386
+
387
+ {
388
+
389
+ foreach (var image in m_Images)
390
+
391
+ {
392
+
393
+ //注:返されたJobHandleに対して何もする必要はありませんが、画像がライブラリに追加された時期を知りたい
394
+
395
+ //場合は、数フレームかかる可能性があるため便利です。
396
+
397
+ // Note: You do not need to do anything with the returned JobHandle, but it can be
398
+
399
+ // useful if you want to know when the image has been added to the library since it may
400
+
401
+ // take several frames.
402
+
403
+ image.jobState = mutableLibrary.ScheduleAddImageWithValidationJob(image.texture, image.name, image.width);
404
+
405
+
406
+
407
+ }
408
+
409
+
410
+
411
+ m_State = State.AddingImages;
412
+
413
+ }
414
+
415
+ catch (InvalidOperationException e)
416
+
417
+ {
418
+
419
+
420
+
421
+ SetError($"ScheduleAddImageJob threw exception: {e.Message}");
422
+
423
+ }
424
+
425
+ }
426
+
427
+ else
428
+
429
+ {
430
+
431
+
432
+
433
+ SetError($"The reference image library is not mutable.");
434
+
435
+ }
436
+
437
+
438
+
439
+ break;
440
+
441
+ }
442
+
443
+ case State.AddingImages:
444
+
445
+ {
446
+
447
+
448
+
449
+ //完了を確認する
450
+
451
+ // Check for completion
452
+
453
+ var done = true;
454
+
455
+ foreach (var image in m_Images)
456
+
457
+ {
458
+
459
+ if (!image.jobState.jobHandle.IsCompleted)
460
+
461
+ {
462
+
463
+ done = false;
464
+
465
+ break;
466
+
467
+ }
468
+
469
+ }
470
+
471
+
472
+
473
+ if (done)
474
+
475
+ {
476
+
477
+ m_State = State.Done;
478
+
479
+ }
480
+
481
+
482
+
483
+ break;
484
+
485
+ }
486
+
487
+ }
488
+
489
+ }
490
+
491
+  }
492
+
493
+
494
+
495
+
496
+
497
+ ```

4

2021/07/07 22:53

投稿

pofinpouty
pofinpouty

スコア20

test CHANGED
@@ -1 +1 @@
1
- ARFoundation +image tracking マーカーの参照先を外部フォルダにしたい
1
+ ARFoundation +image tracking 外部にある画像を認識、テキストを表示したい
test CHANGED
File without changes

3

試したことを追記

2021/06/30 03:08

投稿

pofinpouty
pofinpouty

スコア20

test CHANGED
File without changes
test CHANGED
@@ -7,3 +7,15 @@
7
7
  スクリプトの中身(もしかしてreference image libraryのスクリプトではない…?)を確認したのですがどのようにしたら実現できるのかわかりませんでした…
8
8
 
9
9
  その辺はちゃんと理解していく必要があるのですが、ご教示願いたいです。
10
+
11
+
12
+
13
+ **追記**
14
+
15
+ 試したこととして
16
+
17
+ ![![イメージ説明](133a92a8b8cde8e1191e599d247d9185.png)](e9fab14f3de3923cbc34da70cf1153f9.png)
18
+
19
+
20
+
21
+ trackedimagemanagerのスクリプトのupdateinfoメソッドに、finderのパスを記述してテキストの内容を表示しようとしましたがダメでした…

2

2021/06/29 23:48

投稿

pofinpouty
pofinpouty

スコア20

test CHANGED
@@ -1 +1 @@
1
- ARFoundation +ARKit マーカーの参照先を外部フォルダにしたい
1
+ ARFoundation +image tracking マーカーの参照先を外部フォルダにしたい
test CHANGED
File without changes

1

2021/06/29 03:11

投稿

pofinpouty
pofinpouty

スコア20

test CHANGED
@@ -1 +1 @@
1
- ARFoundation +ARKit マーカーの設定先を
1
+ ARFoundation +ARKit マーカーの参照先を外部フォルダにしたい
test CHANGED
File without changes