Hello,
I am trying to learn Unity as its part of my project. I am using Vuforia AR extension for Unity.
I have a map downloaded from “My Trackables” and i need to show information on that map using AR. To be more specific, i parse a JSON object and i get some information for places on the map (such as lat & lon) and then i have to show a 3D object above each place, dynamically.
I 've read the sample projects and watched some videos but i am a little confused on how to start.
First of all, i created a c# script to download and store the data. Now that i have the information, i want to create 3D objects and show them on the map at specific points…
So, how do i create those objects at run time? Number of places is about 200… Should i create so many 3D objects?
Is there a limit on the number of virtual buttons that an AR app can have?
The project consists of an AR camera, an ImageTarget and a Directional light.
I added the first script as part of the camera in the inspector. Is this correct? Where should i add the script that creates the 3D objects?
any advice would be really helpful!
So, how do i create those objects at run time?
You can use Resources.Load to load a prefab in and then call Instantiate to create an instance of it.
Number of places is about 200… Should i create so many 3D objects?
This depends on what you’re trying to do and how complex these objects are. If they are complex and / or you don’t need to display that many at the same time the common approach is to have a pool of pre-instantiated objects. When you need one you take from the pool and when you are done with an object you put it back. Personally I usually manage that with a linked list class and have both a free and used pool.
I’m guessing as to the design of your app, but you could use the camera frustum to determine the objects state as it either enters or leaves. This would allow to allocate or free up instances of your object.
The alternative brute force approach is to instantiate / destroy what you need when you need it - that has (potentially) some performance issues but might be a good starting point.
Is there a limit on the number of virtual buttons that an AR app can have?
Sorry, I’ve used the Vuforia SDK but I haven’t used the real world buttons. If you’re referring to on-screen touch buttons then the only limit is screen real-estate.
The project consists of an AR camera, an ImageTarget and a Directional light. I added the first script as part of the camera in the inspector. Is this correct? Where should i add the script that creates the 3D objects?
Create your own game object and drop a script on it. One thing you’ll want to do is create your own version of the default event handler script. All that script does is listen for the lost track / found track events and hides / shows the child mesh renderers. If you write your own version you can avoid placing all of your objects as children on the image target.
I would create a gameobject that is a holder / parent of all of your dynamic objects. Drop your custom AR event handler script on that parent. Also add your scripts for spawning / logic.
Hope this helps.