Log in or register to post comments

Why my model isn't display after detect imagetarget ?

October 21, 2013 - 10:44pm #1

Hello,I use Cloud Recognition.Because I want to image target is dynamic.

My problem is my model isn't display after detect imagetarget.Below image is hierarchy in unity.

And I edit code in ContentManager:

in void Start():

mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
      mTrackableBehaviour.RegisterTrackableEventHandler(this);
}

 

in TargetFound()

private void TargetFound()
    {
      
	Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
        Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = true;
        }

    }

 

in TargetLost()

private void TargetLost()

    {

        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);

        Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);



        // Disable rendering:

        foreach (Renderer component in rendererComponents)

        {

            component.enabled = false;

        }



        // Disable colliders:

        foreach (Collider component in colliderComponents)

        {

            component.enabled = false;

        }



        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");



    }

 

AttachmentSize
Binary Data bytes

Why my model isn't display after detect imagetarget ?

November 4, 2013 - 6:52am #5

dorankseo wrote:

Thank you,I can do it. When I touch cancel button.My model is hide. This my method.

private void hide(GameObject game){
		Renderer[] rendererComponents = game.GetComponentsInChildren<Renderer>(true);
        Collider[] colliderComponents = game.GetComponentsInChildren<Collider>(true);
 
        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }
 
        // Disable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = false;
        }
	
	}

 

 

im following your method:

private void hide(GameObject game)

and calling hide(mymodel); on public void OnGUI()

but its still not hiding

 

logcat -> NullReferenceException: Object reference not set to an instance of an object

Why my model isn't display after detect imagetarget ?

October 22, 2013 - 1:07am #4

Thank you,I can do it. When I touch cancel button.My model is hide. This my method.

private void hide(GameObject game){
		Renderer[] rendererComponents = game.GetComponentsInChildren<Renderer>(true);
        Collider[] colliderComponents = game.GetComponentsInChildren<Collider>(true);
 
        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }
 
        // Disable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = false;
        }
	
	}

 

Why my model isn't display after detect imagetarget ?

October 22, 2013 - 12:04am #3

Try checking if you have more than one trackable event handlers, in case they are conflicting with each other.

Also, you could verify whether the GetComponentsInChildren returns a non-empty array of renderers.

Otherwise, try making a simpler test by using a simpler model (e.g. a cube) and see if that works. Then you could extend it to use a mroe sophiscticated 3D model... but you definitely need to debug your problem, by verifying the values of the different components (e.g. use Debug.Log()), to see what goes wrong.

An alternative is to get the game Object of your 3D model and call SetActive( false ) on it.

 

Why my model isn't display after detect imagetarget ?

October 21, 2013 - 11:45pm #2

Now. I Can do it.But I have new problem.

When I tracker image target my model is show.And when I touch cancel button my model  not hide.

Why my model not hide ?

This code ;

private void hide(){
	Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
        Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
 
        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }
 
        // Disable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = false;
        }
	
}
public void OnGUI()
{
if (mCloudRecoBehaviour.CloudRecoInitialized && !mCloudRecoBehaviour.CloudRecoEnabled)
        {
            GUIStyle cancelButtonStyle;
            if (mButtonGUIStyles.TryGetValue("CancelButton", out cancelButtonStyle))
            {
                float buttonWidth = cancelButtonStyle.normal.background.width * DeviceDependentScale;
                float buttonHeight = cancelButtonStyle.normal.background.height * DeviceDependentScale;
                
                if (GUI.Button(new Rect(Screen.width - buttonWidth, 0, buttonWidth, buttonHeight),string.Empty,cancelButtonStyle))
                {
					hide();
                    mCloudRecoBehaviour.CloudRecoEnabled = true;
                    mButtonPressed = true;					
					
                    //mContentManager.TargetDeleted();
                }
            }
        }
}

 

Log in or register to post comments