1
0

FontLoader.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Loader] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. Class for loading a font in JSON format. Returns a font, which is an
  14. array of [page:Shape Shapes] representing the font.
  15. This uses the [page:FileLoader] internally for loading files. <br /><br />
  16. You can convert fonts online using [link:https://gero3.github.io/facetype.js/ facetype.js]
  17. </p>
  18. <h2>Import</h2>
  19. <p>
  20. [name] is an add-on, and must be imported explicitly.
  21. See [link:#manual/introduction/Installation Installation / Addons].
  22. </p>
  23. <code>
  24. import { FontLoader } from 'three/addons/loaders/FontLoader.js';
  25. </code>
  26. <h2>Code Example</h2>
  27. <code>
  28. const loader = new FontLoader();
  29. const font = loader.load(
  30. // resource URL
  31. 'fonts/helvetiker_bold.typeface.json',
  32. // onLoad callback
  33. function ( font ) {
  34. // do something with the font
  35. console.log( font );
  36. },
  37. // onProgress callback
  38. function ( xhr ) {
  39. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  40. },
  41. // onError callback
  42. function ( err ) {
  43. console.log( 'An error happened' );
  44. }
  45. );
  46. </code>
  47. <h2>Examples</h2>
  48. <p>
  49. [example:webgl_geometry_text_shapes geometry / text / shapes ]<br/>
  50. [example:webgl_geometry_text geometry / text ]
  51. </p>
  52. <h2>Constructor</h2>
  53. <h3>[name]( [param:LoadingManager manager] )</h3>
  54. <p>
  55. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  56. Creates a new [name].
  57. </p>
  58. <h2>Properties</h2>
  59. <p>See the base [page:Loader] class for common properties.</p>
  60. <h2>Methods</h2>
  61. <p>See the base [page:Loader] class for common methods.</p>
  62. <h3>[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  63. <p>
  64. [page:String url] — the path or URL to the file. This can also be a
  65. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  66. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded font.<br />
  67. [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.<br />
  68. [page:Function onError] — Will be called when load errors.<br /><br />
  69. Begin loading from url and pass the loaded font to onLoad.
  70. </p>
  71. <h3>[method:Font parse]( [param:Object json] )</h3>
  72. <p>
  73. [page:Object json] — The `JSON` structure to parse.<br /><br />
  74. Parse a `JSON` structure and return a font.
  75. </p>
  76. <h2>Source</h2>
  77. <p>
  78. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/FontLoader.js examples/jsm/loaders/FontLoader.js]
  79. </p>
  80. </body>
  81. </html>