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_gpu_picking

v1.0.4

Published

GPU Object Picking for Three.JS

Downloads

15

Readme

GPU Object Picking for Three.JS

Overview

This library is a production ready implementation of GPU object picking for Three.JS. The advantage this library has over the other ones that are already available is that it doesn't require a seperate picking scene. This is a big deal because you do not have to keep a second scene in sync with the scene that is being rendered.

GPU Picking also works with skinned meshes and performs better with meshes that have a high poly count. The Three.JS raycaster does not currently work with skinned meshes. These cases are shown in the example that is provided. The yellow sphere below has over a half million polys. If CPU picking is used the framerate will drop while the pick is happening, using GPU picking the framerate remains constant. The other case is skinned meshes. If CPU picking is used picking only works against the initial pose of the object whereas GPU picking works against the current animated pose.

Picking Example Note: The example loads slowly because the sphere has so many polys in it.

Install

Two Options:

A) Install with npm, npm install three_gpu_picking

B) This is a one file library, one can just copy gpupicker into their project

Usage

Import the picker

import { GPUPicker } from 'three_gpu_picking';

Create the picker with the following parameters

  • THREE: reference to the ThreeJS library. I do it this way to avoid issues I've had in the past with WebPack having multiple copies of ThreeJS imported and causing issues.
  • renderer: A reference to the THREE.Renderer (must be a WebGLRenderer) being used.
  • scene: A reference to the THREE.Scene
  • camera: A reference to the camera
  // Here's an example that works for GLTF objects.
  var picker = new GPUPicker(THREE, renderer, scene, camera);

Use the picker

Call GPUPicker.pick with the following parameters:

  • x, the x coordinate of the location you want to pick in. Make sure to multiply by window.devicePixelRatio
  • y, the y coordinate of the location you want to pick in. Make sure to multiply by window.devicePixelRatio
  • shouldPickObject, optional, a callback that allows you to not consider some objects pickable. Return false to skip an object.
  var objectId = picker.pick(ev.clientX * window.devicePixelRatio, ev.clientY * window.devicePixelRatio, obj => {
    return obj.myPickingFlag;
  });

This should happen pretty much directly after renderer.render is called. Depending on how complicated your render loop is, you may need to store the picking coordinates of onMouseUp in a variable and then process the pick in your render call. There's an example of this here

Custom shaders

If you have an object that requires a custom material for picking (due to vertex animation or you want alpha support). Set a pickingMaterial property on it and the GPUPicker will use it.

Authors / Thanks

This library was developed at Torch by Brian Richardson with bugfixes from Josh Faust and Benny Lichtner. Big thanks to Torch for allowing us to release this library!

The dancer model is by 12626 used by CC Attribution License.