How to show different prefabs for different images in ARcore-Augmented Image scene using Unity?












0















Hi I am trying to augment different prefabs for different images say around 20 models.Currently testing with 2 models for 2 images in AugmentedImage sample scene.I have added the script AugmentedImageVisualizer.cs to each prefab.I drag and dropped the two models to the script.In the AugmenetedImageExampleController.cs I have made the following changes.



namespace GoogleARCore.Examples.AugmentedImage
{
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GoogleARCore;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Controller for AugmentedImage example.
/// </summary>
public class AugmentedImageExampleController : MonoBehaviour
{
/// <summary>
/// A prefab for visualizing an AugmentedImage.
/// </summary>
// public AugmentedImageVisualizer AugmentedImageVisualizerPrefab;
public List<AugmentedImageVisualizer> AugmentedImageVisualizerPrefab = new List<AugmentedImageVisualizer>();




/// <summary>
/// The overlay containing the fit to scan user guide.
/// </summary>
public GameObject FitToScanOverlay;

private Dictionary<int, AugmentedImageVisualizer> m_Visualizers
= new Dictionary<int, AugmentedImageVisualizer>();

private List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>();

/// <summary>
/// The Unity Update method.
/// </summary>
public void Update()
{


// Exit the app when the 'back' button is pressed.
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}

// Check that motion tracking is tracking.
if (Session.Status != SessionStatus.Tracking)
{
return;
}

// Get updated augmented images for this frame.
Session.GetTrackables<AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated);

// Create visualizers and anchors for updated augmented images that are tracking and do not previously
// have a visualizer. Remove visualizers for stopped images.
foreach (var image in m_TempAugmentedImages)
{
AugmentedImageVisualizer visualizer = null;
m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
if (image.TrackingState == TrackingState.Tracking && visualizer == null)
{
// Create an anchor to ensure that ARCore keeps tracking this augmented image.
Anchor anchor = image.CreateAnchor(image.CenterPose);
visualizer = (AugmentedImageVisualizer)Instantiate(AugmentedImageVisualizerPrefab[image.DatabaseIndex], anchor.transform);
visualizer.Image = image;
m_Visualizers.Add(image.DatabaseIndex, visualizer);


}
else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
{
m_Visualizers.Remove(image.DatabaseIndex);
GameObject.Destroy(visualizer.gameObject);

}

}

// Show the fit-to-scan overlay if there are no images that are Tracking.
foreach (var visualizer in m_Visualizers.Values)
{
if (visualizer.Image.TrackingState == TrackingState.Tracking)
{
FitToScanOverlay.SetActive(false);
return;
}
}

FitToScanOverlay.SetActive(true);
}
}
}


My unity screen looks like below
Unity screen view



Added Augmented Image Visualizer script to the prefabs to Rabbit prefab and Monkey prefab.Image given below
Prefab-Inspector



This is how it should be done?The problem once the model appears it will not disappear.So when I show the next image anther model comes on top of it.How to hide the model when the image is not tracked?



In the AugmentedImageControllerExample.cs we are using the below code.Still I dont understand why the models are not disappearing after they lost tracking of the image.



else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
{
m_Visualizers.Remove(image.DatabaseIndex);
GameObject.Destroy(visualizer.gameObject);

}


AugmentedImageVisualizer.cs code given below?I have referred this Link.



namespace GoogleARCore.Examples.AugmentedImage
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GoogleARCore;
using GoogleARCoreInternal;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Uses 4 frame corner objects to visualize an AugmentedImage.
/// </summary>
public class AugmentedImageVisualizer : MonoBehaviour
{
/// <summary>
/// The AugmentedImage to visualize.
/// </summary>
public AugmentedImage Image;


public GameObject Models;





private void Start()
{

}



/// <summary>
/// A model for the lower left corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameLowerLeft;

/// <summary>
/// A model for the lower right corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameLowerRight;

/// <summary>
/// A model for the upper left corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameUpperLeft;

/// <summary>
/// A model for the upper right corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameUpperRight;

/// <summary>
/// The Unity Update method.
/// </summary>
public void Update()
{
if (Image == null || Image.TrackingState != TrackingState.Tracking)

{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;
}

if (Image == null || Image.TrackingState == TrackingState.Stopped)
{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;

}

if (Image == null || Image.TrackingState == TrackingState.Paused)
{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;

}



Models[Image.DatabaseIndex].SetActive(true);


}
}
}









