-
Hi when i create a entity and insert a PbrBundle. it can display; fn dynamic_render_system(
asset_server: Res<AssetServer>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut commands: Commands,
query: Query<(Entity, &Transform), Added<Cube>>,
) {
const CUBLE_SIZE: f32 = 1.0;
let texture_handle: Handle<Image> = asset_server.load("a.jpg");
// 声明一个 2D 的贴图
let quad_handle = meshes.add(Mesh::from(shape::Quad::new(Vec2::new(
CUBLE_SIZE, CUBLE_SIZE,
))));
// 使用图片生成一种文理
let material_handle = materials.add(StandardMaterial {
base_color_texture: Some(texture_handle.clone()),
alpha_mode: AlphaMode::Blend,
unlit: true,
..default()
});
// 查询新增的 组件
for (ele, transform) in query.iter() {
// 这里 是测试代码 如果组件的 y 小于等于0就进行渲染
// info!("checked");
if transform.translation.y == 0.0 {
commands.entity(ele)
.add_children(|childern| {
childern.spawn_bundle(PbrBundle {
mesh: quad_handle.clone(),
material: material_handle.clone(),
transform: get_transform_by_face_type(
FaceType::Up,
Transform::from_xyz(0.0, 0.0, 0.0),
CUBLE_SIZE,
),
..Default::default()
});
}
}
} if i miss some tips please tell me? |
Beta Was this translation helpful? Give feedback.
Answered by
rparrett
Aug 14, 2022
Replies: 1 comment 1 reply
-
You don't show Root entities of hierarchies need |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
zzhgithub
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't show
ele
being spawned, but I would guess that it is missing some components that are required for visibility propagation.Root entities of hierarchies need
Visibility
andComputedVisibility
for visibility as well asTransform
andGlobalTransform
. You can spawn a SpatialBundle to get everything you need.