Skip to content

Commit

Permalink
Small updates enabling loading of more v0.8 models. (#102)
Browse files Browse the repository at this point in the history
Include physics parameter mapping mode `YX` (functional) and parameter
binding `opacity` (deserialization only).

A proper checklist of new features in 0.8 compared to 0.7 is needed
after this and implemented orderly.
  • Loading branch information
Speykious authored Oct 1, 2024
2 parents 4e1f462 + 6a56634 commit cb35c5b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# Rust
/target
/Cargo.lock

# Inochi2D project/model file
*.inp
*.inx

# renderdoc capture file
*.cap
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"no-inline-html": false,
"first-line-heading": false
},
"cSpell.enabled": false,
// "rust-analyzer.cargo.target": "wasm32-unknown-unknown"
}
3 changes: 3 additions & 0 deletions inox2d/src/formats/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ fn deserialize_simple_physics(obj: JsonObject) -> InoxParseResult<SimplePhysics>
map_mode: match obj.get_str("map_mode")? {
"AngleLength" => PhysicsParamMapMode::AngleLength,
"XY" => PhysicsParamMapMode::XY,
"YX" => PhysicsParamMapMode::YX,
unknown => return Err(InoxParseError::UnknownParamMapMode(unknown.to_owned())),
},

Expand Down Expand Up @@ -454,6 +455,8 @@ fn deserialize_binding_values(param_name: &str, values: &[JsonValue]) -> InoxPar

BindingValues::Deform(Matrix2d::from_slice_vecs(&parsed, true)?)
}
// TODO
"opacity" => BindingValues::Opacity,
param_name => return Err(InoxParseError::UnknownParamName(param_name.to_owned())),
})
}
Expand Down
1 change: 1 addition & 0 deletions inox2d/src/node/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub enum PhysicsModel {
pub enum PhysicsParamMapMode {
AngleLength,
XY,
YX,
}

#[derive(Clone)]
Expand Down
30 changes: 17 additions & 13 deletions inox2d/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum BindingValues {
TransformRY(Matrix2d<f32>),
TransformRZ(Matrix2d<f32>),
Deform(Matrix2d<Vec<Vec2>>),
// TODO
Opacity,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -199,26 +201,28 @@ impl Param {
.expect("Deform param target must have an associated Mesh.");

let vert_len = mesh.vertices.len();
let mut direct_deform: Vec<Vec2> = Vec::with_capacity(vert_len);
direct_deform.resize(vert_len, Vec2::ZERO);

bi_interpolate_vec2s_additive(
val_normed,
range_in,
out_top,
out_bottom,
binding.interpolate_mode,
&mut direct_deform,
);

direct_deform
let mut direct_deform: Vec<Vec2> = Vec::with_capacity(vert_len);
direct_deform.resize(vert_len, Vec2::ZERO);

bi_interpolate_vec2s_additive(
val_normed,
range_in,
out_top,
out_bottom,
binding.interpolate_mode,
&mut direct_deform,
);

direct_deform
};

comps
.get_mut::<DeformStack>(binding.node)
.expect("Nodes being deformed must have a DeformStack component.")
.push(DeformSource::Param(self.uuid), Deform::Direct(direct_deform));
}
// TODO
BindingValues::Opacity => {}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions inox2d/src/physics/pendulum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ impl<T: Pendulum> SimplePhysicsCtx for T {
result.y = -result.y; // Y goes up for params
result
}
PhysicsParamMapMode::YX => {
let local_pos_norm = local_angle * relative_length;
let mut result = local_pos_norm - Vec2::Y;
result.y = -result.y; // Y goes up for params

use glam::Vec2Swizzles;
result.yx()
}
PhysicsParamMapMode::AngleLength => {
let a = f32::atan2(-local_angle.x, local_angle.y) / PI;
Vec2::new(a, relative_length)
Expand Down

0 comments on commit cb35c5b

Please sign in to comment.