share|improve this question

























  • does this if (Image != null && Image.TrackingState == TrackingState.Paused) returns true. Because this is how you achieve it. You can also delete the anchor corresponding to model in your AugmentedImageControllerscript. But if i were you i would create my own visualizer and visualize corresponding model based on Augmented Image DatabaseIndex or name

    – Ali Kanat
    Nov 24 '18 at 11:54













  • @AliKanat else if (image.TrackingState == TrackingState.Stopped && visualizer != null) { m_Visualizers.Remove(image.DatabaseIndex); GameObject.Destroy(visualizer.gameObject); } we are deleting here in the AugmentedImageController right.Still not getting

    – zyonneo
    Nov 26 '18 at 18:27











  • I now realized this is a similar question. You can take a look at this

    – Ali Kanat
    Dec 7 '18 at 10:42
















0















Hi I am trying to augment different prefabs for different images say around 20 models.Currently testing with 2 models for 2 images in AugmentedImage sample scene.I have added the script AugmentedImageVisualizer.cs to each prefab.I drag and dropped the two models to the script.In the AugmenetedImageExampleController.cs I have made the following changes.



namespace GoogleARCore.Examples.AugmentedImage
{
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GoogleARCore;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Controller for AugmentedImage example.
/// </summary>
public class AugmentedImageExampleController : MonoBehaviour
{
/// <summary>
/// A prefab for visualizing an AugmentedImage.
/// </summary>
// public AugmentedImageVisualizer AugmentedImageVisualizerPrefab;
public List<AugmentedImageVisualizer> AugmentedImageVisualizerPrefab = new List<AugmentedImageVisualizer>();




/// <summary>
/// The overlay containing the fit to scan user guide.
/// </summary>
public GameObject FitToScanOverlay;

private Dictionary<int, AugmentedImageVisualizer> m_Visualizers
= new Dictionary<int, AugmentedImageVisualizer>();

private List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>();

/// <summary>
/// The Unity Update method.
/// </summary>
public void Update()
{


// Exit the app when the 'back' button is pressed.
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}

// Check that motion tracking is tracking.
if (Session.Status != SessionStatus.Tracking)
{
return;
}

// Get updated augmented images for this frame.
Session.GetTrackables<AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated);

// Create visualizers and anchors for updated augmented images that are tracking and do not previously
// have a visualizer. Remove visualizers for stopped images.
foreach (var image in m_TempAugmentedImages)
{
AugmentedImageVisualizer visualizer = null;
m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
if (image.TrackingState == TrackingState.Tracking && visualizer == null)
{
// Create an anchor to ensure that ARCore keeps tracking this augmented image.
Anchor anchor = image.CreateAnchor(image.CenterPose);
visualizer = (AugmentedImageVisualizer)Instantiate(AugmentedImageVisualizerPrefab[image.DatabaseIndex], anchor.transform);
visualizer.Image = image;
m_Visualizers.Add(image.DatabaseIndex, visualizer);


}
else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
{
m_Visualizers.Remove(image.DatabaseIndex);
GameObject.Destroy(visualizer.gameObject);

}

}

// Show the fit-to-scan overlay if there are no images that are Tracking.
foreach (var visualizer in m_Visualizers.Values)
{
if (visualizer.Image.TrackingState == TrackingState.Tracking)
{
FitToScanOverlay.SetActive(false);
return;
}
}

FitToScanOverlay.SetActive(true);
}
}
}


My unity screen looks like below
Unity screen view



Added Augmented Image Visualizer script to the prefabs to Rabbit prefab and Monkey prefab.Image given below
Prefab-Inspector



This is how it should be done?The problem once the model appears it will not disappear.So when I show the next image anther model comes on top of it.How to hide the model when the image is not tracked?



