UP-Viagg-io/LocalPackages/depthkit.studio/Editor/StudioMeshSourceGizmosDrawe...

57 lines
2.6 KiB
C#

/************************************************************************************
Depthkit Unity SDK License v1
Copyright 2016-2024 Simile Inc dba Scatter. All Rights reserved.
Licensed under the the Simile Inc dba Scatter ("Scatter")
Software Development Kit License Agreement (the "License");
you may not use this 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 http://www.depthkit.tv/license-agreement-v1
Unless required by applicable law or agreed to in writing,
the 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 UnityEngine;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using System.Linq;
using System.Collections.Generic;
using System;
namespace Depthkit
{
public class StudioMeshSourceGizmosDrawer
{
[DrawGizmo(GizmoType.Selected | GizmoType.Active)]
static void DrawGizmosFor(Depthkit.StudioMeshSource meshSource, GizmoType gizmoType)
{
if(meshSource.showLevelOfDetailGizmo)
{
Camera cam = Camera.main;
Vector3 origin = meshSource.transform.position + meshSource.volumeBounds.center;
Vector3 dir = (cam.transform.position - origin).normalized;
float segmentLength = (cam.farClipPlane / meshSource.levelOfDetailDistance) / meshSource.numLevelOfDetailLevels;
for(int i = 0; i < meshSource.numLevelOfDetailLevels; ++i)
{
Color c = Color.HSVToRGB(1.0f / (float)i, 1.0f, 1.0f);
Vector3 start = dir * segmentLength * i + origin;
Vector3 end = start + dir * segmentLength;
Gizmos.color = c;
Gizmos.DrawLine(start, end);
Matrix4x4 storedMatrix = Gizmos.matrix;
Gizmos.matrix = Matrix4x4.Translate(end - cam.transform.position);
Gizmos.matrix *= Matrix4x4.LookAt(cam.transform.position, origin, cam.transform.up);
Gizmos.DrawWireCube(Vector3.zero, new Vector3(1, 1, 0.001f));
Gizmos.matrix = storedMatrix;
}
}
}
}
}