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

@pixi/graphics-smooth

v1.1.0

Published

PixiJS v7 plugin for smooth HHAA rendering of shapes

Downloads

30,553

Readme

PixiJS Smooth Graphics

PixiJS v7 plugin for making smooth shapes using HHAA shader.

Build npm version

:link: Links

Features

This is very early version of the plugin.

Here's how it looks, compared to pixi graphics (antialias=false)

img_1.png

You can find examples in examples folder, you have to start the local webserver in repo folder to view them.

How to draw lines

This is drop-in replacement of PIXI.Graphics, API is compatible.

import { SmoothGraphics as Graphics } from '@pixi/graphics-smooth';

const graphics = new Graphics();

graphics.moveTo(100, 100);
graphics.lineTo(200, 200);

LineScaleMode

For lines, native mode is renamed to scaleMode, you can ignore scale of element or even set default value for it!

import { SmoothGraphics, LINE_SCALE_MODE, settings } from '@pixi/graphics-smooth';

graphics.lineStyle({ width: 2.0, scaleMode: LINE_SCALE_MODE.NONE }); // now its always 2 independent from scale

//alternatively
settings.LINE_SCALE_MODE = LINE_SCALE_MODE.NONE;

const graphics2 = new SmoothGraphics();
graphics.lineStyle(2.0, 0xffffff, 1.0); //the usual, but scaleMode works by default

settings.LINE_SCALE_MODE = LINE_SCALE_MODE.NORMAL;
graphics.lineStyle(2.0, 0xffffff, 1.0); //its normal again

Note: NONE was the only option for graphics-smooth <= 0.0.6. Please update your code if you used early versions!

How to draw fills

Fills have a bit of a problem - smoothing works good only on concave objects. It works only on circles and polygons. It is not implemented for rects and rounded rects yet.

graphics.beginFill(0xffffff, 1.0, true); //third param for beginFill

HHAA doesn't work with texture fill yet.

drawStar and other graphics-extras

That's what you have to do if you need functions from graphics-extras package:

import { SmoothGraphics } from '@pixi/graphics-smooth';
import { Graphics } from '@pixi/graphics';
import '@pixi/graphics-extras';

Object.assign(SmoothGraphics.prototype, {
    drawTorus: Graphics.prototype.drawTorus,
    drawChamferRect: Graphics.prototype.drawChamferRect,
    drawFilletRect: Graphics.prototype.drawFilletRect,
    drawRegularPolygon: Graphics.prototype.drawRegularPolygon,
    drawRoundedPolygon: Graphics.prototype.drawRoundedPolygon,
    drawStar: Graphics.prototype.drawStar,
});

For UMD:

PIXI.smooth.SmoothGraphics.prototype.drawStar = PIXI.Graphics.prototype.drawStar;

Pixel Perfect

You might notice that for diagonal lines, coverage differs from canvas2d a lot, especially if you do line animations. Solution is easy:

import { settings } from '@pixi/graphics-smooth';
settings.PIXEL_LINE = 1;

It has to be done before first GraphicsSmooth is created.

This setting is disabled by default because it adds extra computations in coverage calculation. It is not researched yet how it will affect performance.

What are we working on

  • better AA on fills
  • support for line textures
  • rope mode for line textures

Performance

Currently graphics geometry uses 11 floats per vertex, when original graphics used only 8. Number of vertices also differ, it might use up to 2x of original.

Uniforms are used to store styles depends on (lineWidth * scaleMode, lineAlignment, texture, matrix).

If style buffer is too big (for now its max 24), one more drawcall will spawn.

What are we working on

  • support instancing
  • support Uniform Buffer Objects
  • support batching of multiple graphics elements

Build & Test

npm install
npm start