Panorama180 Render : Use API from script (Editor)

Developer : ft-lab (Yutaka Yoshisaka).
05/13/2019 - 03/01/2022.

Back

This document used the google/DeepL translation.

Use API from script (Editor)

This script will be run in Unity Editor.
For more information about using scripts in Runtime, please refer to "Use API from script (Runtime)".
Starting with "Panorama 180 Render" ver. 1.0.2, you can output panoramic still images using a script.
"Demo/Scripts/MultipleCapture.cs" is a sample script.
"Demo/Scenes/APITest.unity" is a sample scene.

MultipleCapture.cs

Move the camera at regular intervals and output the panorama180-3D still image and the depth image.
The "Panorama180Render" script needs to be assigned to the MainCamera component in advance.
In this example, "MultipleCapture" is assigned as a component of MainCamera.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Panorama180Render {
    [RequireComponent(typeof(Camera))]
    public class MultipleCapture : MonoBehaviour
    {
        // Camera start position.
        [SerializeField] Vector3 startPosition = new Vector3(0, 0, 0);
        
        // Camera end position.
        [SerializeField] Vector3 endPosition = new Vector3(1, 0, 0);

        // capture count.
        [SerializeField, TooltipAttribute("Capture count"), Range(1, 100)] int captureCount = 4;

        // Save filename.
        [SerializeField, TooltipAttribute("Save file name")] string fileName = "capture";

        // Camera near distance.
        [SerializeField] float nearDistance = 0.1f;
        
        // Camera far distance.
        [SerializeField] float farDistance = 100.0f;

        // Synchronize gaze direction (ver.1.1.0).
        [SerializeField] bool synchronizeGazeDirection = false;

        // Camera position.
        private Vector3 m_baseCameraPos;

        void Start()
        {
            m_baseCameraPos = this.transform.position;

            // Coroutine that outputs still images.
            StartCoroutine(m_OutputStillImages());
        }

        void Update()
        {
        }

        /**
         * Output still images.
         */
        IEnumerator m_OutputStillImages () {
            Panorama180Render panorama180Render = this.GetComponent<Panorama180Render>();

            Vector3 cameraPos = this.transform.position;

            Vector3 pD = (endPosition - startPosition) / (float)Mathf.Max(1, (captureCount - 1));

            // Camera near,far distance.
            panorama180Render.SetCameraNearFarDistance(nearDistance, farDistance);

            // Set the depth linear type to linear.
            panorama180Render.SetDepthLinearType(Panorama180Render.OutputDepthLinearType.Linear);

            // Depth type is one quarter resolution.
            panorama180Render.SetDepthTextureType(Panorama180Render.OutputDepthTextureType.DepthOneQuarter);

            // Synchronize gaze direction (ver.1.1.0 -).
            panorama180Render.SetSynchronizeGazeDirection(synchronizeGazeDirection);

            for (int loop = 0; loop < captureCount; ++loop) {
                // Change camera position.
                Vector3 newPos = startPosition + (pD * loop);
                yield return StartCoroutine(panorama180Render.SetCameraPosition(newPos));

                // Set output file name. 
                panorama180Render.SetOutputImageFileName(fileName + "_" + (loop).ToString());

                // Save image.
                panorama180Render.OutputStillImage();           // RGB image.
                panorama180Render.OutputStillImage(true);       // Depth image(exr).
            }

            this.transform.position = m_baseCameraPos;
        }
    }
}
			
This script divides coordinate position of startPosition to endPosition into captureCount,
and outputs panorama180-3D images/depth images at each position.

Control is done by coroutine.
The function of the first argument is called as a coroutine by specifying "StartCoroutine(m_OutputStillImages());" in the Start function.

Get the Panorama180Render class with "Panorama180Render panorama180Render = this.GetComponent<Panorama180Render>();".
The namespace for this class is "Panorama180Render".

With the "panorama180Render.SetCameraNearFarDistance(nearDistance, farDistance)" function, specifies the distance to the near clipping plane and the distance to the far clipping plane of the camera.
With the "panorama180Render.SetDepthLinearType(Panorama180Render.OutputDepthLinearType.Linear)" function, make the interpolation at depth texture output linear.
With the "panorama180Render.SetDepthTextureType(Panorama180Render.OutputDepthTextureType.DepthOneQuarter)" function, the Depth texture is 1/4 the size of the panorama image.

"panorama180Render.SetSynchronizeGazeDirection(synchronizeGazeDirection);" function will reflect the XZ rotation in addition to the camera's Y-axis rotation when outputting the panorama image if it is set to true.

With the "panorama180Render.SetCameraPosition(newPos)" function, change the camera position.
This is called using a coroutine.
When changing the camera rotation etc., specify it before this function and then specify panorama180Render.SetCameraPosition.
This function waits for the screen update to complete.

