|
@@ -1,16 +1,16 @@
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
-use binrw::{BinRead, BinWrite};
|
|
|
+use binrw::{binrw, BinRead, BinWrite};
|
|
|
use diff::Diff;
|
|
|
use modular_bitfield::{
|
|
|
bitfield,
|
|
|
- specifiers::{B1, B2, B21, B4},
|
|
|
+ specifiers::{B1, B18},
|
|
|
};
|
|
|
|
|
|
use crate::{
|
|
|
array_of::ArrayOf,
|
|
|
field_of::FieldOf,
|
|
|
- types::{Field, WString, F64, U32},
|
|
|
+ types::{Field, F64, U32},
|
|
|
};
|
|
|
|
|
|
use super::{line::Lines, Object, ObjectCore};
|
|
@@ -23,26 +23,24 @@ use super::{line::Lines, Object, ObjectCore};
|
|
|
#[br(map = Self::from_bytes)]
|
|
|
#[bw(map = |&x| Self::into_bytes(x))]
|
|
|
pub struct ObjectFlags {
|
|
|
- #[skip]
|
|
|
- __: B1,
|
|
|
+ pub all_calc: B1,
|
|
|
pub follow_edge_once: B1,
|
|
|
+ pub continuous_pattern: B1, // Hatch type 4 when combined with bidirectional_pattern
|
|
|
+ pub bidirectional_pattern: B1, // Hatch type 2
|
|
|
+ pub ring_pattern: B1, // Hatch type 3
|
|
|
#[skip]
|
|
|
- __: B4,
|
|
|
+ __: B1,
|
|
|
pub auto_rotate_hatch_angle: B1,
|
|
|
pub average_distribute_line: B1,
|
|
|
#[skip]
|
|
|
- __: B2,
|
|
|
- pub cross_patch: B1,
|
|
|
+ __: B1,
|
|
|
+ pub gong_pattern: B1, // Hatch type 5 when combined with bidirectional_pattern
|
|
|
+ pub cross_hatch: B1,
|
|
|
+ pub background_pattern: B1, // Hatch type 6, must set all_calc as well
|
|
|
+ pub fill_pattern: B1, // Hatch type 7 when combined with continuous_pattern and bidirectional_pattern
|
|
|
+ pub zigzag_pattern: B1, // Hatch type 8
|
|
|
#[skip]
|
|
|
- __: B21,
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(BinRead, BinWrite, Debug, Diff, PartialEq)]
|
|
|
-#[diff(attr(
|
|
|
- #[derive(Debug, PartialEq)]
|
|
|
-))]
|
|
|
-pub struct HatchLine {
|
|
|
- lines: ArrayOf<Lines>,
|
|
|
+ __: B18,
|
|
|
}
|
|
|
|
|
|
#[cfg_attr(feature = "default-debug", derive(Debug))]
|
|
@@ -51,49 +49,99 @@ pub struct HatchLine {
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
))]
|
|
|
#[brw(magic(46u32))] // Number of fields in this struct
|
|
|
-pub struct HatchSettings1 {
|
|
|
+pub struct LegacyHatchSetting {
|
|
|
pub mark_contour: U32,
|
|
|
- _unknown_1: Field,
|
|
|
- pub pen: U32,
|
|
|
- pub flags: FieldOf<ObjectFlags>,
|
|
|
- pub edge_offset: F64,
|
|
|
- pub line_spacing: F64,
|
|
|
- pub start_offset: F64,
|
|
|
- pub end_offset: F64,
|
|
|
- pub angle: F64,
|
|
|
- _unknown_2: [Field; 9],
|
|
|
- pub auto_rotate_angle: F64,
|
|
|
- _unknown_3: [Field; 10],
|
|
|
- pub line_reduction: F64,
|
|
|
- _unknown_4: [Field; 2],
|
|
|
- pub loop_count: U32,
|
|
|
- _unknown_5: [Field; 2],
|
|
|
- pub loop_distance: F64,
|
|
|
- _unknown_6: [Field; 5],
|
|
|
- pub contour_first: U32,
|
|
|
- pub count: U32,
|
|
|
- _unknown_7: [Field; 3],
|
|
|
+ pub hatch_1_enable: U32,
|
|
|
+ pub hatch_1_pen: U32,
|
|
|
+ pub hatch_1_flags: FieldOf<ObjectFlags>,
|
|
|
+ pub hatch_1_edge_offset: F64,
|
|
|
+ pub hatch_1_line_spacing: F64,
|
|
|
+ pub hatch_1_start_offset: F64,
|
|
|
+ pub hatch_1_end_offset: F64,
|
|
|
+ pub hatch_1_angle: F64,
|
|
|
+ pub hatch_2_enable: U32,
|
|
|
+ pub hatch_2_pen: U32,
|
|
|
+ pub hatch_2_flags: FieldOf<ObjectFlags>,
|
|
|
+ pub hatch_2_edge_offset: F64,
|
|
|
+ pub hatch_2_line_spacing: F64,
|
|
|
+ pub hatch_2_start_offset: F64,
|
|
|
+ pub hatch_2_end_offset: F64,
|
|
|
+ pub hatch_2_angle: F64,
|
|
|
+ pub any_hatch_enabled: U32,
|
|
|
+ pub hatch_1_auto_rotate_angle: F64,
|
|
|
+ pub hatch_2_auto_rotate_angle: F64,
|
|
|
+ pub hatch_3_enable: U32,
|
|
|
+ pub hatch_3_pen: U32,
|
|
|
+ pub hatch_3_flags: FieldOf<ObjectFlags>,
|
|
|
+ pub hatch_3_edge_offset: F64,
|
|
|
+ pub hatch_3_line_spacing: F64,
|
|
|
+ pub hatch_3_start_offset: F64,
|
|
|
+ pub hatch_3_end_offset: F64,
|
|
|
+ pub hatch_3_angle: F64,
|
|
|
+ pub hatch_3_auto_rotate_angle: F64,
|
|
|
+ pub hatch_1_line_reduction: F64,
|
|
|
+ pub hatch_2_line_reduction: F64,
|
|
|
+ pub hatch_3_line_reduction: F64,
|
|
|
+ pub hatch_1_loop_count: U32,
|
|
|
+ pub hatch_2_loop_count: U32,
|
|
|
+ pub hatch_3_loop_count: U32,
|
|
|
+ pub hatch_1_loop_distance: F64,
|
|
|
+ pub hatch_2_loop_distance: F64,
|
|
|
+ pub hatch_3_loop_distance: F64,
|
|
|
+ _unknown_1: [Field; 3],
|
|
|
+ pub contour_priority: U32,
|
|
|
+ pub hatch_1_count: U32,
|
|
|
+ pub hatch_2_count: U32,
|
|
|
+ pub hatch_3_count: U32,
|
|
|
}
|
|
|
|
|
|
// Custom Debug implementation to only print known fields
|
|
|
#[cfg(not(feature = "default-debug"))]
|
|
|
-impl Debug for HatchSettings1 {
|
|
|
+impl Debug for LegacyHatchSetting {
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
- f.debug_struct("HatchSettings1")
|
|
|
+ f.debug_struct("LegacyHatchSetting")
|
|
|
.field("mark_contour", &self.mark_contour)
|
|
|
- .field("pen", &self.pen)
|
|
|
- .field("flags", &self.flags)
|
|
|
- .field("edge_offset", &self.edge_offset)
|
|
|
- .field("line_spacing", &self.line_spacing)
|
|
|
- .field("start_offset", &self.start_offset)
|
|
|
- .field("end_offset", &self.end_offset)
|
|
|
- .field("angle", &self.angle)
|
|
|
- .field("auto_rotate_angle", &self.auto_rotate_angle)
|
|
|
- .field("line_reduction", &self.line_reduction)
|
|
|
- .field("loop_count", &self.loop_count)
|
|
|
- .field("loop_distance", &self.loop_distance)
|
|
|
- .field("contour_first", &self.contour_first)
|
|
|
- .field("count", &self.count)
|
|
|
+ .field("hatch_1_enable", &self.hatch_1_enable)
|
|
|
+ .field("hatch_1_pen", &self.hatch_1_pen)
|
|
|
+ .field("hatch_1_flags", &self.hatch_1_flags)
|
|
|
+ .field("hatch_1_edge_offset", &self.hatch_1_edge_offset)
|
|
|
+ .field("hatch_1_line_spacing", &self.hatch_1_line_spacing)
|
|
|
+ .field("hatch_1_start_offset", &self.hatch_1_start_offset)
|
|
|
+ .field("hatch_1_end_offset", &self.hatch_1_end_offset)
|
|
|
+ .field("hatch_1_angle", &self.hatch_1_angle)
|
|
|
+ .field("hatch_2_enable", &self.hatch_2_enable)
|
|
|
+ .field("hatch_2_pen", &self.hatch_2_pen)
|
|
|
+ .field("hatch_2_flags", &self.hatch_2_flags)
|
|
|
+ .field("hatch_2_edge_offset", &self.hatch_2_edge_offset)
|
|
|
+ .field("hatch_2_line_spacing", &self.hatch_2_line_spacing)
|
|
|
+ .field("hatch_2_start_offset", &self.hatch_2_start_offset)
|
|
|
+ .field("hatch_2_end_offset", &self.hatch_2_end_offset)
|
|
|
+ .field("hatch_2_angle", &self.hatch_2_angle)
|
|
|
+ .field("any_hatch_enabled", &self.any_hatch_enabled)
|
|
|
+ .field("hatch_1_auto_rotate_angle", &self.hatch_1_auto_rotate_angle)
|
|
|
+ .field("hatch_2_auto_rotate_angle", &self.hatch_2_auto_rotate_angle)
|
|
|
+ .field("hatch_3_enable", &self.hatch_3_enable)
|
|
|
+ .field("hatch_3_pen", &self.hatch_3_pen)
|
|
|
+ .field("hatch_3_flags", &self.hatch_3_flags)
|
|
|
+ .field("hatch_3_edge_offset", &self.hatch_3_edge_offset)
|
|
|
+ .field("hatch_3_line_spacing", &self.hatch_3_line_spacing)
|
|
|
+ .field("hatch_3_start_offset", &self.hatch_3_start_offset)
|
|
|
+ .field("hatch_3_end_offset", &self.hatch_3_end_offset)
|
|
|
+ .field("hatch_3_angle", &self.hatch_3_angle)
|
|
|
+ .field("hatch_3_auto_rotate_angle", &self.hatch_3_auto_rotate_angle)
|
|
|
+ .field("hatch_1_line_reduction", &self.hatch_1_line_reduction)
|
|
|
+ .field("hatch_2_line_reduction", &self.hatch_2_line_reduction)
|
|
|
+ .field("hatch_3_line_reduction", &self.hatch_3_line_reduction)
|
|
|
+ .field("hatch_1_loop_count", &self.hatch_1_loop_count)
|
|
|
+ .field("hatch_2_loop_count", &self.hatch_2_loop_count)
|
|
|
+ .field("hatch_3_loop_count", &self.hatch_3_loop_count)
|
|
|
+ .field("hatch_1_loop_distance", &self.hatch_1_loop_distance)
|
|
|
+ .field("hatch_2_loop_distance", &self.hatch_2_loop_distance)
|
|
|
+ .field("hatch_3_loop_distance", &self.hatch_3_loop_distance)
|
|
|
+ .field("contour_priority", &self.contour_priority)
|
|
|
+ .field("hatch_1_count", &self.hatch_1_count)
|
|
|
+ .field("hatch_2_count", &self.hatch_2_count)
|
|
|
+ .field("hatch_3_count", &self.hatch_3_count)
|
|
|
.finish()
|
|
|
}
|
|
|
}
|
|
@@ -104,9 +152,9 @@ impl Debug for HatchSettings1 {
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
))]
|
|
|
#[brw(magic(15u32))] // Number of fields in this struct
|
|
|
-pub struct HatchSettings2 {
|
|
|
+pub struct HatchSetting {
|
|
|
pub count: U32,
|
|
|
- _unknown_1: Field,
|
|
|
+ pub enabled: U32,
|
|
|
pub pen: U32,
|
|
|
pub flags: FieldOf<ObjectFlags>,
|
|
|
pub edge_offset: F64,
|
|
@@ -118,15 +166,16 @@ pub struct HatchSettings2 {
|
|
|
pub line_reduction: F64,
|
|
|
pub loop_distance: F64,
|
|
|
pub loop_count: U32,
|
|
|
- _unknown_2: [Field; 2],
|
|
|
+ _unknown_1: [Field; 2],
|
|
|
}
|
|
|
|
|
|
// Custom Debug implementation to only print known fields
|
|
|
#[cfg(not(feature = "default-debug"))]
|
|
|
-impl Debug for HatchSettings2 {
|
|
|
+impl Debug for HatchSetting {
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
- f.debug_struct("HatchSettings2")
|
|
|
+ f.debug_struct("HatchSettings")
|
|
|
.field("count", &self.count)
|
|
|
+ .field("enabled", &self.enabled)
|
|
|
.field("pen", &self.pen)
|
|
|
.field("flags", &self.flags)
|
|
|
.field("edge_offset", &self.edge_offset)
|
|
@@ -142,39 +191,50 @@ impl Debug for HatchSettings2 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#[cfg_attr(feature = "default-debug", derive(Debug))]
|
|
|
-#[derive(BinRead, BinWrite, Diff, PartialEq)]
|
|
|
+#[derive(BinRead, BinWrite, Debug, Diff, PartialEq)]
|
|
|
+#[diff(attr(
|
|
|
+ #[derive(Debug, PartialEq)]
|
|
|
+))]
|
|
|
+pub struct HatchLine {
|
|
|
+ pub lines: ArrayOf<Lines>,
|
|
|
+}
|
|
|
+
|
|
|
+#[derive(BinRead, BinWrite, Debug, Diff, PartialEq)]
|
|
|
+#[diff(attr(
|
|
|
+ #[derive(Debug, PartialEq)]
|
|
|
+))]
|
|
|
+#[brw(magic(16_u32))] // ObjectType::HatchLine
|
|
|
+pub struct HatchLines {
|
|
|
+ pub core: ObjectCore,
|
|
|
+ pub hatches: ArrayOf<HatchLine>,
|
|
|
+}
|
|
|
+
|
|
|
+#[derive(BinRead, BinWrite, Debug, Diff, PartialEq)]
|
|
|
+#[diff(attr(
|
|
|
+ #[derive(Debug, PartialEq)]
|
|
|
+))]
|
|
|
+pub struct Hatches {
|
|
|
+ pub core: ObjectCore,
|
|
|
+ pub hatches: ArrayOf<HatchLines>,
|
|
|
+}
|
|
|
+
|
|
|
+#[binrw]
|
|
|
+#[derive(Debug, Diff, PartialEq)]
|
|
|
#[diff(attr(
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
))]
|
|
|
pub struct Hatch {
|
|
|
pub core: ObjectCore,
|
|
|
pub outline: ArrayOf<Object>,
|
|
|
- pub settings_1: HatchSettings1,
|
|
|
- pub settings_2: HatchSettings2,
|
|
|
- _unknown_1: ArrayOf<Field>,
|
|
|
- _unknown_2: u32,
|
|
|
- _unknown_3: u32,
|
|
|
- _unknown_4: u32,
|
|
|
- pub pen: U32,
|
|
|
- _unknown_5: [Field; 2],
|
|
|
- pub name: WString,
|
|
|
- _unknown_6: [Field; 13],
|
|
|
- pub lines: ArrayOf<HatchLine>,
|
|
|
-}
|
|
|
+ pub legacy_setting: LegacyHatchSetting,
|
|
|
|
|
|
-// Custom Debug implementation to only print known fields
|
|
|
-#[cfg(not(feature = "default-debug"))]
|
|
|
-impl Debug for Hatch {
|
|
|
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
- f.debug_struct("Hatch")
|
|
|
- .field("core", &self.core)
|
|
|
- .field("outline", &self.outline)
|
|
|
- .field("settings_1", &self.settings_1)
|
|
|
- .field("settings_2", &self.settings_2)
|
|
|
- .field("pen", &self.pen)
|
|
|
- .field("name", &self.name)
|
|
|
- .field("lines", &self.lines)
|
|
|
- .finish()
|
|
|
- }
|
|
|
+ #[br(temp)]
|
|
|
+ #[bw(try_calc(u32::try_from(hatch_settings.len()).unwrap().try_into()))]
|
|
|
+ pub num_settings: U32,
|
|
|
+
|
|
|
+ #[br(count = num_settings.value)]
|
|
|
+ pub hatch_settings: Vec<HatchSetting>,
|
|
|
+
|
|
|
+ #[brw(if(legacy_setting.any_hatch_enabled.value == 1))]
|
|
|
+ pub hatches: Option<Hatches>,
|
|
|
}
|