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

babylon-msdf-text

v0.0.4

Published

Introducing babylon-msdf-text, that implements the Multi-channel Signed Distance Field (MSDF) technique for text rendering. This library provides developers with an efficient and straightforward way to render high-quality, scalable, and anti-aliased text

Downloads

28

Readme

babylon-msdf-text

Introducing babylon-msdf-text, that implements the Multi-channel Signed Distance Field (MSDF) technique for text rendering. This library provides developers with an efficient and straightforward way to render high-quality, scalable, and anti-aliased text in their Babylon.js projects. Leveraging the power of MSDF, it allows for superior text rendering, especially in WebGL contexts, overcoming the limitations of traditional bitmap fonts. Here is Live Demo

npm npm

Installation

npm install babylon-msdf-text

Usage

import { createTextMesh } from "babylon-msdf-text";

The createTextMesh function is used to create a text mesh. It accepts the following parameters: 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)

  • text: The text string you want to render in the scene.
  • font: A JSON file with font data (Required).
  • scene: The Babylon.js scene in which you want to render the text (Required).
  • atlas: A PNG image of the font (Required).
  • engine: The Babylon.js engine (Required).
  • width : width of text block.
  • opacity : opacity of text.
  • lineHeight : The line height in percent. Default and minimum is 1.
  • letterSpacing : the letter spacing in pixel
  • align : Horizontal text alignment. Can be "left", 'center' or "right". Default is "left"
  • color : fill color of text. can be babylon's Color3 class or object of r, g and b values.

Example

// Import Babylon.js
import * as BABYLON from "@babylonjs/core";
// Import createTextMesh, font data and font png
import { createTextMesh } from "babylon-msdf-text";
import fnt from "./fontAssets/roboto-regular.json";
import png from "./fontAssets/roboto-regular.png";

// Create Babylon.js scene
const initCamera = (scene) => {
  const camera = new BABYLON.ArcRotateCamera(
    "camera",
    0,
    0,
    10,
    new BABYLON.Vector3(0, 0, 0),
    scene
  );

  camera.attachControl(true);
  camera.setPosition(new BABYLON.Vector3(0, 0, -400));
  return camera;
};

const canvas = document.getElementById("renderCanvas");
const engine = new BABYLON.Engine(canvas);

const createScene = function (engine) {
  const scene = new BABYLON.Scene(engine);
  scene.clearColor = new BABYLON.Color3(1, 1, 1);
  //CAMERA
  initCamera(scene);

  return scene;
};

const scene = createScene(engine);

engine.runRenderLoop(function () {
  scene.render();
});

window.addEventListener("resize", function () {
  engine.resize();
});

// Create text mesh
let textGeo = createTextMesh({
  text: `Hello Babylon`,
  font: fnt,
  scene,
  atlas: png,
  engine,
});

textGeo.position.x = -textGeo.getBoundingInfo().boundingBox.center.x / 2;
textGeo.position.y = textGeo.getBoundingInfo().boundingBox.center.y / 2;

How to create assets for MSDF

You can use online MSDF assets generator to generate json and png file.

  • Just upload .ttf file of your choice of font
  • Type the characters you wanna pack in assets (including space)
  • select the size of texture
  • And create MSDF and that's it 🎉

Roadmap

  • Option to add stroke
  • More Examples
  • NPM Publish workflow

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.