x


Dynamic import of collada asset

Hi everybody.

I absolutely need to import a collada (.dae) asset dynamically through a script. Dynamically because I'm building an application which models a mesh accordingly to some user input, so I cannot recompile in Unity.

I tried to use AssetBundles but I'm quite a newbie in Unity, maybe I'm missing some important point.

Here my few lines of code, the script is attached to a empty game object in unity. Basically I want to import the collada asset in the path and put the object "monkey" inside the scene. :-|

WWW urlExternalAsset = new WWW("file://D:/Unity/monkey.dae"); GameObject go; void Start () { AssetBundle bundle = urlExternalAsset.assetBundle; go = bundle.Load("monkey", typeof(GameObject)) as GameObject; Instantiate(go); }

Thank you for your help. I'm doing a project with my university and this part is fundametal for me;)

Luca

more ▼

asked Apr 27 '12 at 03:10 PM

bertinerd gravatar image

bertinerd
1 2 2 3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

To use AssetBundles you need to:

1 Build an AssetBundle that includes the Monkey Asset. Note that this is not the collada file, but the Asset that you see in the Project folder. The instructions to do that you can find in these places:

http://unity3d.com/support/documentation/Manual/AssetBundles http://unity3d.com/support/documentation/ScriptReference/BuildPipeline.BuildAssetBundle.html

*Note: The file extension for the AssetBundle is not important.

2 Put that AssetBundle file in a location where you will load it from:

D:/Unity/monkey.assetbundle

3 Download the AssetBundle using the WWW class:

IEnumerator Start (){
   WWW urlExternalAsset = new WWW("file://D:/Unity/monkey.assetbundle");
   yield return www;

   // 4. Retrieve the AssetBundle from the WWW object:
   AssetBundle bundle = urlExternalAsset.assetBundle;

   // 5. Load the Mokey GameObject from the AssetBundle:
   GameObject go = bundle.Load("monkey", typeof(GameObject)) as GameObject;

   // 6. Instantiate the GameObject:
   Instantiate(go);
}

Enjoy!

more ▼

answered Apr 27 '12 at 05:17 PM

ricardo_arango gravatar image

ricardo_arango
1.3k 2 6 11

(comments are locked)
10|3000 characters needed characters left

Ok. I think that what I've done is just what you described in point 3.

I can't understand the meaning of what is described in the first 2 points...what does build the asset bundle mean? Considering that I'm creating the .dae file runtime I need to load it also runtime in a previously built file. I can't launch the unity editor, I can just use scripts.

I will try to summarize of does my pipeline work

  • I have a C# program continuosly getting infos from a Kinect
  • On the other side, I have a unity .exe (which I already created), that shows a 3d avatar.
  • After an acquisition phase I stop getting data from the Kinect and I run the previously built Unity .exe, which should use the data acquired runtime to build the 3d world. I did it successfully with textures...now I want to apply the same procedure also to meshes. --> That's why I need to import collada .dae dynamically.

Do you think this is possible with AssetBundles? What could use if not?

Thank you so much.

Luca

more ▼

answered May 03 '12 at 10:28 PM

bertinerd gravatar image

bertinerd
1 2 2 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x381
x374
x28
x15

asked: Apr 27 '12 at 03:10 PM

Seen: 865 times

Last Updated: May 03 '12 at 10:28 PM