MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / cache_model_if_static

Method cache_model_if_static

native/shared/src/renderer/mod.rs:12289–12340  ·  view source on GitHub ↗

Returns true if the model was cached successfully (static model). Returns false if the model is skinned (uncacheable).

(&mut self, handle_bits: u64, meshes: &[crate::models::MeshData])

Source from the content-addressed store, hash-verified

12287 /// Returns true if the model was cached successfully (static model).
12288 /// Returns false if the model is skinned (uncacheable).
12289 pub fn cache_model_if_static(&mut self, handle_bits: u64, meshes: &[crate::models::MeshData]) -> bool {
12290 if let Some(entry) = self.model_gpu_cache.get(&handle_bits) {
12291 return entry.is_some();
12292 }
12293
12294 // Check if any vertex is skinned
12295 let is_skinned = meshes.iter().any(|m|
12296 m.vertices.iter().any(|v| v.weights[0] + v.weights[1] + v.weights[2] + v.weights[3] > 0.01));
12297
12298 if is_skinned {
12299 self.model_gpu_cache.insert(handle_bits, None);
12300 return false;
12301 }
12302
12303 let gpu_meshes: Vec<GpuMesh> = meshes.iter().map(|mesh| {
12304 let vb = self.device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
12305 label: Some("cached_model_vb"),
12306 contents: bytemuck::cast_slice(&mesh.vertices),
12307 usage: wgpu::BufferUsages::VERTEX,
12308 });
12309 let ib = self.device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
12310 label: Some("cached_model_ib"),
12311 contents: bytemuck::cast_slice(&mesh.indices),
12312 usage: wgpu::BufferUsages::INDEX,
12313 });
12314 let base_color_idx = mesh.texture_idx.unwrap_or(0);
12315 let normal_idx = mesh.normal_texture_idx.unwrap_or(0);
12316 let mr_idx = mesh.metallic_roughness_texture_idx.unwrap_or(0);
12317 let em_idx = mesh.emissive_texture_idx.unwrap_or(0);
12318 let occ_idx = mesh.occlusion_texture_idx.unwrap_or(0);
12319 let material_uniform = self.create_scene_material_uniform(
12320 mesh.metallic_factor,
12321 mesh.roughness_factor,
12322 mesh.emissive_factor,
12323 mesh.metallic_roughness_texture_idx.is_some(),
12324 mesh.alpha_cutoff,
12325 );
12326 let material_bg = self.create_scene_material_bg(
12327 base_color_idx, normal_idx, mr_idx, em_idx, occ_idx, &material_uniform,
12328 );
12329 GpuMesh {
12330 vb,
12331 ib,
12332 index_count: mesh.indices.len() as u32,
12333 material_bg,
12334 _material_uniform: material_uniform,
12335 }
12336 }).collect();
12337
12338 self.model_gpu_cache.insert(handle_bits, Some(gpu_meshes));
12339 true
12340 }
12341
12342 /// Record a cached model draw command. The actual rendering happens in end_frame().
12343 pub fn draw_model_cached(&mut self, handle_bits: u64, position: [f32; 3], scale: f32, tint: [f32; 4]) {

Callers 15

bloom_draw_modelFunction · 0.80
bloom_draw_materialFunction · 0.80
bloom_draw_modelFunction · 0.80
bloom_draw_materialFunction · 0.80
bloom_draw_modelFunction · 0.80
bloom_draw_materialFunction · 0.80
bloom_draw_modelFunction · 0.80
bloom_draw_materialFunction · 0.80

Calls 4

iterMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected