Creating-text.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <div>
  13. <p>
  14. There are often times when you might need to use text in your three.js application - here are
  15. a couple of ways that you can do so.
  16. </p>
  17. </div>
  18. <h2>1. DOM + CSS</h2>
  19. <div>
  20. <p>
  21. Using HTML is generally the easiest and fastest manner to add text. This is the method
  22. used for descriptive overlays in most three.js examples.
  23. </p>
  24. <p>You can add content to a</p>
  25. <code>&lt;div id="info"&gt;Description&lt;/div&gt;</code>
  26. <p>
  27. and use CSS markup to position absolutely at a position above all others with a
  28. z-index especially if you are running three.js full screen.
  29. </p>
  30. <code>
  31. #info {
  32. position: absolute;
  33. top: 10px;
  34. width: 100%;
  35. text-align: center;
  36. z-index: 100;
  37. display:block;
  38. }
  39. </code>
  40. </div>
  41. <h2>2. Draw text to canvas and use as a [page:Texture]</h2>
  42. <div>
  43. <p>Use this method if you wish to draw text easily on a plane in your three.js scene.</p>
  44. </div>
  45. <h2>3. Create a model in your favourite 3D application and export to three.js</h2>
  46. <div>
  47. <p>Use this method if you prefer working with your 3d applications and importing the models to three.js</p>
  48. </div>
  49. <h2>4. Procedural Text Geometry</h2>
  50. <div>
  51. <p>
  52. If you prefer to work purely in THREE.js or to create procedural and dynamic 3D
  53. text geometries, you can create a mesh whose geometry is an instance of THREE.TextGeometry:
  54. </p>
  55. <p>
  56. <code>new THREE.TextGeometry( text, parameters );</code>
  57. </p>
  58. <p>
  59. In order for this to work, however, your TextGeometry will need an instance of THREE.Font
  60. to be set on its "font" parameter.
  61. See the [page:TextGeometry] page for more info on how this can be done, descriptions of each
  62. accepted parameter, and a list of the JSON fonts that come with the THREE.js distribution itself.
  63. </p>
  64. <h3>Examples</h3>
  65. [example:webgl_geometry_text WebGL / geometry / text]<br />
  66. [example:webgl_shadowmap WebGL / shadowmap]
  67. <p>
  68. If Typeface is down, or you want to use a font that is not there, there's a tutorial
  69. with a python script for blender that allows you to export text to Three.js's JSON format:
  70. [link:http://www.jaanga.com/2012/03/blender-to-threejs-create-3d-text-with.html]
  71. </p>
  72. </div>
  73. <h2>5. Bitmap Fonts</h2>
  74. <div>
  75. <p>
  76. BMFonts (bitmap fonts) allow batching glyphs into a single BufferGeometry. BMFont rendering
  77. supports word-wrapping, letter spacing, kerning, signed distance fields with standard
  78. derivatives, multi-channel signed distance fields, multi-texture fonts, and more.
  79. See [link:https://github.com/Jam3/three-bmfont-text three-bmfont-text].
  80. </p>
  81. <p>
  82. Stock fonts are available in projects like
  83. [link:https://github.com/etiennepinchon/aframe-fonts A-Frame Fonts], or you can create your own
  84. from any .TTF font, optimizing to include only characters required for a project.
  85. </p>
  86. <p>
  87. Some helpful tools:
  88. </p>
  89. <ul>
  90. <li>[link:http://msdf-bmfont.donmccurdy.com/ msdf-bmfont-web] <i>(web-based)</i></li>
  91. <li>[link:https://github.com/soimy/msdf-bmfont-xml msdf-bmfont-xml] <i>(commandline)</i></li>
  92. <li>[link:https://github.com/libgdx/libgdx/wiki/Hiero hiero] <i>(desktop app)</i></li>
  93. </ul>
  94. </div>
  95. </body>
  96. </html>