With the "panorama180Render.SetOutputImageFileName" function, changes the output image file name.
With the "panorama180Render.OutputStillImage()" function, outputs a still image.
With the "panorama180Render.OutputStillImage(true)" function, outputs a still image(depth).

Script function list

The following functions are available in "Panorama180Render.Panorama180Render".

int GetVersion ();

Get the version of "Panorama180Render".
In the case of hexadecimal "0x1020", it becomes ver.1.0.2.

void SetOutputImageFileName (string fileName);

Specifies the still image output file name.
Argument nameDetails
fileNameOutput file name

string GetOutputImageFileName ();

Gets the still image output file name.

void SetOutputImageFileFormat (int fileFormat);

Specifies the file format for outputting still image.
Argument nameDetails
fileFormat0:jpg, 1:png

void SetOutputImageJpegQuality (int jpegQuality);

Specifies the JPEG quality when outputting a still image.
Argument nameDetails
jpegQuality0:Superb, 1:Good, 2:Normal, 3:Average, 4:Bad

bool IsOutputBusy ();

Returns true if still image output is in preparation or can not be output yet.

void SetRenderTextureSize (int texSize);

Specifies the texture size in one face of cube map.
Argument nameDetails
texSize512, 1024, 2048, 4096, 8192

int GetRenderTextureSize ();

Gets the texture size in one plane of cube map.
It can be 512, 1024, 2048, 4096 or 8192.

void SetOutputAlignType (AlignType type);

Specifies the type of arrangement of the panorama at the time of output.
Argument nameDetails
type Align type
AlignType.TopAndBottom ... up and down
AlignType.SideBySide ... left and right

AlignType GetOutputAlignType ();

Gets the type of arrangement of the panorama at the time of output.
AlignType.TopAndBottom is placed up and down, AlignType.SideBySide is placed on the left and right.

void SetOutputTextureSizeType (OutputTextureSizeType sType);

Specifies the output texture size type for Panorama 180-3D.
Argument nameDetails
sType Type of output texture size.
OutputTextureSizeType._512 ... 512*2 x 512 or 512 x 512*2
OutputTextureSizeType._1024 ... 1024*2 x 1024 or 1024 x 1024*2
OutputTextureSizeType._2048 ... 2048*2 x 2048 or 2048 x 2048*2
OutputTextureSizeType._4096 ... 4096*2 x 4096 or 4096 x 4096*2
OutputTextureSizeType._4K ... 3840 x 2160 (Side by side only)
OutputTextureSizeType._5_7K ... 5760 x 2880 (Side by side only)
OutputTextureSizeType._8K ... 7680 x 4320 (Side by side only)
OutputTextureSizeType._16K ... 15360 x 8640 (Side by side only)
OutputTextureSizeType._16384 ... 16384 x 8192 (Side by side only)

OutputTextureSizeType GetOutputTextureSizeType ();

Get the output texture size type for Panorama 180-3D.
This is the size of the texture when placing the two-eye panorama that will eventually be output.
OutputTextureSizeType._512, OutputTextureSizeType._1024, OutputTextureSizeType._2048, OutputTextureSizeType._4096,
OutputTextureSizeType._4K, OutputTextureSizeType._5_7K, OutputTextureSizeType._8K, OutputTextureSizeType._16K or OutputTextureSizeType._16384 is returned.

void SetPostProcessing (bool enableF);

Specifies Post Processing On/Off.
Argument nameDetails
enableFtrue on, false off

bool GetPostProcessing ();

Get Post Processing On/Off.

void SetDepthTextureType (OutputDepthTextureType type);

Specifies the type to output Depth.
Argument nameDetails
type Type when outputting Depth
OutputDepthTextureType.None ... Do not output
OutputDepthTextureType.DepthDefault ... Same size as panorama image
OutputDepthTextureType.DepthOneHalf ... 1/2 size
OutputDepthTextureType.DepthOneQuarter ... 1/4 size

OutputDepthTextureType GetDepthTextureType ();

Gets the type when outputting Depth.
OutputDepthTextureType.None does not output depth.
OutputDepthTextureType.DepthDefault outputs the same size as the panorama image.
OutputDepthTextureType.DepthOneHalf outputs with 1/2 size of panorama image.
OutputDepthTextureType.DepthOneQuarter outputs with 1/4 size of panorama image.

void SetDepthLinearType (OutputDepthLinearType type);

Specifies the type of interpolation at depth output.
Argument nameDetails
type Interpolation type when outputting depth
OutputDepthLinearType.Linear ... linear
OutputDepthLinearType.NonLinear ... non-linear

OutputDepthLinearType GetDepthLinearType ();

Gets the type of interpolation at depth output.
OutputDepthLinearType.Linear is linear.
OutputDepthLinearType.NonLinear is non-linear.

void SetCameraNearFarDistance (float nearP, float farP);

Specifies the distance of the camera near / far plane.
Argument nameDetails
nearPDistance to near clip plane
farPDistance to far clip plane

