smpl_gloss_integration/
conversions.rs1use burn::tensor::backend::Backend;
2use gloss_hecs::{CommandBuffer, Entity};
3use gloss_renderer::{
4 components::{Faces, ModelMatrix, Normals, Tangents, UVs, Verts, VisMesh, VisPoints},
5 scene::Scene,
6};
7use gloss_utils::tensor::{DynamicTensorFloat2D, DynamicTensorInt2D};
8use smpl_rs::common::smpl_model::SmplModel;
9#[allow(clippy::too_many_arguments)]
13#[allow(clippy::similar_names)]
14#[allow(clippy::too_many_lines)]
15pub fn update_entity_on_backend<B: Backend>(
16 entity: Entity,
17 scene: &Scene,
18 commands: &mut CommandBuffer,
19 with_uv: bool,
20 new_verts: &DynamicTensorFloat2D,
21 new_normals: &DynamicTensorFloat2D,
22 new_tangents: Option<DynamicTensorFloat2D>,
23 uv: DynamicTensorFloat2D,
24 faces: DynamicTensorInt2D,
25 _smpl_model: &dyn SmplModel<B>,
26) where
27 <B as Backend>::FloatTensorPrimitive<2>: Sync,
28 <B as Backend>::IntTensorPrimitive<2>: Sync,
29{
30 if with_uv && !scene.world.has::<UVs>(entity).unwrap() {
31 commands.insert_one(entity, UVs(uv));
32 }
33 if with_uv {
34 if let Some(tangents) = new_tangents {
35 commands.insert_one(entity, Tangents(tangents.clone()));
36 }
37 }
38 if !scene.world.has::<Faces>(entity).unwrap() {
39 commands.insert_one(entity, Faces(faces));
40 }
41 commands.insert_one(entity, Normals(new_normals.clone()));
42 commands.insert_one(entity, Verts(new_verts.clone()));
43 if !scene.world.has::<VisMesh>(entity).unwrap() {
44 commands.insert_one(
45 entity,
46 VisMesh {
47 added_automatically: true,
48 ..Default::default()
49 },
50 );
51 }
52 if !scene.world.has::<VisPoints>(entity).unwrap() {
53 commands.insert_one(
54 entity,
55 VisPoints {
56 added_automatically: true,
57 ..Default::default()
58 },
59 );
60 }
61 if !scene.world.has::<ModelMatrix>(entity).unwrap() {
62 commands.insert_one(entity, ModelMatrix::default());
63 }
64}