Creating-text.html 3.5 KB

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