当前位置:网站首页>Arfoundation Getting Started tutorial 7-url dynamically loading image tracking Library
Arfoundation Getting Started tutorial 7-url dynamically loading image tracking Library
2022-07-29 08:28:00 【suelee_ hm】
Reference Image Library Image tracking uses a static method , Establish a reference library in advance , Add the reference diagram and establish the corresponding relationship for its index . For applications with a large number of reference diagrams , It's about to use MutableRuntimeReferenceImageLibrary 了 .
MutableRuntimeReferenceImageLibrary Support dynamic addition of reference images .
from 《ARFoundation Starting from scratch 6-url Dynamically load image rendering materials 》 Example continue :
Project sample source code :
GitHub - sueleeyu/ar-netdynamic: from url Get image rendering dynamically
One 、 Add the component
1. add to AR Tracked Image Manager


2. newly build DynamicImageLib.cs:

3. To write cs Code , Download pictures and add them to the tracking Library , Simple code .
using System.Collections;
using System.Collections.Generic;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.IO;
namespace UnityEngine.XR.ARFoundation.Samples
{
publicclassDynamicImageLib : MonoBehaviour
{
ARTrackedImageManager aRTrackedImageManager;
GameObject mTrackedImagePrefab;
Texture2D imgToTexture2d;
public MutableRuntimeReferenceImageLibrary myRuntimeImageLibrary;
public Text msgText;
//public Text numText;
bool isRunning = false;
List<string> allURLs = new List<string> { "https://doutuji.cn/h5/one.png","https://doutuji.cn/h5/two.png"};
voidAwake()
{
//Screen.sleepTimeout = SleepTimeout.NeverSleep;
aRTrackedImageManager = GetComponent<ARTrackedImageManager>();
aRTrackedImageManager.enabled = false;
myRuntimeImageLibrary = aRTrackedImageManager.CreateRuntimeLibrary() as MutableRuntimeReferenceImageLibrary;
aRTrackedImageManager.requestedMaxNumberOfMovingImages = 4;
aRTrackedImageManager.trackedImagePrefab = mTrackedImagePrefab;
aRTrackedImageManager.trackedImagesChanged += OnImageChanged;
}
publicvoid DownLibImages()
{
StartCoroutine(AddImageTrackerByUrl());
}
publicvoid OnImageChanged(ARTrackedImagesChangedEventArgs args)
{
foreach (var trackedImage in args.added)
{
//Logger.Log("DynamicImageLib myRuntimeImageLibrary" + trackedImage.name);
msgText.text = " Identified :" + trackedImage.referenceImage.name;
}
}
IEnumerator AddImageTrackerByUrl()
{
Logger.Log("DynamicImageLib-AddImageTrackerByUrl");
msgText.text = "lib Number of drawings :0" ;
isRunning = true;
aRTrackedImageManager.enabled = false;
if (aRTrackedImageManager.descriptor.supportsMutableLibrary)
{
foreach (var link in allURLs)
{
using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(link))
{
yieldreturn webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.ConnectionError)
{
Debug.Log("Error is " + webRequest.error);
}
else
{
imgToTexture2d = DownloadHandlerTexture.GetContent(webRequest);
//Unity.Jobs.JobHandle jobHandle = myRuntimeImageLibrary.ScheduleAddImageJob(imgToTexture2d, Path.GetFileName(link), 0.2f);
AddReferenceImageJobState jobState = myRuntimeImageLibrary.ScheduleAddImageWithValidationJob(imgToTexture2d, Path.GetFileName(link), imgToTexture2d.width);
jobState.jobHandle.Complete();
if (!jobState.jobHandle.IsCompleted)
{
Logger.Log("!jobState.jobHandle.IsCompleted");
}
if (myRuntimeImageLibrary != null)
{
//Debug.Log("Image Library Count: " + myRuntimeImageLibrary.count);
msgText.text = "lib Number of drawings :" + myRuntimeImageLibrary.count.ToString();
aRTrackedImageManager.referenceLibrary = myRuntimeImageLibrary;
Logger.Log("DynamicImageLib myRuntimeImageLibrary");
}
webRequest.downloadHandler.Dispose();
imgToTexture2d = null;
aRTrackedImageManager.enabled = true;
}
}
}
}
}
}
}
4. choice AR Session Origin, mount DynamicImageLib.cs file , Drag the Text To cs Of documents Msg Text

5. add to Button Of click event . choice “ Download trace map ”Button, Drag the AR Session Origin, choice Function function .


Two 、unity Knowledge point
3、 ... and 、android Packaging operation
If not configured , see 《ARFoundation Starting from scratch 5》.
1. Installation and operation


Four 、 common problem
5、 ... and 、 reference
1. Unity api:
Unity - Manual: Unity User Manual 2021.3 (LTS)
Class MutableRuntimeReferenceImageLibrary | AR Subsystems | 4.1.10
2.ARFoundation Example :
https://github.com/Unity-Technologies/arfoundation-samples
3. The sample source code of this project :
GitHub - sueleeyu/ar-netdynamic: from url Get image rendering dynamically
边栏推荐
- Four pin OLED display based on stm32
- Detailed steps of installing MySQL 5.7 for windows
- ROS tutorial (Xavier)
- Cs4344 domestic substitute for dp4344 192K dual channel 24 bit DA converter
- Data warehouse layered design and data synchronization,, 220728,,,,
- Random lottery turntable wechat applet project source code
- Smart energy management system solution
- Component transfer participation lifecycle
- Huawei wireless device configuration uses WDS technology to deploy WLAN services
- Day13: file upload vulnerability
猜你喜欢

分段分页以及段页结合

Huawei wireless device configuration uses WDS technology to deploy WLAN services

Day4: SQL server is easy to use

What constitutes the smart charging pile system?

Time function in MySQL

Data warehouse layered design and data synchronization,, 220728,,,,

Segment paging and segment page combination

pnpm install出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies

Day6: use PHP to write file upload page

Dp1332e multi protocol highly integrated contactless read-write chip
随机推荐
Day4: the establishment of MySQL database and its simplicity and practicality
Application scheme of charging pile
QT version of Snake game project
数仓分层设计及数据同步问题,,220728,,,,
Osg3.6.5 failed to compile freetype
Use SQL client How can the job generated by SH achieve breakpoint continuation after cancle?
深度学习(2):图片文字识别
Alibaba political commissar system - Chapter III, Alibaba political commissar and cultural docking
深度学习(1):银行客户流失预测
Deep learning (2): image and character recognition
BiSeNet v2
Second week of postgraduate freshman training: convolutional neural network foundation
C language macro define command exercise
Personal study notes
Simple operation of SQL server data table
RPC and rest
Preparation of SQL judgment statement
Proteus simulation based on msp430f2491
Multifunctional signal generator based on AD9850
TCP - sliding window