Description of Scene Manager
The following is code for required components of SceneManager
Required Components
ARManager
ARCamera
VPSStudioController
CameraBackgroundBahavior
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.");
}
When rendered 3D Objects are visibly hidden from the building mesh is called Occlusion Culling. Occlusion is applied when runtimeBuildingMaterial is rendered.
foreach (GameObject eachGameObject in occlusionObjects)
{
Renderer[] cullingRenderer = eachGameObject.GetComponentsInChildren<Renderer>();
foreach (Renderer eachRenderer in cullingRenderer)
{
eachRenderer.material.renderQueue = 1900;
eachRenderer.material = runtimeBuildingMaterial;
}
}
스마트폰과 스마트 글래스와 같은 모바일 기기 환경에서는 아래 코드를 통해 하드웨어 카메라가 시작됩니다. MAC OS X와 Windows 환경에서는 VPSStudioController를 통해 선택한 시뮬레이션 데이터가 시작됩니다. 이를 통해 현장에 직접 나가지 않아도 앱 개발이 가능합니다.
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();
}
}
VPS Tracker를 시작하기 위해서는 해당 VPS 공간지도에 접근할 수 있도록 서버 이름을 입력해야 합니다.
TrackerManager.GetInstance().StartTracker();
if (serverName != "")
{
string vpsquery = "{\"vps_server\":\"" + serverName + "\"}";
TrackerManager.GetInstance().AddTrackerData(vpsquery);
}
트래킹 결과는 UpdateFrame()과 GetARFrame()을 통해서 얻을 수 있습니다. GetARFrame()을 통해 얻은 ARFrame의 인스턴스에는 현재 트래킹 상태, 이미지, 6자유도 자세를 포함되어 있습니다.
ARFrame의 GetARLocationRecognitionState()를 통해서 현재 위치 인식 상태를 얻을 수 있습니다. 이 상태 정보에 맞춰 증강시킬 3D Object의 활성화 여부를 결정합니다.
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);
}
}