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-typeable-text

v0.1.6

Published

Typeable text for three.js

Downloads

11

Readme

The Three.js Typeable Text Library v0.1.6

The intention of this library is to make creation and integration of typeable text elements seamless with threejs.

Support me here https://ko-fi.com/joshfield Follow me here https://twitter.com/HexaField

Design:

This is designed to be as simple as creating the ThreeTypeableText object, adding it to the scene, and optionally updating it to show the cursor. There is some basic functionality that should integrate with most project designs easily. You can find what is planned for this at the bottom.

Example:

A live demo can be found here

Usage:

function init()
{
    // ... initialise threejs

    var textField = new ThreeTypeableText({
        camera: camera,
        font: font,
        string: 'Hello text!'
    });
    
    scene.add(textField.getObject())
}

function animate()
{
    // ...
    
    textField.updateCursor() // only used for displaying the cursor, not necessary for functionality

    // ...
}

Parameters:

camera A THREE.Camera (only needed if useDocumentListeners is true)

font The THREE.Font to use (always needed)

string The text to display

useDocumentListeners: Use built-in document listeners (default: true)

material A THREE.Material to use (default: new THREE.MeshBasicMaterial({ side: THREE.DoubleSide }))

align Shifts the text. (options: 'left', 'center', 'right', default: 'center')

fontScale Scales the geometry (default: 1)

onChange A callback that is fired when the text changes internally

onFocus A callback that is fired when the focus changes internally (true if gaining focus, false otherwise)

maxEditHistory The number of copies of the string to put in edit history (default: 32)

API:

Setting useDocumentListeners to false will require you to use the following functions to update the text manually

// Change the text
textField.setText('New text!');

// Returns the text
textField.getText(); // returns 'New text!'

// To access the text as an object use
textField.getObject().position.setY(10)

// Move the cursor 3 letters to the right
textField.actionMoveCursor(3);

// Returns the character index of the cursor
textField.getCursorIndex(); // returns 3

// Text will now display 'Ne text!'
textField.actionBackspace();

// Text will now display 'Netext!'
textField.actionDelete();

// Move the cursor 1 letter to the left
textField.actionMoveCursor(-1);

// Text will now display 'N8etext!'
textField.actionType('8');

// Will now display 'Ne text!'
textField.actionUndo(2);

// Will return 'Netext!'
textField.actionRedo(1);

// Will stop all internal document listeners & hide the cursor
textField.actionFocus(false);

// Get the text height
textField.getLineHeight(); // depends on fontScale and the font itself

// Check to see if the user has clicked
// This should run on your mouse click event

// - supplying a valid THREE.Vector3 will move the cursor
// - supplying an invalid point will defocus the text

raycaster.setFromCamera(mouse, camera)
var intersections = raycaster.intersectObject(textField.getObject())
textField.actionClick(intersections.length > 0 ? intersections[0].point : false);

Planned Features:

API

  • mobile typing support
  • shift + arrows to make selection
  • control + c / v / x - copy cut paste
  • click and drag to make selection
  • control + arrows to jump words
  • control + delete / backspace to delete / backspace whole words
  • better text alignment & spacing
  • text outline
    • thickness
    • dotted
    • empty interior
  • extrusion & bevel
  • add onFocus / onUnFocus events
  • formatting

INTERNALS:

  • generate letter by letter to not have to regenreate the whole string every time a letter is changed
  • add & remove document listeners on focus & unfocus