Skip to content

Commit 3fc2bd7

Browse files
authored
Cosmetic tweaks to query_gltf_primitives (bevyengine#16102)
# Objective This example is really confusing to look at and tell at a glance whether it's broken or not. It's displaying a strange shape -- a cube with two vertices stretched in a couple dimensions at an odd angle, and doing its vertex position modification in a way where the intent isn't obvious. ## Solution - Change the gltf geometry so that the object is a recognizable regular shape - Change the vertex modification so that the entire cube top is being "lifted" from the cube - Adjust colors, lighting, and camera location so we can see what's going on - Also remove some irrelevant shadow and environment map setup ## Before ![Image](https://github.com/user-attachments/assets/e5dd5075-0480-49d4-b1ed-cf1fe6106f3c) ## After <img width="1280" alt="image" src="https://github.com/user-attachments/assets/59cab60d-efbc-47c3-8688-e4544b462421">
1 parent 7451900 commit 3fc2bd7

File tree

2 files changed

+17
-44
lines changed

2 files changed

+17
-44
lines changed
-112 Bytes
Binary file not shown.

examples/3d/query_gltf_primitives.rs

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
44
use std::f32::consts::PI;
55

6-
use bevy::{
7-
gltf::GltfMaterialName,
8-
pbr::{CascadeShadowConfigBuilder, DirectionalLightShadowMap},
9-
prelude::*,
10-
render::mesh::VertexAttributeValues,
11-
};
6+
use bevy::{gltf::GltfMaterialName, prelude::*, render::mesh::VertexAttributeValues};
127

138
fn main() {
149
App::new()
15-
.insert_resource(DirectionalLightShadowMap { size: 4096 })
1610
.add_plugins(DefaultPlugins)
1711
.add_systems(Startup, setup)
1812
.add_systems(Update, find_top_material_and_mesh)
@@ -36,20 +30,22 @@ fn find_top_material_and_mesh(
3630
if let Color::Hsla(ref mut hsla) = material.base_color {
3731
*hsla = hsla.rotate_hue(time.delta_secs() * 100.0);
3832
} else {
39-
material.base_color = Color::from(Hsla::hsl(0.0, 0.8, 0.5));
33+
material.base_color = Color::from(Hsla::hsl(0.0, 0.9, 0.7));
4034
}
4135
}
4236

4337
if let Some(mesh) = meshes.get_mut(mesh_handle) {
4438
if let Some(VertexAttributeValues::Float32x3(positions)) =
4539
mesh.attribute_mut(Mesh::ATTRIBUTE_POSITION)
4640
{
47-
positions[0] = (
48-
ops::sin(2.0 * PI * time.elapsed_secs()),
49-
positions[0][1],
50-
positions[0][2],
51-
)
52-
.into();
41+
for position in positions {
42+
*position = (
43+
position[0],
44+
1.5 + 0.5 * ops::sin(time.elapsed_secs() / 2.0),
45+
position[2],
46+
)
47+
.into();
48+
}
5349
}
5450
}
5551
}
@@ -59,38 +55,15 @@ fn find_top_material_and_mesh(
5955
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
6056
commands.spawn((
6157
Camera3d::default(),
62-
Transform::from_xyz(0.6, 1.6, 11.3).looking_at(Vec3::new(0.0, 0.0, 3.0), Vec3::Y),
63-
EnvironmentMapLight {
64-
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
65-
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
66-
intensity: 500.0,
67-
rotation: Quat::IDENTITY,
68-
},
58+
Transform::from_xyz(4.0, 4.0, 12.0).looking_at(Vec3::new(0.0, 0.0, 0.5), Vec3::Y),
6959
));
7060

7161
commands.spawn((
72-
DirectionalLight {
73-
shadows_enabled: true,
74-
..default()
75-
},
76-
// This is a relatively small scene, so use tighter shadow
77-
// cascade bounds than the default for better quality.
78-
// We also adjusted the shadow map to be larger since we're
79-
// only using a single cascade.
80-
CascadeShadowConfigBuilder {
81-
num_cascades: 1,
82-
maximum_distance: 1.6,
83-
..default()
84-
}
85-
.build(),
86-
));
87-
commands.spawn((
88-
SceneRoot(asset_server.load(
89-
GltfAssetLabel::Scene(0).from_asset("models/GltfPrimitives/gltf_primitives.glb"),
90-
)),
91-
Transform {
92-
rotation: Quat::from_rotation_y(-90.0 / 180.0 * PI),
93-
..default()
94-
},
62+
Transform::from_rotation(Quat::from_euler(EulerRot::ZYX, 0.0, 1.0, -PI / 4.)),
63+
DirectionalLight::default(),
9564
));
65+
66+
commands.spawn(SceneRoot(asset_server.load(
67+
GltfAssetLabel::Scene(0).from_asset("models/GltfPrimitives/gltf_primitives.glb"),
68+
)));
9669
}

0 commit comments

Comments
 (0)