Log in or register to post comments

Please provide sample for swapping dataset in Unity3D

October 15, 2012 - 10:09pm #1

I came across https://ar.qualcomm.at/, mastering advanced topics.

But find it is pretty hard to implement the same in Unity 3d. It is confusing more Cry

So can anyone of you please provide me with an sample code block or example to make use of the swappable dataset.

 

Thank you,

Muthukumar

Please provide sample for swapping dataset in Unity3D

November 6, 2012 - 7:27pm #21

Sorry For my mistake and Thank you...

Please provide sample for swapping dataset in Unity3D

November 6, 2012 - 4:02am #20

Please see my response to your identical question here

https://ar.qualcomm.at/content/dynamically-load-unity-trackable-file-web#comment-2017280

..and in future please avoid double and tripple posting of the same issue.

N

Please provide sample for swapping dataset in Unity3D

November 6, 2012 - 1:35am #19

BeHappy wrote:

okay NalinS,

Let me try as you suggested.

Thank you.

 

As you suggested, i extracted the .xml and .dat from unitypackage and uploaded to the server. I could now able to download them to my device and tried to load it using STORAGE_ABSOLUTE....But nothing seems working...

My .xml and .dat files are now located in "/mnt/sdcard/Android/data/com.BeHappy.SwapDataset/files". I dont want any default dataset to be loaded through inspector, i want to download this two files once when user opens the application....

So can you please help me out on bringing this dataset to work and track all the images associated with it.

Thanks a lot.

Please provide sample for swapping dataset in Unity3D

November 3, 2012 - 12:41am #18

okay NalinS,

Let me try as you suggested.

Thank you.

Please provide sample for swapping dataset in Unity3D

November 2, 2012 - 4:36am #17

"So you mean that i have to download the trackable from "My Trackables" Section and make use of it directly by downloading it to the application and then instantiate the dataset."

yes

"But as far as i know, we cant instantiate an unity package directly in a game...."

so take the .dat and .xml from the .unitypackage by extracting manually - and then you can put these on your server to download, and ten you can instantiate them in your client.

N

Please provide sample for swapping dataset in Unity3D

November 2, 2012 - 3:48am #16

Hi NalinS,

So you mean that i have to download the trackable from "My Trackables" Section and make use of it directly by downloading it to the application and then instantiate the dataset.

But as far as i know, we cant instantiate an unity package directly in a game....

Could you please explain ???

 

Thank you.

Please provide sample for swapping dataset in Unity3D

October 29, 2012 - 8:12am #15

OK - I have checked internally and the advice is this:

Unitypackages are distinct from Asset Bundles. Where a *.unitypackage can bundle a diversity of file types as an archive, Asset Bundles are intended for binary assets and compile these into a proprietary format recognized by Unity's scene loader.

We do not recommend trying to put datasets in asset bundles because the Unity packager will most likely reject it.

Therefore it is best to download and instantiate the datasets within a .unitypackage - you'll need to download these to the local directory and use STORAGE_ABSOLUTE

Here is some idea of how to organise the download from Unity:

http://forum.unity3d.com/threads/122110-Can-anyone-tell-me-HOW

HTH, and sorry for any confusion.

N

 

Please provide sample for swapping dataset in Unity3D

October 29, 2012 - 7:50am #14