In the AugmentedImageControllerExample.cs we are using the below code.Still I dont understand why the models are not disappearing after they lost tracking of the image.



else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
{
m_Visualizers.Remove(image.DatabaseIndex);
GameObject.Destroy(visualizer.gameObject);

}


AugmentedImageVisualizer.cs code given below?I have referred this Link.



namespace GoogleARCore.Examples.AugmentedImage
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GoogleARCore;
using GoogleARCoreInternal;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Uses 4 frame corner objects to visualize an AugmentedImage.
/// </summary>
public class AugmentedImageVisualizer : MonoBehaviour
{
/// <summary>
/// The AugmentedImage to visualize.
/// </summary>
public AugmentedImage Image;


public GameObject Models;





private void Start()
{

}



/// <summary>
/// A model for the lower left corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameLowerLeft;

/// <summary>
/// A model for the lower right corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameLowerRight;

/// <summary>
/// A model for the upper left corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameUpperLeft;

/// <summary>
/// A model for the upper right corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameUpperRight;

/// <summary>
/// The Unity Update method.
/// </summary>
public void Update()
{
if (Image == null || Image.TrackingState != TrackingState.Tracking)

{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;
}

if (Image == null || Image.TrackingState == TrackingState.Stopped)
{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;

}

if (Image == null || Image.TrackingState == TrackingState.Paused)
{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;

}



Models[Image.DatabaseIndex].SetActive(true);


}
}
}









share|improve this question

























  • does this if (Image != null && Image.TrackingState == TrackingState.Paused) returns true. Because this is how you achieve it. You can also delete the anchor corresponding to model in your AugmentedImageControllerscript. But if i were you i would create my own visualizer and visualize corresponding model based on Augmented Image DatabaseIndex or name

    – Ali Kanat
    Nov 24 '18 at 11:54













  • @AliKanat else if (image.TrackingState == TrackingState.Stopped && visualizer != null) { m_Visualizers.Remove(image.DatabaseIndex); GameObject.Destroy(visualizer.gameObject); } we are deleting here in the AugmentedImageController right.Still not getting

    – zyonneo
    Nov 26 '18 at 18:27











  • I now realized this is a similar question. You can take a look at this

    – Ali Kanat
    Dec 7 '18 at 10:42














0












0








0








Hi I am trying to augment different prefabs for different images say around 20 models.Currently testing with 2 models for 2 images in AugmentedImage sample scene.I have added the script AugmentedImageVisualizer.cs to each prefab.I drag and dropped the two models to the script.In the AugmenetedImageExampleController.cs I have made the following changes.



namespace GoogleARCore.Examples.AugmentedImage
{
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GoogleARCore;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Controller for AugmentedImage example.
/// </summary>
public class AugmentedImageExampleController : MonoBehaviour
{
/// <summary>
/// A prefab for visualizing an AugmentedImage.
/// </summary>
// public AugmentedImageVisualizer AugmentedImageVisualizerPrefab;
public List<AugmentedImageVisualizer> AugmentedImageVisualizerPrefab = new List<AugmentedImageVisualizer>();




/// <summary>
/// The overlay containing the fit to scan user guide.
/// </summary>
public GameObject FitToScanOverlay;

private Dictionary<int, AugmentedImageVisualizer> m_Visualizers
= new Dictionary<int, AugmentedImageVisualizer>();

private List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>();

/// <summary>
/// The Unity Update method.
/// </summary>
public void Update()
{


// Exit the app when the 'back' button is pressed.
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}

// Check that motion tracking is tracking.
if (Session.Status != SessionStatus.Tracking)
{
return;
}

// Get updated augmented images for this frame.
Session.GetTrackables<AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated);

// Create visualizers and anchors for updated augmented images that are tracking and do not previously
// have a visualizer. Remove visualizers for stopped images.
foreach (var image in m_TempAugmentedImages)
{
AugmentedImageVisualizer visualizer = null;
m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
if (image.TrackingState == TrackingState.Tracking && visualizer == null)
{
// Create an anchor to ensure that ARCore keeps tracking this augmented image.
Anchor anchor = image.CreateAnchor(image.CenterPose);
visualizer = (AugmentedImageVisualizer)Instantiate(AugmentedImageVisualizerPrefab[image.DatabaseIndex], anchor.transform);
visualizer.Image = image;
m_Visualizers.Add(image.DatabaseIndex, visualizer);


}
else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
{
m_Visualizers.Remove(image.DatabaseIndex);
GameObject.Destroy(visualizer.gameObject);

}

}

// Show the fit-to-scan overlay if there are no images that are Tracking.
foreach (var visualizer in m_Visualizers.Values)
{
if (visualizer.Image.TrackingState == TrackingState.Tracking)
{
FitToScanOverlay.SetActive(false);
return;
}
}

FitToScanOverlay.SetActive(true);
}
}
}


