Scripting API

TODO : this is not up to date

You can access some of Predict Unity functionalities via script. The full documentation of the Predict Unity scripting API is not available yet but you can find bellow a quick view of the main functionalities.

The main clases that can be called within the Predict Unity plug-in are the following :

Managers :


Components :


Pickers :

The main functionalities in the Predict Unity plug-in are described bellow :

Start processes

Start a process 

You can start a new process by calling the following method :

public void StartOverlayProcessWithCurrentStructureForCamera(Camera camera)

{

  UVR.PluginEnvironment.StartCoroutine(UVR.ProcessManager.StartProcessForCameraAsync(camera, EngineProcess.ProcessTarget.Overlay, false);

}

Enable the Predict Engine overlay

You can enable the engine overlay by calling the following method :

public void EnableOverlay()

{

    UVR.ProcessManager.SetOverlayEnabled(true);

}

Start the Predict Engine view

You can start the engine view by calling the following method (editor only) :

public void StartRenderView()

{

    UVR.EngineViewManager.Play();

}

Get processes

Get the process for a camera used in the Predict Engine overlay

You can get the process for a camera used in the engine overlay by calling one of the following methods :

public UVR.EngineProcess GetProcessForOverlayCamera(Camera camera)

{

    if (camera == null) return;


    UVR.EngineProcess lCameraProcess = UVR.ProcessManager.GetProcessForCamera(camera);

    return lCameraProcess;

}

Get all the overlay processes

You can get all the processes used in the engine overlay by calling the following method :

public List<UVR.EngineProcess> GetAllOverlayProcesses()

{

    List<UVR.EngineProcess> lOverlayProcesses = UVR.ProcessManager.GetAllOverlayProcesses();

    return lOverlayProcesses;

}

Get the process for the engine view

You can get the process for the engine view by calling the following method :

public UVR.EngineProcess GetProcessForRenderView()

{

    UVR.EngineProcess lProcess = UVR.ProcessManager.GetRendererProcess();

    return lProcess;

}

Get all the processes

You can get all the processes currently started by calling the following method :

public List<UVR.EngineProcess> GetAllProcesses()

{

    List<UVR.EngineProcess> lProcesses = UVR.ProcessManager.GetAllProcesses();

    return lProcesses;

}

Get the process for the batch renderer

You can get the process for a camera used in the engine overlay by calling the following method :

public UVR.EngineProcess GetProcessForBatchRenderer()

{

    UVR.EngineProcess lBatchProcess = UVR.ProcessManager.GetBatchProcess();

    return lBatchProcess;

}

Pause processes

Pause an overlay process

You can pause the Predict Engine renderer for an overlay process by calling the following method :

public void PauseTheRendererForProcess(UVR.EngineProcess process)

{

    if (process == null) return;


    process.Pause(true);

}

Pause all overlay processes

You can pause the Predict Engine renderer for all overlay processes by calling the following method :

public void PauseTheRendererForAllOverlayProcesses()

{

    UVR.ProcessManager.PauseProcessForAllOverlayCameras(true);

}

Pause the engine view

You can pause the Predict Engine in the engine view by calling the following method :

public void PauseRenderView()

{

    UVR.EngineViewManager.Pause();

}

Reload processes

Reload an overlay process

After you have made changes in the Unity scene, you can reload the Predict Engine scene for a given process by calling the following method:

public void UpdateStructureAndReloadOverlayProcess(UVR.EngineProcess process)

{

    if (process == null) return;


    UVR.PluginEnvironment.StartCoroutine(UVR.ProcessManager.ReloadOverlayProcess(process, true));

}

Reload all processes for the engine overlay

After you have made changes in the Unity scene, you can reload the Predict Engine scene for all overlay processes by calling the following method:

public void ReloadAllOverlayProcesses()

{

    UVR.ProcessManager.ReloadProcessForAllOverlayCameras();

}

Reload the engine view

You can reload the engine view by calling the following method :

public void ReloadRenderView()

{

    UVR.EngineViewManager.Reload();

}

Stop processes

Stop a process

You can stop a process by calling the following method :

public void StopProcess(UVR.EngineProcess process)

{

    if (process == null) return;


    UVR.ProcessManager.StopProcess(process);

}

Stop all overlay processes

You can stop all overlay processes by calling the following method :

public void StopAllOverlayProcesses()

{

    UVR.ProcessManager.StopProcessForAllOverlayCameras();

}

Disable the engine overlay

You can disable the engine overlay by calling the following method :

public void DisableOmenOverlay()

{

    UVR.ProcessManager.SetOverlayEnabled(false);

}

Stop the engine view

You can stop the engine view by calling the following method :

public void StopRenderView()

{

    UVR.EngineViewManager.Stop();

}

Quit the application

You can quit the application by calling the following method :


#if UNITY_EDITOR

    UnityEditor.EditorApplication.isPlaying = false;

#else

    Application.Quit();

#endif

public void QuitTheApplication()

{

    UVR.ShortcutManager.Quit();

}

Save simulations

Save a simulation from the overlay

You can save the Predict Engine simulation from the engine overlay by calling the following method : 

public void SaveProcessedRenderFromAllOverlayProcess()

{

    UVR.InputManager.OpenImageSaver(UVR.InputManager.ImageSaverMode.Processed, null, true, false);

}

public void SaveRawRenderFromOverlayProcess(UVR.EngineProcess process)

{

    if (process == null) return;


    UVR.InputManager.OpenImageSaver(UVR.InputManager.ImageSaverMode.Raw, process);

}

Save a simulation from the engine view

You can save the Predict Engine simulation from the engine view by calling one of the following methods : 

public void SaveProcessedRenderFromRenderView()

{

    UVR.EngineViewManager.SaveProcessed();

}

public void SaveRawRenderFromRenderView()

{

    UVR.EngineViewManager.SaveRaw();

}

Performances

Get the current Predict Engine performances for the engine view

You can get the Predict Engine performances for the engine view by calling the following method :

public void DebugEnginePerformancesForRenderView()

{

  UVR.EngineViewManager.EngineStats stats = UVR.EngineViewManager.GetEngineStats();


    UnityEngine.Debug.Log("Predictive Engine state = " + stats.state.ToString());

    UnityEngine.Debug.Log("Predictive Engine FPS = " + stats.fpsCount.ToString("F1"));

    UnityEngine.Debug.Log("Predictive Engine render time (sec) = " + stats.renderTime.ToString());

    UnityEngine.Debug.Log("Predictive Engine samples per pixel = " + stats.sppCount.ToString());

    UnityEngine.Debug.Log("Predictive Engine scene is dirty = " + stats.isDirty.ToString());

}

Get the current Predict Engine performances for a process

You can get the Predict Engine performances for a process by calling the following methods :

public void DebugOmenPerformancesForProcess(UVR.EngineProcess process)

{

    if (process == null) return;


    UnityEngine.Debug.Log("OMEN process state = " + process.getState().ToString());

    UnityEngine.Debug.Log("OMEN process FPS = " + process.getFPS().ToString("F1"));

    UnityEngine.Debug.Log("OMEN process render time (sec) = " + process.getRenderTime().ToString());

    UnityEngine.Debug.Log("OMEN process samples per pixel = " + process.getSppMinMaxAvg().ToString());

    UnityEngine.Debug.Log("OMEN process is dirty = " + process.isDirty().ToString());

}

Edit interactive settings

Change the exposure

You can get the current exposure of a process' camera by calling the following method :


You can change the exposure on all cameras in the scene by calling the following methods :

public void ChangeToneMapperExposureForOverlayCamera(Camera camera)

{

    if (camera == null) return;


    UVR.EngineProcess lCameraProcess = UVR.ProcessManager.GetProcessForCamera(camera, UVR.EngineProcess.ProcessTarget.Overlay);

    if (lCameraProcess == null) return;


    float currentExposure = UVR.InputManager.GetExposure(lCameraProcess);


    UVR.InputManager.SetExposure(lCameraProcess, currentExposure + 1e-6f);


    UVR.InputManager.AugmentExposure(lCameraProcess);


    UVR.InputManager.ReduceExposure(lCameraProcess);


    UVR.InputManager.EnableAutoExposure(lCameraProcess);

}

Enable/disable the denoiser

You can enable and disable the denoiser in Predict Engine by calling the following method :

public void ToggleDenoiserForOverlayProcesses()

{

    UVR.InputManager.ToggleDenoiserState();

}

Switch between RGB and false colors

If a Camera Settings component uses a Photometric sensor, you can switch between RGB and False Colors rendering by calling the following methods:

These methods won't have any effect on cameras that are not using a Photometric sensor.

public void ToggleBetweenRgbAndFalseColorsInOverlay()

{

    UVR.InputManager.SwitchRenderWithFalseColor();

}

public void SetColorSystemInOverlay(UVR.RenderViewSettings.ColorSystemType type)

{

    UVR.InputManager.ChangeColorSystem(type);

}

Hide and show the false color scale in the engine overlay

If an Camera Settings component uses a False Color Color System, you can hide and show the false color scale in the engine overlay by calling the following method :

public void ToggleFalseColorScaleDisplayInOverlay()

{

    UVR.InputManager.HideAndShowFalseColorScale();

}

Edit the scene at runtime

Edit the scene using a Picker

Pickers enable you to define a set of configurations for your scene. See the Pickers section for more details.

Once the application is running, you can call a picker with the following methods : 


When calling a picker, the modification will be automatically applied in Predictive Engine and the scene will be reloaded if required.

public void SelectAPickerOption(UVR.GenericPicker picker, int optionId)

{

    if (picker != null || optionId < 0) return;


    picker.PickOption(optionId);

}

public void SwitchOptionOnThisMaterialPicker()

{

    UVR.MaterialPicker picker = this.GetComponent<UVR.MaterialPicker>();

    if (picker == null) return;

    

    picker.SwitchOption();    

}

Edit the scene manually and reload the Predict Engine render

If you don't want to use the pickers, you can edit the scene manually or with a custom script of yours. In this case, the modification will not be automatically applied in Predictive Engine : you must reload the scene after editing it. See section above or example bellow.

public void SetANewMaterialManually(MeshRenderer renderer, Material material)

{

    if (renderer == null || material == null) return;


    renderer.sharedMaterial = material;


 //Overlay processes only

    UVR.ShortcutManager.Reload();


 //All processes

    UVR.InputManager.ProcessInput(new UVR.InputManager.EngineInput(UVR.InputManager.EngineInputAction.ToggleDenoiser), true); 

}

Overlay

Enable and disable the overlay

You can find out whether the engine overlay is enabled with the following property :

You can enable and disable the engine overlay by calling the following method :

public void EnableOmenOverlay()

{

    if (!UVR.ProcessManager.IsOverlayEnabled())

    {

        UVR.ProcessManager.SetOverlayEnabled(true);

    }

}

Change the overlay display mode

The engine overlay is displayed in the Unity game view. There are different display modes, see the Overlay Options section for more details on the overlay modes.

Reminder : The 4 overlay modes can be organized depending on whether or not they are interactive and automatic :

You can change the overlay mode by calling the following methods :

public void SetOverlayMode(UVR.ScreenOverlay.DisplayMode mode)

{

    UVR.InputManager.SetOverlayMode((int)mode);

}

You can change the overlay automatic mode by calling the following methods :

public void ToggleOverlayAutomatic()

{

    UVR.InputManager.ToggleOverlayAutomatic();

}

public void SetOverlayAutomatic(bool automatic)

{

    UVR.InputManager.SetOverlayAutomatic(automatic);

}

You can change the overlay interactive mode by calling the following methods :

public void ToggleOverlayInteractive()

{

    UVR.InputManager.ToggleOverlayInteractive();

}

public void SetOverlayInteractive(bool interactive)

{

    UVR.InputManager.SetOverlayInteractive(interactive);

}

Hide and show the overlay

You can hide and show the overlay by calling the following method :

public void ShowOverlay(bool visible)

{

    UVR.InputManager.HideAndShowOverlay(visible);

}