clean project
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities 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 UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.HandPosing.SnapSurfaces.Editor
|
||||
{
|
||||
[CustomEditor(typeof(BoxSurface))]
|
||||
[CanEditMultipleObjects]
|
||||
public class BoxEditor : UnityEditor.Editor
|
||||
{
|
||||
private static readonly Color NONINTERACTABLE_COLOR = new Color(0f, 1f, 1f, 0.1f);
|
||||
private static readonly Color INTERACTABLE_COLOR = new Color(0f, 1f, 1f, 0.5f);
|
||||
|
||||
private BoxBoundsHandle _boxHandle = new BoxBoundsHandle();
|
||||
private BoxSurface _surface;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_boxHandle.handleColor = INTERACTABLE_COLOR;
|
||||
_boxHandle.wireframeColor = NONINTERACTABLE_COLOR;
|
||||
_boxHandle.axes = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Z;
|
||||
|
||||
_surface = (target as BoxSurface);
|
||||
}
|
||||
|
||||
public void OnSceneGUI()
|
||||
{
|
||||
DrawRotator(_surface);
|
||||
DrawBoxEditor(_surface);
|
||||
DrawSlider(_surface);
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
DrawSnapLines(_surface);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSnapLines(BoxSurface surface)
|
||||
{
|
||||
Handles.color = INTERACTABLE_COLOR;
|
||||
|
||||
Vector3 rightAxis = surface.Rotation * Vector3.right;
|
||||
Vector3 forwardAxis = surface.Rotation * Vector3.forward;
|
||||
Vector3 forwardOffset = forwardAxis * surface.Size.z;
|
||||
|
||||
Vector3 bottomLeft = surface.transform.position - rightAxis * surface.Size.x * (1f - surface.WidthOffset);
|
||||
Vector3 bottomRight = surface.transform.position + rightAxis * surface.Size.x * (surface.WidthOffset);
|
||||
Vector3 topLeft = bottomLeft + forwardOffset;
|
||||
Vector3 topRight = bottomRight + forwardOffset;
|
||||
|
||||
Handles.DrawLine(bottomLeft + rightAxis * surface.SnapOffset.y, bottomRight + rightAxis * surface.SnapOffset.x);
|
||||
Handles.DrawLine(topLeft - rightAxis * surface.SnapOffset.x, topRight - rightAxis * surface.SnapOffset.y);
|
||||
Handles.DrawLine(bottomLeft - forwardAxis * surface.SnapOffset.z, topLeft - forwardAxis * surface.SnapOffset.w);
|
||||
Handles.DrawLine(bottomRight + forwardAxis * surface.SnapOffset.w, topRight + forwardAxis * surface.SnapOffset.z);
|
||||
}
|
||||
|
||||
private void DrawSlider(BoxSurface surface)
|
||||
{
|
||||
Handles.color = INTERACTABLE_COLOR;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Vector3 rightDir = surface.Rotation * Vector3.right;
|
||||
Vector3 forwardDir = surface.Rotation * Vector3.forward;
|
||||
Vector3 bottomRight = surface.transform.position
|
||||
+ rightDir * surface.Size.x * (surface.WidthOffset);
|
||||
Vector3 bottomLeft = surface.transform.position
|
||||
- rightDir * surface.Size.x * (1f - surface.WidthOffset);
|
||||
Vector3 topRight = bottomRight + forwardDir * surface.Size.z;
|
||||
|
||||
Vector3 rightHandle = DrawOffsetHandle(bottomRight + rightDir * surface.SnapOffset.x, rightDir);
|
||||
Vector3 leftHandle = DrawOffsetHandle(bottomLeft + rightDir * surface.SnapOffset.y, -rightDir);
|
||||
Vector3 topHandle = DrawOffsetHandle(topRight + forwardDir * surface.SnapOffset.z, forwardDir);
|
||||
Vector3 bottomHandle = DrawOffsetHandle(bottomRight + forwardDir * surface.SnapOffset.w, -forwardDir);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(surface, "Change Offset Box");
|
||||
Vector4 offset = surface.SnapOffset;
|
||||
offset.x = DistanceToHandle(bottomRight, rightHandle, rightDir);
|
||||
offset.y = DistanceToHandle(bottomLeft, leftHandle, rightDir);
|
||||
offset.z = DistanceToHandle(topRight, topHandle, forwardDir);
|
||||
offset.w = DistanceToHandle(bottomRight, bottomHandle, forwardDir);
|
||||
surface.SnapOffset = offset;
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 DrawOffsetHandle(Vector3 point, Vector3 dir)
|
||||
{
|
||||
float size = HandleUtility.GetHandleSize(point) * 0.2f;
|
||||
return Handles.Slider(point, dir, size, Handles.ConeHandleCap, 0f);
|
||||
}
|
||||
|
||||
private float DistanceToHandle(Vector3 origin, Vector3 handlePoint, Vector3 dir)
|
||||
{
|
||||
float distance = Vector3.Distance(origin, handlePoint);
|
||||
if (Vector3.Dot(handlePoint - origin, dir) < 0f)
|
||||
{
|
||||
distance = -distance;
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
private void DrawRotator(BoxSurface surface)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Quaternion rotation = Handles.RotationHandle(surface.Rotation, surface.transform.position);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(surface, "Change Rotation Box");
|
||||
surface.Rotation = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBoxEditor(BoxSurface surface)
|
||||
{
|
||||
Quaternion rot = surface.Rotation;
|
||||
Vector3 size = surface.Size;
|
||||
|
||||
Vector3 snapP = surface.transform.position;
|
||||
|
||||
_boxHandle.size = size;
|
||||
float widthPos = Mathf.Lerp(-size.x * 0.5f, size.x * 0.5f, surface.WidthOffset);
|
||||
_boxHandle.center = new Vector3(widthPos, 0f, size.z * 0.5f);
|
||||
|
||||
Matrix4x4 handleMatrix = Matrix4x4.TRS(
|
||||
snapP,
|
||||
rot,
|
||||
Vector3.one
|
||||
);
|
||||
|
||||
using (new Handles.DrawingScope(handleMatrix))
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
_boxHandle.DrawHandle();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(surface, "Change Box Properties");
|
||||
|
||||
surface.Size = _boxHandle.size;
|
||||
float width = _boxHandle.size.x;
|
||||
surface.WidthOffset = width != 0f ? (_boxHandle.center.x + width * 0.5f) / width : 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
private float RemapClamped(float value, (float, float) from, (float, float) to)
|
||||
{
|
||||
value = Mathf.Clamp(value, from.Item1, from.Item2);
|
||||
return to.Item1 + (value - from.Item1) * (to.Item2 - to.Item1) / (from.Item2 - from.Item1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: baf3d860debef0947b62cdebdd94cb74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,132 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities 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 UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.HandPosing.SnapSurfaces.Editor
|
||||
{
|
||||
[CustomEditor(typeof(CylinderSurface))]
|
||||
[CanEditMultipleObjects]
|
||||
public class CylinderEditor : UnityEditor.Editor
|
||||
{
|
||||
private static readonly Color NONINTERACTABLE_COLOR = new Color(0f, 1f, 1f, 0.1f);
|
||||
private static readonly Color INTERACTABLE_COLOR = new Color(0f, 1f, 1f, 0.5f);
|
||||
private const float DRAW_SURFACE_ANGULAR_RESOLUTION = 5f;
|
||||
|
||||
private ArcHandle _arcHandle = new ArcHandle();
|
||||
private Vector3[] _surfaceEdges;
|
||||
|
||||
CylinderSurface _surface;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_arcHandle.SetColorWithRadiusHandle(INTERACTABLE_COLOR, 0f);
|
||||
_surface = (target as CylinderSurface);
|
||||
}
|
||||
|
||||
public void OnSceneGUI()
|
||||
{
|
||||
DrawEndsCaps(_surface);
|
||||
DrawArcEditor(_surface);
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
DrawSurfaceVolume(_surface);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawEndsCaps(CylinderSurface surface)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
Quaternion handleRotation = (surface.RelativeTo ?? surface.transform).rotation;
|
||||
|
||||
Vector3 startPosition = Handles.PositionHandle(surface.StartPoint, handleRotation);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(surface, "Change Start Cylinder Position");
|
||||
surface.StartPoint = startPosition;
|
||||
}
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Vector3 endPosition = Handles.PositionHandle(surface.EndPoint, handleRotation);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(surface, "Change Start Cylinder Position");
|
||||
surface.EndPoint = endPosition;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSurfaceVolume(CylinderSurface surface)
|
||||
{
|
||||
Vector3 start = surface.StartPoint;
|
||||
Vector3 end = surface.EndPoint;
|
||||
float radius = surface.Radius;
|
||||
|
||||
Handles.color = INTERACTABLE_COLOR;
|
||||
Handles.DrawWireArc(end,
|
||||
surface.Direction,
|
||||
surface.StartAngleDir,
|
||||
surface.Angle,
|
||||
radius);
|
||||
|
||||
Handles.DrawLine(start, end);
|
||||
Handles.DrawLine(start, start + surface.StartAngleDir * radius);
|
||||
Handles.DrawLine(start, start + surface.EndAngleDir * radius);
|
||||
Handles.DrawLine(end, end + surface.StartAngleDir * radius);
|
||||
Handles.DrawLine(end, end + surface.EndAngleDir * radius);
|
||||
|
||||
int edgePoints = Mathf.CeilToInt((2 * surface.Angle) / DRAW_SURFACE_ANGULAR_RESOLUTION) + 3;
|
||||
if (_surfaceEdges == null
|
||||
|| _surfaceEdges.Length != edgePoints)
|
||||
{
|
||||
_surfaceEdges = new Vector3[edgePoints];
|
||||
}
|
||||
|
||||
Handles.color = NONINTERACTABLE_COLOR;
|
||||
int i = 0;
|
||||
for (float angle = 0f; angle < surface.Angle; angle += DRAW_SURFACE_ANGULAR_RESOLUTION)
|
||||
{
|
||||
Vector3 direction = Quaternion.AngleAxis(angle, surface.Direction) * surface.StartAngleDir;
|
||||
_surfaceEdges[i++] = start + direction * radius;
|
||||
_surfaceEdges[i++] = end + direction * radius;
|
||||
}
|
||||
_surfaceEdges[i++] = start + surface.EndAngleDir * radius;
|
||||
_surfaceEdges[i++] = end + surface.EndAngleDir * radius;
|
||||
Handles.DrawPolyLine(_surfaceEdges);
|
||||
}
|
||||
|
||||
private void DrawArcEditor(CylinderSurface surface)
|
||||
{
|
||||
float radius = surface.Radius;
|
||||
_arcHandle.angle = surface.Angle;
|
||||
_arcHandle.radius = radius;
|
||||
|
||||
Matrix4x4 handleMatrix = Matrix4x4.TRS(
|
||||
surface.StartPoint,
|
||||
Quaternion.LookRotation(surface.StartAngleDir, surface.Direction),
|
||||
Vector3.one
|
||||
);
|
||||
using (new Handles.DrawingScope(handleMatrix))
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
_arcHandle.DrawHandle();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(surface, "Change Cylinder Properties");
|
||||
surface.Angle = _arcHandle.angle;
|
||||
radius = _arcHandle.radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69099ed7427360a4ab3734573c188647
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities 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 UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.HandPosing.SnapSurfaces.Editor
|
||||
{
|
||||
[CustomEditor(typeof(SphereSurface))]
|
||||
[CanEditMultipleObjects]
|
||||
public class SphereEditor : UnityEditor.Editor
|
||||
{
|
||||
private static readonly Color NONINTERACTABLE_COLOR = new Color(0f, 1f, 1f, 0.1f);
|
||||
private static readonly Color INTERACTABLE_COLOR = new Color(0f, 1f, 1f, 0.5f);
|
||||
|
||||
private SphereBoundsHandle _sphereHandle = new SphereBoundsHandle();
|
||||
private SphereSurface _surface;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_sphereHandle.SetColor(INTERACTABLE_COLOR);
|
||||
_sphereHandle.midpointHandleDrawFunction = null;
|
||||
|
||||
_surface = (target as SphereSurface);
|
||||
}
|
||||
|
||||
public void OnSceneGUI()
|
||||
{
|
||||
DrawCentre(_surface);
|
||||
Handles.color = Color.white;
|
||||
DrawSphereEditor(_surface);
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
DrawSurfaceVolume(_surface);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCentre(SphereSurface surface)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Quaternion handleRotation = (surface.RelativeTo ?? surface.transform).rotation;
|
||||
Vector3 centrePosition = Handles.PositionHandle(surface.Centre, handleRotation);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(surface, "Change Centre Sphere Position");
|
||||
surface.Centre = centrePosition;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSurfaceVolume(SphereSurface surface)
|
||||
{
|
||||
Handles.color = INTERACTABLE_COLOR;
|
||||
Vector3 startLine = surface.Centre;
|
||||
Vector3 endLine = startLine + surface.Rotation * Vector3.forward * surface.Radius;
|
||||
Handles.DrawDottedLine(startLine, endLine, 5);
|
||||
}
|
||||
private void DrawSphereEditor(SphereSurface surface)
|
||||
{
|
||||
_sphereHandle.radius = surface.Radius;
|
||||
_sphereHandle.center = surface.Centre;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
_sphereHandle.DrawHandle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee7657a153e652d448fa1b7775ca7f8c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user