textBuilder.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import type { Color4 } from "../../Maths/math.color";
  2. import { Path2 } from "../../Maths/math.path";
  3. import type { Vector4 } from "../../Maths/math.vector";
  4. import type { Scene } from "../../scene";
  5. import type { Nullable } from "../../types";
  6. import { Mesh } from "../mesh";
  7. /**
  8. * Parser inspired by https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/FontLoader.js
  9. */
  10. /**
  11. * Represents glyph data generated by http://gero3.github.io/facetype.js/
  12. */
  13. export interface IGlyphData {
  14. /** Commands used to draw (line, move, curve, etc..) */
  15. o: string;
  16. /** Width */
  17. ha: number;
  18. }
  19. /**
  20. * Represents font data generated by http://gero3.github.io/facetype.js/
  21. */
  22. export interface IFontData {
  23. /**
  24. * Font resolution
  25. */
  26. resolution: number;
  27. /** Underline tickness */
  28. underlineThickness: number;
  29. /** Bounding box */
  30. boundingBox: {
  31. yMax: number;
  32. yMin: number;
  33. };
  34. /** List of supported glyphs */
  35. glyphs: {
  36. [key: string]: IGlyphData;
  37. };
  38. }
  39. declare class ShapePath {
  40. private _paths;
  41. private _tempPaths;
  42. private _holes;
  43. private _currentPath;
  44. private _resolution;
  45. /** Create the ShapePath used to support glyphs
  46. * @param resolution defines the resolution used to determine the number of points per curve (default is 4)
  47. */
  48. constructor(resolution: number);
  49. /** Move the virtual cursor to a coordinate
  50. * @param x defines the x coordinate
  51. * @param y defines the y coordinate
  52. */
  53. moveTo(x: number, y: number): void;
  54. /** Draw a line from the virtual cursor to a given coordinate
  55. * @param x defines the x coordinate
  56. * @param y defines the y coordinate
  57. */
  58. lineTo(x: number, y: number): void;
  59. /** Create a quadratic curve from the virtual cursor to a given coordinate
  60. * @param cpx defines the x coordinate of the control point
  61. * @param cpy defines the y coordinate of the control point
  62. * @param x defines the x coordinate of the end point
  63. * @param y defines the y coordinate of the end point
  64. */
  65. quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
  66. /**
  67. * Create a bezier curve from the virtual cursor to a given coordinate
  68. * @param cpx1 defines the x coordinate of the first control point
  69. * @param cpy1 defines the y coordinate of the first control point
  70. * @param cpx2 defines the x coordinate of the second control point
  71. * @param cpy2 defines the y coordinate of the second control point
  72. * @param x defines the x coordinate of the end point
  73. * @param y defines the y coordinate of the end point
  74. */
  75. bezierCurveTo(cpx1: number, cpy1: number, cpx2: number, cpy2: number, x: number, y: number): void;
  76. /** Extract holes based on CW / CCW */
  77. extractHoles(): void;
  78. /** Gets the list of paths */
  79. get paths(): Path2[];
  80. /** Gets the list of holes */
  81. get holes(): Path2[];
  82. }
  83. /**
  84. * Creates shape paths from a text and font
  85. * @param text the text
  86. * @param size size of the font
  87. * @param resolution resolution of the font
  88. * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)
  89. * @returns array of ShapePath objects
  90. */
  91. export declare function CreateTextShapePaths(text: string, size: number, resolution: number, fontData: IFontData): ShapePath[];
  92. /**
  93. * Create a text mesh
  94. * @param name defines the name of the mesh
  95. * @param text defines the text to use to build the mesh
  96. * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)
  97. * @param options defines options used to create the mesh
  98. * @param scene defines the hosting scene
  99. * @param earcutInjection can be used to inject your own earcut reference
  100. * @returns a new Mesh
  101. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/text
  102. */
  103. export declare function CreateText(name: string, text: string, fontData: IFontData, options?: {
  104. size?: number;
  105. resolution?: number;
  106. depth?: number;
  107. sideOrientation?: number;
  108. faceUV?: Vector4[];
  109. faceColors?: Color4[];
  110. perLetterFaceUV?: (letterIndex: number) => Vector4[];
  111. perLetterFaceColors?: (letterIndex: number) => Color4[];
  112. }, scene?: Nullable<Scene>, earcutInjection?: any): Nullable<Mesh>;
  113. export {};