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

webgl-three-library

v1.0.1

Published

WebGL library based on Three.js to use simply shaders effects

Downloads

4

Readme

✨ WEBGL LIBRARY ✨


npm install webgl-three-library
  • src
    • Utils
      • Time.js
      • Size.js
      • MouseTracking.js
      • index.js
      • DOMImages.js
      • Ressources.js
      • Scroll.js
    • effects
      • Effect
        • shaders
          • fragment.glsl
          • vertex.glsl
        • effect.js
      • ...
      • Camera.js
      • Experience.js
      • Renderer.js

1. Instanciate main class

Create <canvas class="webgl"></canvas> on your html. Instantiate the Experience class which gathers all the classes of the library.

new Experience(document.querySelector('canvas.webgl'), { parameters });

It takes different parameters :

| Parameter | Value | | Description | | ----------- | ----------- | ----------- | ----------- | | activeOrbitControls | bool | required | Active Three.js OrbitControls | | planeOptions.widthSegments | number | required | Refer to threejs documentation | | planeOptions.heightSegments | number | required | Refer to threejs documentation | | uniformsOptions | object | not required | For add uniforms. Refer to threejs documentation | | shaderOptions.vertexShader | vertex.glsl | required | Can import the vertex shader from effects folder | | shaderOptions.fragmentShader | fragment.glsl | required | Can import the fragment shader from effects folder | | cameraOptions.fov | number | required | Refer to threejs documentation | | cameraOptions.instance.x | number | not required | Refer to threejs documentation | | cameraOptions.instance.y | number | not required | Refer to threejs documentation | | cameraOptions.instance.z | number | not required | Refer to threejs documentation | | cameraOptions.lookat | Threejs instance| not required | Refer to threejs documentation. By default can put new THREE.Vector3() | | rendererOptions | object | not required | Refer to threejs documentation. | | actions.onEnter | func | required | Function executed when the mouse enter the planes. The intersect parameter allows to access the intersected plane | | actions.onLeave | func | required | Function executed when the mouse leave the planes. The intersect parameter allows to access the intersected plane | | actions.onMove | func | required | Function executed when the mouse moves on the window | | actions.onScroll | func | required | Function executed on scroll | | loaderState.startLoader | func | required | Function executed on html images start loading | | loaderState.stopLoader | func | required | Function executed on html images finish loading |

2. Insert images

Create ./static folder for all images

uMouse: {
  value: this.mousePosition // get mouse coordinates in 3D renderer (x, y)
},
uTime: {
  value: 0.0 // get time
},
uHover: {
  value: new THREE.Vector2(0.5, 0.5) // get hover centered position
},
uHoverState: {
  value: 1.0 // 1 if is not hovered and 0 if is hovered
}

How to implement effect ?

To use each effect, use fragments shader and vertex shader from the effects/effect.js :

import { shadersOptions } from '../src/Experience/effects/wavesEffect/wavesEffect';

shaderOptions: {
  vertexShader: shadersOptions.vertex,
  fragmentShader: shadersOptions.fragment,
}

To recreate effect can retrieve in demo library, this is the default options and functions :

Effects default setup

Waves & interaction effect

Default animation :

// plane options
planeOptions: {
  widthSegments: 8,
  heightSegments: 8,
},

// camera otpions
cameraOptions: {
  fov: 70,
  instance: {
    x: 1,
    y: 1,
    z: 600,
  },
  lookAt: new THREE.Vector3(),
},

// actions
function onEnter(intersect) {
  intersect.object.material.uniforms.uHover.value = intersect.uv;
  intersect.object.material.uniformsNeedUpdate = true;
}

function onLeave(intersect) {
  intersect.object.material.uniforms.uTime.value = 0.0;
  intersect.object.material.uniformsNeedUpdate = true;
}

function onTimeRunning() {
  experience.DOMImages.imageParameters;
  if(experience.DOMImages.imageParameters) {
    experience.DOMImages.imageParameters.forEach(imageParameter => {
      imageParameter.mesh.material.uniforms.uTime.value = experience.time.elapsed * 0.002;
    });
  }
}

Ripple rgb effect

Default animation :

// plane options
planeOptions: {
  widthSegments: 16,
  heightSegments: 16,
}

// camera options
cameraOptions: {
  fov: 70,
  instance: {
    x: 1,
    y: 1,
    z: 600,
  },
  lookAt: new THREE.Vector3(),
}

// actions
function onEnter(intersect) {
  intersect.object.material.uniforms.uHover.value = intersect.uv;
  intersect.object.material.uniforms.uTime.value = experience.time.elapsed * 0.001;
  intersect.object.material.uniformsNeedUpdate = true;
}

function onLeave(intersect) {
  intersect.object.material.uniforms.uTime.value = 0.0;
  intersect.object.material.uniformsNeedUpdate = true;
}