114 lines
4.9 KiB
C#
114 lines
4.9 KiB
C#
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
* All rights reserved.
|
|
*
|
|
* Licensed under the Oculus SDK License Agreement (the "License");
|
|
* you may not use the Oculus SDK except in compliance with the License,
|
|
* which is provided at the time of installation or download, or which
|
|
* otherwise accompanies this software in either electronic or hard copy form.
|
|
*
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* https://developer.oculus.com/licenses/oculussdk/
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SampleVirtualFrames : MonoBehaviour
|
|
{
|
|
public OVRSceneManager _sceneManager;
|
|
|
|
public SimpleResizable _doorPrefab;
|
|
public SimpleResizable _windowPrefab;
|
|
|
|
public SimpleResizable _wallPrefab;
|
|
|
|
void Awake()
|
|
{
|
|
MarcsWebLogger.Log("SampleVirtualFrames::Awake()");
|
|
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_ANDROID
|
|
OVRManager.eyeFovPremultipliedAlphaModeEnabled = false;
|
|
#endif
|
|
_sceneManager.SceneModelLoadedSuccessfully += InitializeRoom;
|
|
}
|
|
|
|
void InitializeRoom()
|
|
{
|
|
MarcsWebLogger.Log("SampleVirtualFrames::InitializeRoom()");
|
|
OVRSceneAnchor[] sceneAnchors = FindObjectsOfType<OVRSceneAnchor>();
|
|
if (sceneAnchors != null)
|
|
{
|
|
for (int i = 0; i < sceneAnchors.Length; i++)
|
|
{
|
|
OVRSceneAnchor instance = sceneAnchors[i];
|
|
OVRSemanticClassification classification = instance.GetComponent<OVRSemanticClassification>();
|
|
|
|
if (classification.Contains(OVRSceneManager.Classification.WallFace))
|
|
{
|
|
var randomNumber = UnityEngine.Random.Range(10000, 99999);
|
|
MarcsWebLogger.Log($"{randomNumber} | FOUND A WALL");
|
|
try
|
|
{
|
|
SimpleResizer resizer = new SimpleResizer();
|
|
SimpleResizable prefab = _wallPrefab;
|
|
Vector3 dimensions = instance.transform.GetChild(0).localScale;
|
|
if (prefab.GetComponent<ResizablePadding>())
|
|
{
|
|
dimensions += prefab.GetComponent<ResizablePadding>().dimensionPadding;
|
|
}
|
|
resizer.CreateResizedObject(dimensions, sceneAnchors[i].gameObject, prefab);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
MarcsWebLogger.Log($"{randomNumber} | Error: {e.Message}");
|
|
}
|
|
MarcsWebLogger.Log($"{randomNumber} | PLACED A WALL");
|
|
//i = 99999;
|
|
}
|
|
/*
|
|
else if (classification.Contains(OVRSceneManager.Classification.WindowFrame) ||
|
|
classification.Contains(OVRSceneManager.Classification.DoorFrame))
|
|
{
|
|
windows.Add(instance.transform);
|
|
|
|
SimpleResizer resizer = new SimpleResizer();
|
|
SimpleResizable prefab = classification.Contains(OVRSceneManager.Classification.DoorFrame) ? _doorPrefab : _windowPrefab;
|
|
Vector3 dimensions = instance.transform.GetChild(0).localScale;
|
|
|
|
// spawn an optional butterfly
|
|
if (classification.Contains(OVRSceneManager.Classification.DoorFrame) && _butterflyPrefab && !butterflyAdded)
|
|
{
|
|
GameObject butterfly = Instantiate(_butterflyPrefab, instance.transform);
|
|
butterfly.transform.localPosition = Vector3.zero;
|
|
butterfly.transform.rotation = Quaternion.LookRotation(instance.transform.forward, Vector3.up);
|
|
// this is to only spawn one, regardless of door count
|
|
butterflyAdded = true;
|
|
}
|
|
|
|
// the Resizer scales the mesh so that the bounds are flush with the window extents
|
|
// in this case, we want the mesh frame to extend "outside" of the extents, so we adjust it
|
|
// as well, the vines on the door also require special treatment
|
|
if (prefab.GetComponent<ResizablePadding>())
|
|
{
|
|
dimensions += prefab.GetComponent<ResizablePadding>().dimensionPadding;
|
|
}
|
|
resizer.CreateResizedObject(dimensions, sceneAnchors[i].gameObject, prefab);
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MarcsWebLogger.Log("NO ANCHORS FOUND. ");
|
|
}
|
|
}
|
|
}
|