MCPcopy Create free account
hub / github.com/PerroEngine/Perro / expect_quat

Function expect_quat

perro_source/core/perro_animation/src/panim/fields.rs:446–462  ·  view source on GitHub ↗
(value: &SceneValue, key: &str, line_no: usize)

Source from the content-addressed store, hash-verified

444 .ok_or_else(|| format!("line {}: `{}` expects vec3", line_no, key))?;
445 Ok(Vector3::new(x, y, z))
446}
447
448fn expect_color3(value: &SceneValue, key: &str, line_no: usize) -> Result<[f32; 3], String> {
449 let (x, y, z) = value
450 .as_vec3()
451 .ok_or_else(|| format!("line {}: `{}` expects vec3", line_no, key))?;
452 Ok([x, y, z])
453}
454
455fn expect_quat(value: &SceneValue, key: &str, line_no: usize) -> Result<Quaternion, String> {
456 if let Some((x, y, z, w)) = value.as_vec4() {
457 let mut quat = Quaternion::new(x, y, z, w);
458 quat.normalize();
459 return Ok(quat);
460 }
461
462 // Keep parity with scene parser behavior: Node3D rotation accepts Euler XYZ radians.
463 if let Some((x, y, z)) = value.as_vec3() {
464 let mut rotation = Quaternion::IDENTITY;
465 rotation.rotate_xyz(x, y, z);

Callers 2

parse_node_3d_actionFunction · 0.85

Calls 4

rotate_xyzMethod · 0.80
as_vec4Method · 0.45
normalizeMethod · 0.45
as_vec3Method · 0.45

Tested by

no test coverage detected