My unity screen looks like below
Unity screen view



Added Augmented Image Visualizer script to the prefabs to Rabbit prefab and Monkey prefab.Image given below
Prefab-Inspector



This is how it should be done?The problem once the model appears it will not disappear.So when I show the next image anther model comes on top of it.How to hide the model when the image is not tracked?



In the AugmentedImageControllerExample.cs we are using the below code.Still I dont understand why the models are not disappearing after they lost tracking of the image.



else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
{
m_Visualizers.Remove(image.DatabaseIndex);
GameObject.Destroy(visualizer.gameObject);

}


AugmentedImageVisualizer.cs code given below?I have referred this Link.



namespace GoogleARCore.Examples.AugmentedImage
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GoogleARCore;
using GoogleARCoreInternal;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Uses 4 frame corner objects to visualize an AugmentedImage.
/// </summary>
public class AugmentedImageVisualizer : MonoBehaviour
{
/// <summary>
/// The AugmentedImage to visualize.
/// </summary>
public AugmentedImage Image;


public GameObject Models;





private void Start()
{

}



/// <summary>
/// A model for the lower left corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameLowerLeft;

/// <summary>
/// A model for the lower right corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameLowerRight;

/// <summary>
/// A model for the upper left corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameUpperLeft;

/// <summary>
/// A model for the upper right corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameUpperRight;

/// <summary>
/// The Unity Update method.
/// </summary>
public void Update()
{
if (Image == null || Image.TrackingState != TrackingState.Tracking)

{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;
}

if (Image == null || Image.TrackingState == TrackingState.Stopped)
{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;

}

if (Image == null || Image.TrackingState == TrackingState.Paused)
{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;

}



Models[Image.DatabaseIndex].SetActive(true);


}
}
}









share|improve this question
















Hi I am trying to augment different prefabs for different images say around 20 models.Currently testing with 2 models for 2 images in AugmentedImage sample scene.I have added the script AugmentedImageVisualizer.cs to each prefab.I drag and dropped the two models to the script.In the AugmenetedImageExampleController.cs I have made the following changes.



namespace GoogleARCore.Examples.AugmentedImage
{
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GoogleARCore;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Controller for AugmentedImage example.
/// </summary>
public class AugmentedImageExampleController : MonoBehaviour
{
/// <summary>
/// A prefab for visualizing an AugmentedImage.
/// </summary>
// public AugmentedImageVisualizer AugmentedImageVisualizerPrefab;
public List<AugmentedImageVisualizer> AugmentedImageVisualizerPrefab = new List<AugmentedImageVisualizer>();




/// <summary>
/// The overlay containing the fit to scan user guide.
/// </summary>
public GameObject FitToScanOverlay;

private Dictionary<int, AugmentedImageVisualizer> m_Visualizers
= new Dictionary<int, AugmentedImageVisualizer>();

private List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>();

/// <summary>
/// The Unity Update method.
/// </summary>
public void Update()
{


// Exit the app when the 'back' button is pressed.
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}

// Check that motion tracking is tracking.
if (Session.Status != SessionStatus.Tracking)
{
return;
}

// Get updated augmented images for this frame.
Session.GetTrackables<AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated);

// Create visualizers and anchors for updated augmented images that are tracking and do not previously
// have a visualizer. Remove visualizers for stopped images.
foreach (var image in m_TempAugmentedImages)
{
AugmentedImageVisualizer visualizer = null;
m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
if (image.TrackingState == TrackingState.Tracking && visualizer == null)
{
// Create an anchor to ensure that ARCore keeps tracking this augmented image.
Anchor anchor = image.CreateAnchor(image.CenterPose);
visualizer = (AugmentedImageVisualizer)Instantiate(AugmentedImageVisualizerPrefab[image.DatabaseIndex], anchor.transform);
visualizer.Image = image;
m_Visualizers.Add(image.DatabaseIndex, visualizer);


}
else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
{
m_Visualizers.Remove(image.DatabaseIndex);
GameObject.Destroy(visualizer.gameObject);

}

}

// Show the fit-to-scan overlay if there are no images that are Tracking.
foreach (var visualizer in m_Visualizers.Values)
{
if (visualizer.Image.TrackingState == TrackingState.Tracking)
{
FitToScanOverlay.SetActive(false);
return;
}
}

FitToScanOverlay.SetActive(true);
}
}
}


