Skip to content

Commit

Permalink
Add support for NoAutomaticBatching and hence fix skinned/morphed mes…
Browse files Browse the repository at this point in the history
…hes.
  • Loading branch information
komadori committed Jul 21, 2024
1 parent 664be88 commit 185c50d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ impl GetBatchData for OutlinePipeline {
entity: Entity,
) -> Option<(Self::BufferData, Option<Self::CompareData>)> {
let outline = outline_query.get(entity).unwrap();
Some((outline.instance_data.clone(), Some(outline.mesh_id)))
Some((
outline.instance_data.clone(),
outline.automatic_batching.then_some(outline.mesh_id),
))
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/uniforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy::{
math::Affine3,
prelude::*,
render::{
batching::no_gpu_preprocessing::BatchedInstanceBuffer,
batching::{no_gpu_preprocessing::BatchedInstanceBuffer, NoAutomaticBatching},
render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass},
render_resource::{BindGroup, BindGroupEntry, ShaderType},
renderer::RenderDevice,
Expand All @@ -17,6 +17,7 @@ use crate::{pipeline::OutlinePipeline, ComputedOutline};
pub(crate) struct ExtractedOutline {
pub depth_mode: DepthMode,
pub mesh_id: AssetId<Mesh>,
pub automatic_batching: bool,
pub instance_data: OutlineInstanceUniform,
}

Expand Down Expand Up @@ -59,14 +60,23 @@ pub(crate) fn set_outline_visibility(mut query: Query<(&mut ViewVisibility, &Com
#[allow(clippy::type_complexity)]
pub(crate) fn extract_outline_uniforms(
mut commands: Commands,
query: Extract<Query<(Entity, &ComputedOutline, &GlobalTransform, &Handle<Mesh>)>>,
query: Extract<
Query<(
Entity,
&ComputedOutline,
&GlobalTransform,
&Handle<Mesh>,
Has<NoAutomaticBatching>,
)>,
>,
) {
for (entity, computed, transform, mesh) in query.iter() {
for (entity, computed, transform, mesh, no_automatic_batching) in query.iter() {
let cmds = &mut commands.get_or_spawn(entity);
if let ComputedOutline(Some(computed)) = computed {
cmds.insert(ExtractedOutline {
depth_mode: computed.mode.value.depth_mode,
mesh_id: mesh.id(),
automatic_batching: !no_automatic_batching,
instance_data: OutlineInstanceUniform {
world_from_local: Affine3::from(&transform.affine()).to_transpose(),
origin_in_world: computed.mode.value.world_origin,
Expand Down

0 comments on commit 185c50d

Please sign in to comment.