Skip to content

Commit

Permalink
Fix LOD overrides for generateOnImport and meshSimplifierType
Browse files Browse the repository at this point in the history
  • Loading branch information
amirebrahimi committed Apr 26, 2018
1 parent 64715f0 commit d126b50
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Scripts/Editor/ModelImporterLODGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ struct MeshLOD
public Mesh inputMesh;
public Mesh outputMesh;
public float quality;
public Type meshSimplifierType;
}

void OnPostprocessModel(GameObject go)
{
if (enabled && !go.GetComponentInChildren<LODGroup>() && meshSimplifierType != null)
if (!go.GetComponentInChildren<LODGroup>() && meshSimplifierType != null)
{
if (go.GetComponentsInChildren<SkinnedMeshRenderer>().Any())
{
Expand Down Expand Up @@ -87,7 +88,7 @@ void OnPostprocessModel(GameObject go)

if (!overrideDefaults)
{
importSettings.generateOnImport = true;
importSettings.generateOnImport = enabled;
importSettings.meshSimplifier = meshSimplifierType.AssemblyQualifiedName;
importSettings.maxLODGenerated = maxLOD;
importSettings.initialLODMaxPolyCount = initialLODMaxPolyCount;
Expand All @@ -98,6 +99,8 @@ void OnPostprocessModel(GameObject go)

if (!overrideDefaults || importSettings.generateOnImport)
{
var simplifierType = Type.GetType(importSettings.meshSimplifier) ?? meshSimplifierType;

if (polyCount > importSettings.initialLODMaxPolyCount)
{
foreach (var mf in originalMeshFilters)
Expand All @@ -113,6 +116,7 @@ void OnPostprocessModel(GameObject go)
meshLOD.inputMesh = inputMesh;
meshLOD.outputMesh = outputMesh;
meshLOD.quality = (float)importSettings.initialLODMaxPolyCount / (float)polyCount;
meshLOD.meshSimplifierType = simplifierType;
meshLODs.Add(meshLOD);

preprocessMeshes.Add(outputMesh.GetInstanceID());
Expand Down Expand Up @@ -158,6 +162,7 @@ void OnPostprocessModel(GameObject go)
meshLOD.inputMesh = inputMesh;
meshLOD.outputMesh = outputMesh;
meshLOD.quality = Mathf.Pow(0.5f, i);
meshLOD.meshSimplifierType = simplifierType;
meshLODs.Add(meshLOD);
}

Expand Down Expand Up @@ -321,7 +326,7 @@ static void GenerateMeshLOD(MeshLOD meshLOD, HashSet<int> preprocessMeshes)
if (!preprocessMeshes.Contains(inputMeshID))
inputMesh = meshLOD.inputMesh.ToWorkingMesh();

var meshSimplifier = (IMeshSimplifier)Activator.CreateInstance(meshSimplifierType);
var meshSimplifier = (IMeshSimplifier)Activator.CreateInstance(meshLOD.meshSimplifierType);
#if !SINGLE_THREADED
var worker = new BackgroundWorker();
worker.DoWork += (sender, args) =>
Expand Down

0 comments on commit d126b50

Please sign in to comment.