Unity 3D

Installation

You can find .unitypackage file at https://github.com/Realistic3D/real_api_unity/releases

Render

1. Add login class

  • Add class RealAPI to any active gameObject and add your login information.

using REAL;
using REAL.Networks;

[RequireComponent(typeof(RealAPI))]
public class RendererScene : MonoBehaviour
{
    public RealAPI real;

    private void Awake()
    {
        real = GetComponent<RealAPI>();
    }
}
  1. Get Real API scene (binary scene)

You can render whole scene or even some GameObjects of your scene it depends upon your requirement

// Step 1: Get scene from whole Scene

Camera camera = myCam; // Optional
Scene scene = myScene; // Required
var realScene = Real.RealScene(scene, camera);

OR

// Step 1: Get scene from some gameobjects in Scene

Camera camera = myCam; // Optional
List<GameObject> allObjects = requiredObject; // Required
var realScene = Real.RealScene(allObjects, camera);

Note:

  • camera is an Optional parameter in this function.

  • If you have multiple Camera in scene or list , the camera you want to render can be named as REAL_EYE or you can bypass directly to the function Real.RealScene(allObjects, camera)

  1. Create new job

// Step 2: Apply new job

var apiResponse = await ApiRequests.PostRequest(login, AskService.NewJob);
var resData = apiResponse.data; 
var uri = resData.url;
  1. Upload scene

// Step 3: Upload scene

bool uploaded = await ApiRequests.PutRequest(uri, realScene);
  1. Submit job

// Step 4: Submit job

await ApiRequests.PostRequest(login, AskService.Submit, resData.jobID);

Final script

using REAL;
using REAL.Networks;
using UnityEngine;
using UnityEngine.SceneManagement;

[RequireComponent(typeof(RealAPI))]
public class RendererScene : MonoBehaviour
{
    public RealAPI real;

    private void Awake()
    {
        real = GetComponent<RealAPI>();
    }

    public async void RenderScene()
    {
        var login = real.login;
        
        // Step 1: Get Scene
        
        var camera = Camera.main;
        var scene = SceneManager.GetActiveScene();
        var realScene = Real.RealScene(scene, camera);
        
        // Step 2: Apply new job
        
        var apiResponse = await ApiRequests.PostRequest(login, AskService.NewJob);
        var resData = apiResponse.data; 
        var uri = resData.url;
        
        // Step 3: Upload scene

        bool uploaded = await ApiRequests.PutRequest(uri, realScene);
        
        // Step 4: Submit job

        await ApiRequests.PostRequest(login, AskService.Submit, resData.jobID);
    }
}

Last updated