npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

three-msdf

v1.0.2

Published

Bitmap font rendering for ThreeJS. Based on three-bmfont-text by Jam3 (https://github.com/Jam3/three-bmfont-text). With more parameters, auto-loading and es6 syntax.

Downloads

3

Readme

MSDF Text for ThreeJS

Bitmap font rendering for ThreeJS. Based on three-bmfont-text by Jam3 (https://github.com/Jam3/three-bmfont-text). With more parameters, auto-loading and es6 syntax.

Install

npm i three-msdf --save

Examples

Custom loading

Load your font files before

import loadFont from 'load-bmfont'
import { TextureLoader } from 'three'
import ThreeMSDF from 'three-msdf'

loadFont('fonts/myFont.json', (err, font) => {
  if (err) throw err
  new TextureLoader().load('fonts/myFont.png', (texture) => {
    const text = new ThreeMSDF({
      options: {
        font: font,
        text: 'Hello World!'
      },
      texture: texture,
      camera: yourCamera,
      renderer: yourWebGLRenderer
    })
  })
})

Auto loading font files

Give your font path files and the module will load these for you

import ThreeMSDF from 'three-msdf'

const text = new ThreeMSDF({
  options: {
    fontInfos: 'fonts/myFont.json',
    fontImage: 'fonts/myFont.png'
    text: 'Hello World!'
  },
  camera: yourCamera,
  renderer: yourWebGLRenderer
})

Parameters

  • options (object)

    • flipY (boolean) whether the texture will be Y-flipped (default true)
    • multipage (boolean) whether to construct this geometry with an extra buffer containing page IDs. This is necessary for multi-texture fonts (default false)
    • font (required) the BMFont definition which holds chars, kernings, etc
    • text (string) the text to layout. Newline characters (\n) will cause line breaks
    • width (number, optional) the desired width of the text box, causes word-wrapping and clipping in "pre" mode. Leave as undefined to remove word-wrapping (default behaviour)
    • mode (string) a mode for word-wrapper; can be 'pre' (maintain spacing), or 'nowrap' (collapse whitespace but only break on newline characters), otherwise assumes normal word-wrap behaviour (collapse whitespace, break at width or newlines)
    • align (string) can be "left", "center" or "right" (default: left)
    • letterSpacing (number) the letter spacing in pixels (default: 0)
    • lineHeight (number) the line height in pixels (default to font.common.lineHeight)
    • tabSize (number) the number of spaces to use in a single tab (default 4)
    • start (number) the starting index into the text to layout (default 0)
    • end (number) the ending index (exclusive) into the text to layout (default text.length)
    • fontInfos (string) Path of your font file (default false)
    • fontImage (string) Path of your Image font file (default false)
    • fontSize (number) Size of your text (default 16)
    • anchor (object)
      • x(string) Text anchor. Can be left, center or right (default left)
      • y(string) Text anchor. Can be top, center or bottom (default top)
    • segments (object)
      • x(number) Number of divisions by letter (default 1)
      • y(number) Number of divisions by letter (default 1)
  • texture (string) ThreeJS texture of your font

  • shaders (object)

    • vertex (string) Custom vertex shader
    • fragment (string) Custom fragment shader
  • uniforms (object) Custom uniforms

  • parameters (object) ThreeJS parameters for the ShaderMaterial

  • camera ThreeJS Camera. This is needed for the calculation of the font size

  • renderer ThreeJS Renderer. This is needed for the calculation of the font size