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

Function bloom_create_mesh

native/linux/src/lib.rs:1193–1214  ·  view source on GitHub ↗
(vertex_ptr: *const f64, vertex_count: f64, index_ptr: *const f64, index_count: f64)

Source from the content-addressed store, hash-verified

1191
1192#[no_mangle]
1193pub extern "C" fn bloom_create_mesh(vertex_ptr: *const f64, vertex_count: f64, index_ptr: *const f64, index_count: f64) -> f64 {
1194 // Perry's TS `number[]` is f64-laid-out in memory; Perry passes a
1195 // pointer to that data. A previous version of this FFI declared
1196 // *const f32 / *const u32, which silently read the low 4 bytes
1197 // of each f64 slot as garbage f32/u32 values — meshes registered
1198 // (non-zero handle) but were unrenderable.
1199 //
1200 // Caller must pass `vertex_count` and `index_count` derived from
1201 // a literal-initialized array OR from values it computed itself.
1202 // Don't compute these via `arr.length` after `.push()` — Perry's
1203 // `.length` property currently reflects the literal-init size,
1204 // not the post-push count (a Perry codegen bug). Workaround on
1205 // the TS side: track the count manually or use literal arrays.
1206 if vertex_ptr.is_null() || index_ptr.is_null() { return 0.0; }
1207 let vcount = vertex_count as usize;
1208 let icount = index_count as usize;
1209 let vertex_f64 = unsafe { std::slice::from_raw_parts(vertex_ptr, vcount * 12) };
1210 let index_f64 = unsafe { std::slice::from_raw_parts(index_ptr, icount) };
1211 let vertex_data: Vec<f32> = vertex_f64.iter().map(|&v| v as f32).collect();
1212 let index_data: Vec<u32> = index_f64.iter().map(|&v| v as u32).collect();
1213 engine().models.create_mesh(&vertex_data, &index_data)
1214}
1215
1216// ============================================================
1217// Phase 1c — material system FFI

Callers

nothing calls this directly

Calls 3

iterMethod · 0.80
create_meshMethod · 0.80
engineFunction · 0.70

Tested by

no test coverage detected