Skip to content

Commit

Permalink
Search for matching material names rather than having to specify them…
Browse files Browse the repository at this point in the history
… manually when compiling a model
  • Loading branch information
xezno committed Sep 10, 2024
1 parent 6c44341 commit 9f9a2c8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Source/MochaTool.AssetCompiler/Handlers/Model/Assimp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,27 @@ private static Model ProcessMesh( Mesh mesh, Scene scene, Matrix4x4 transform, M

string material = "internal:missing";

if ( mesh.MaterialIndex >= 0 && mesh.MaterialIndex < modelInfo.Materials.Count )
var materialSearchName = scene.Materials[mesh.MaterialIndex].Name;
var searchPaths = new[]
{
$"materials/{materialSearchName}.mmat",
$"materials/{materialSearchName}/{materialSearchName}.mmat",
$"textures/{materialSearchName}/{materialSearchName}.mmat",
$"textures/{materialSearchName}.mmat",
};
var materialWasFound = false;

foreach ( var searchPath in searchPaths )
{
if ( FileSystem.Mounted.Exists( searchPath ) )
{
material = searchPath;
materialWasFound = true;
break;
}
}

if ( !materialWasFound && mesh.MaterialIndex >= 0 && mesh.MaterialIndex < modelInfo.Materials.Count )
material = modelInfo.Materials[mesh.MaterialIndex];

return new Model( vertices.ToArray(), indices.ToArray(), material );
Expand Down

0 comments on commit 9f9a2c8

Please sign in to comment.