Skip to content

Commit cb35c5b

Browse files
authored
Small updates enabling loading of more v0.8 models. (#102)
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.
2 parents 4e1f462 + 6a56634 commit cb35c5b

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1+
# Rust
12
/target
23
/Cargo.lock
4+
5+
# Inochi2D project/model file
6+
*.inp
7+
*.inx
8+
9+
# renderdoc capture file
10+
*.cap

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"no-inline-html": false,
44
"first-line-heading": false
55
},
6+
"cSpell.enabled": false,
67
// "rust-analyzer.cargo.target": "wasm32-unknown-unknown"
78
}

inox2d/src/formats/payload.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ fn deserialize_simple_physics(obj: JsonObject) -> InoxParseResult<SimplePhysics>
157157
map_mode: match obj.get_str("map_mode")? {
158158
"AngleLength" => PhysicsParamMapMode::AngleLength,
159159
"XY" => PhysicsParamMapMode::XY,
160+
"YX" => PhysicsParamMapMode::YX,
160161
unknown => return Err(InoxParseError::UnknownParamMapMode(unknown.to_owned())),
161162
},
162163

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

455456
BindingValues::Deform(Matrix2d::from_slice_vecs(&parsed, true)?)
456457
}
458+
// TODO
459+
"opacity" => BindingValues::Opacity,
457460
param_name => return Err(InoxParseError::UnknownParamName(param_name.to_owned())),
458461
})
459462
}

inox2d/src/node/components.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub enum PhysicsModel {
130130
pub enum PhysicsParamMapMode {
131131
AngleLength,
132132
XY,
133+
YX,
133134
}
134135

135136
#[derive(Clone)]

inox2d/src/params.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub enum BindingValues {
3232
TransformRY(Matrix2d<f32>),
3333
TransformRZ(Matrix2d<f32>),
3434
Deform(Matrix2d<Vec<Vec2>>),
35+
// TODO
36+
Opacity,
3537
}
3638

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

201203
let vert_len = mesh.vertices.len();
202-
let mut direct_deform: Vec<Vec2> = Vec::with_capacity(vert_len);
203-
direct_deform.resize(vert_len, Vec2::ZERO);
204-
205-
bi_interpolate_vec2s_additive(
206-
val_normed,
207-
range_in,
208-
out_top,
209-
out_bottom,
210-
binding.interpolate_mode,
211-
&mut direct_deform,
212-
);
213-
214-
direct_deform
204+
let mut direct_deform: Vec<Vec2> = Vec::with_capacity(vert_len);
205+
direct_deform.resize(vert_len, Vec2::ZERO);
206+
207+
bi_interpolate_vec2s_additive(
208+
val_normed,
209+
range_in,
210+
out_top,
211+
out_bottom,
212+
binding.interpolate_mode,
213+
&mut direct_deform,
214+
);
215+
216+
direct_deform
215217
};
216218

217219
comps
218220
.get_mut::<DeformStack>(binding.node)
219221
.expect("Nodes being deformed must have a DeformStack component.")
220222
.push(DeformSource::Param(self.uuid), Deform::Direct(direct_deform));
221223
}
224+
// TODO
225+
BindingValues::Opacity => {}
222226
}
223227
}
224228
}

inox2d/src/physics/pendulum.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ impl<T: Pendulum> SimplePhysicsCtx for T {
6262
result.y = -result.y; // Y goes up for params
6363
result
6464
}
65+
PhysicsParamMapMode::YX => {
66+
let local_pos_norm = local_angle * relative_length;
67+
let mut result = local_pos_norm - Vec2::Y;
68+
result.y = -result.y; // Y goes up for params
69+
70+
use glam::Vec2Swizzles;
71+
result.yx()
72+
}
6573
PhysicsParamMapMode::AngleLength => {
6674
let a = f32::atan2(-local_angle.x, local_angle.y) / PI;
6775
Vec2::new(a, relative_length)

0 commit comments

Comments
 (0)