store typed id directly in hashmaps
This commit is contained in:
parent
012d2d1837
commit
926e57790e
@ -47,42 +47,42 @@ pub fn convert(roblox_physics_data:&[u8])->Result<model::Mesh,Error>{
|
||||
let mut vertex_id_from=HashMap::new();
|
||||
let mut acquire_pos_id=|pos|{
|
||||
let p=vec3::try_from_f32_array(pos).map_err(Error::Planar64Vec3)?;
|
||||
Ok(PositionId::new(*pos_id_from.entry(p).or_insert_with(||{
|
||||
let pos_id=unique_pos.len();
|
||||
Ok(*pos_id_from.entry(p).or_insert_with(||{
|
||||
let pos_id=PositionId::new(unique_pos.len() as u32);
|
||||
unique_pos.push(p);
|
||||
pos_id
|
||||
}) as u32))
|
||||
}))
|
||||
};
|
||||
let mut acquire_tex_id=|tex|{
|
||||
let h=bytemuck::cast::<[f32;2],[u32;2]>(tex);
|
||||
TextureCoordinateId::new(*tex_id_from.entry(h).or_insert_with(||{
|
||||
let tex_id=unique_tex.len();
|
||||
*tex_id_from.entry(h).or_insert_with(||{
|
||||
let tex_id=TextureCoordinateId::new(unique_tex.len() as u32);
|
||||
unique_tex.push(glam::Vec2::from_array(tex));
|
||||
tex_id
|
||||
}) as u32)
|
||||
})
|
||||
};
|
||||
let mut acquire_normal_id=|normal|{
|
||||
let n=vec3::try_from_f32_array(normal).map_err(Error::Planar64Vec3)?;
|
||||
Ok(NormalId::new(*normal_id_from.entry(n).or_insert_with(||{
|
||||
let normal_id=unique_normal.len();
|
||||
Ok(*normal_id_from.entry(n).or_insert_with(||{
|
||||
let normal_id=NormalId::new(unique_normal.len() as u32);
|
||||
unique_normal.push(n);
|
||||
normal_id
|
||||
}) as u32))
|
||||
}))
|
||||
};
|
||||
let mut acquire_color_id=|color|{
|
||||
let h=bytemuck::cast::<[f32;4],[u32;4]>(color);
|
||||
ColorId::new(*color_id_from.entry(h).or_insert_with(||{
|
||||
let color_id=unique_color.len();
|
||||
*color_id_from.entry(h).or_insert_with(||{
|
||||
let color_id=ColorId::new(unique_color.len() as u32);
|
||||
unique_color.push(glam::Vec4::from_array(color));
|
||||
color_id
|
||||
}) as u32)
|
||||
})
|
||||
};
|
||||
let mut acquire_vertex_id=|vertex:IndexedVertex|{
|
||||
VertexId::new(*vertex_id_from.entry(vertex.clone()).or_insert_with(||{
|
||||
let vertex_id=unique_vertices.len();
|
||||
*vertex_id_from.entry(vertex.clone()).or_insert_with(||{
|
||||
let vertex_id=VertexId::new(unique_vertices.len() as u32);
|
||||
unique_vertices.push(vertex);
|
||||
vertex_id
|
||||
}) as u32)
|
||||
})
|
||||
};
|
||||
let color=acquire_color_id([1.0f32;4]);
|
||||
let tex=acquire_tex_id([0.0f32;2]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user