mirror of
https://github.com/bevyengine/bevy
synced 2024-11-14 00:47:32 +00:00
Retrieve the stack_index
from Node
in extract_ui_material_nodes
instead of walking UiStack
(#15104)
# Objective `ExtractedUiMaterialNode` is still walking the whole `UiStack`. more info: https://github.com/bevyengine/bevy/pull/9853 ## Solution Retrieve the `stack_index` from the `Node` component instead. Also changed the `stack_index` field of `ExtractedUiMaterialNode` to `u32`.
This commit is contained in:
parent
66b5128b6f
commit
4de9edeaa6
1 changed files with 48 additions and 56 deletions
|
@ -327,7 +327,7 @@ impl<P: PhaseItem, M: UiMaterial> RenderCommand<P> for DrawUiMaterialNode<M> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExtractedUiMaterialNode<M: UiMaterial> {
|
pub struct ExtractedUiMaterialNode<M: UiMaterial> {
|
||||||
pub stack_index: usize,
|
pub stack_index: u32,
|
||||||
pub transform: Mat4,
|
pub transform: Mat4,
|
||||||
pub rect: Rect,
|
pub rect: Rect,
|
||||||
pub border: [f32; 4],
|
pub border: [f32; 4],
|
||||||
|
@ -355,7 +355,6 @@ impl<M: UiMaterial> Default for ExtractedUiMaterialNodes<M> {
|
||||||
pub fn extract_ui_material_nodes<M: UiMaterial>(
|
pub fn extract_ui_material_nodes<M: UiMaterial>(
|
||||||
mut extracted_uinodes: ResMut<ExtractedUiMaterialNodes<M>>,
|
mut extracted_uinodes: ResMut<ExtractedUiMaterialNodes<M>>,
|
||||||
materials: Extract<Res<Assets<M>>>,
|
materials: Extract<Res<Assets<M>>>,
|
||||||
ui_stack: Extract<Res<UiStack>>,
|
|
||||||
default_ui_camera: Extract<DefaultUiCamera>,
|
default_ui_camera: Extract<DefaultUiCamera>,
|
||||||
uinode_query: Extract<
|
uinode_query: Extract<
|
||||||
Query<
|
Query<
|
||||||
|
@ -386,12 +385,10 @@ pub fn extract_ui_material_nodes<M: UiMaterial>(
|
||||||
// If there is only one camera, we use it as default
|
// If there is only one camera, we use it as default
|
||||||
let default_single_camera = default_ui_camera.get();
|
let default_single_camera = default_ui_camera.get();
|
||||||
|
|
||||||
for (stack_index, entity) in ui_stack.uinodes.iter().enumerate() {
|
for (entity, uinode, style, transform, handle, view_visibility, clip, camera) in
|
||||||
if let Ok((entity, uinode, style, transform, handle, view_visibility, clip, camera)) =
|
uinode_query.iter()
|
||||||
uinode_query.get(*entity)
|
|
||||||
{
|
{
|
||||||
let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_single_camera)
|
let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_single_camera) else {
|
||||||
else {
|
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -411,24 +408,20 @@ pub fn extract_ui_material_nodes<M: UiMaterial>(
|
||||||
let left =
|
let left =
|
||||||
resolve_border_thickness(style.border.left, parent_width, ui_logical_viewport_size)
|
resolve_border_thickness(style.border.left, parent_width, ui_logical_viewport_size)
|
||||||
/ uinode.size().x;
|
/ uinode.size().x;
|
||||||
let right = resolve_border_thickness(
|
let right =
|
||||||
style.border.right,
|
resolve_border_thickness(style.border.right, parent_width, ui_logical_viewport_size)
|
||||||
parent_width,
|
/ uinode.size().x;
|
||||||
ui_logical_viewport_size,
|
|
||||||
) / uinode.size().x;
|
|
||||||
let top =
|
let top =
|
||||||
resolve_border_thickness(style.border.top, parent_width, ui_logical_viewport_size)
|
resolve_border_thickness(style.border.top, parent_width, ui_logical_viewport_size)
|
||||||
/ uinode.size().y;
|
/ uinode.size().y;
|
||||||
let bottom = resolve_border_thickness(
|
let bottom =
|
||||||
style.border.bottom,
|
resolve_border_thickness(style.border.bottom, parent_width, ui_logical_viewport_size)
|
||||||
parent_width,
|
/ uinode.size().y;
|
||||||
ui_logical_viewport_size,
|
|
||||||
) / uinode.size().y;
|
|
||||||
|
|
||||||
extracted_uinodes.uinodes.insert(
|
extracted_uinodes.uinodes.insert(
|
||||||
entity,
|
entity,
|
||||||
ExtractedUiMaterialNode {
|
ExtractedUiMaterialNode {
|
||||||
stack_index,
|
stack_index: uinode.stack_index,
|
||||||
transform: transform.compute_matrix(),
|
transform: transform.compute_matrix(),
|
||||||
material: handle.id(),
|
material: handle.id(),
|
||||||
rect: Rect {
|
rect: Rect {
|
||||||
|
@ -440,7 +433,6 @@ pub fn extract_ui_material_nodes<M: UiMaterial>(
|
||||||
camera_entity,
|
camera_entity,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue