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.blurredline

v1.3.0

Published

Drawing smooth blurred lines in THREE.js

Downloads

17

Readme

THREE.BlurredLine

NPM Package

Draw lines of varying width, blur, color and opacity in THREE.js

This libary draws lines as a mesh and internally creates a BufferGeometry.

It is useful not only for drawing wide soft lines, but also extremely thin lines neatly.

Examples

  • All features: Demo of all the features
  • Simple: Simple Example
  • Modifiers: Using modifier functions to draw varying line widths, blur widths and colors

Usage

  • Include script
  • Create a Curve
  • Create a BlurredLineMaterial
  • Create a BlurredLine supplying curve and material

Including the script

Include script after THREE is included:

<script src="src/index.js"></script>

or include directly from unpkg.com:

<script src="https://unpkg.com/three.blurredline"></script>

or use npm to install it:

npm i three.blurredline

or use yarn to install it:

yarn add three.blurredline

and include it in your code:

import * as THREE from 'three';
import { BlurredLine, BlurredLineMaterial } from 'three.blurredline';

Create a Curve

First create a Curve e.g. using THREE.CubicBezierCurve3, THREE.EllipseCurve, THREE.LineCurve3, THREE.Path or THREE.SplineCurve.

var curve = new THREE.LineCurve3(
  new THREE.Vector3(0, 0, 0),
  new THREE.Vector3(100, 0, 0)
);

Create a BlurredLineMaterial

var material = new BlurredLineMaterial({
  color: new THREE.Color('#FF0000'),
  opacity: 1.0,
});
  • colorTHREE.Color
  • opacity – alpha value from 0 to 1

Create a BlurredLine

Use Curve and BlurredLineMaterial to create a BlurredLine mesh, call updateGeometry() and add it to the scene. The third parameter specifies the resolution:

var line = new BlurredLine(curve, material, 50);
line.lineWidth = 2.0;
line.blurWidth = 10.0;
line.blur = true;
line.updateGeometry();
scene.add(line);

updateGeometry() needs to be called again whenever any parameter affecting the geometry changes (angleBisection, blur, blurWidth, blurWidthModifier, curve, lineWidth, lineWidthModifier, upVector).

API

BlurredLine class

Extends THREE.Mesh.

Constructor:

BlurredLine(curve : THREE.Curve, material: BlurredLineMaterial, resolution : number)

Variables:

angleBisection: boolean – use angle bisection to calculate the side vectors (better for 2D lines)

blur: boolean – whether to use blurWidth or draw hard lines instead (uses less triangles when set to false)

blurWidth: number – blur width of the line

blurWidthModifier: function – modifier function for the blur width of the line. Has to return a number. For example cubic easing in: (p) => { return p * p; }

closed: boolean – whether the line is closed (e.g. used for ellipses)

color: THREE.Color – defaults to white and is multiplied with material color while drawing.

colorModifier: function – modifier function for the line color. Has to return a THREE.Color. colorModifier is multiplied with color and material color while drawing. For example for a transition between two colors: (p) => { return new THREE.Color(0x000000).lerp(new THREE.Color(0xff0000), p); }

curve: THREE.Curve – base curve

lineWidth: number – thickness of the line

lineWidthModifier: function – modifier function for the width of the line. Has to return a number. For example cubic easing in: (p) => { return p * p; }

opacity: number – opacity of the line, is multiplied with material opacity while drawing.

opacityModifier: function – modifier function for the opacity of the line. Has to return a number. opacityModifier is multiplied with color and material color while drawing. For example cubic easing in: (p) => { return p * p; }

upVector: THREE.Vector3 – upvector, e.g. vector facing the camera, defaults to (0.0, 0.0, 1.0).

Methods:

updateColors() – needs to be called again whenever any parameter affecting the color changes (color, colorModifier, opacity, opacityModifier). Material parameter changes are updated automatically.

updateGeometry() – needs to be called again whenever any parameter affecting the geometry changes (angleBisection, blur, blurWidth, blurWidthModifier, curve, lineWidth, lineWidthModifier, upVector). Internally calls updateColors() as well. Material parameter changes are updated automatically.

BlurredLineMaterial class

Extends THREE.RawShaderMaterial.

Constructor:

BlurredLineMaterial(parameters : Object) parameters – (optional) an object with one or more properties defining the material's appearance. Any property of the material (including any property inherited from Material and ShaderMaterial) can be passed in here.

Properties:

Also see the base THREE.RawShaderMaterial class for common properties.

color (THREE.Color) – defaults to white and is multiplied with material color while drawing.

opacity (number) – opacity of the line, is multiplied with material opacity while drawing.

Methods:

See the base THREE.RawShaderMaterial class for common methods.

License

MIT licensed

Copyright (C) 2021 Markus Lerner, http://www.markuslerner.com