@@ -25,20 +25,20 @@ use bevy_ecs::{
2525 query:: With ,
2626 resource:: Resource ,
2727 schedule:: IntoScheduleConfigs as _,
28- system:: { Query , Res , ResMut } ,
28+ system:: { Commands , Local , Query , Res , ResMut } ,
2929} ;
3030use bevy_image:: Image ;
3131use bevy_light:: { ClusteredDecal , DirectionalLightTexture , PointLightTexture , SpotLightTexture } ;
3232use bevy_math:: Mat4 ;
3333use bevy_platform:: collections:: HashMap ;
3434use bevy_render:: {
35- extract_component:: ExtractComponentPlugin ,
3635 render_asset:: RenderAssets ,
3736 render_resource:: {
3837 binding_types, BindGroupLayoutEntryBuilder , Buffer , BufferUsages , RawBufferVec , Sampler ,
3938 SamplerBindingType , ShaderType , TextureSampleType , TextureView ,
4039 } ,
4140 renderer:: { RenderAdapter , RenderDevice , RenderQueue } ,
41+ sync_component:: SyncComponentPlugin ,
4242 sync_world:: RenderEntity ,
4343 texture:: { FallbackImage , GpuImage } ,
4444 Extract , ExtractSchedule , Render , RenderApp , RenderSystems ,
@@ -142,7 +142,7 @@ impl Plugin for ClusteredDecalPlugin {
142142 fn build ( & self , app : & mut App ) {
143143 load_shader_library ! ( app, "clustered.wgsl" ) ;
144144
145- app. add_plugins ( ExtractComponentPlugin :: < ClusteredDecal > :: default ( ) ) ;
145+ app. add_plugins ( SyncComponentPlugin :: < ClusteredDecal > :: default ( ) ) ;
146146
147147 let Some ( render_app) = app. get_sub_app_mut ( RenderApp ) else {
148148 return ;
@@ -151,7 +151,7 @@ impl Plugin for ClusteredDecalPlugin {
151151 render_app
152152 . init_resource :: < DecalsBuffer > ( )
153153 . init_resource :: < RenderClusteredDecals > ( )
154- . add_systems ( ExtractSchedule , extract_decals)
154+ . add_systems ( ExtractSchedule , ( extract_decals, extract_clustered_decal ) )
155155 . add_systems (
156156 Render ,
157157 prepare_decals
@@ -165,6 +165,21 @@ impl Plugin for ClusteredDecalPlugin {
165165 }
166166}
167167
168+ // This is needed because of the orphan rule not allowing implementing
169+ // foreign trait ExtractComponent on foreign type ClusteredDecal
170+ fn extract_clustered_decal (
171+ mut commands : Commands ,
172+ mut previous_len : Local < usize > ,
173+ query : Extract < Query < ( RenderEntity , & ClusteredDecal ) > > ,
174+ ) {
175+ let mut values = Vec :: with_capacity ( * previous_len) ;
176+ for ( entity, query_item) in & query {
177+ values. push ( ( entity, query_item. clone ( ) ) ) ;
178+ }
179+ * previous_len = values. len ( ) ;
180+ commands. try_insert_batch ( values) ;
181+ }
182+
168183/// The GPU data structure that stores information about each decal.
169184#[ derive( Clone , Copy , Default , ShaderType , Pod , Zeroable ) ]
170185#[ repr( C ) ]
0 commit comments