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

draft-n-draw

v0.3.1

Published

### 🖍️ A utility for drawing debug visualizations in threejs.

Downloads

30

Readme

Draft-n-Draw

🖍️ A utility for drawing debug visualizations in threejs.

Easily visualize bounding boxes, raycasts, points, lights and more in threejs. Fully typed, it can be used with vanilla JS or TypeScript and also has convenient React components for use in react-three-fiber.

npm install draft-n-draw

Getting started

React

You begin by adding the DrafterProvider component to the top level of your app.

import { Canvas } from '@react-three/fiber';
import { DrafterProvider } from '@draft-n-draw/react';

function App() {
  return (
    <Canvas>
      <DrafterProvider>
        <Game />
      </DrafterProvider>
    </Canvas>
  );
}

And then we can access the drafter either inside a component with a hook or outside a component with a getter function.

import { getDrafter, useDrafter } from '@draft-n-draw/react';

// Outside a component.
const drafter = getDrafter();

// Inside a component.
function Component() {
  const drafter2 = useDrafter();

  //...
}

👉 Note: If you just want the React package you can install @draft-n-draw/react.

npm install @draft-n-draw/react

Vanilla JS

You begin by creating a drafter for your scene.

import { Drafter } from '@draft-n-draw/vanilla';

const drafter = new Drafter(scene);

👉 Note: If you just want the vanilla JS package you can install @draft-n-draw/vanilla.

npm install @draft-n-draw/vanilla

Draw!

Then anywhere you are debugging request a draw.

drafter.drawBox3(myBox3);
drafter.drawRay({ origin, direction, distance });

By default, draws only last a single frame and are kept active by being called in a loop. This way you can safely inline them in functions you are debugging without worrying about spawning too many scene objects or cleaning them up when done — Draft-n-Draw will handle that for you.

If instead you want the draw to persist, you can specify it in the draw options.

drafter.drawSpotLight(mySpotLight, { persist: true });

👉 Note: This will cause a new draw to be persisted on screen each call, so be careful!

A persisted draw can be cleaned up using the dispose() method with the object being visualized as the key.

drafter.dispose(mySpotLight);

Finally, there are additional draw options for controlling the visuals such as drawing on top and adjusting color or opacity.

drafter.drawWireSphere({ center, radius }, { color: 'yellow', alwaysOnTop: true, opacity: 0.5 });

API

The draw coverage is a work in progress. Our drafter is learning on the job! First we have the generic draw() method which can draw any custom visualization or helper. It has all the generic options discussed above.

| Method | Object | Options | | ------ | -------------- | ----------------------------------------------------------------------------------------------- | | draw() | THREE.Object3D | { color: THREE.ColorRepresentation, alwaysOnTop: boolean, opacity: number, persist: boolean } |

And then we have draws for math objects. Unless stated otherwise all options are shared with draw().

| Method | Object | Special options | | ---------------- | ----------------------------------------------------------------------- | ------------------ | | drawBox3 | THREE.Box3 | None. | | drawRay | { origin: THREE.Vector3, direction: THREE.Vector3, distance: number } | None. | | drawPoint | THREE.Vector3 | radius: number | | drawWireTriangle | THREE.Triangle | None. | | drawTriangle | THREE.Triangle | winZFight: boolean | | drawWireSphere | { center: THREE.Vector3, radius: number } or THREE.Sphere | None. | | drawSphere | { center: THREE.Vector3, radius: number } or THREE.Sphere | None. |

And finally some draws for lights. Unless stated otherwise all options are shared with draw().

| Method | Object | Special options | | -------------------- | ---------------------- | --------------- | | drawSpotlight | THREE.SpotLight | None. | | drawPointlight | THREE.PointLight | None. | | drawDirectionalLight | THREE.DirectionalLight | None. | | drawHemisphereLight | THREE.HemisphereLight | None. |