# three.textsprite

> Automatically computes the optimal font size depending on the distance to the camera and the size of the renderer canvas.

Latest version **20.0.0** (published 2019-04-26) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install three.textsprite
pnpm add three.textsprite
yarn add three.textsprite
bun add three.textsprite
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 20.0.0 |
| Published | 2019-04-26 |
| First published | 2017-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 157 |
| Author | Sergej Sintschilin |
| Maintainers | seregpie |
| Keywords | 3d, canvas, class, font, group, object, plugin, resolution, scale, size, text, texture, three |

## Links

- npm: https://www.npmjs.com/package/three.textsprite
- Repository: https://github.com/SeregPie/THREE.TextSprite
- Homepage: https://github.com/SeregPie/THREE.TextSprite#readme
- Issues: https://github.com/SeregPie/THREE.TextSprite/issues
- npm.io page: https://npm.io/package/three.textsprite

## Dependencies (1)

- [three.texttexture](https://npm.io/package/three.texttexture.md) ^20.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 20.0.0 (latest) — 2019-04-26
- 19.0.0 — 2019-01-31
- 18.10.25 — 2019-01-30
- 18.10.24 — 2018-10-24
- 18.8.6 — 2018-08-05
- 18.7.14 — 2018-07-13
- 18.6.7 — 2018-07-06
- 18.3.19 — 2018-03-19
- 18.3.3 — 2018-03-03
- 18.1.16 — 2018-01-16
- 17.11.23 — 2017-11-23
- 17.11.21 — 2017-11-21
- 17.11.5 — 2017-11-05
- 17.10.2-2.2 — 2017-10-22
- 17.10.2-2.1 — 2017-10-22
- … 3 more at https://npm.io/package/three.textsprite/versions

## README

# THREE.TextSprite

`class THREE.TextSprite extends THREE.Sprite`

An instance of `TextSprite` automatically computes the optimal font size depending on the distance to the camera and the size of the renderer canvas.

## demo

[Try it out!](https://seregpie.github.io/THREE.TextSprite/)

## dependencies

- [THREE.TextTexture](https://github.com/SeregPie/THREE.TextTexture)

## setup

### npm

```shell
npm i three.textsprite
```

### ES module

```javascript
import TextSprite from 'three.textsprite';
```

### browser

```html
<script src="https://unpkg.com/three"></script>
<script src="https://unpkg.com/three.texttexture"></script>
<script src="https://unpkg.com/three.textsprite"></script>
```

The class `TextSprite` will be available under the namespace `THREE`.

## members

```
.constructor({
  material,
  maxFontSize,
  minFontSize,
  redrawInterval,
  textSize,
  texture,
})
```

| argument | description |
| ---: | :--- |
| `material` | The parameters to pass to the constructor of [`SpriteMaterial`](https://threejs.org/docs/index.html#api/materials/SpriteMaterial). |
| `texture` | The parameters to pass to the constructor of [`TextTexture`](https://github.com/SeregPie/THREE.TextTexture). |

```javascript
let sprite = new THREE.TextSprite({
  material: {
    color: 0xffbbff,
    fog: true,
  },
  redrawInterval: 250,
  textSize: 10,
  texture: {
    fontFamily: 'Arial, Helvetica, sans-serif',
    text: 'Be happy. Be bright. Be you.',
  },  
});
scene.add(sprite);
```

---

`.isTextSprite = true`

Used to check whether this is an instance of `TextSprite`.

You should not change this, as it is used internally for optimisation.

---

`.textSize = 1`

The size of the text.

---

`.redrawInterval = 1`

The minimum time that must elapse before the canvas is redrawn.

---

`.minFontSize = 0`

The minimum font size.

---

`.maxFontSize = Infinity`

The maximum font size.

---

`.dispose()`

Disposes the texture and the material.

---
_Source: https://npm.io/package/three.textsprite · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
