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-path-geometry

v1.0.2

Published

thick 2D lines for ThreeJS

Downloads

11

Readme

three-path-geometry

experimental

Above: a BufferGeometry combines several variations of an SVG file.

Thick 2D line geometry for ThreeJS, converting a polyline into triangles. This has been optimized and designed for a specific application, so its feature set is limited:

  • Supports "Move To" and "Line To" commands for a polyline
  • Designed for fixed line thickness
  • Supported joins: miter or bevel (with miter limiting)
  • Uses a mix of front and back side indexing
  • Can incrementally add new paths to the geometry in an optimized manner

This is best suited for a drawing app that needs to render thousands of commands, i.e. using a static geometry.

:bulb: Dynamic growing/shrinking of buffers is only supported in ThreeJS r82 and higher.

Install

npm install three-path-geometry --save

Example

See ./demo/index.js for a full demo, which renders the earlier screenshot of the SVG.

global.THREE = reqiure('three');
const PathGeometry = require('three-path-geometry');

const geometry = new PathGeometry({ thickness: 2 });
geometry.update([
  { type: 'M', position: [ 25, 15 ] },
  { type: 'L', position: [ 50, 15 ] },
  { type: 'L', position: [ 50, 25 ] }
]);

const material = new THREE.MeshBasicMaterial({
  color: 'black',
  side: THREE.DoubleSide // needed for this geometry
});

const mesh = new THREE.Mesh(geometry, material);
mesh.frustumCulled = false; // currently needed for 2D geometries

scene.add(mesh);

This module expects THREE to exist on global scope.

Usage

NPM

geometry = new PathGeometry([opt])

Creates a new PathGeometry with the options:

  • thickness — the thickness of the line in world units, default 1
  • miterLimit — the limit to use when mitering line joins, default 8 (use Infinity for pure bevel, 0 for pure miter)

geometry.clear()

Clears the current geometry and its paths.

geometry.update(path)

Clears the geometry and sets it to the new path, which is an array of commands like so:

[
  { type: 'M', position: [ 25, 15 ] },
  { type: 'L', position: [ 50, 15 ] }
]

Commands can be either type 'M' (moveTo) or 'L' (lineTo). The position is a 2D plain array with the [ x, y ] value.

geometry.append(path)

Appends a new path to the existing geometry, without clearing anything first. The commands are the same format as in update.

geometry.thickness

The current thickness of the geometry.

geometry.miterLimit

The current miter limit of the geometry.

License

MIT, see LICENSE.md for details.