Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vasturiano/three-spritetext

A sprite based text component for ThreeJS
https://github.com/vasturiano/three-spritetext

sprite text threejs

Last synced: 14 days ago
JSON representation

A sprite based text component for ThreeJS

Awesome Lists containing this project

README

        

three-spritetext
==============

[![NPM package][npm-img]][npm-url]
[![Build Size][build-size-img]][build-size-url]
[![NPM Downloads][npm-downloads-img]][npm-downloads-url]

A sprite based text component for [ThreeJS](https://threejs.org/). The text is drawn to canvas, converted into a [Texture](https://threejs.org/docs/#api/textures/Texture) and then used as a material on a [Sprite](https://threejs.org/docs/#api/objects/Sprite).
Because a sprite is being used, the text will always face the camera, and has its orientation fixed relative to the camera.

## Quick start

```js
import SpriteText from 'three-spritetext';
```
or using a *script* tag
```html

```
then
```js
const myText = new SpriteText('My text');

const myScene = new THREE.Scene();
myScene.add(myText);
```

## API reference

### Constructor

SpriteText ([text, textHeight, color])

### Properties

| Property | Description | Default |
| --- | --- | :--: |
| text | The text to be displayed on the sprite. Supports center aligned multi-lines, using the `\n` character to define line breaks. ||
| textHeight | The height of the text. | `10` |
| color | The fill color of the text. | `white` |
| backgroundColor | The canvas background color. A falsy value makes the canvas transparent. | `false` |
| strokeWidth | The width of the text stroke, proportional to the text size. A value of `0` disables stroking. | `0` |
| strokeColor | The color of the text stroke. | `white` |
| fontFace | The font type of the text. | `Arial` |
| fontSize | The resolution of the text, in terms of vertical number of pixels. Lower values may cause text to look blurry. Higher values will yield sharper text, at the cost of performance. | `90` |
| fontWeight | The weight (or boldness) of the font. The weights available depend on the font-family you are using. | `normal` |
| padding | The amount of padding between the text and the canvas edge. Supports either single values, or a tuple with two values representing horizontal and vertical padding. | `0` |
| borderWidth | The size of the border around the canvas. Supports either single values, or a tuple with two values representing horizontal and vertical border size. | `0` |
| borderRadius | The corner radius of the border. Supports either single values, or an array of four values representing the four corners in order: top-left, top-right, bottom-right, bottom-left. | `0` |
| borderColor | The color of the border. | `white` |

## Giving Back

[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=L398E7PKP47E8&currency_code=USD&source=url) If this project has helped you and you'd like to contribute back, you can always [buy me a ☕](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=L398E7PKP47E8&currency_code=USD&source=url)!

[npm-img]: https://img.shields.io/npm/v/three-spritetext
[npm-url]: https://npmjs.org/package/three-spritetext
[build-size-img]: https://img.shields.io/bundlephobia/minzip/three-spritetext
[build-size-url]: https://bundlephobia.com/result?p=three-spritetext
[npm-downloads-img]: https://img.shields.io/npm/dt/three-spritetext
[npm-downloads-url]: https://www.npmtrends.com/three-spritetext