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

Function read_f32_vec

native/watchos/src/models.rs:504–528  ·  view source on GitHub ↗

Resolve accessor → raw float slice from the bin chunk. `components` is the expected vector width (3 for position/normal, 2 for uv). glTF stores accessor.componentType = 5126 (FLOAT) for these.

(
    accessors: &[JVal], buf_views: &[JVal], bin: &[u8],
    acc_idx: usize, components: usize,
)

Source from the content-addressed store, hash-verified

502/// the expected vector width (3 for position/normal, 2 for uv). glTF stores
503/// accessor.componentType = 5126 (FLOAT) for these.
504fn read_f32_vec(
505 accessors: &[JVal], buf_views: &[JVal], bin: &[u8],
506 acc_idx: usize, components: usize,
507) -> Option<Vec<f32>> {
508 let acc = accessors.get(acc_idx)?;
509 let bv_idx = acc.get("bufferView")?.num()? as usize;
510 let count = acc.get("count")?.num()? as usize;
511 let byte_off_acc = acc.get("byteOffset").and_then(|v| v.num()).unwrap_or(0.0) as usize;
512
513 let bv = buf_views.get(bv_idx)?;
514 let byte_off_bv = bv.get("byteOffset").and_then(|v| v.num()).unwrap_or(0.0) as usize;
515 let stride = bv.get("byteStride").and_then(|v| v.num()).map(|n| n as usize)
516 .unwrap_or(components * 4);
517
518 let mut out = Vec::with_capacity(count * components);
519 for i in 0..count {
520 let base = byte_off_bv + byte_off_acc + i * stride;
521 if base + components * 4 > bin.len() { return None; }
522 for c in 0..components {
523 let b = base + c * 4;
524 out.push(f32::from_le_bytes([bin[b], bin[b+1], bin[b+2], bin[b+3]]));
525 }
526 }
527 Some(out)
528}
529
530/// Indices — componentType 5121 (u8), 5123 (u16), or 5125 (u32). Always
531/// returned as u32.

Callers 2

parse_glbFunction · 0.85
parse_primitiveFunction · 0.85

Calls 3

numMethod · 0.80
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected