阶段性完成
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace AutoLOD.MeshDecimator
|
||||
{
|
||||
public enum MeshDecimatorBackend
|
||||
{
|
||||
Fast = 0,
|
||||
HighQuality
|
||||
}
|
||||
|
||||
public class AutoLODProperties : Editor
|
||||
{
|
||||
|
||||
public Renderer _target;
|
||||
public bool _customSettings = false;
|
||||
public MeshDecimatorBackend _backend = MeshDecimatorBackend.HighQuality;
|
||||
public bool _foldout = false;
|
||||
public bool _lodGroupFoldout = false;
|
||||
|
||||
public int _lodLevels = 4;
|
||||
public float _reductionRate = 2f;
|
||||
public bool _autoReductionRate = true;
|
||||
public float _performance = 0.5f;
|
||||
public float _relativeHeightCulling = 0.002f;
|
||||
public bool _flatShading = false;
|
||||
|
||||
public bool _writeMeshOnDisk;
|
||||
public string _filePath;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_filePath = (EditorPrefs.GetString("autolodDefaultExportFolder", "Assets/AutoLOD/Generated")).Replace("//", "/");
|
||||
if (_filePath.StartsWith("Assets/"))
|
||||
_filePath = _filePath.Substring(7);
|
||||
}
|
||||
|
||||
public void Apply(AutoLODProperties other)
|
||||
{
|
||||
_customSettings = false;
|
||||
_backend = other._backend;
|
||||
_foldout = false;
|
||||
_lodGroupFoldout = false;
|
||||
_lodLevels = other._lodLevels;
|
||||
_reductionRate = other._reductionRate;
|
||||
_autoReductionRate = other._autoReductionRate;
|
||||
_performance = other._performance;
|
||||
_relativeHeightCulling = other._relativeHeightCulling;
|
||||
_flatShading = other._flatShading;
|
||||
_writeMeshOnDisk = other._writeMeshOnDisk;
|
||||
_filePath = other._filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9f2f7c8778fe6542bceb35a43d41150
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1 @@
|
||||
// This file is no longer required since AutoLOD 5.0
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bd03e1fdccd55b469c60491ab81d186
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
73
Assets/OtherPlugins/AutoLOD/Scripts/Tools/MeshUtility.cs
Normal file
73
Assets/OtherPlugins/AutoLOD/Scripts/Tools/MeshUtility.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AutoLOD.MeshDecimator {
|
||||
public class AutoLODMeshUtility
|
||||
{
|
||||
public static void Smooth2FlatShading(Mesh mesh)
|
||||
{
|
||||
Vector3[] oldVerts = mesh.vertices;
|
||||
Vector2[] oldUv = mesh.uv;
|
||||
Vector2[] oldUv2 = mesh.uv2;
|
||||
Vector2[] oldUv3 = mesh.uv3;
|
||||
Vector2[] oldUv4 = mesh.uv4;
|
||||
Color[] oldColors = mesh.colors;
|
||||
BoneWeight[] oldBoneWeights = mesh.boneWeights;
|
||||
|
||||
bool hasUv = oldUv.Length != 0;
|
||||
bool hasUv2 = oldUv2.Length != 0;
|
||||
bool hasUv3 = oldUv3.Length != 0;
|
||||
bool hasUv4 = oldUv4.Length != 0;
|
||||
bool hasColors = oldColors.Length != 0;
|
||||
bool hasBones = oldBoneWeights.Length != 0;
|
||||
|
||||
List<Vector3> newVertices = new List<Vector3>();
|
||||
List<int>[] newTriangles = new List<int>[mesh.subMeshCount];
|
||||
List<Vector2> newUv = new List<Vector2>();
|
||||
List<Vector2> newUv2 = new List<Vector2>();
|
||||
List<Vector2> newUv3 = new List<Vector2>();
|
||||
List<Vector2> newUv4 = new List<Vector2>();
|
||||
List<Color> newColors = new List<Color>();
|
||||
List<BoneWeight> newBoneWeights = new List<BoneWeight>();
|
||||
|
||||
for (int submesh = 0; submesh < mesh.subMeshCount; submesh++)
|
||||
{
|
||||
int[] submeshTriangles = mesh.GetTriangles(submesh);
|
||||
newTriangles[submesh] = new List<int>();
|
||||
|
||||
for (int i = 0; i < submeshTriangles.Length; i++)
|
||||
{
|
||||
int vertexIndex = submeshTriangles[i];
|
||||
|
||||
newVertices.Add(oldVerts[vertexIndex]);
|
||||
newTriangles[submesh].Add(newVertices.Count - 1);
|
||||
|
||||
if (hasUv) newUv.Add(oldUv[vertexIndex]);
|
||||
if (hasUv2) newUv2.Add(oldUv2[vertexIndex]);
|
||||
if (hasUv3) newUv3.Add(oldUv3[vertexIndex]);
|
||||
if (hasUv4) newUv4.Add(oldUv4[vertexIndex]);
|
||||
if (hasColors) newColors.Add(oldColors[vertexIndex]);
|
||||
if (hasBones) newBoneWeights.Add(oldBoneWeights[vertexIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
if (newVertices.Count > 65535)
|
||||
mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
|
||||
|
||||
mesh.vertices = newVertices.ToArray();
|
||||
if (hasUv) mesh.uv = newUv.ToArray();
|
||||
if (hasUv2) mesh.uv2 = newUv2.ToArray();
|
||||
if (hasUv3) mesh.uv3 = newUv3.ToArray();
|
||||
if (hasUv4) mesh.uv4 = newUv4.ToArray();
|
||||
if (hasColors) mesh.colors = newColors.ToArray();
|
||||
if (hasBones) mesh.boneWeights = newBoneWeights.ToArray();
|
||||
|
||||
for (int submesh = 0; submesh < mesh.subMeshCount; submesh++)
|
||||
{
|
||||
mesh.SetTriangles(newTriangles[submesh].ToArray(), submesh);
|
||||
}
|
||||
|
||||
mesh.RecalculateNormals();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfe480a8f5a43764c940787b8ea8535f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user