# SceneManager Description

## Required components of SceneManager

The following is code for required components of SceneManager

{% hint style="success" %}
**Required Components**

* ARManager
* ARCamera
* VPSStudioController
* CameraBackgroundBahavior
* RootTrackable
  {% endhint %}

{% code title="MaxstSceneManager.cs" %}

```csharp
ARManager arManagr = FindObjectOfType<ARManager>();
if (arManagr == null)
{
    Debug.LogError("Can't find ARManager. You need to add ARManager prefab in scene.");
    return;
}
else
{
    arCamera = arManagr.gameObject;
}

vPSStudioController = FindObjectOfType<VPSStudioController>();
if (vPSStudioController == null)
{
    Debug.LogError("Can't find VPSStudioController. You need to add VPSStudio prefab in scene.");
    return;
}
else
{
    string serverName = vPSStudioController.vpsServerName;
    vPSStudioController.gameObject.SetActive(false);
}

cameraBackgroundBehaviour = FindObjectOfType<CameraBackgroundBehaviour>();
if (cameraBackgroundBehaviour == null)
{
    Debug.LogError("Can't find CameraBackgroundBehaviour.");
    return;
}

if(rootTrackable == null)
{
    Debug.LogError("You need to add RootTrackable.");
}
```

{% endcode %}

{% hint style="info" %}
Use **VPSStudioController** to learn the name of server using location positioning
{% endhint %}

## Occlusion Culling&#x20;

When rendered 3D Objects are visibly hidden from the building mesh is called Occlusion Culling. Occlusion is applied when runtimeBuildingMaterial is rendered.

{% code title="MaxstSceneManager.cs" %}

```bash
foreach (GameObject eachGameObject in occlusionObjects)
{
    Renderer[] cullingRenderer = eachGameObject.GetComponentsInChildren<Renderer>();
    foreach (Renderer eachRenderer in cullingRenderer)
    {
        eachRenderer.material.renderQueue = 1900;
        eachRenderer.material = runtimeBuildingMaterial;
    }
}
```

{% endcode %}

## 카메라 시작 / 시뮬레이션 시작&#x20;

스마트폰과 스마트 글래스와 같은 모바일 기기 환경에서는 아래 코드를 통해 하드웨어 카메라가 시작됩니다. MAC OS X와 Windows 환경에서는 VPSStudioController를 통해 선택한 시뮬레이션 데이터가 시작됩니다. 이를 통해 현장에 직접 나가지 않아도 앱 개발이 가능합니다.

{% code title="MaxstSceneManager.cs" %}

```csharp
if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsEditor)
{
    string simulatePath = vPSStudioController.vpsSimulatePath;
    if (Directory.Exists(simulatePath))
    {
        CameraDevice.GetInstance().Start(simulatePath);
        MaxstAR.SetScreenOrientation((int)ScreenOrientation.Portrait);
    }
}
else
{
    if (CameraDevice.GetInstance().IsFusionSupported(CameraDevice.FusionType.ARCamera))
    {
        CameraDevice.GetInstance().Start();
    }
    else
    {
        TrackerManager.GetInstance().RequestARCoreApk();
    }
}

```

{% endcode %}

## VPS Tracker 시작

VPS Tracker를 시작하기 위해서는 해당 VPS 공간지도에 접근할 수 있도록 서버 이름을 입력해야 합니다.

{% code title="MaxstSceneManager.cs" %}

```csharp
TrackerManager.GetInstance().StartTracker();

if (serverName != "")
{
    string vpsquery = "{\"vps_server\":\"" + serverName + "\"}";
    TrackerManager.GetInstance().AddTrackerData(vpsquery);
}
```

{% endcode %}

## VPS 트래킹 결과 얻기&#x20;

트래킹 결과는 UpdateFrame()과 GetARFrame()을 통해서 얻을 수 있습니다. GetARFrame()을 통해 얻은 ARFrame의 인스턴스에는 현재 트래킹 상태, 이미지, 6자유도 자세를 포함되어 있습니다.

ARFrame의 GetARLocationRecognitionState()를 통해서 현재 위치 인식 상태를 얻을 수 있습니다. 이 상태 정보에 맞춰 증강시킬 3D Object의 활성화 여부를 결정합니다.

{% code title="MaxstSceneManager.cs" %}

```csharp
void Update()
{
    TrackerManager.GetInstance().UpdateFrame();

    ARFrame arFrame = TrackerManager.GetInstance().GetARFrame();
    
    TrackedImage trackedImage = arFrame.GetTrackedImage();


    if (trackedImage.IsTextureId())
    {
        IntPtr[] cameraTextureIds = trackedImage.GetTextureIds();
        cameraBackgroundBehaviour.UpdateCameraBackgroundImage(cameraTextureIds);
    }
    else
    {
        cameraBackgroundBehaviour.UpdateCameraBackgroundImage(trackedImage);
    }

    if(arFrame.GetARLocationRecognizeState() == ARLocationRecognizeState.ARLocationRecognizeStateNormal)
    {
        Matrix4x4 targetPose = arFrame.GetTransform();

        arCamera.transform.position = MatrixUtils.PositionFromMatrix(targetPose);
        arCamera.transform.rotation = MatrixUtils.QuaternionFromMatrix(targetPose);
        arCamera.transform.localScale = MatrixUtils.ScaleFromMatrix(targetPose);

        rootTrackable.SetActive(true);
    }
    else
    {
        rootTrackable.SetActive(false);
    }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maxstvps.gitbook.io/documentation-eng/-MbEQLJaN0vXKGxXQmJX/scene-manager-1/scene-manager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
