(vertex_ptr: *const f64, vertex_count: f64, index_ptr: *const f64, index_count: f64)
| 1191 | |
| 1192 | #[no_mangle] |
| 1193 | pub 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 |
nothing calls this directly
no test coverage detected