/*
     * set up world from json string
     */
    public void SetUpWorld(string json)
    {
        // generate lab instance model object from json string
        LabInstance li = JsonUtility.FromJson <LabInstance>(json);

        // set laser object from json
        laser.transform.position = li.lm.pos;
        laser.transform.rotation = li.lm.rot;

        // set lab manager's refratable material componenet from json
        rm.SetPresetRefraction((RefractableMaterial.IndexesOfRefraction)Enum.ToObject(typeof(RefractableMaterial.IndexesOfRefraction), li.worldRM.presetRefraction));
        rm.SetCustomRefraction(li.worldRM.n);

        int x = 0;

        // set available refratable materials
        foreach (RefractableMaterial rm in rms)
        {
            rm.transform.position = li.refractableMaterials.materials[x].pos;
            rm.transform.rotation = li.refractableMaterials.materials[x].rot;
            rm.SetPresetRefraction((RefractableMaterial.IndexesOfRefraction)Enum.ToObject(typeof(RefractableMaterial.IndexesOfRefraction), li.refractableMaterials.materials[x].presetRefraction));
            rm.SetCustomRefraction(li.refractableMaterials.materials[x].n);

            x++;
        }

        // if there are more materials to generate, create new ones
        while (rms.Count < li.refractableMaterials.materials.Count)
        {
            RefractableMaterial temp = AddObject();

            temp.transform.position = li.refractableMaterials.materials[x].pos;
            temp.transform.rotation = li.refractableMaterials.materials[x].rot;
            temp.SetPresetRefraction((RefractableMaterial.IndexesOfRefraction)Enum.ToObject(typeof(RefractableMaterial.IndexesOfRefraction), li.refractableMaterials.materials[x].presetRefraction));

            Debug.Log(li.refractableMaterials.materials[x].presetRefraction);
            Debug.Log("PR: " + temp.GetPresetIndex());

            temp.SetCustomRefraction(li.refractableMaterials.materials[x].n);

            x++;
        }
    }
    public string defaultInstance;              // json string of default instance

    // Start is called before the first frame update
    void Start()
    {
        rm    = GetComponent <RefractableMaterial>();
        laser = FindObjectOfType <LaserController>();

        rm.SetPresetRefraction(RefractableMaterial.IndexesOfRefraction.AIR);

        rms = new List <RefractableMaterial>();

        foreach (RefractableMaterial rm in FindObjectsOfType <RefractableMaterial>())
        {
            rms.Add(rm);
        }

        rms.Remove(rm);

        drag = false;

        defaultInstance = GenerateJSON();

        Load();
    }
    /*
     * when a new preset index of refraction is set for a selected object
     */
    public void OnIndexChange()
    {
        RefractableMaterial rm = lm.obj.GetComponent <RefractableMaterial>();

        rm.SetPresetRefraction((RefractableMaterial.IndexesOfRefraction)Enum.ToObject(typeof(RefractableMaterial.IndexesOfRefraction), indexesMenu.value));
    }