The problem involves mapping barcodes with their respective 3D models, so that when a specific barcode is scanned, its corresponding 3D model is superimposed on the object until the barcode is no longer in view and also seamlessly switches between the associated 3D models based on the scanning of their respective barcodes.
i tried simple approach where i made a serialized dictionary that mapped the barcode id to the respective 3d models, and used vuforia for barcode scanning ( attached a simple barcode scanning script) and modified the script where it loaded the model when its respective barcode is being scanned .
public class SimpleBarcodeScanner : MonoBehaviour
{
public TMPro.TextMeshProUGUI barcodeAsText;
BarcodeBehaviour mBarcodeBehaviour;
public DictionarySerializer dictionarySerializer;
private GameObject prevModel;
void Start()
{
mBarcodeBehaviour = GetComponent<BarcodeBehaviour>();
prevModel = null;
}
// Update is called once per frame
void Update()
{
if (mBarcodeBehaviour != null && mBarcodeBehaviour.InstanceData != null)
{
string barcodeText = mBarcodeBehaviour.InstanceData.Text;
barcodeAsText.text = barcodeText;
Debug.Log("Scanned Barcode ID: " + barcodeText);
if (dictionarySerializer.GetObjectsDictionary() != null && dictionarySerializer.GetObjectsDictionary().ContainsKey(barcodeText))
{
// Get the corresponding GameObject from the dictionary
GameObject model = dictionarySerializer.GetObjectsDictionary()[barcodeText];
Debug.Log("Loading Model: " + model.name);
// Activate the model
model.SetActive(true);
prevModel = model;
}
}
else if(mBarcodeBehaviour.InstanceData == null)
{
Debug.Log("Barcode not found ");
if (prevModel != null)
{
prevModel.SetActive(false);
prevModel = null;
}
}
}
- this did load the model on scanning of its barcode but it still remains in the screen even when i remove the barcode.
how do i implement it correctly?
anya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.