Log in or register to post comments

Terrain Won't disappear

August 30, 2012 - 3:14pm #1

hello vuforia community 

I'm having when viewing the 3D model on my trackable. The terrain wont disappear when the camera isn't pointing at the trackable. All the obects dissapear but for some reason the terrain won't.

 

Please help! 

Terrain Won't disappear

December 30, 2016 - 4:15am #7

This is the Mod script.

/*==============================================================================

Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.

All Rights Reserved.

Confidential and Proprietary - Protected under copyright and other laws.

==============================================================================*/

using UnityEngine;

namespace Vuforia

{

    /// <summary>

    /// A custom handler that implements the ITrackableEventHandler interface.

    /// </summary>

    public class DefaultTrackableEventHandlerMod : MonoBehaviour,

                                                ITrackableEventHandler

    {

        #region PRIVATE_MEMBER_VARIABLES



        private TrackableBehaviour mTrackableBehaviour;

   

        #endregion // PRIVATE_MEMBER_VARIABLES

 

        #region UNTIY_MONOBEHAVIOUR_METHODS

   

        void Start()

        {

            mTrackableBehaviour = GetComponent<TrackableBehaviour>();

            if (mTrackableBehaviour)

            {

                mTrackableBehaviour.RegisterTrackableEventHandler(this);

            }

        }

        #endregion // UNTIY_MONOBEHAVIOUR_METHODS

        #region PUBLIC_METHODS

        /// <summary>

        /// Implementation of the ITrackableEventHandler function called when the

        /// tracking state changes.

        /// </summary>

        public void OnTrackableStateChanged(

                                        TrackableBehaviour.Status previousStatus,

                                        TrackableBehaviour.Status newStatus)

        {

            if (newStatus == TrackableBehaviour.Status.DETECTED ||

                newStatus == TrackableBehaviour.Status.TRACKED ||

                newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

            {

                OnTrackingFound();

            }

            else

            {

                OnTrackingLost();

            }

        }

        #endregion // PUBLIC_METHODS

        #region PRIVATE_METHODS



  private void OnTrackingFound()

  {

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

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

  

   Terrain[] terrainComponents = GetComponentsInChildren<Terrain>();

  

   foreach( Terrain component in terrainComponents )

   {

    component.enabled = true;

   }

  

   // Enable rendering:

   foreach (Renderer component in rendererComponents)

   {

    component.enabled = true;

   }

  

   // Enable colliders:

   foreach (Collider component in colliderComponents)

   {

    component.enabled = true;

   }

  

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

  

  }

 

  private void OnTrackingLost()

  {

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

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

  

   Terrain[] terrainComponents = GetComponentsInChildren<Terrain>();

  

   foreach( Terrain component in terrainComponents )

   {

    component.enabled = false;

   }

  

   // 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");

  

  }

        #endregion // PRIVATE_METHODS

    }

}

 

 

 

Terrain Won't disappear

January 25, 2013 - 11:12am #6

DavidBeard wrote:

You can modify your trackable event handler ( e.g. DefaultTrackableEventHandler.cs ) to specifically enable / disable your Terrain in response to tracking events.

e.g.

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

        Terrain[] terrainComponents = GetComponentsInChildren<Terrain>();
       
        foreach( Terrain component in terrainComponents )
        {
            component.enabled = true;
        }

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

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

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

    }

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

        Terrain[] terrainComponents = GetComponentsInChildren<Terrain>();
       
        foreach( Terrain component in terrainComponents )
        {
            component.enabled = false;
        }

        // 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");

    }
 

 

 

Thank you very much, works like a charm.

 

Can i know the actual reason for this to happen, i understand that the vuforia's scrit just enables and disables the rendering of the childs of imagetarget, but why a terrain is different?

 

Thank you again!

 

Terrain Won't disappear

September 17, 2012 - 3:18pm #5

Hey David 

Thanks for the code this worked perfect terrain now disappears when the camera is not on the tracker.

Terrain Won't disappear

September 4, 2012 - 9:39am #4

You can modify your trackable event handler ( e.g. DefaultTrackableEventHandler.cs ) to specifically enable / disable your Terrain in response to tracking events.

e.g.

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

        Terrain[] terrainComponents = GetComponentsInChildren<Terrain>();
       
        foreach( Terrain component in terrainComponents )
        {
            component.enabled = true;
        }

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

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

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

    }

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

        Terrain[] terrainComponents = GetComponentsInChildren<Terrain>();
       
        foreach( Terrain component in terrainComponents )
        {
            component.enabled = false;
        }

        // 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");

    }

 

Terrain Won't disappear

September 3, 2012 - 7:27pm #3

I'm using the Android Unity extension and the terrain is a child of the target instance. Any and all objects disappear when I move the camera from the printed target but the terrain remains have you heard of this problem?

Terrain Won't disappear

August 30, 2012 - 6:51pm #2

Are you working with the native Android SDK or the Android Unity extension? If it's the latter, is your terrain a child of your target instance in the hierarchy?

Log in or register to post comments