Пример #1
0
 /// <summary>
 /// Helper method to set a custom defined engine param.
 /// </summary>
 /// <param name="param">The engine param to set.</param>
 /// <param name="value">The engine param value.</param>
 private void SetEngineParam(DatabaseParams param, object value)
 {
     // Engine params can't be set once the config set goes live
     if (this.SetParamDelegate == null)
     {
         this.ParamStore[(int)param] = value;
     }
     else
     {
         throw new EsentAlreadyInitializedException();
     }
 }
 //Construct a new DatabaseParams as a copy of a given DatabaseParams
 public DatabaseParams(DatabaseParams toCopy)
 {
     pixelScale     = toCopy.getPixelScale();
     alphaColor     = toCopy.getAlphaColor();
     alphaThreshold = toCopy.getAlphaThreshold();
     alphaSoftness  = toCopy.getAlphaThreshold();
     hasAlpha       = toCopy.getHasAlpha();
     minPhi         = toCopy.getMinPhi();
     maxPhi         = toCopy.getMaxPhi();
     minTheta       = toCopy.getMinTheta();
     maxTheta       = toCopy.getMaxTheta();
     phiRescaled    = toCopy.getPhiRescaled();
     thetaRescaled  = toCopy.getThetaRescaled();
     invertPhi      = toCopy.getInvertPhi();
     invertTheta    = toCopy.getInvertTheta();
     phiAlignment   = toCopy.getPhiAlignment();
     thetaAlignment = toCopy.getThetaAlignment();
     directory      = toCopy.getDirectory();
     online         = toCopy.getOnline();
 }
Пример #3
0
    private void Init()
    {
        string directory = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar));

        if (!singleDatabase)
        {
            //Load multiple databases
            //Read file into JSONObject
            JSONObject json_data = new JSONObject(File.ReadAllText(path));

            //Attempt to create boundaries from data in json, throwing an exception if data couldn't be found
            try {
                Vector3 max = VectorFromJson(json_data["metadata"]["maxBounds"]);
                Vector3 min = VectorFromJson(json_data["metadata"]["minBounds"]);
                CreateBoundaries(max, min);
            } catch (Exception e) {
                CreateBoundaries(new Vector3(100, 100, 100), new Vector3(-100, -100, -100));
                addError("Boundaries not defined.\n" +
                         "Defaulting to [100,100,100],[-100,-100,-100].\n" +
                         "Details:\n" + e.GetType().ToString() + "\n" + e.Message);
            }

            try {
                Cache.maxItems = int.Parse(json_data["metadata"]["maxCacheSize"].ToString());
            }
            catch (Exception e) {
                addError("Max cache size not defined.\nDefaulting to 100 images.\n" +
                         "Details:\n" + e.GetType().ToString() + "\n" + e.Message);
                Cache.maxItems = 100;
            }

            float scale;
            try {
                scale = float.Parse(json_data["metadata"]["scale"].ToString());
            } catch (Exception) {
                scale = 1.0f;
            }

            defaultParams = new DatabaseParams();
            try {
                defaultParams.parseParameters(json_data["metadata"]);
            } catch (Exception e) {
                addError("Error parsing default parameters:\n" + e.GetType().ToString() + "\n" + e.Message);
            }

            //Iterate through databases and instantiate a database prefab for each one
            JSONObject[] databases = new JSONObject[0];
            if (json_data.HasField("runs"))
            {
                databases = new JSONObject[json_data["runs"].Count];
            }
            else
            {
                addError("Error reading JSON: Couldn't find field 'runs'");
            }

            for (int i = 0; i < databases.Length; i++)
            {
                try {
                    databases[i] = json_data["runs"][i];
                    Vector3 spawnPos = VectorFromJson(databases[i]["position"]);
                    spawnPos *= scale;
                    GameObject newDatabase = (GameObject)Instantiate(databasePrefab, spawnPos, new Quaternion());
                    newDatabase.SetActive(false);
                    CinemaDatabase db = newDatabase.GetComponent <CinemaDatabase>();

                    db.setParams(new DatabaseParams(defaultParams));
                    db.getParams().parseParameters(databases[i]);
                    if (!db.getParams().getOnline())
                    {
                        db.getParams().setDirectory(directory + db.getParams().getDirectory());
                    }
                    newDatabase.SetActive(true);
                } catch (Exception e) {
                    addError("Error initializing database:\n" + e.GetType().ToString() + "\n" + e.Message);
                }
            }
        }
        else
        {
            try {
                //Load single database
                CreateBoundaries(new Vector3(15, 15, 15), new Vector3(-15, -15, -15));
                GameObject     newDatabase = (GameObject)Instantiate(databasePrefab);
                CinemaDatabase db          = newDatabase.GetComponent <CinemaDatabase>();
                db.setParams(new DatabaseParams());
                db.getParams().setDirectory(directory);
                Cache.maxItems = 100;
            }
            catch (Exception e) {
                addError("Error initializing database:\n" + e.GetType() + "\n" + e.Message);
            }
        }
    }
Пример #4
0
 public void setParams(DatabaseParams newParams)
 {
     databaseParams = newParams;
 }
Пример #5
0
 /// <summary>
 /// Helper method to get a custom defined engine param.
 /// </summary>
 /// <typeparam name="T">The type of the engine param.</typeparam>
 /// <param name="param">The engine param to get.</param>
 /// <returns>The engine param value.</returns>
 private T GetEngineParam <T>(DatabaseParams param)
 {
     // Engine params are always accessed from the config store dictionary (even if the config set is live)
     return(ConfigSetBase.GetValueOrDefault <T>(this.ParamStore.TryGetValue, (int)param));
 }