@@ -485,6 +485,8 @@ pub struct MeshUniform {
485
485
/// Low 16 bits: index of the material inside the bind group data.
486
486
/// High 16 bits: index of the lightmap in the binding array.
487
487
pub material_and_lightmap_bind_group_slot : u32 ,
488
+ /// User supplied tag to identify this mesh instance.
489
+ pub tag : u32 ,
488
490
}
489
491
490
492
/// Information that has to be transferred from CPU to GPU in order to produce
@@ -541,10 +543,10 @@ pub struct MeshInputUniform {
541
543
/// Low 16 bits: index of the material inside the bind group data.
542
544
/// High 16 bits: index of the lightmap in the binding array.
543
545
pub material_and_lightmap_bind_group_slot : u32 ,
546
+ /// User supplied tag to identify this mesh instance.
547
+ pub tag : u32 ,
544
548
/// Padding.
545
- pub pad_a : u32 ,
546
- /// Padding.
547
- pub pad_b : u32 ,
549
+ pub pad : u32 ,
548
550
}
549
551
550
552
/// Information about each mesh instance needed to cull it on GPU.
@@ -578,6 +580,7 @@ impl MeshUniform {
578
580
maybe_lightmap : Option < ( LightmapSlotIndex , Rect ) > ,
579
581
current_skin_index : Option < u32 > ,
580
582
previous_skin_index : Option < u32 > ,
583
+ tag : Option < u32 > ,
581
584
) -> Self {
582
585
let ( local_from_world_transpose_a, local_from_world_transpose_b) =
583
586
mesh_transforms. world_from_local . inverse_transpose_3x3 ( ) ;
@@ -598,6 +601,7 @@ impl MeshUniform {
598
601
previous_skin_index : previous_skin_index. unwrap_or ( u32:: MAX ) ,
599
602
material_and_lightmap_bind_group_slot : u32:: from ( material_bind_group_slot)
600
603
| ( ( lightmap_bind_group_slot as u32 ) << 16 ) ,
604
+ tag : tag. unwrap_or ( 0 ) ,
601
605
}
602
606
}
603
607
}
@@ -729,6 +733,8 @@ pub struct RenderMeshInstanceShared {
729
733
/// Index of the slab that the lightmap resides in, if a lightmap is
730
734
/// present.
731
735
pub lightmap_slab_index : Option < LightmapSlabIndex > ,
736
+ /// User supplied tag to identify this mesh instance.
737
+ pub tag : u32 ,
732
738
}
733
739
734
740
/// Information that is gathered during the parallel portion of mesh extraction
@@ -808,6 +814,7 @@ impl RenderMeshInstanceShared {
808
814
fn from_components (
809
815
previous_transform : Option < & PreviousGlobalTransform > ,
810
816
mesh : & Mesh3d ,
817
+ tag : Option < & MeshTag > ,
811
818
not_shadow_caster : bool ,
812
819
no_automatic_batching : bool ,
813
820
) -> Self {
@@ -828,6 +835,7 @@ impl RenderMeshInstanceShared {
828
835
// This gets filled in later, during `RenderMeshGpuBuilder::update`.
829
836
material_bindings_index : default ( ) ,
830
837
lightmap_slab_index : None ,
838
+ tag : tag. map_or ( 0 , |i| * * i) ,
831
839
}
832
840
}
833
841
@@ -1160,8 +1168,8 @@ impl RenderMeshInstanceGpuBuilder {
1160
1168
material_and_lightmap_bind_group_slot : u32:: from (
1161
1169
self . shared . material_bindings_index . slot ,
1162
1170
) | ( ( lightmap_slot as u32 ) << 16 ) ,
1163
- pad_a : 0 ,
1164
- pad_b : 0 ,
1171
+ tag : self . shared . tag ,
1172
+ pad : 0 ,
1165
1173
} ;
1166
1174
1167
1175
// Did the last frame contain this entity as well?
@@ -1296,6 +1304,7 @@ pub fn extract_meshes_for_cpu_building(
1296
1304
& GlobalTransform ,
1297
1305
Option < & PreviousGlobalTransform > ,
1298
1306
& Mesh3d ,
1307
+ Option < & MeshTag > ,
1299
1308
Has < NoFrustumCulling > ,
1300
1309
Has < NotShadowReceiver > ,
1301
1310
Has < TransmittedShadowReceiver > ,
@@ -1314,6 +1323,7 @@ pub fn extract_meshes_for_cpu_building(
1314
1323
transform,
1315
1324
previous_transform,
1316
1325
mesh,
1326
+ tag,
1317
1327
no_frustum_culling,
1318
1328
not_shadow_receiver,
1319
1329
transmitted_receiver,
@@ -1341,6 +1351,7 @@ pub fn extract_meshes_for_cpu_building(
1341
1351
let shared = RenderMeshInstanceShared :: from_components (
1342
1352
previous_transform,
1343
1353
mesh,
1354
+ tag,
1344
1355
not_shadow_caster,
1345
1356
no_automatic_batching,
1346
1357
) ;
@@ -1402,6 +1413,7 @@ pub fn extract_meshes_for_gpu_building(
1402
1413
Option < & Lightmap > ,
1403
1414
Option < & Aabb > ,
1404
1415
& Mesh3d ,
1416
+ Option < & MeshTag > ,
1405
1417
Has < NoFrustumCulling > ,
1406
1418
Has < NotShadowReceiver > ,
1407
1419
Has < TransmittedShadowReceiver > ,
@@ -1459,6 +1471,7 @@ pub fn extract_meshes_for_gpu_building(
1459
1471
lightmap,
1460
1472
aabb,
1461
1473
mesh,
1474
+ tag,
1462
1475
no_frustum_culling,
1463
1476
not_shadow_receiver,
1464
1477
transmitted_receiver,
@@ -1487,6 +1500,7 @@ pub fn extract_meshes_for_gpu_building(
1487
1500
let shared = RenderMeshInstanceShared :: from_components (
1488
1501
previous_transform,
1489
1502
mesh,
1503
+ tag,
1490
1504
not_shadow_caster,
1491
1505
no_automatic_batching,
1492
1506
) ;
@@ -1840,6 +1854,7 @@ impl GetBatchData for MeshPipeline {
1840
1854
maybe_lightmap. map ( |lightmap| ( lightmap. slot_index , lightmap. uv_rect ) ) ,
1841
1855
current_skin_index,
1842
1856
previous_skin_index,
1857
+ Some ( mesh_instance. tag ) ,
1843
1858
) ,
1844
1859
mesh_instance. should_batch ( ) . then_some ( (
1845
1860
material_bind_group_index. group ,
@@ -1907,6 +1922,7 @@ impl GetFullBatchData for MeshPipeline {
1907
1922
maybe_lightmap. map ( |lightmap| ( lightmap. slot_index , lightmap. uv_rect ) ) ,
1908
1923
current_skin_index,
1909
1924
previous_skin_index,
1925
+ Some ( mesh_instance. tag ) ,
1910
1926
) )
1911
1927
}
1912
1928
0 commit comments