Giter VIP home page Giter VIP logo

react-particles-webgl's Introduction

React Particles WebGL

A 2D/3D particle library built with React, Three.js and WebGL

react-particles-webgl was inspired by the popular particles.js library and built with react-three-fiber to offer smooth 60FPS high-count particle fields in both two and three dimensions.

Documentation https://timellenberger.com/libraries/react-particles-webgl

Config Generator https://timellenberger.com/particles

Code Sandbox Demos

npm NPM PRs Welcome Travis (.org)

2D "Particles.js" Canvas 3D Particle Field

✨ Features

  • Simple drop-in usage, plays nice with SSR (the demo is running Next.js)
  • Smooth 60FPS particles and lines via WebGL
  • Full Three.js OrbitControls for extreme (optional) scene interactivity
  • Highly customizable particles and lines

Install

yarn add react-particles-webgl three

Usage

import React from 'react';
import ParticleField from 'react-particles-webgl';

/**
 * The default configuation for the ParticleField component
 *
 * Any option passed in via props will overwrite the default config
 */
const config = {
  // Display reference cube, useful for orienting the field
  showCube: true,
  // '2D' or '3D' particle field
  dimension: '3D',
  // 'bounce' or 'passthru'
  // 'bounce' will make particles behave like balls thrown at a wall when hitting canvas boundaries
  // 'passthru' particles will disappear after hitting canvas boundaries and be added back into the scene elsewhere
  boundaryType: 'bounce',
  // Maximum velocity of particles
  velocity: 2,
  // Toggles antialiasing -- must be set during construction, cannot be changed after initial render
  // Slight performance optimization to set false, although lines will appear more jagged
  antialias: false,
  // Min/Max multipliers which constraint how particles move in each direction
  // The default values here allow for particles to move in completely random x, y, z directions
  // See the "Snowfall" preset for an example of how to use these values
  direction: {
    xMin: -1,
    xMax: 1,
    yMin: -1,
    yMax: 1,
    zMin: -1,
    zMax: 1
  },
  lines: {
    // 'rainbow' or 'solid' color of lines
    colorMode: 'rainbow',
    // Color of lines if colorMode: 'solid', must be hex color
    color: '#351CCB',
    // Transparency of lines
    transparency: 0.9,
    // true/false limit the maximum number of line connections per particle
    limitConnections: true,
    maxConnections: 20,
    // Minimum distance needed to draw line between to particles
    minDistance: 150,
    // true/false render lines
    visible: true
  },
  particles: {
    // 'rainbow' or 'solid' color of particles
    colorMode: 'rainbow',
    // Color of lines if colorMode: 'solid', must be hex color
    color: '#3FB568',
    // Transparency of particles
    transparency: 0.9,
    // 'square' or 'circle' shape of particles
    shape: 'square',
    // The exact number of particles to render
    count: 500,
    // The minimum particle size
    minSize: 10,
    // The maximum particle size
    maxSize: 75,
    // true/false render particles
    visible: true
  },
  /*
   * The camera rig is comprised of Three.js OrbitControls
   * Pass any valid OrbitControls properties, consult docs for more info
   *
   * https://threejs.org/docs/#examples/controls/OrbitControls
   */
  cameraControls: {
    // Enable or disable all camera interaction (click, drag, touch etc)
    enabled: true,
    // Enable or disable smooth dampening of camera movement
    enableDamping: true,
    dampingFactor: 0.2,
    // Enable or disable zooming in/out of camera
    enableZoom: true,
    // Enable or disable constant rotation of camera around scene
    autoRotate: true,
    // Rotation speed -- higher is faster
    autoRotateSpeed: 0.3,
    // If true, camera position will be reset whenever any option changes (including this one)
    // Useful when turning off autoRotate, the camera will return to FOV where scene fits to canvas
    resetCameraFlag: false
  }
};

export default () => <ParticleField config={config} />;

Local Development

Clone the repo

git clone https://github.com/tim-soft/react-particles-webgl.git react-particles-webgl
cd react-particles-webgl

Setup symlinks

yarn link
cd example
yarn link react-particles-webgl

Run the library in development mode

yarn start

Run the example app in development mode

cd example
yarn start

Changes to the library code should hot reload in the demo app

License

MIT © Tim Ellenberger

react-particles-webgl's People

Contributors

seans84 avatar tim-soft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-particles-webgl's Issues

reset

it will be reset when form inputed , used antd form

raf loops aren't necessary

A small suggestion for:

requestAnimationFrame(() => controlsRef.current.update());
// Animate current state of particles + lines
requestAnimationFrame(() => animate(animation.current));

They will downgrade performance a little bit, because useRender contents are already called in a raf loop. You can simply call update functions in there. Browsers don't take multiple frame ops kindly and unifying these operations gives a little bit more room.

React Three Fiber

Your project is interesting, but it would be great to see a particle system utility built FOR react-three-fiber, instead of on top of it. I was wondering if you had any plans for something like that.

.setDynamic() has been deprecated (warning)

Hello,
The following warnings are displayed when run on Chrome:

three.module.js:33602 THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.
setDynamic @ three.module.js:33602
three.module.js:33623 THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().

TypeError callback is not a function

hey i wanted to check this extension for my little project, i try to visit any sandbox uploaded by tim, but every time i get the typeerror, could you tell me what can be the reason behind it? i want to use 3d snowfall in my r3f scene...


`TypeError
callback is not a function
flushFirstCallback
https://308zj3k7l1.csb.app/node_modules/scheduler/cjs/scheduler.development.js:107:28
flushWork
https://308zj3k7l1.csb.app/node_modules/scheduler/cjs/scheduler.development.js:219:11
$csb$eval/channel.port1.onmessage
https://308zj3k7l1.csb.app/node_modules/scheduler/cjs/scheduler.development.js:611:30
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.
This error overlay is powered by `react-error-overlay` used in `create-react-app`.`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.