Kindly help.... :-(Innocent

Please provide sample for swapping dataset in Unity3D

October 25, 2012 - 11:05pm #13

Thanks a lot for the below code slice....

 

I have finished now with downloading the asset bundle...

But what should i have to put inside asset bundle while creating it ? Do i need to add the Trackable unity package(.unity3d) which i will download from Qualcomm Trackables or the datasets along with dat and xml files, after uncompressing the target package ??

An example to make use of stones and chips trackables by building the asset bundle and downloading it from WWW and assigning them to an image target will be of Very Much HELP to me....And this is what am exactly struggling for the past one week...

Sorry if my questions were annoying a lot :-(

Kindly help...

Please provide sample for swapping dataset in Unity3D

October 25, 2012 - 10:59pm #12

First of all Thanks a ton, NalinS and Davidbeard....You are helping all the way...Without you people i wouldnt have progressed much...

My ultimate aim of the app is,

* I have one set of trackable(around 20 images) while publishing, but twice a week i will get new images that need to be recognized along with the 20 images available with the app.

* And also i dont want to show any game objects(cube) while identifying image target, i just need the name of the marker traced. so that i can send the name to the web service and get the result.

* As of now, am done with web service and initial dataset and it is working perfect.

* Am struggling to find the right path to download and recognize new images :-(  I have unity pro right now, but not sure of how to make use of the new dataset ? 

* And do i need to add more image target to track the newly added image or using one image target itself i can find all the trackables associated with the dataset ??

with you people's suggestion i will look more into asset bundle.

Once again, Thanks a lot and lot for your continuous support. :-)

Please provide sample for swapping dataset in Unity3D

October 22, 2012 - 6:49am #11

Have a look at this thread where David shows some code that can access ImageTargets and associated augmentations from an AssetBundle downloaded via the web.

https://ar.qualcomm.at/content/child-gameobject-imagetarget

I have reproduced the code below for convenience.

HTH

N

using UnityEngine;
using System.Collections;

public class LoadAssetBundleCube : MonoBehaviour {

public WWW www;
public string url = "Cube.unity3d";
public string resourcePath = "Cube";
public int guiOffset = 20;
public AssetBundle assetBundle;
public Object instanced;

private GameObject go;
private int progress;

public LoadAssetBundleCube()
{
}

// Use this for initialization
IEnumerator Start()
{
// Start a download of the given URL
www = WWW.LoadFromCacheOrDownload(url, 1);

// Wait for download to complete
yield return www;

// Load and retrieve the AssetBundle
assetBundle = www.assetBundle;

// Load the GameObject
//go = assetBundle.Load("mainAsset", typeof(GameObject)) as GameObject;
go = (GameObject)assetBundle.mainAsset;

// Instantiate the GameObject
Instantiate(go);


GameObject goImageTarget = GameObject.Find("ImageTarget");
GameObject goCube = GameObject.Find("Cube(Clone)");
goCube.transform.parent = goImageTarget.transform;
}

// Update is called once per frame
void OnGUI()
{
GUILayout.Space(guiOffset);
progress = (int)(www.progress * 100);
GUILayout.Label("download: " + progress + "%");
}
}


* keep in mind that AssetBundles for mobile need to be built specifically for the target platform.

Please provide sample for swapping dataset in Unity3D

October 21, 2012 - 8:40pm #10

Please help...

Please provide sample for swapping dataset in Unity3D

October 18, 2012 - 10:45pm #9

I think my approach is wrong as i am not able to move imagetarget as a prefab and cant set target in a prefab.....

And also i could not move scene objects to a asset bundle as it will throw error,  "Assets included in a asset bundle can not be scene objects, instead place them in a prefab, then export them." 

So what approach should i follow for this ?

Thanks.

Please provide sample for swapping dataset in Unity3D

October 18, 2012 - 9:42pm #8

Hi

Am using unity pro version only right now. So i guess i could make use of the AssetBundles as it is the very easy way.

So if i need to load more trackables, then i can make change in my project(like removing or adding more trackables) and move them as a asset bundle, download from WWW when needed and instantiate this while application starts up right ??

My question is like, when i instantiate the new one after downloading, what will happen to the pre existing data sets and trackables ??

Is that my approach is right ?

 

Thank you.

Please provide sample for swapping dataset in Unity3D

October 18, 2012 - 5:54am #7

Hi

It seems like you are using Unity assets so it will require the use of AssetBundles (Unity pro only)

pjt ? Not sure what you mean here?

N

Please provide sample for swapping dataset in Unity3D

October 18, 2012 - 5:48am #6

Hi NalinS,

Which one should i use as unity 3d Asset to instantiate ?

Because i tried to load trackables downloaded from Qualcomm which is a unity package and unable to put it inside the pjt or instantiate it as it allows only AssetBundles ?

Any suggestions on this...

 

Thanks,

Muthukumar

Please provide sample for swapping dataset in Unity3D

October 17, 2012 - 4:16am #5

Thanks a lot...I followed the assetBundle option and it works pretty good...But lot more to do on my side...will do more and get my doubts clarified...

But thanks a lot for helping in all the situations....

I used the following code to load the asset bundle from https location but want to check with the Android Device,

function Start () {

var form = new WWWForm();

form.AddField( "name", "value" );

var headers = form.headers;

var rawData = form.data;

var url = "https://myserver.com/unity.3d";

 

// Add a custom header to the request.

// In this case a basic authentication to access a password protected resource.

headers["Authorization"]="Basic " + System.Convert.ToBase64String(

    System.Text.Encoding.ASCII.GetBytes("userID:password"));

 

// Post a request to an URL with our custom headers

var www = new WWW(url, rawData, headers);

yield www;

 

Debug.Log(www);

Debug.Log(www.error);

Debug.Log(www.isDone);

Debug.Log(www.size);

var newAsset = Instantiate(www.assetBundle.mainAsset);

}

 

 

Please provide sample for swapping dataset in Unity3D

October 17, 2012 - 3:14am #4

Hi,

Basically there are two ways to achieve this:

1 Using a unity package, though this requires the use of asset bundles which are a Unity pro only feature

This is described here in more detail:   https://ar.qualcomm.at/content/dynamically-load-unity-trackable-file-web

2 Download the .dat and .xml files to the Documents directory (on iOS, and the equivalent on Android), and then instantiate the datasets by using STORAGE_ABSOLUTE

This approach does not require Unity Pro, but it is a little more work, and there may be platform differences as described above which you will need to navigate.  This approach is described here in more detail, along with some sample code:  https://ar.qualcomm.at/content/swapping-datasets

HTH

N

 

Please provide sample for swapping dataset in Unity3D

October 16, 2012 - 9:20pm #3

Hi NalinS,

Oh...I missed that completely...Thanks a lot Cool

And i also have one more doubt, 

In my project i would check with the server for the new updated version of image target and if not i have to download them from the server and use it. So for download, do i need to download the unity package(trackables) directly or only xml and dat is enough ??

Because if i place only xml and dat files in Unity Editor and try to load, it says no data set found.

Please suggest....

 

Please provide sample for swapping dataset in Unity3D

October 16, 2012 - 4:38am #2

Hi Muthukumar

All is not lost :)

Please look at the Image Targets sample because when you touch the screen a menu pops up giving you the option to switch datasets from "Chips & Stones" to "Tarmac".

This is the sample code to look at.

 

HTH

N

Log in or register to post comments