Log in or register to post comments

How can i load 3d model dynamically from resources

October 10, 2013 - 3:33am #1

Hi,

I'm new on Vuforia CR . I want to load 3d model dynamically according to targetSearchResult.MetaData value.

I'll do this on OnNewSearchResult but how to implement it?

 

I try this code but cannot load 3d model. 

Thanks. 

public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        // This code demonstrates how to reuse an ImageTargetBehaviour for new search results and modifying it according to the metadata
        // Depending on your application, it can make more sense to duplicate the ImageTargetBehaviour using Instantiate(), 
        // or to create a new ImageTargetBehaviour for each new result

        // Vuforia will return a new object with the right script automatically if you use
        // TargetFinder.EnableTracking(TargetSearchResult result, string gameObjectName)
        
        //Check if the metadata isn't null
        if(targetSearchResult.MetaData == null)
        {
            return;
        }
		
		//GUILayout.Label(targetSearchResult.MetaData.ToString());

        // enable the new result with the same ImageTargetBehaviour:
        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, mParentOfImageTargetTemplate);

        if (imageTargetBehaviour != null)
        {
			if(targetSearchResult.MetaData.ToString() == "testmetadata")
			{
				Transform myModel = GameObject.Instantiate(Resources.Load("MURCIELAGO640")) as Transform;
				myModel.parent = imageTargetBehaviour.gameObject.transform;
				myModel.localPosition = new Vector3(0f, 0.002499813f, 0f);
				myModel.localRotation = Quaternion.identity;
				myModel.localScale = new Vector3(15f,15f,15f);
				myModel.gameObject.SetActive(true);
			}

            // stop the target finder
            mCloudRecoBehaviour.CloudRecoEnabled = false;
            
            // Calls the TargetCreated Method of the SceneManager object to start loading
            // the BookData from the JSON
            //mContentManager.TargetCreated(targetSearchResult.MetaData);
        }
    }

 

How can i load 3d model dynamically from resources

October 24, 2013 - 3:43am #4

Good to hear :)

N

How can i load 3d model dynamically from resources

October 23, 2013 - 11:44pm #3

Thanks I have done it

 

Harun

How can i load 3d model dynamically from resources

October 10, 2013 - 4:43am #2

This is more a general question about Unity rather than specific to Vuforia, so we cannot really help you.

My suggestion is to work out how to do this in Unity and then go through the code to figure out where exactly it needs to be in the CR sample.  You might be better off by having the models within the application as prefabs, and then instantiating those rather than trying to load one specifically.

 

N

Log in or register to post comments