浏览代码

-Added new prefab for plane classification visualization which includes a modifying the plane color based on classification as well as displaying the classification in a TextMesh at the center of each plane.

-New plane classification scene is disabled by default in the BuildSetting UI.
/3.1
Mike Durand 5 年前
当前提交
e0443584
共有 8 个文件被更改,包括 348 次插入78 次删除
  1. 2
      Assets/Scenes/Plane Detection/PlaneClassification.unity
  2. 2
      ProjectSettings/EditorBuildSettings.asset
  3. 2
      Assets/Scenes/Plane Detection/PlaneClassificationLabeler.cs.meta
  4. 247
      Assets/Scenes/Plane Detection/AR Plane Classification Visualizer.prefab
  5. 7
      Assets/Scenes/Plane Detection/AR Plane Classification Visualizer.prefab.meta
  6. 91
      Assets/Scenes/Plane Detection/PlaneClassificationLabeler.cs
  7. 75
      Assets/Scripts/PlaneClassification.cs
  8. 0
      /Assets/Scenes/Plane Detection/PlaneClassificationLabeler.cs.meta

2
Assets/Scenes/Plane Detection/PlaneClassification.unity


m_Script: {fileID: 11500000, guid: e1760703bbd54c04488a8d10600262ab, type: 3}
m_Name:
m_EditorClassIdentifier:
m_PlanePrefab: {fileID: 1568414836858200, guid: f0e0be81472ff1243aa2afa27e5d0e61,
m_PlanePrefab: {fileID: 1568414836858200, guid: 55818d52702e343009fa8489d262df47,
type: 3}
m_DetectionMode: -1

2
ProjectSettings/EditorBuildSettings.asset


- enabled: 0
path: Assets/Scenes/ReferencePoints.unity
guid: 5cba9114a192a46a7aef31da62316e39
- enabled: 1
- enabled: 0
path: Assets/Scenes/Plane Detection/PlaneClassification.unity
guid: ea35aff45ed534fb9b030b82a5d980f4
m_configObjects:

2
Assets/Scenes/Plane Detection/PlaneClassificationLabeler.cs.meta


fileFormatVersion: 2
guid: 803c29a161dbe4031b453a8be8a1d810
guid: 67c9b09069d9d4d3a9be9eee154ea7dd
MonoImporter:
externalObjects: {}
serializedVersion: 2

247
Assets/Scenes/Plane Detection/AR Plane Classification Visualizer.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1568414836858200
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5814555526566707470}
- component: {fileID: 114420653519937450}
- component: {fileID: 114505523171528268}
- component: {fileID: 64075061905826896}
- component: {fileID: 23757564266038714}
- component: {fileID: 120517587746667212}
- component: {fileID: 6028667637951273774}
- component: {fileID: 6206394168086558779}
- component: {fileID: 8946482329426427816}
m_Layer: 0
m_Name: AR Plane Classification Visualizer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &5814555526566707470
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568414836858200}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &114420653519937450
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568414836858200}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f66da7470dce8f4d821d71dd2b1d4ac, type: 3}
m_Name:
m_EditorClassIdentifier:
m_DestroyOnRemoval: 1
m_VertexChangedThreshold: 0.01
--- !u!114 &114505523171528268
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568414836858200}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3d180956a54db4646a1c6342921672ad, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!64 &64075061905826896
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568414836858200}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 3
m_Convex: 0
m_CookingOptions: 14
m_Mesh: {fileID: 0}
--- !u!23 &23757564266038714
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568414836858200}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: da88c2617acace440ac7cacccc82cb89, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!120 &120517587746667212
LineRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568414836858200}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 0
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
m_RenderingLayerMask: 4294967295
m_RendererPriority: 0
m_Materials:
- {fileID: 10306, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Positions:
- {x: 0, y: 0, z: 0}
- {x: 0, y: 0, z: 1}
m_Parameters:
serializedVersion: 3
widthMultiplier: 0.005
widthCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
colorGradient:
serializedVersion: 2
key0: {r: 0, g: 0, b: 0, a: 1}
key1: {r: 0, g: 0, b: 0, a: 1}
key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 0
ctime3: 0
ctime4: 0
ctime5: 0
ctime6: 0
ctime7: 0
atime0: 0
atime1: 65535
atime2: 0
atime3: 0
atime4: 0
atime5: 0
atime6: 0
atime7: 0
m_Mode: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 2
numCornerVertices: 4
numCapVertices: 4
alignment: 0
textureMode: 0
shadowBias: 0
generateLightingData: 0
m_UseWorldSpace: 0
m_Loop: 1
--- !u!222 &6028667637951273774
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568414836858200}
m_CullTransparentMesh: 0
--- !u!33 &6206394168086558779
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568414836858200}
m_Mesh: {fileID: 0}
--- !u!114 &8946482329426427816
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568414836858200}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 67c9b09069d9d4d3a9be9eee154ea7dd, type: 3}
m_Name:
m_EditorClassIdentifier:

