-
Notifications
You must be signed in to change notification settings - Fork 3
Working on the Light Struct #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good progress!
There are a few minor things and a couple of general I'm going to mention here:
- All structs should be renamed, since they all, by default, start with capital letters (it's a
serde/serde_xmlimpl detail) - All fields & structs must be
pub - I've realised that I've forgotten to add the default values as a documentation, so make sure to include this as well in the docs.
- Can you also add tests please?
You can add a raw string of xml deserialized into a struct which will also check for the default values. So the xml won't have the values set but you will expect them in the resulting deserialize struct.
| #[derive(Debug, Serialize, Deserialize)] | ||
| pub struct Light {} | ||
| pub struct Light { | ||
| // A unique name for the light |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please use doc comments
///so that the information shows in the documentation.
| pub struct Light { | ||
| // A unique name for the light | ||
| name: String, | ||
| // The light type: point, directional spot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- there is a missing comma
point, directional, spot
| // A unique name for the light | ||
| name: String, | ||
| // The light type: point, directional spot | ||
| #[serde(default)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The default should be set up using
serde. - Use an Enum since the available options are only 3
point,directional,spot
You might need to use https://crates.io/crates/parse-display for this. I'm not aware how Enums with no data are deserialized so you have to double-check this. - Make sure to rename the
light_typetotypewith anserdeattribute
| cast_shadows: Option<bool>, | ||
| // Scale factor to set the relative power of a light | ||
| #[serde(default)] | ||
| intensity: Option<f64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The default for this value is
1, right now withserde(default)it isNone.
| diffuse: Option<Color>, | ||
| // Specular light color | ||
| #[serde(default)] | ||
| specular: Option<Color>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please add default functions that set the correct values for
diffuse(1 1 1 1) &specular(0.1 0.1 0.1 1). This could be achieved by adding associated functions toColorfor the default values, likeColor::specular_default()
| attenuation: Vec<Attenuation>, | ||
| // Direction of light, only applicable for spot and directional light | ||
| #[serde(default)] | ||
| direction: Vec<i32>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vec3 actually means a mathematical vector.
You can use a tuple struct and eventually we might use something like nalgebra's structs but this is not required for the moment
https://docs.rs/nalgebra/0.29.0/nalgebra/base/type.Vector3.html
- Please add proper default.
| pub struct Attenuation { | ||
| range: f64, | ||
| linear: Option<f64>, | ||
| constant: Option<f64>, | ||
| quadratic: Option<f64>, | ||
| } | ||
|
|
||
| // Spot light parameters | ||
| pub struct Spot { | ||
| inner_angle: f64, | ||
| outer_angle: f64, | ||
| falloff: f64, | ||
| } | ||
|
|
||
| // A position and orientation with respect to the frame named in relative_to attribute | ||
| pub struct Pose { | ||
| relative_to: Option<String>, | ||
| } | ||
|
|
||
| // Unit struct for tpe `color` | ||
| struct Color(u8, u8, u8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- structs are missing the documentation of the fields.
-
deriveDebug, Deser. & Ser.
|
|
||
| // A position and orientation with respect to the frame named in relative_to attribute | ||
| pub struct Pose { | ||
| relative_to: Option<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Posehas value as well
<pose relative_to="...">value</pose>
|
I found an example of how to force attributes (will be done in future PRs though as it requires a lot of enums) and use an enum for #[derive(Debug, Serialize, Deserialize, PartialEq)]
enum PitchType { FourSeam, TwoSeam, Changeup, Cutter, Curve, Slider, Knuckle, Pitchout }You can see the documentation of serde_xml: |
Hey, @elpiel can you take a look at this PR and give comments on what needs improvement? The other two should be ready by the end of today.