#pragma endian little #pragma pattern_limit 512000 #include #include #include #include struct RGBA8 { u8 red; u8 green; u8 blue; u8 alpha; } [[static, color(std::format("{:02X}{:02X}{:02X}", red, green, blue))]]; struct Point { double x; double y; }; struct MultiLine { u32 points; Point point[points]; }; enum WobbleType : u32 { Spiral = 0, Sinusoidal = 1, Ellipse = 2, Vert_8 = 3, Hoti_8 = 4, }; // Field of a custom defined type struct FieldOf { u32 length; T value; if (length != sizeof(value)) { std::error(std::format("Field size mismatch at 0x{:02X}", $)); } } [[sealed, format("format_field_of")]]; fn format_field_of(FieldOf f) { return f.value; }; // Field of generic types struct Field { u32 length; match (length) { (4): u32 value; (8): double value; (2): u16 value; // ?? (16): Point value; // ?? (_): { std::warning(std::format("Unknown length tag: {} at 0x{:02X}", length, $)); u8 value[length]; } } } [[sealed, format("format_field")]]; fn format_field(Field f) { return f.value; }; // Variable length field of a fixed type. struct String { u32 length; char16 value[length / sizeof(char16)]; } [[sealed, format("format_string")]]; fn format_string(String s) { return s.value; }; struct Header { char16 magic[0x8]; u8 unknown[0x338]; }; struct Pen { u32 num_fields; // Number of fields in this struct (236) Field color; String name; Field disabled; Field use_default_param; Field loop_count; Field speed; // Changes with wobble relative speed Field power; Field frequency; Field unknown_1[1]; Field start_tc; Field end_tc; Field polygon_tc; Field jump_speed; Field unknown_2[10]; Field laser_off_tc; Field wave; // Only available if continue_mode is false Field unknown_3[1]; Field wobble_enable; Field wobble_diameter; Field wobble_distance; Field unknown_4[8]; Field min_jump_tc; Field max_jump_tc; Field jump_limit; Field unknown_5[2]; Field frequency2; Field unknown_6[152]; FieldOf wobble_type; Field continue_mode; Field unknown_7[12]; Field wobble_diameter2; // Only with wobble type ellipse Field unknown_8[26]; }; bitfield ObjectFlags { disabled : 1; aspect_ratio_unlocked : 1; // ?? padding : 14; }; enum ObjectType: u16 { Curve = 1, Point = 2, Rectangle = 3, Circle = 4, Ellipse = 5, Polygon = 6, HatchLine = 16, Hatch = 32, }; struct ObjCommon { u32 num_fields; // Number of fields in this struct (17) Field pen; //Field type; // Seems to always be same value as object type FieldOf; FieldOf; String name; Field count; Field unknown_2; Field io_control_enable_mask; Field io_control_disable_mask; Field unknown_3[5]; FieldOf origin; Field z; Field a; Field index; // Increments for each hatch line, -1 for certain hatch patterns if (index.value != 0) { std::warning(std::format("Unexpected unknown value {} at 0x{:02X}", index.value, $)); } }; enum LineType : u16 { Point = 0x0001, Line = 0x0100, Bezier = 0x0300, }; struct LineEntry { LineType type; u32; // Zeros match (type) { (LineType::Point): Point; (LineType::Line): { u32 count; Point points[count]; } (LineType::Bezier): { u32 count; Point points[count]; } (_): std::error(std::format("Unknown line type: 0x{:02X} at 0x{:02X}", u32(type), $)); } }; struct LineSet : ObjCommon { u32 count; u32; // Zeros LineEntry entries[count]; }; struct ClosedSet : ObjCommon { u32 count; Field entries[count]; }; struct Rectangle : ObjCommon { u32 num_fields; // Number of fields in this struct (8) FieldOf corner_a; FieldOf corner_b; Field round_bottom_left; Field round_bottom_right; Field round_top_right; Field round_top_left; Field unknown; u32 length; u8 bytes[length]; }; struct Circle : ObjCommon { u32 num_fields; // Number of fields in this struct (6) FieldOf origin; Field radius; Field start_angle; // Radians Field clockwise; Field unknown[2]; }; struct Ellipse : ObjCommon { u32 num_fields; // Number of fields in this struct (8) Field clockwise; FieldOf corner_a; FieldOf corner_b; Field start_angle; // Radians Field end_angle; // Radians Field unknown[2]; Field open_curve; }; struct Polygon : ObjCommon { u32 num_fields; // Number of fields in this struct (10) Field invert_shape; FieldOf corner_a; FieldOf corner_b; Field offset_cx; // Moves (intial) sharper corner Field offset_cy; // Moves (initial)sharper corner Field offset_dx; Field offset_dy; Field edges; Field unknown_3[2]; }; struct HatchLine { u32 num_lines; LineSet line[num_lines]; }; using Object; bitfield HatchFlags { all_calc : 1; // Will always be set when background_pattern is set follow_edge_once : 1; continuous_pattern : 1; // Hatch type 4 when combined with bidirectional_pattern bidirectional_pattern : 1; // Hatch type 2 ring_pattern : 1; // Hatch type 3 padding : 1; auto_rotate_hatch_angle : 1; average_distribut_line : 1; padding : 1; gong_pattern : 1; // Hatch type 5 when combined with bidirectional_pattern cross_hatch : 1; background_pattern: 1; // Hatch type 6 (TODO, missing parsing) fill_pattern : 1; // Hatch type 7 when combined with continuous_pattern and bidirectional_pattern zigzag_pattern : 1; // Hatch type 8 padding : 18; }; // TODO: hatch types 1/2 will set last field of ObjCommon in HatchLines to 1 // TODO: hatch types 3/4/5/7/8 will set last field of ObjCommon in HatchLines to -1 (0xFFFFFFFF) struct HatchSettings { u32 num_fields; // 46 Field mark_contour; Field hatch_1_enable; Field hatch_1_pen; FieldOf hatch_1_flags; Field hatch_1_edge_offset; Field hatch_1_line_spacing; Field hatch_1_start_offset; Field hatch_1_end_offset; Field hatch_1_angle; Field hatch_2_enable; Field hatch_2_pen; FieldOf hatch_2_flags; Field hatch_2_edge_offset; Field hatch_2_line_space; Field hatch_2_start_offset; Field hatch_2_end_offset; Field hatch_2_angle; Field any_hatch_enabled; Field hatch_1_auto_rotate_angle; Field hatch_2_auto_rotate_angle; Field hatch_3_enable; Field hatch_3_pen; FieldOf hatch_3_flags; Field hatch_3_edge_offset; Field hatch_3_line_space; Field hatch_3_start_offset; Field hatch_3_end_offset; Field hatch_3_angle; Field hatch_3_auto_rotate_angle; Field hatch_1_line_reduction; Field hatch_2_line_reduction; Field hatch_3_line_reduction; Field hatch_1_num_loops; Field hatch_2_num_loops; Field hatch_3_num_loops; Field hatch_1_loop_distance; Field hatch_2_loop_distance; Field hatch_3_loop_distance; Field unknown_1[3]; Field contour_priority; Field hatch_1_count; Field hatch_2_count; Field hatch_3_count; }; struct HatchSettings2 { u32 num_fields; // 15 Field count; Field enabled; Field pen; FieldOf flags; Field edge_offset; Field line_spacing; Field start_offset; Field end_offset; Field angle; Field auto_rotate_angle; Field line_reduction; Field loop_distance; Field num_loops; Field unknown_1; // Mirror unknown_1 in settings Field unknown_2; }; struct HatchLines { u32; // 16 (tag?) ObjCommon; u32 num_lines; HatchLine lines2[num_lines]; }; struct Hatch : ObjCommon { u32 num_outlines; Object outline[num_outlines]; HatchSettings settings; Field num_settings; HatchSettings2 settings_2[num_settings.value]; // Following fields are not defined if hatch is disabled if (settings.any_hatch_enabled.value == 1) { ObjCommon; u32 num_hatches; HatchLines hatches[num_hatches]; } }; struct Object { ObjectType type; u16; // zero match (type) { (ObjectType::Curve): LineSet; (ObjectType::Point): LineSet; (ObjectType::Rectangle): Rectangle; (ObjectType::Circle): Circle; (ObjectType::Ellipse): Ellipse; (ObjectType::Polygon): Polygon; (ObjectType::Hatch): Hatch; (_): std::error(std::format("Unknown object type: 0x{:02X} at 0x{:02X}", u32(type), $)); } }; struct Layer { u32 num_fields_1; // Number of fields before object list (17) Field unknown_1[3]; String name; Field count; Field unknown_2[1]; Field input_signal_wait_enable_mask; Field input_signal_wait_disable_mask; Field unknown_3[9]; u32 object_count; Object objects[object_count]; u32 num_fields_2; // Number of fields to footer (151) Field unknown_4[54]; Field output_signal_start_enable_mask; Field output_signal_start_disable_mask; Field output_signal_end_enable_mask; Field output_signal_end_disable_mask; Field unknown_5[9]; Field fixture_offset; Field unknown_6[64]; Field output_signal_start_delay; Field output_signal_end_delay; Field input_signal_wait_enable; Field unknown_7[2]; Field output_signal_start_pulse; Field output_signal_end_pulse; Field unknown_8[12]; u32 footer; }; struct Layers { u32 count; Layer layer[count]; }; struct File { Header header; RGBA8 thumbnail[40000]; // 200x200? padding[16]; Pen pens[256]; Layers; }; File file @ 0x0;