7
Assets/Scenes/Plane Detection/AR Plane Classification Visualizer.prefab.meta


fileFormatVersion: 2
guid: 55818d52702e343009fa8489d262df47
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

91
Assets/Scenes/Plane Detection/PlaneClassificationLabeler.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
/// <summary>
/// Manages the label and plane material color for each recognized plane based on
/// the PlaneClassification enumeration defined in ARSubsystems.
/// </summary>
[RequireComponent(typeof(ARPlane))]
[RequireComponent(typeof(MeshRenderer))]
public class PlaneClassificationLabeler : MonoBehaviour
{
ARPlane m_ARPlane;
MeshRenderer m_PlaneMeshRenderer;
TextMesh m_TextMesh;
GameObject m_TextObj;
Vector3 m_TextFlipVec = new Vector3(0, 180, 0);
void Awake()
{
m_ARPlane = GetComponent<ARPlane>();
m_PlaneMeshRenderer = GetComponent<MeshRenderer>();
// Setup label
m_TextObj = new GameObject();
m_TextMesh = m_TextObj.AddComponent<TextMesh>();
m_TextMesh.characterSize = 0.05f;
m_TextMesh.color = Color.black;
}
void Update()
{
UpdateLabel();
UpdatePlaneColor();
}
void UpdateLabel()
{
// Update text
m_TextMesh.text = m_ARPlane.classification.ToString();
// Update Pose
m_TextObj.transform.position = m_ARPlane.center;
m_TextObj.transform.LookAt(Camera.main.transform);
m_TextObj.transform.Rotate(m_TextFlipVec);
}
void UpdatePlaneColor()
{
Color planeMatColor = Color.cyan;
switch (m_ARPlane.classification)
{
case PlaneClassification.None:
planeMatColor = Color.cyan;
break;
case PlaneClassification.Wall:
planeMatColor = Color.white;
break;
case PlaneClassification.Floor:
planeMatColor = Color.green;
break;
case PlaneClassification.Ceiling:
planeMatColor = Color.blue;
break;
case PlaneClassification.Table:
planeMatColor = Color.yellow;
break;
case PlaneClassification.Seat:
planeMatColor = Color.magenta;
break;
case PlaneClassification.Door:
planeMatColor = Color.red;
break;
case PlaneClassification.Window:
planeMatColor = Color.clear;
break;
}
planeMatColor.a = 0.33f;
m_PlaneMeshRenderer.material.color = planeMatColor;
}
void OnDestroy()
{
Destroy(m_TextObj);
}
}

75
Assets/Scripts/PlaneClassification.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class PlaneClassification : MonoBehaviour
{
ARPlaneManager m_ARPlaneManager;
void Awake()
{
m_ARPlaneManager = GetComponent<ARPlaneManager>();
}
void OnEnable()
{
m_ARPlaneManager.planesChanged += OnPlanesChanged;
}
void OnDisable()
{
m_ARPlaneManager.planesChanged -= OnPlanesChanged;
}
void OnPlanesChanged(ARPlanesChangedEventArgs eventArgs)
{
OnPlanesAdded(eventArgs.added);
OnPlanesUpdated(eventArgs.updated);
OnPlanesRemoved(eventArgs.removed);
}
void OnPlanesAdded(List<ARPlane> addedPlanes)
{
foreach (var plane in addedPlanes)
{
GameObject textObj = new GameObject();
textObj.transform.SetParent(plane.gameObject.transform, false);
TextMesh planeText = textObj.AddComponent<TextMesh>();
if (planeText)
{
planeText.characterSize = 0.05f;
planeText.text = plane.classification.ToString();
}
}
}
void OnPlanesUpdated(List<ARPlane> updatedPlanes)
{
foreach (var plane in updatedPlanes)
{
TextMesh planeText = plane.GetComponentInChildren<TextMesh>();
if (planeText)
{
planeText.text = plane.classification.ToString();
}
}
}
void OnPlanesRemoved(List<ARPlane> removedPlanes)
{
foreach (var plane in removedPlanes)
{
Component[] textMeshes;
textMeshes = plane.gameObject.GetComponentsInChildren(typeof(TextMesh));
foreach (TextMesh planeText in textMeshes)
{
Destroy(planeText.gameObject);
}
}
}
}

/Assets/Scripts/PlaneClassification.cs.meta → /Assets/Scenes/Plane Detection/PlaneClassificationLabeler.cs.meta

正在加载...
取消
保存