Skip to content

Commit

Permalink
improve support multiple meshes in gpu instancing
Browse files Browse the repository at this point in the history
  • Loading branch information
bertt committed Oct 16, 2024
1 parent a0c2589 commit a0cb718
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/GPUTileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,28 @@ private static SceneBuilder AddModels(IEnumerable<Instance> instances, Vector3 t
return sceneBuilder;
}


private static void AddModelInstancesToScene(SceneBuilder sceneBuilder, IEnumerable<Instance> instances, bool UseScaleNonUniform, Vector3 translation, string model)
{
var modelInstances = instances.Where(s => s.Model.Equals(model)).ToList();
var modelRoot = ModelRoot.Load(model);

var pointId = 0;

var meshbuilders = new List<IMeshBuilder<MaterialBuilder>>();
foreach (var mesh in modelRoot.LogicalMeshes)
{
var meshBuilder = mesh.ToMeshBuilder();
meshbuilders.Add(meshBuilder);
}

foreach (var instance in modelInstances)
{
foreach(var mesh in modelRoot.LogicalMeshes)
foreach (var meshBuilder in meshbuilders)
{
var meshBuilder = mesh.ToMeshBuilder(); // todo: what if there are multiple meshes?
var sceneBuilderModel = GetSceneBuilder(meshBuilder, instance, UseScaleNonUniform, translation, pointId);
sceneBuilder.AddScene(sceneBuilderModel, Matrix4x4.Identity);
}

pointId++;
}
}
Expand Down

0 comments on commit a0cb718

Please sign in to comment.