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

Function parse_param

perro_source/core/perro_animation/src/panim/events.rs:90–165  ·  view source on GitHub ↗
(value: &SceneValue, line_no: usize)

Source from the content-addressed store, hash-verified

88}
89
90fn parse_param(value: &SceneValue, line_no: usize) -> Result<AnimationParam, String> {
91 match value {
92 SceneValue::Bool(v) => Ok(AnimationParam::Bool(*v)),
93 SceneValue::I32(v) => Ok(AnimationParam::I32(*v)),
94 SceneValue::F32(v) => Ok(AnimationParam::F32(*v)),
95 SceneValue::Str(v) => parse_text_param(v.as_ref(), line_no),
96 SceneValue::Key(v) => parse_text_param(v.0.as_ref(), line_no),
97 SceneValue::Vec2 { x, y } => Ok(AnimationParam::Vec2([*x, *y])),
98 SceneValue::Vec3 { x, y, z } => Ok(AnimationParam::Vec3([*x, *y, *z])),
99 SceneValue::Vec4 { x, y, z, w } => Ok(AnimationParam::Vec4([*x, *y, *z, *w])),
100 SceneValue::Object(fields) => {
101 let mut position2 = None;
102 let mut rotation2 = None;
103 let mut scale2 = None;
104 let mut position3 = None;
105 let mut rotation3 = None;
106 let mut scale3 = None;
107 for (k, v) in fields.iter() {
108 match k.as_ref() {
109 "position" => {
110 if let Some((x, y)) = v.as_vec2() {
111 position2 = Some(Vector2::new(x, y));
112 }
113 if let Some((x, y, z)) = v.as_vec3() {
114 position3 = Some(Vector3::new(x, y, z));
115 }
116 }
117 "rotation" => {
118 if let Some(r) = v.as_f32() {
119 rotation2 = Some(r);
120 }
121 if let Some((x, y, z)) = v.as_vec3() {
122 let mut q = Quaternion::IDENTITY;
123 q.rotate_xyz(x, y, z);
124 q.normalize();
125 rotation3 = Some(q);
126 }
127 if let Some((x, y, z, w)) = v.as_vec4() {
128 let mut q = Quaternion::new(x, y, z, w);
129 q.normalize();
130 rotation3 = Some(q);
131 }
132 }
133 "rotation_deg" => {
134 if let Some(r) = v.as_f32() {
135 rotation2 = Some(r.to_radians());
136 }
137 if let Some((x, y, z)) = v.as_vec3() {
138 let mut q = Quaternion::IDENTITY;
139 q.rotate_xyz(x.to_radians(), y.to_radians(), z.to_radians());
140 q.normalize();
141 rotation3 = Some(q);
142 }
143 }
144 "scale" => {
145 if let Some((x, y)) = v.as_vec2() {
146 scale2 = Some(Vector2::new(x, y));
147 }

Callers 2

parse_set_varFunction · 0.85
parse_paramsFunction · 0.85

Calls 11

parse_text_paramFunction · 0.85
Transform2DClass · 0.85
Transform3DClass · 0.85
rotate_xyzMethod · 0.80
as_refMethod · 0.45
iterMethod · 0.45
as_vec2Method · 0.45
as_vec3Method · 0.45
as_f32Method · 0.45
normalizeMethod · 0.45
as_vec4Method · 0.45

Tested by

no test coverage detected