Loading...

2017.

Welcome to VOID AR

VOID AR is devoted to the continuous development of new AR technology in order to fulfill the AR developers with ultimate imaginaries, creativities and more high quality AR contents.
You can learn to use our products from here if you are trying VOID AR for the first time.

Dynamic Load

Part 1. Introduction

Dynamic Load Moduke, is dynamically add or delete the ImageTarget (Marker) and models in runtime.

Part 2. Reading Guidelines

This tutorial is mainly to introduce how to process in Unity environment.

We assume that readers have basic experience in app development and unity usage.

For more unity3d usage information, please visit the official website of unity3d documentation.

Part 3. Development Environment

You need to install and prepare your development environment as below before handling the models:

OS

- Windows 7 or higher
- OS X 10.10 or higher

Unity Version

Unity3D Version: 5.2.x - 5.6.x ( 32bit or 64bit ) , 2017.1

We recommends Unity3D 5.4 or above for better renderring quality.

Download: https://unity3d.com/cn/get-unity/download/archive

Unity3D of this tutorial: 5.5.2 ( 64bit )

Part 4. Implementation process

Step 1. Open new Unity project

Open Unity with new project. Fill the Project name with “VOIDAR_Test”, and select the location, and click [ Create project ].

59.png

Step 2. Import VOID AR SDK

Select[ Assets ] -> [ Import Package ] -> [ Custom Package... ], import VOID AR SDK.

2.png

Select the downloaded SDK file (.unitypackage), and click [ Open ] button.

3.png

Click [ Import ] from the prompted window. It takes minutes during the import process.

4.png

If there is a prompt window of “API Update Required” interface,please click [ I Made a Backup, Go Ahead! ].

5.png

Step 3. Delete Main Camera

When you open the Unity3D, you will see the new scene in default. The new scene has two GameObjects: a Main Camera and a Directional Light. We need to use the ARCamera from SDK, so please delete the default Camera.

Right click the "Main Camera” from the scene, and select [ Delete ].

6.png

Step 4. Drag the prefabs “ARCamera”

Expand the directory [ Assets ] -> [ VoidAR ] -> [ Prefabs ], and drag the prefabs “ARCamera” to the scene.

60.png

When you finish the process, it shows as below:

61.png

Step 5. ARCamera Setup

Select ARCamera, and look up in the “Inspector” area on the right side, setup “Void AR Behaviour (Script)” properties.

- Set MarkerType = "Image", stands for image target recognition
- Set Simultaneous Tracking = "1", stands for the tracking marker number is 1 at the same time

62.png

Step 6. Resource Setup

All resource used in this tutorial is SDK built-in resource.

- ImageTarget ( Marker ): Assets / StreamingAssets / 1yuan.jpg
  63.png

- Display Model: Assets / VoidARDemo / Prefabs / CubeTarget.prefab
  64.png

You need to package the model resource into AssetBundle resource in Unity.

In the folder of [ VoidARDemo] -> [ Prefabs ], select the "CubeTarget.prefab" and click [ VoidAR ] -> [ AssetBundleBuilder ].

65.png

Click the [ BuildAssetBundles ] from prompting window.

Different platform requires different option checked.

This tutorial has all options checked.

66.png

It takes minutes for generating, please wait...

67.png

Close this window after generating is done.

There will be a folder “Assetbundle" under the directory "StreamingAssets".

There will be a platform folder corresponding to each platform, shown as below:

68.png

Resource setup is done.

Step 7. Writing code for resource load

Add a new script named “MyTest” to ARCamera.

Select "ARCamera", and click [ Add Compoent ], fill in the search blank with words "MyTest", and then click [ New Script ].

69.png

Click [ Create and Add ] to add a script.

70.png

After that, it shows as below:

71.png

Click the setting button to select the [ Edit Script ] to edit the script.

72.png

The editor (VS2015, MonoDevelop, etc.) will be automatically opened.

73.png

Replace with the contents below:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    public class MyTest : MonoBehaviour {
        void OnGUI()
        {
            var btnHeight = Screen.height * 0.1f;
            var btnWidth = btnHeight * 2f;
            var gap = 20;
            if (GUI.Button(new Rect(Screen.width - btnWidth, gap, btnWidth, btnHeight), "添加目标"))
            {
                Debug.Log(" add marker");
                string markerURL = VoidARUtils.GetStreamDirForWWW() + "1yuan.jpg";
                string targetURL = VoidARUtils.GetStreamingAssetbuddleResourcePath() + "CubeTarget.assetbundle";
                StartCoroutine(LoadGameObjects(markerURL, targetURL));
            }
        }
   
        private IEnumerator LoadGameObjects(string markerURL,string targetURL)
        {
            if (!VoidAR.GetInstance().isMarkerExist(markerURL))
            {
                WWW file = new WWW(markerURL);
                yield return file;
   
                if (file.error != null)
                {
                    Debug.Log("Can not Load " + markerURL);
                }
                else
                {
                    WWW bundle = new WWW(targetURL);
                    yield return bundle;
                    if (bundle.error != null)
                    {
                        Debug.Log("Can not Load " + targetURL);
                    }
                    else
                    {
                        VoidAR.Image2ImageTarget obj = new VoidAR.Image2ImageTarget();
                        obj.imageUrl = markerURL;
                        obj.isMarkerLocal = true;
                        obj.ImageTarget = (GameObject)Instantiate(bundle.assetBundle.mainAsset);
   
                        Texture2D tex = new Texture2D(2, 2);
                        tex.LoadImage(file.bytes);
                        obj.imagewidth = tex.width;
                        obj.imageheight = tex.height;
                        obj.imagedata = VoidARUtils.Color32ArrayToByteArray(tex.GetPixels32());
                        List<VoidAR.Image2ImageTarget> image2ImageTargetes = new List<VoidAR.Image2ImageTarget>();
                        image2ImageTargetes.Add(obj);
                        VoidAR.GetInstance().addTargets(image2ImageTargetes);
                        bundle.assetBundle.Unload(false);
                    }
                }
            }
        }
    }