My unity screen looks like below
Unity screen view



Added Augmented Image Visualizer script to the prefabs to Rabbit prefab and Monkey prefab.Image given below
Prefab-Inspector



This is how it should be done?The problem once the model appears it will not disappear.So when I show the next image anther model comes on top of it.How to hide the model when the image is not tracked?



In the AugmentedImageControllerExample.cs we are using the below code.Still I dont understand why the models are not disappearing after they lost tracking of the image.



else if (image.TrackingState == TrackingState.Stopped && visualizer != null)
{
m_Visualizers.Remove(image.DatabaseIndex);
GameObject.Destroy(visualizer.gameObject);

}


AugmentedImageVisualizer.cs code given below?I have referred this Link.



namespace GoogleARCore.Examples.AugmentedImage
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GoogleARCore;
using GoogleARCoreInternal;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Uses 4 frame corner objects to visualize an AugmentedImage.
/// </summary>
public class AugmentedImageVisualizer : MonoBehaviour
{
/// <summary>
/// The AugmentedImage to visualize.
/// </summary>
public AugmentedImage Image;


public GameObject Models;





private void Start()
{

}



/// <summary>
/// A model for the lower left corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameLowerLeft;

/// <summary>
/// A model for the lower right corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameLowerRight;

/// <summary>
/// A model for the upper left corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameUpperLeft;

/// <summary>
/// A model for the upper right corner of the frame to place when an image is detected.
/// </summary>
// public GameObject FrameUpperRight;

/// <summary>
/// The Unity Update method.
/// </summary>
public void Update()
{
if (Image == null || Image.TrackingState != TrackingState.Tracking)

{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;
}

if (Image == null || Image.TrackingState == TrackingState.Stopped)
{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;

}

if (Image == null || Image.TrackingState == TrackingState.Paused)
{
Models[Image.DatabaseIndex].SetActive(false);

//Models[0].SetActive(false);
//Models[1].SetActive(false);

return;

}



Models[Image.DatabaseIndex].SetActive(true);


}
}
}






unity3d augmented-reality arcore






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 6:25







zyonneo

















asked Nov 24 '18 at 6:54









zyonneozyonneo

4082720




4082720













  • does this if (Image != null && Image.TrackingState == TrackingState.Paused) returns true. Because this is how you achieve it. You can also delete the anchor corresponding to model in your AugmentedImageControllerscript. But if i were you i would create my own visualizer and visualize corresponding model based on Augmented Image DatabaseIndex or name

    – Ali Kanat
    Nov 24 '18 at 11:54













  • @AliKanat else if (image.TrackingState == TrackingState.Stopped && visualizer != null) { m_Visualizers.Remove(image.DatabaseIndex); GameObject.Destroy(visualizer.gameObject); } we are deleting here in the AugmentedImageController right.Still not getting

    – zyonneo
    Nov 26 '18 at 18:27











  • I now realized this is a similar question. You can take a look at this

    – Ali Kanat
    Dec 7 '18 at 10:42



















  • does this if (Image != null && Image.TrackingState == TrackingState.Paused) returns true. Because this is how you achieve it. You can also delete the anchor corresponding to model in your AugmentedImageControllerscript. But if i were you i would create my own visualizer and visualize corresponding model based on Augmented Image DatabaseIndex or name

    – Ali Kanat
    Nov 24 '18 at 11:54













  • @AliKanat else if (image.TrackingState == TrackingState.Stopped && visualizer != null) { m_Visualizers.Remove(image.DatabaseIndex); GameObject.Destroy(visualizer.gameObject); } we are deleting here in the AugmentedImageController right.Still not getting

    – zyonneo
    Nov 26 '18 at 18:27











  • I now realized this is a similar question. You can take a look at this

    – Ali Kanat
    Dec 7 '18 at 10:42

















