Skip to content

Commit

Permalink
Added ModelImporter.GenerateColliders option to auto add MeshColliders
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsakharov committed Apr 16, 2024
1 parent ea35cc4 commit 446f097
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Prowl.Editor/Assets/Importers/ModelImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ModelImporter : ScriptedImporter
{
public static readonly string[] Supported = { ".obj", ".blend", ".dae", ".fbx", ".gltf", ".ply", ".pmx", ".stl" };

public bool GenerateColliders = false;
public bool GenerateNormals = true;
public bool GenerateSmoothNormals = false;
public bool CalculateTangentSpace = true;
Expand Down Expand Up @@ -199,7 +200,7 @@ public override void Import(SerializedAsset ctx, FileInfo assetPath)
ctx.SetMainObject(rootNode);
}

static void AddMeshComponent(List<(GameObject, Node)> GOs, GameObject go, MeshMaterialBinding uMeshAndMat)
void AddMeshComponent(List<(GameObject, Node)> GOs, GameObject go, MeshMaterialBinding uMeshAndMat)
{
if (uMeshAndMat.AMesh.HasBones)
{
Expand All @@ -216,6 +217,12 @@ static void AddMeshComponent(List<(GameObject, Node)> GOs, GameObject go, MeshMa
mr.Mesh = uMeshAndMat.Mesh;
mr.Material = uMeshAndMat.Material;
}

if (GenerateColliders)
{
var mc = go.AddComponent<MeshCollider>();
mc.mesh = uMeshAndMat.Mesh;
}
}
}

Expand Down Expand Up @@ -681,6 +688,7 @@ public override void OnInspectorGUI()

private static void Meshes(ModelImporter importer, SerializedAsset? serialized)
{
ImGui.Checkbox("Generate Mesh Colliders", ref importer.GenerateColliders);
ImGui.Checkbox("Generate Normals", ref importer.GenerateNormals);
if (importer.GenerateNormals)
ImGui.Checkbox("Generate Smooth Normals", ref importer.GenerateSmoothNormals);
Expand Down

0 comments on commit 446f097

Please sign in to comment.