Coding is finished.

Step 8. Save Scene

Select [ File] -> [ Save Scenes ] , click for saving your setup.

14.png

Setup the name as “VOIDAR_Test”, and click [ save ] button.

74.png

Step 9. Debug

Make sure your PC is connected with a camera, and click [ Play ] button.

75.png

While running, click the button “添加目标” (Drawn by OnGUI function in code) and face the camera to the marker, the model will appear soon.

76.png

Step 10. Build for Android or iOS

Build Process includes Android and iOS.

- Android

First, switch the PC platform to Android platform from [ File ] -> [ Build Settings... ].

18.png

Select Android tag, if the [ Switch Platform ] button is grey, you need to download the Unity Android Support. Please click on the right side of the [ Open Download Page ] button, download and install.

19.png

Click [ Switch Platform ] button, switch the platform to Android.

20.png

After switch process, close the Build Settings interface first, and continue with packing.

Select [ Edit ] -> [ Preferences... ], setup the preferences parameters.

47.png

Select “External Tools” option, setup Android SDK and JDK。

If you do not have SDK and JDK, please click [ Download ] from the interface, it will guide you to download from the prompted website.

Or you can also download from links below:

SDK: https://developer.android.com/studio/index.html#Other

JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html

After the installation of SDK and JDK, you are able to setup their directory.

48.png

Select ARCamera, and look up in the “Inspector” area on the right side, setup “Void AR Behaviour (Script)” properties.

- Set Camera = "后置摄像头"(Rear camera)

77.png

Select [ File ] -> [ Build Settings... ], cancel all defalt scenes, and click [ Add Open Scenes ] button to add current scene into the build area.

21.png

It shows as below:

78.png

Click [ Player Settings... ] button, check the “Inspector” area, setup the parameters as below or as your needs.

- Set Company = "VOIDAR"

- Set Product Name = "VOIDAR_Test"

- Set Bundle Identifier = "com.VOIDAR.Test"

Caution: Bundle Identifier cannot use default, otherwise it fail to build.

79.png

Finish the settings, and click [ Build ] button.

80.png

Set the file name as “VOIDAR_Test”, and click [ save ] button to start building.

81.png

It takes minutes while building, please wait...

82.png

When the build is done, it will generate an apk file “VOIDAR_Test.apk”. Android Build is completed.


- iOS

iOS Build requires Mac device ( such as MacBook Pro、MacBook、iMac、Mac mini etc. )

Switch the platform to iOS platform in Unity, and build Xcode project.

Caution: It is recommended to use Mac device to build Xcode project. If previously you make the project in Windows environment, you can copy the whole Unity directory of this project to Mac device and build for xcode project.


Lauch Unity and open the saved or copied VOIDAR_Test project. ( Skip this step if project opened already )

28.png

Click [ Open ] button to open the project.

83.png

Switch to iOS platform in Unity, click [ File ] -> [ Build Settings... ].

30.png

Select iOS tag, if the [ Switch Platform ] button is grey, you need to download the Unity iOS Support. Please click on the right side of the [ Open Download Page ] button, download and install.

31.png

Click [ Switch Platform ] button, switch the platform to iOS.

32.png

Close the Build Settings interface after switch.

Select ARCamera, check the “Inspector” area on the right side, setup the "Void AR Behaviour (Script)” properties.

- Set Camera = "后置摄像头"(Rear Camera)

84.png

Select [ File ] -> [ Build Settings... ], cancel all defalt scenes, and click [ Add Open Scenes ] button to add current scene into the build area.

34.png

It shows as below:

85.png

Finish the settings, and click [ Build ] button.

86.png

Set the project folder name “Output”, and click [ Save ].

 37.png

Open the Xcode project.

38.png

Filling in your configurations: your certificate, deployment target

Click [ Unity-iPhone ] on the left side, config the parameters as below or by your customization:

- Display Name = "VOIDAR_Test"

- Bundle Identifier = "com.VOIDAR.Demo"

- Version = "1.0"

- Build = “1.0”

- Team = “Your Certificate”

- Deployment Target = “8.1”

39.png

Select General tag and scroll down, click the "+" in the "Linked Frameworks and Libraries".

40.png

Select “Accelerate.framework” from the prompted window, and click [ Add ].

41.png

After doing that, you will see “Accelerate.framework” from the list of "Linked Frameworks and Libraries" as below:

42.png

Add camera usage privacy.

Select “Info” tag, click the "+" below the "Supported interface orientations". Select “Privacy - Camera Usage Description” in the prompting list.

43.png

44.png

Select ”Build Settings” tag, set Enable Bitcode = “No”.

45.png

Connect iphone or ipad to the Mac device, Click [ Run ].

46.png

After building, there will be an application(“VOIDAR_Test”) built into your iphone or ipad.

The iOS build is done.


By here, the Dynamic Load process is done.