@@ -790,6 +790,7 @@ bool Hatch::isLineSegment(const QuadraticBezier& bezier)
790790 return lenSqA < exp (-23 .0f ) * dot (quadratic.B , quadratic.B );
791791}
792792
793+ // TODO: the shape functions below should work with this instead of magic numbers
793794static constexpr uint32_t2 HatchFillPatternGlyphExtents = uint32_t2(8 , 8 );
794795
795796void line (std::vector<CPolyline>& polylines, float64_t2 begin, float64_t2 end)
@@ -816,45 +817,68 @@ void square(std::vector<CPolyline>& polylines, float64_t2 position, float64_t2 s
816817 polylines.push_back (polyline);
817818}
818819
819- void checkered (std::vector<CPolyline>& polylines)
820+ void checkered (std::vector<CPolyline>& polylines, float64_t2 offset )
820821{
821- line (polylines, float64_t2 (0.0 , 0.0 ), float64_t2 (4.0 , 0.0 ));
822- line (polylines, float64_t2 (4.0 , 0.0 ), float64_t2 (4.0 , 4.0 ));
823- line (polylines, float64_t2 (4.0 , 4.0 ), float64_t2 (0.0 , 4.0 ));
824- line (polylines, float64_t2 (0.0 , 4.0 ), float64_t2 (0.0 , 0.0 ));
825-
826- line (polylines, float64_t2 (4.0 , 4.0 ), float64_t2 (8.0 , 4.0 ));
827- line (polylines, float64_t2 (8.0 , 4.0 ), float64_t2 (8.0 , 8.0 ));
828- line (polylines, float64_t2 (8.0 , 8.0 ), float64_t2 (4.0 , 8.0 ));
829- line (polylines, float64_t2 (4.0 , 8.0 ), float64_t2 (4.0 , 4.0 ));
822+ {
823+ CPolyline polyline;
824+ std::array<float64_t2, 5u > points =
825+ {
826+ float64_t2 (0.0 , 8.0 ) + offset,
827+ float64_t2 (4.0 , 8.0 ) + offset,
828+ float64_t2 (4.0 , 4.0 ) + offset,
829+ float64_t2 (0.0 , 4.0 ) + offset,
830+ float64_t2 (0.0 , 8.0 ) + offset,
831+ };
832+ polyline.addLinePoints (points);
833+ polylines.push_back (polyline);
834+ }
835+ {
836+ CPolyline polyline;
837+ std::array<float64_t2, 5u > points =
838+ {
839+ float64_t2 (4.0 , 4.0 ) + offset,
840+ float64_t2 (8.0 , 4.0 ) + offset,
841+ float64_t2 (8.0 , 0.0 ) + offset,
842+ float64_t2 (4.0 , 0.0 ) + offset,
843+ float64_t2 (4.0 , 4.0 ) + offset,
844+ };
845+ polyline.addLinePoints (points);
846+ polylines.push_back (polyline);
847+ }
830848}
831849
832- void diamonds (std::vector<CPolyline>& polylines)
850+ void diamonds (std::vector<CPolyline>& polylines, float64_t2 offset, float64_t innerSize = 4.0 , float64_t outerSize = 8.0 )
833851{
852+ const std::array<float64_t2, 5u > diamondPointsCW = {
853+ float64_t2 (0.0 , 0.5 ),
854+ float64_t2 (0.5 , 0.0 ),
855+ float64_t2 (0.0 , -0.5 ),
856+ float64_t2 (-0.5 , 0.0 ),
857+ float64_t2 (0.0 , 0.5 ),
858+ };
859+ const std::array<float64_t2, 5u > diamondPointsCCW = {
860+ float64_t2 (0.0 , 0.5 ),
861+ float64_t2 (-0.5 , 0.0 ),
862+ float64_t2 (0.0 , -0.5 ),
863+ float64_t2 (0.5 , 0.0 ),
864+ float64_t2 (0.0 , 0.5 ),
865+ };
866+
867+ // Outer
834868 {
835- // Outer
836- std::vector<float64_t2> points = {
837- float64_t2 (3.5 , 8.0 ),
838- float64_t2 (7.0 , 4.5 ),
839- float64_t2 (3.5 , 1.0 ),
840- float64_t2 (0.0 , 4.5 ),
841- float64_t2 (3.5 , 8.0 ),
842- };
843869 CPolyline polyline;
870+ std::vector<float64_t2> points;
871+ points.reserve (diamondPointsCW.size ());
872+ for (const auto & p : diamondPointsCW) points.push_back (p * outerSize + float64_t2 (4.0 , 4.0 ) + offset);
844873 polyline.addLinePoints (points);
845874 polylines.push_back (polyline);
846875 }
876+ // Inner
847877 {
848- // Inner
849- std::vector<float64_t2> points = {
850- float64_t2 (3.5 , 6.5 ),
851- float64_t2 (1.5 , 4.5 ),
852- float64_t2 (3.5 , 2.5 ),
853- float64_t2 (5.5 , 4.5 ),
854- float64_t2 (3.5 , 6.5 )
855- };
856-
857878 CPolyline polyline;
879+ std::vector<float64_t2> points;
880+ points.reserve (diamondPointsCCW.size ());
881+ for (const auto & p : diamondPointsCCW) points.push_back (p * innerSize + float64_t2 (4.0 , 4.0 ) + offset);
858882 polyline.addLinePoints (points);
859883 polylines.push_back (polyline);
860884 }
@@ -1113,47 +1137,63 @@ void shaded(std::vector<CPolyline>& polylines)
11131137
11141138core::smart_refctd_ptr<asset::ICPUBuffer> Hatch::generateHatchFillPatternMSDF (nbl::ext::TextRendering::TextRenderer* textRenderer, HatchFillPattern fillPattern, uint32_t2 msdfExtents)
11151139{
1140+ constexpr std::array<float64_t2, 1u > offsets = {
1141+ float64_t2 (0.0 , 0.0 ),
1142+ // float64_t2(-8.0, -8.0),
1143+ // float64_t2(0.0, -8.0),
1144+ // float64_t2(8.0, -8.0),
1145+ // float64_t2(8.0, 8.0),
1146+ // float64_t2(-8.0, 8.0),
1147+ // float64_t2(0.0, 8.0),
1148+ // float64_t2(-8.0, 0.0),
1149+ // float64_t2(8.0, 0.0),
1150+ };
1151+
11161152 std::vector<CPolyline> polylines;
1117- switch (fillPattern)
1153+
1154+ for (const auto & offset : offsets)
11181155 {
1119- case HatchFillPattern::CHECKERED:
1120- checkered (polylines);
1121- break ;
1122- case HatchFillPattern::DIAMONDS:
1123- diamonds (polylines);
1124- break ;
1125- case HatchFillPattern::CROSS_HATCH:
1126- crossHatch (polylines);
1127- break ;
1128- case HatchFillPattern::HATCH:
1129- hatch (polylines);
1130- break ;
1131- case HatchFillPattern::HORIZONTAL:
1132- horizontal (polylines);
1133- break ;
1134- case HatchFillPattern::VERTICAL:
1135- vertical (polylines);
1136- break ;
1137- case HatchFillPattern::INTERWOVEN:
1138- interwoven (polylines);
1139- break ;
1140- case HatchFillPattern::REVERSE_HATCH:
1141- reverseHatch (polylines);
1142- break ;
1143- case HatchFillPattern::SQUARES:
1144- squares (polylines);
1145- break ;
1146- case HatchFillPattern::CIRCLE:
1147- circle (polylines);
1148- break ;
1149- case HatchFillPattern::LIGHT_SHADED:
1150- lightShaded (polylines);
1151- break ;
1152- case HatchFillPattern::SHADED:
1153- shaded (polylines);
1154- break ;
1155- default :
1156- break ;
1156+ switch (fillPattern)
1157+ {
1158+ case HatchFillPattern::CHECKERED:
1159+ checkered (polylines, offset);
1160+ break ;
1161+ case HatchFillPattern::DIAMONDS:
1162+ diamonds (polylines, offset);
1163+ break ;
1164+ case HatchFillPattern::CROSS_HATCH:
1165+ crossHatch (polylines);
1166+ break ;
1167+ case HatchFillPattern::HATCH:
1168+ hatch (polylines);
1169+ break ;
1170+ case HatchFillPattern::HORIZONTAL:
1171+ horizontal (polylines);
1172+ break ;
1173+ case HatchFillPattern::VERTICAL:
1174+ vertical (polylines);
1175+ break ;
1176+ case HatchFillPattern::INTERWOVEN:
1177+ interwoven (polylines);
1178+ break ;
1179+ case HatchFillPattern::REVERSE_HATCH:
1180+ reverseHatch (polylines);
1181+ break ;
1182+ case HatchFillPattern::SQUARES:
1183+ squares (polylines);
1184+ break ;
1185+ case HatchFillPattern::CIRCLE:
1186+ circle (polylines);
1187+ break ;
1188+ case HatchFillPattern::LIGHT_SHADED:
1189+ lightShaded (polylines);
1190+ break ;
1191+ case HatchFillPattern::SHADED:
1192+ shaded (polylines);
1193+ break ;
1194+ default :
1195+ break ;
1196+ }
11571197 }
11581198
11591199 // Generate MSDFgen Shape
@@ -1176,7 +1216,7 @@ core::smart_refctd_ptr<asset::ICPUBuffer> Hatch::generateHatchFillPatternMSDF(nb
11761216 }
11771217 }
11781218 glyphShapeBuilder.finish ();
1179- glyph.normalize ();
1219+ // glyph.normalize();
11801220
11811221 float scaleX = (1.0 / float (HatchFillPatternGlyphExtents.x )) * float (msdfExtents.x );
11821222 float scaleY = (1.0 / float (HatchFillPatternGlyphExtents.y )) * float (msdfExtents.y );
0 commit comments