does this if (Image != null && Image.TrackingState == TrackingState.Paused) returns true. Because this is how you achieve it. You can also delete the anchor corresponding to model in your AugmentedImageControllerscript. But if i were you i would create my own visualizer and visualize corresponding model based on Augmented Image DatabaseIndex or name

– Ali Kanat
Nov 24 '18 at 11:54







does this if (Image != null && Image.TrackingState == TrackingState.Paused) returns true. Because this is how you achieve it. You can also delete the anchor corresponding to model in your AugmentedImageControllerscript. But if i were you i would create my own visualizer and visualize corresponding model based on Augmented Image DatabaseIndex or name

– Ali Kanat
Nov 24 '18 at 11:54















@AliKanat else if (image.TrackingState == TrackingState.Stopped && visualizer != null) { m_Visualizers.Remove(image.DatabaseIndex); GameObject.Destroy(visualizer.gameObject); } we are deleting here in the AugmentedImageController right.Still not getting

– zyonneo
Nov 26 '18 at 18:27





@AliKanat else if (image.TrackingState == TrackingState.Stopped && visualizer != null) { m_Visualizers.Remove(image.DatabaseIndex); GameObject.Destroy(visualizer.gameObject); } we are deleting here in the AugmentedImageController right.Still not getting

– zyonneo
Nov 26 '18 at 18:27













I now realized this is a similar question. You can take a look at this

– Ali Kanat
Dec 7 '18 at 10:42





I now realized this is a similar question. You can take a look at this

– Ali Kanat
Dec 7 '18 at 10:42












1 Answer
1






active

oldest

votes


















0














The problem is, that in your update function you set always both models active true. But you should only set the model active you are tracking! So like said in the comment you should use the AugmentedImage DatabseIndex.
For example your Models[0] is the model coresponding to the first Image in the Database and the Models[1] is coresponding to the second Image.
So instead of:



// Wrong code, because you're always setting both models active
Models[0].SetActive(true);
Models[1].SetActive(true);


you can write:



// Only set the tracking Image active
Models[Image.DatabaseIndex].SetActive(true);


Another thing is in your if (Image != null && Image.TrackingState == TrackingState.Paused) and if (Image != null && Image.TrackingState == TrackingState.Stopped) you could write a return; after deactivating your model, so that you quit your Update function and don't set the model active again.






share|improve this answer
























  • if (Image == null || Image.TrackingState == TrackingState.Paused) { Models[Image.DatabaseIndex].SetActive(false); return; } Models[Image.DatabaseIndex].SetActive(true); I gave code like this in the Update statement.Models appear but they do not disappear when the target image is moved away from the camera

    – zyonneo
    Nov 26 '18 at 9:36













  • Updated to my full code .

    – zyonneo
    Nov 27 '18 at 6:26











  • sorry I haven't so much time at moment, maybe I can lookt at it later this week. But what I experienced, is that the TrackingState isn't updated instantly when the image isn't in view, see also: github.com/google-ar/arcore-unity-sdk/issues/290

    – xFL
    Nov 27 '18 at 13:34











  • I have seen similar question on github but no correct answers. I think this is a issue which needed to be resolved

    – zyonneo
    Nov 28 '18 at 6:33











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455908%2fhow-to-show-different-prefabs-for-different-images-in-arcore-augmented-image-sce%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The problem is, that in your update function you set always both models active true. But you should only set the model active you are tracking! So like said in the comment you should use the AugmentedImage DatabseIndex.
For example your Models[0] is the model coresponding to the first Image in the Database and the Models[1] is coresponding to the second Image.
So instead of:



