create VmcExtBlendVal

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-30 09:44:35 -05:00
parent 3054bcc8fe
commit 61cc7bcb81

View File

@ -238,10 +238,9 @@ struct VmcExtBonePos {
impl MessageBehavior for VmcExtBonePos { impl MessageBehavior for VmcExtBonePos {
fn to_sendable_osc_message(&self) -> OscMessage { fn to_sendable_osc_message(&self) -> OscMessage {
let addr = String::from("/VMC/Ext/Bone/Pos");
let quat = self.transform.basis.to_quat(); let quat = self.transform.basis.to_quat();
return OscMessage { return OscMessage {
addr, addr: String::from("/VMC/Ext/Bone/Pos"),
args: vec![ args: vec![
OscType::from(self.name.to_owned()), OscType::from(self.name.to_owned()),
OscType::from(self.transform.origin.x), OscType::from(self.transform.origin.x),
@ -304,3 +303,36 @@ impl MessageBehavior for VmcExtBonePos {
}); });
} }
} }
struct VmcExtBlendVal {
name: String,
value: f32,
}
impl MessageBehavior for VmcExtBlendVal {
fn to_sendable_osc_message(&self) -> OscMessage {
return OscMessage {
addr: String::from("/VMC/Ext/Blend/Val"),
args: vec![
OscType::from(self.name.to_owned()),
OscType::from(self.value),
],
};
}
fn parse_from_osc_message(msg: OscMessage) -> Result<Self, String> {
let name: String;
let value: f32;
if msg.args.len() != 2 {
return Err(String::from("arg count invalid"));
}
match &msg.args[0] {
OscType::String(s) => name = s.to_owned(),
_ => return Err(String::from("arg type invalid")),
}
match msg.args[1] {
OscType::Float(f) => value = f,
_ => return Err(String::from("arg type invalid")),
}
return Ok(VmcExtBlendVal { name, value });
}
}