Description of Scene Manager
The following is code for required components of SceneManager
Required Components
ARManager
ARCamera
VPSStudioController
CameraBackgroundBahavior
When rendered 3D Objects are visibly hidden from the building mesh is called Occlusion Culling. Occlusion is applied when runtimeBuildingMaterial is rendered.
์ค๋งํธํฐ๊ณผ ์ค๋งํธ ๊ธ๋์ค์ ๊ฐ์ ๋ชจ๋ฐ์ผ ๊ธฐ๊ธฐ ํ๊ฒฝ์์๋ ์๋ ์ฝ๋๋ฅผ ํตํด ํ๋์จ์ด ์นด๋ฉ๋ผ๊ฐ ์์๋ฉ๋๋ค. MAC OS X์ Windows ํ๊ฒฝ์์๋ VPSStudioController๋ฅผ ํตํด ์ ํํ ์๋ฎฌ๋ ์ด์ ๋ฐ์ดํฐ๊ฐ ์์๋ฉ๋๋ค. ์ด๋ฅผ ํตํด ํ์ฅ์ ์ง์ ๋๊ฐ์ง ์์๋ ์ฑ ๊ฐ๋ฐ์ด ๊ฐ๋ฅํฉ๋๋ค.
VPS Tracker๋ฅผ ์์ํ๊ธฐ ์ํด์๋ ํด๋น VPS ๊ณต๊ฐ์ง๋์ ์ ๊ทผํ ์ ์๋๋ก ์๋ฒ ์ด๋ฆ์ ์ ๋ ฅํด์ผ ํฉ๋๋ค.
ํธ๋ํน ๊ฒฐ๊ณผ๋ UpdateFrame()๊ณผ GetARFrame()์ ํตํด์ ์ป์ ์ ์์ต๋๋ค. GetARFrame()์ ํตํด ์ป์ ARFrame์ ์ธ์คํด์ค์๋ ํ์ฌ ํธ๋ํน ์ํ, ์ด๋ฏธ์ง, 6์์ ๋ ์์ธ๋ฅผ ํฌํจ๋์ด ์์ต๋๋ค.
ARFrame์ GetARLocationRecognitionState()๋ฅผ ํตํด์ ํ์ฌ ์์น ์ธ์ ์ํ๋ฅผ ์ป์ ์ ์์ต๋๋ค. ์ด ์ํ ์ ๋ณด์ ๋ง์ถฐ ์ฆ๊ฐ์ํฌ 3D Object์ ํ์ฑํ ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํฉ๋๋ค.
RootTrackable
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.");
}foreach (GameObject eachGameObject in occlusionObjects)
{
Renderer[] cullingRenderer = eachGameObject.GetComponentsInChildren<Renderer>();
foreach (Renderer eachRenderer in cullingRenderer)
{
eachRenderer.material.renderQueue = 1900;
eachRenderer.material = runtimeBuildingMaterial;
}
}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();
}
}
TrackerManager.GetInstance().StartTracker();
if (serverName != "")
{
string vpsquery = "{\"vps_server\":\"" + serverName + "\"}";
TrackerManager.GetInstance().AddTrackerData(vpsquery);
}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);
}
}