Skip to content

Commit 4e6abbb

Browse files
committed
Fmt.
1 parent 285cd46 commit 4e6abbb

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed

crates/processing_pyo3/examples/gltf_load.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ def draw():
2323
global frame
2424
t = frame * 0.02
2525

26-
radius = 150.0
26+
radius = 1.5
2727
lx = math.cos(t) * radius
28-
ly = 150.0
28+
ly = 1.5
2929
lz = math.sin(t) * radius
3030
light.position(lx, ly, lz)
31-
light.look_at(0.0, 80.0, 0.0)
31+
light.look_at(0.0, 0.8, 0.0)
3232

33-
r = math.sin(t * 0.7) * 0.5 + 0.5
34-
g = math.sin(t * 0.7 + 2.0) * 0.5 + 0.5
35-
b = math.sin(t * 0.7 + 4.0) * 0.5 + 0.5
33+
r = math.sin(t * 8.0) * 0.5 + 0.5
34+
g = math.sin(t * 8.0 + 2.0) * 0.5 + 0.5
35+
b = math.sin(t * 8.0 + 4.0) * 0.5 + 0.5
3636
duck_mat.set_float4("base_color", r, g, b, 1.0)
3737

3838
background(25)

crates/processing_pyo3/src/gltf.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ impl Gltf {
3333
}
3434

3535
pub fn camera(&self, index: usize) -> PyResult<()> {
36-
gltf_camera(self.entity, index)
37-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
36+
gltf_camera(self.entity, index).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
3837
}
3938

4039
pub fn light(&self, index: usize) -> PyResult<Light> {
41-
let entity = gltf_light(self.entity, index)
42-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
40+
let entity =
41+
gltf_light(self.entity, index).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
4342
Ok(Light { entity })
4443
}
4544
}
@@ -48,7 +47,7 @@ impl Gltf {
4847
#[pyo3(pass_module)]
4948
pub fn load_gltf(module: &Bound<'_, PyModule>, path: &str) -> PyResult<Gltf> {
5049
let graphics = get_graphics(module)?;
51-
let entity = gltf_load(graphics.entity, path)
52-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
50+
let entity =
51+
gltf_load(graphics.entity, path).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
5352
Ok(Gltf { entity })
5453
}

crates/processing_render/src/gltf.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use bevy::{
66
AssetPath, LoadState, handle_internal_asset_events,
77
io::{AssetSourceId, embedded::GetAssetServer},
88
},
9+
camera::visibility::RenderLayers,
910
ecs::system::RunSystemOnce,
1011
gltf::{Gltf, GltfMeshName},
1112
prelude::*,
12-
camera::visibility::RenderLayers,
1313
scene::SceneSpawner,
1414
};
1515

@@ -52,10 +52,7 @@ fn block_on_load(world: &mut World, load_state: impl Fn(&World) -> LoadState) ->
5252
}
5353

5454
fn compute_global_transform(world: &World, entity: Entity) -> Transform {
55-
let local = world
56-
.get::<Transform>(entity)
57-
.copied()
58-
.unwrap_or_default();
55+
let local = world.get::<Transform>(entity).copied().unwrap_or_default();
5956
match world.get::<ChildOf>(entity) {
6057
Some(child_of) => {
6158
let parent_global = compute_global_transform(world, child_of.parent());
@@ -99,14 +96,12 @@ pub fn load(
9996

10097
// we spawn the scene in to the world in a blocking fashion so that bevy runs all
10198
// its hooks for the gltf, ex creating standard material instances
102-
let instance_id =
103-
world.resource_scope(|world, mut spawner: Mut<SceneSpawner>| {
104-
spawner
105-
.spawn_sync(world, &scene_handle)
106-
.map_err(|e| ProcessingError::GltfLoadError(format!("Scene spawn failed: {e}")))
107-
})?;
99+
let instance_id = world.resource_scope(|world, mut spawner: Mut<SceneSpawner>| {
100+
spawner
101+
.spawn_sync(world, &scene_handle)
102+
.map_err(|e| ProcessingError::GltfLoadError(format!("Scene spawn failed: {e}")))
103+
})?;
108104

109-
110105
// we have to remove the existing cameras from the scene -- the user can request to set *this*
111106
// graphics to a camera, but the scenes cameras should not exist
112107
{
@@ -144,7 +139,7 @@ pub fn geometry(
144139

145140
let (mesh_handle, global_transform) = {
146141
let spawner = world.resource::<SceneSpawner>();
147-
142+
148143
// find the mesh with the given name component that bevy added post-spawn
149144
// name is derived from gltf node or computed
150145
let mesh_entity = spawner
@@ -248,17 +243,10 @@ pub fn material_names(In(gltf_entity): In<Entity>, world: &mut World) -> Result<
248243
let gltf = gltf_assets
249244
.get(&gltf_handle)
250245
.ok_or_else(|| ProcessingError::GltfLoadError("GLTF asset not found".into()))?;
251-
Ok(gltf
252-
.named_materials
253-
.keys()
254-
.map(|k| k.to_string())
255-
.collect())
246+
Ok(gltf.named_materials.keys().map(|k| k.to_string()).collect())
256247
}
257248

258-
pub fn camera(
259-
In((gltf_entity, index)): In<(Entity, usize)>,
260-
world: &mut World,
261-
) -> Result<()> {
249+
pub fn camera(In((gltf_entity, index)): In<(Entity, usize)>, world: &mut World) -> Result<()> {
262250
let gltf_handle = world
263251
.get::<GltfHandle>(gltf_entity)
264252
.ok_or(ProcessingError::InvalidEntity)?;
@@ -324,10 +312,7 @@ pub fn camera(
324312
Ok(())
325313
}
326314

327-
pub fn light(
328-
In((gltf_entity, index)): In<(Entity, usize)>,
329-
world: &mut World,
330-
) -> Result<Entity> {
315+
pub fn light(In((gltf_entity, index)): In<(Entity, usize)>, world: &mut World) -> Result<Entity> {
331316
let gltf_handle = world
332317
.get::<GltfHandle>(gltf_entity)
333318
.ok_or(ProcessingError::InvalidEntity)?;

crates/processing_render/src/render/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,13 @@ pub fn flush_draw_commands(
319319

320320
let z_offset = -(batch.draw_index as f32 * 0.001);
321321
let mut transform = state.transform.to_bevy_transform();
322-
322+
323323
// if the "source" geometry was parented in a gltf scene, we need to make sure that
324324
// we apply the parent transform here to ensure the correct final transform
325325
// TODO: think about how hierarchies should work, especially for retained
326326
if let Some(nt) = node_transform {
327-
transform = Transform::from_matrix(
328-
transform.to_matrix() * nt.0.to_matrix(),
329-
);
327+
transform =
328+
Transform::from_matrix(transform.to_matrix() * nt.0.to_matrix());
330329
}
331330
transform.translation.z += z_offset;
332331

0 commit comments

Comments
 (0)