IEnumerator SetCameraPosition (Vector3 cameraPos);

Change the camera position.
It must be called from the coroutine to synchronize.
Argument nameDetails
cameraPosCamera position
This function waits for synchronization of the camera's drawing when generating a panorama image.
To specify camera rotation etc. separately, change the camera information first and then call this function.

bool OutputStillImage (bool depthF = false);

Output still image to file.
Argument nameDetails
depthFDepth output if true, RGB output if false
If the output of a still image is successful, true is returned.
When outputting Depth, the file extension is exr.

void SetSynchronizeGazeDirection (bool b);

This function was added in ver.1.1.0.
Specify whether XZ axis rotation is reflected in addition to Y axis rotation when panoramic image is generated.
Argument nameDetails
bIf true, the camera's XYZ rotation is reflected.
If false, only the camera's Y rotation is reflected.

bool IsSynchronizeGazeDirection ();

This function was added in ver.1.1.0.
If it is true, the XYZ rotation of the camera is reflected when generating panorama images.
If it is false, only the Y rotation of the camera is reflected.

void SetIPD (float t);

Specify the distance between the two eyes (IPD: interpupillary distance).
Argument nameDetails
t IPD (Unit : m)

float GetIPD ();

Get the distance between the two eyes (IPD: interpupillary distance).

void SetSimulateVR180Camera (bool b);

Specifies whether to process the panorama like a VR180 camera when using Panorama 180-3D.
Argument nameDetails
b If true, it will process the panorama like a VR180 camera.
In the case of false, the parallax when facing left or right is also interpolated as much as possible.

bool IsSimulateVR180Camera ();

When panorama 180-3D, returns true if the panorama is processed like a VR180 camera.
In the case of false, the parallax when facing left or right is also interpolated as much as possible.

string GetOutputImageFullPathName (bool depthF = false);

This function was added in ver.2.0.0.
Get the full path of the file name where the still image will be output.
Argument nameDetails
depthFDepth output if true, RGB output if false

void SetGameViewMode (GameViewMode vMode);

This function was added in ver.2.0.0.
Specify the "Game View Mode".
Argument nameDetails
vMode GameViewMode.Default ... default view
GameViewMode.PanoramaView ... panoramic view

GameViewMode GetGameViewMode ();

This function was added in ver.2.0.0.
Get the "Game View Mode" specification.
GameViewMode.Default/GameViewMode.PanoramaView will be returned.

void SetPanoramaMode (PanoramaMode pMode);

This function was added in ver.2.0.0.
Specify the "Panorama Mode" (Panorama 180-3D, Panorama 360-3D).
Argument nameDetails
vMode PanoramaMode.Panorama180 ... Panorama 180-3D
PanoramaMode.Panorama360 ... Panorama 360-3D

PanoramaMode GetPanoramaMode ();

This function was added in ver.2.0.0.
Get the "Panorama Mode" (Panorama 180-3D, Panorama 360-3D).
PanoramaMode.Panorama180/PanoramaMode.Panorama360 will be returned.

void SetOutputTextureSizeType360 (OutputTextureSizeType360 sType);

This function was added in ver.2.0.0.
Specifies the output texture size type for Panorama 360-3D.
Argument nameDetails
sType Output texture size type.
OutputTextureSizeType360._512 ... 512 x 512
OutputTextureSizeType360._1024 ... 1024 x 1024
OutputTextureSizeType360._2048 ... 2048 x 2048
OutputTextureSizeType360._3072 ... 3072 x 3072
OutputTextureSizeType360._4096 ... 4096 x 4096
OutputTextureSizeType360._4K ... 3840 x 3840
OutputTextureSizeType360._5_7K ... 5760 × 5760
OutputTextureSizeType360._8K ... 7680 x 7680
OutputTextureSizeType360._16K ... 15360 x 15360
OutputTextureSizeType360._16384 ... 16384 x 16384

OutputTextureSizeType360 GetOutputTextureSizeType360 ();

This function was added in ver.2.0.0.
Get the output texture size type for Panorama 360-3D.
This is the size of the texture when placing the two-eye panorama that will eventually be output.
OutputTextureSizeType360._512, OutputTextureSizeType360._1024, OutputTextureSizeType360._2048,
OutputTextureSizeType360._3072, OutputTextureSizeType360._4096, OutputTextureSizeType360._4K,
OutputTextureSizeType360._5_7K, OutputTextureSizeType360._8K, OutputTextureSizeType360._16K or
OutputTextureSizeType360._16384 is returned

void SetEyesType (EyesType eType);

This function was added in ver.2.0.1.
Specifies monocular or stereo.
Argument nameDetails
eType Monocular/stereo types
EyesType.Stereo ... Stereo (Default)
EyesType.Mono ... Monocular

EyesType GetEyesType ();

This function was added in ver.2.0.1.
Get monocular or stereo.
EyesType.Stereo, EyesType.Mono is returned.

Back