
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
three-msdf-text-webgpu
Advanced tools
Text rendering in Three.js with WebGPU using MSDF fonts.
Forked from three-msdf-text-utils.
This package requires using MSDF fonts which can be created using either the msdf-bmfont-xml cmd line tool or with Dom McCurdy's web tool.
npm install three-msdf-text-webgpu
There are two main methods to create a MSDFText mesh:
This method involves manually defining the text string along with various CSS options to determine how the mesh is rendered.
import * as THREE from "three/webgpu";
import { Font, FontLoader } from "three/examples/jsm/loaders/FontLoader.js";
import { MSDFText, type BMFontJSON } from "three-msdf-text-webgpu";
const fontLoader = new FontLoader();
const textureLoader = new THREE.TextureLoader();
// Load generated MSDF font files
const font = await this.fontLoader.loadAsync("/font/Roboto-Regular-msdf.json"),
const atlas = await this.textureLoader.loadAsync("/font/Roboto-Regular.png")
const options = {
text: "MSDF Text",
textStyles: {
widthPx: 500,
fontFamily: "Roboto",
fontSize: 32,
fontWeight: "400",
lineHeightPx: 50,
letterSpacingPx: 0,
textAlign: 'left',
whiteSpace: 'normal',
color: '#ff0000',
opacity: 1
}
}
const textMesh = new MSDFText(options, { atlas, data: font.data })
Note: The width/height of the resultant geometry will be equal to the pixel width/height of the rendered text, so the resulting mesh will need to be scaled.
The available options are:
text (string: required)textStylesWith textStyles:
widthPx (number: required) - Width of the text in pixels. Determines where text is wrapped.fontFamily (string): Default - RobotofontSize (number px): Default - 16fontWeight (string): Default - "400"fontStyle (string): Default - "normal"lineHeightPx (number): Default - 16letterSpacingPx (number): Default - 0textAlign ("center" | "end" | "left" | "right" | "start"): Default - "left"whiteSpace ("normal" | "nowrap" | "pre" | "pre-wrap" | "pre-line" | "break-spaces"): Default - "normal"color (string): Default - "#000000"opacity (number): Default - 1The method .update(options) can be called with partial options to update the text geometry and material.
By passing a HTMLElement, the styling of the text will match that of the element.
import * as THREE from "three/webgpu";
import { Font, FontLoader } from "three/examples/jsm/loaders/FontLoader.js";
import { MSDFText, type BMFontJSON } from "three-msdf-text-webgpu";
const fontLoader = new FontLoader();
const textureLoader = new THREE.TextureLoader();
// Load generated MSDF font files
const font = await this.fontLoader.loadAsync("/font/Roboto-Regular-msdf.json"),
const atlas = await this.textureLoader.loadAsync("/font/Roboto-Regular.png")
const textElement = document.querySelector<HTMLDivElement>('[data-3d]')!;
const textMesh = new SyncMSDFText(
textElement,
{ atlas, data: font.data as unknown as BMFontJSON },
)
Using this method also allows mesh.update(camera: THREE.Camera) to be called which will update the transform of the mesh to align with the DOM element in the camera's view at a given depth (5 units by default).
See the github pages site for a sandbox demo.
To run the example demo locally, run:
npm i
npm run example
For more information on this package, see this blog page.
FAQs
Text rendering in Three.js with WebGPU using MSDF fonts.
The npm package three-msdf-text-webgpu receives a total of 0 weekly downloads. As such, three-msdf-text-webgpu popularity was classified as not popular.
We found that three-msdf-text-webgpu demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.