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

frustum-grass

v0.0.3

Published

This is an **incomplete** a-frame component that provides an easy to use/performant grass renderer. You can check it out [here](https://bernardo.lol/frustum-grass/index.html).

Downloads

5

Readme

frustum-grass

This is an incomplete a-frame component that provides an easy to use/performant grass renderer. You can check it out here.

What it does

You give frustum-grass a set of vertices representing your scene, and it adds a bunch of grass to your scene. It has a couple tricks to keep your framerate high.

  • It uses Web Workers to perform spawning and culling calculations in a background thread, which help keep framerate stable.
  • It improves rendering performance using instanced meshes via the aframe-instanced-mesh package.

How to use it

Since frustum-grass uses Web Workers, you'll have to make sure the frustum-grass-worker.js file isn't bundled in with everything else.

I'm using webpack in my projects, so I always add something like this to my webpack.config.js:

{
  module: {
    rules: [
      {
        test: /frustum-grass-worker/,
        generator: {
          // You'll have to change your publicPath and outputPath
          // values to suit your exact desired output structure.
          publicPath: "assets/scripts/",
          outputPath: "assets/scripts",
          filename: "frustum-grass-worker.js"
        }
      },
    ]
  }
}

Once the Web Worker script is in its own file, you'll have to pass its location to the component.

  const grassWorkerUrl = new URL("frustum-grass/frustum-grass-worker", import.meta.url)
  grassWorkerUrl.searchParams.append("isFile", "true")

  const grassWrapper = document.querySelector("#frustumGrass") as any
  grassWrapper.setAttribute("frustum-grass", {
    workerUrl: grassWorkerUrl,
    fov: Math.PI / 1.5,
    density: 32,
    color: "rgb(102, 244, 76)"
  })

Finally, you'll have to give your grass component some vertices so it can start spawning terrain. I built frustum-grass to be used with Terrainosaurus, my procedural terrain generator. You can pass the vertices generated by Terrainosaurus to frustum-grass, and it'll figure out everything from there.

terrain.addEventListener("terrainInitialized", (event: CustomEvent) => {
  const { detail: { terrainClient: { vertices } } } = event
  const isTerrainosaurus = true
  const grassWrapper = document.querySelector("#frustumGrass") as any
  grassWrapper.components["frustum-grass"].setVertices(vertices, isTerrainosaurus)
})

What needs improvement

There are several things that aren't working that are must-haves before I consider this project truly complete.

  • Grass doesn't sway. I have a custom material with a vertex shader that accomplish this, but to make it work I need to update a uniform every tick, and I cannot figure out how to do this.
  • Instanced meshes seem to interfere with vertex shaders. I had a simplified vertex shader that did work but didn't have a good lighting model. However, even this shader stopped working as soon as I started using instanced meshes.

Other things I would like to do.

  • Since I am constantly adding and removing objects from the scene, it seems logical to use a-frame's object pooling feature, but I can't get this to work with instanced meshes. I don't know enough about object pooling and/or instanced meshes to say whether this is an optimization worth making.
  • Dynamically set the fov based on current viewport (and camera height?).