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

@dkostenevich/tree-js

v0.6.0

Published

<p align="center"> <img src="https://github.com/dkostenevich/tree-js/assets/3814912/d42076c3-06ad-469d-bca1-f84a1a5eb2cb" width="400"> </p>

Downloads

21

Readme

Tree.js

A procedural tree generator built with Three.js. Over 30 tunable parameters and support for exporting to .glb.

Installation

The tree generation code is published as an npm package and can be imported into your own project.

npm i @dkostenevich/tree-js

Usage

// Create new instance
const tree = new Tree();

// Set parameters
tree.options.trunk.length = 20;
tree.options.branch.levels = 3;

// Generate tree and add to scene
tree.generate();
scene.add(tree);

Any time the tree parametes are changed, you must call generate() to regenerate the geometry.

For more info, see the demo app for an example on how to create a tree.

Demo

The demo application is a Three.js app which allows you to tune the parameters of the tree in real-time. It also has options for exporting the generated mesh to a .glb file, as well as a .png export of the current view for 2D applications.

Running Demo Locally

npm install
npm run build:npm
npm run demo

Running Demo with Docker

docker compose build
docker compose up -d

Parameters

  • seed - Seed for RNG

Trunk

  • color - Color of the tree trunk
  • flatShading - Use face normals for shading instead of vertex normals
  • length - Length of the base trunk
  • radius - Starting radius of the trunk

Branches

  • levels - Number of branch recursions ( Keep under 5 )
  • children - Number of child branches
  • start - Defines where child branches start forming on the parent branch. A value of 0.6 means the child branches can start forming 60% of the way up the parent branch
  • stop - Defines where child branches stop forming on the parent branch. A value of 0.9 means the child branches stop forming 90% of the way up the parent branch
  • angle - Angle between child branch and parent branch (radians)
  • angleVariance - Variation in angle (radians)
  • lengthVariance - Variation in branch length
  • lengthMultiplier - Length of child branch relative to parent
  • radiusMultiplier - Radius of child branch relative to parent
  • taper - Radius of end of branch relative to the start of the branch
  • gnarliness - Max amplitude of random angle added to each section's orientation
  • twist - Amount of twisting about the vertical axis

External Force

  • direction - Influences the direction the tree grows towards
  • strength - Strength of the sun influence

Geometry

  • sections - Number of sections that make up this branch
  • segments - Number of faces around the circumference of the branch
  • lengthVariance - % variance in the nominal section length
  • radiusVariance - % variance in the nominal section radius
  • randomization - Randomization factor applied to vertices

Leaves

  • style - Leaf billboard style (single or double)
  • type - Leaf type (Ash, Aspen or Oak)
  • color - Leaf color
  • count - Number of leaves per branch
  • size - Size of leaf texture
  • sizeVariance - Variance in leaf size between branches