// Wrong code, because you're always setting both models active
Models[0].SetActive(true);
Models[1].SetActive(true);


you can write:



// Only set the tracking Image active
Models[Image.DatabaseIndex].SetActive(true);


Another thing is in your if (Image != null && Image.TrackingState == TrackingState.Paused) and if (Image != null && Image.TrackingState == TrackingState.Stopped) you could write a return; after deactivating your model, so that you quit your Update function and don't set the model active again.






share|improve this answer
























  • if (Image == null || Image.TrackingState == TrackingState.Paused) { Models[Image.DatabaseIndex].SetActive(false); return; } Models[Image.DatabaseIndex].SetActive(true); I gave code like this in the Update statement.Models appear but they do not disappear when the target image is moved away from the camera

    – zyonneo
    Nov 26 '18 at 9:36













  • Updated to my full code .

    – zyonneo
    Nov 27 '18 at 6:26











  • sorry I haven't so much time at moment, maybe I can lookt at it later this week. But what I experienced, is that the TrackingState isn't updated instantly when the image isn't in view, see also: github.com/google-ar/arcore-unity-sdk/issues/290

    – xFL
    Nov 27 '18 at 13:34











  • I have seen similar question on github but no correct answers. I think this is a issue which needed to be resolved

    – zyonneo
    Nov 28 '18 at 6:33
















0














The problem is, that in your update function you set always both models active true. But you should only set the model active you are tracking! So like said in the comment you should use the AugmentedImage DatabseIndex.
For example your Models[0] is the model coresponding to the first Image in the Database and the Models[1] is coresponding to the second Image.
So instead of:



// Wrong code, because you're always setting both models active
Models[0].SetActive(true);
Models[1].SetActive(true);


you can write:



// Only set the tracking Image active
Models[Image.DatabaseIndex].SetActive(true);


Another thing is in your if (Image != null && Image.TrackingState == TrackingState.Paused) and if (Image != null && Image.TrackingState == TrackingState.Stopped) you could write a return; after deactivating your model, so that you quit your Update function and don't set the model active again.






share|improve this answer
























  • if (Image == null || Image.TrackingState == TrackingState.Paused) { Models[Image.DatabaseIndex].SetActive(false); return; } Models[Image.DatabaseIndex].SetActive(true); I gave code like this in the Update statement.Models appear but they do not disappear when the target image is moved away from the camera

    – zyonneo
    Nov 26 '18 at 9:36













  • Updated to my full code .

    – zyonneo
    Nov 27 '18 at 6:26











  • sorry I haven't so much time at moment, maybe I can lookt at it later this week. But what I experienced, is that the TrackingState isn't updated instantly when the image isn't in view, see also: github.com/google-ar/arcore-unity-sdk/issues/290

    – xFL
    Nov 27 '18 at 13:34











  • I have seen similar question on github but no correct answers. I think this is a issue which needed to be resolved

    – zyonneo
    Nov 28 '18 at 6:33














0












0








0







The problem is, that in your update function you set always both models active true. But you should only set the model active you are tracking! So like said in the comment you should use the AugmentedImage DatabseIndex.
For example your Models[0] is the model coresponding to the first Image in the Database and the Models[1] is coresponding to the second Image.
So instead of:



// Wrong code, because you're always setting both models active
Models[0].SetActive(true);
Models[1].SetActive(true);


you can write:



// Only set the tracking Image active
Models[Image.DatabaseIndex].SetActive(true);


Another thing is in your if (Image != null && Image.TrackingState == TrackingState.Paused) and if (Image != null && Image.TrackingState == TrackingState.Stopped) you could write a return; after deactivating your model, so that you quit your Update function and don't set the model active again.






share|improve this answer













The problem is, that in your update function you set always both models active true. But you should only set the model active you are tracking! So like said in the comment you should use the AugmentedImage DatabseIndex.
For example your Models[0] is the model coresponding to the first Image in the Database and the Models[1] is coresponding to the second Image.
So instead of:



// Wrong code, because you're always setting both models active
Models[0].SetActive(true);
Models[1].SetActive(true);


you can write:



// Only set the tracking Image active
Models[Image.DatabaseIndex].SetActive(true);


Another thing is in your if (Image != null && Image.TrackingState == TrackingState.Paused) and if (Image != null && Image.TrackingState == TrackingState.Stopped) you could write a return; after deactivating your model, so that you quit your Update function and don't set the model active again.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 7:46









xFLxFL

303110




303110













  • if (Image == null || Image.TrackingState == TrackingState.Paused) { Models[Image.DatabaseIndex].SetActive(false); return; } Models[Image.DatabaseIndex].SetActive(true); I gave code like this in the Update statement.Models appear but they do not disappear when the target image is moved away from the camera

    – zyonneo
    Nov 26 '18 at 9:36













  • Updated to my full code .

    – zyonneo
    Nov 27 '18 at 6:26











  • sorry I haven't so much time at moment, maybe I can lookt at it later this week. But what I experienced, is that the TrackingState isn't updated instantly when the image isn't in view, see also: github.com/google-ar/arcore-unity-sdk/issues/290

    – xFL
    Nov 27 '18 at 13:34











  • I have seen similar question on github but no correct answers. I think this is a issue which needed to be resolved

    – zyonneo
    Nov 28 '18 at 6:33



















  • if (Image == null || Image.TrackingState == TrackingState.Paused) { Models[Image.DatabaseIndex].SetActive(false); return; } Models[Image.DatabaseIndex].SetActive(true); I gave code like this in the Update statement.Models appear but they do not disappear when the target image is moved away from the camera

    – zyonneo
    Nov 26 '18 at 9:36













  • Updated to my full code .

    – zyonneo
    Nov 27 '18 at 6:26











  • sorry I haven't so much time at moment, maybe I can lookt at it later this week. But what I experienced, is that the TrackingState isn't updated instantly when the image isn't in view, see also: github.com/google-ar/arcore-unity-sdk/issues/290

    – xFL
    Nov 27 '18 at 13:34











  • I have seen similar question on github but no correct answers. I think this is a issue which needed to be resolved

    – zyonneo
    Nov 28 '18 at 6:33

















if (Image == null || Image.TrackingState == TrackingState.Paused) { Models[Image.DatabaseIndex].SetActive(false); return; } Models[Image.DatabaseIndex].SetActive(true); I gave code like this in the Update statement.Models appear but they do not disappear when the target image is moved away from the camera

– zyonneo
Nov 26 '18 at 9:36







if (Image == null || Image.TrackingState == TrackingState.Paused) { Models[Image.DatabaseIndex].SetActive(false); return; } Models[Image.DatabaseIndex].SetActive(true); I gave code like this in the Update statement.Models appear but they do not disappear when the target image is moved away from the camera

– zyonneo
Nov 26 '18 at 9:36















Updated to my full code .

– zyonneo
Nov 27 '18 at 6:26





Updated to my full code .

– zyonneo
Nov 27 '18 at 6:26













sorry I haven't so much time at moment, maybe I can lookt at it later this week. But what I experienced, is that the TrackingState isn't updated instantly when the image isn't in view, see also: github.com/google-ar/arcore-unity-sdk/issues/290

– xFL
Nov 27 '18 at 13:34





sorry I haven't so much time at moment, maybe I can lookt at it later this week. But what I experienced, is that the TrackingState isn't updated instantly when the image isn't in view, see also: github.com/google-ar/arcore-unity-sdk/issues/290

– xFL
Nov 27 '18 at 13:34













I have seen similar question on github but no correct answers. I think this is a issue which needed to be resolved

– zyonneo
Nov 28 '18 at 6:33





I have seen similar question on github but no correct answers. I think this is a issue which needed to be resolved

– zyonneo
Nov 28 '18 at 6:33


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455908%2fhow-to-show-different-prefabs-for-different-images-in-arcore-augmented-image-sce%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Basket-ball féminin

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

I want to find a topological embedding $f : X rightarrow Y$ and $g: Y rightarrow X$, yet $X$ is not...