✂ Multiple scenes, one canvas! WebGL Scissoring implementation for React Three Fiber.

Overview

react-three-scissor

Multiple scenes, one canvas! WebGL Scissoring implementation for React Three Fiber.


Version Downloads Twitter Discord


scissor lets you render an infinite number of individual scenes (limited by your processing capability of course) on one single WebGL context and canvas.

It is as easy as:

// ... Any number of windows">
<Canvas>
  // Add Scissored components to the canvas
  <Scissor />
</Canvas>

// Define sissor windows.
<ScissorWindow>
    <Cube color="red" />
</ScissorWindow>

<ScissorWindow>
    <Cube color="blue" />
</ScissorWindow>

// ... Any number of windows

Why this?

Havigng multiple WebGL contests within one webpage is generally a bad idea because (from ThreeJS manual):

  • The browser limits how many WebGL contexts you can have. Typically that limit is around 8 of them. After which, the oldest ones lose context.
  • WebGL resources can not be shared across contexts. That means expensive operation like loading models and compiling shaders would have to be repeated.

Instead, we create the issusion of multiple canvases by having one large one and drawing on very speciifc parts of it. This process is called Scissoring.

Getting Started

⚡️ Jump Start

# Install the entire library
npm install @react-three/scissor
import { Box } from '@react-three/drei'
import { Scissor, ScissorWindow } from '@react-three/scissor'

export default function App() {
  return (
    <>
      <Canvas>
        <Scissor />
      </Canvas>

      <div>
        <ScissorWindow>
          <Box>
            <meshStandardMaterial color={'cyan'} />
          </Box>
        </ScissorWindow>

        <ScissorWindow>{/* Any R3F Components */}</ScissorWindow>
      </div>
    </>
  )
}

It's as simple as that to create scroll-in animations.

💅 Styling Windows

CSS

ScissorWindow can be styled, positioned and scaled with any CSS property.

{/* Any R3F Components */} ">
<ScissorWindow
    className="window"
    style={{
        ...
    }}
>
    {/* Any R3F Components */}
</ScissorWindow>

Or,

.window {
  width: 420px;
  height: 420px;
  border: 2px solid black;

  position: absolute;
  top: 0;
  ...;
}

Styled components

It can also be wrapped in styled-component definitions like so:

const StyledScissorWindow = styled(ScissorWindow)`
  width: 420px;
  height: 420px;
  border: 2px solid black;

  position: absolute;
  top: 0;
  ...
`

Roadmap

Major TODOs

  • Controls support
  • Drei helpers support
  • Per-window camera
You might also like...

This is a Javascript / React implementation of Discord's OverlappingPanels

Overlapping Panels Gestures-driven navigation UI for React.js This is a Javascript / React implementation of Discord's OverlappingPanels. Gesture-base

Feb 18, 2022

A React-fullstack platform to track all cryptocurrency in one place.

A React-fullstack platform to track all cryptocurrency in one place.

A React-fullstack platform to track all cryptocurrency in one place. Create your account and add your favorite coins.

Oct 10, 2022

A React-Fullstack platform helps to track & compare your Incomes & Expenses transactions in one place via detailed Graphical information to manage your Budget.

A React-Fullstack platform helps to track & compare your Incomes & Expenses transactions in one place via detailed Graphical information to manage your Budget.

Budget Master Track your income and expenses in one place via detailed graphical information to manage your budget. Manage your budget and transaction

Nov 27, 2022

Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.

Recoil · Recoil is an experimental set of utilities for state management with React. Please see the website: https://recoiljs.org Installation The Rec

Jan 8, 2023

nextjs-multiple-page-i18n

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Sep 10, 2022

The ember implementation of UIkit

ember-uikit This addon is a wrapper for the CSS library UIkit which exposes certain components to give users an easy way for using UIkit in ember apps

Oct 20, 2022

Ember implementation of Google's Material Design

No longer maintained This project is no longer maintained. For an up-to-date material design project, please use Ember Paper. Ember-material-design Th

Mar 1, 2022

Simple implementation of online contract signature.

react-pdf-signaturer Simple implementation of online contract signature. Example online demo: https://buynao.github.io/react-pdf-signaturer/ Usage $ g

Nov 28, 2022

Ember implementation of the game

Ember implementation of the game

Apr 27, 2022
Comments
  • Error: https://registry.yarnpkg.com/@react-three%2fscissor: Not found

    Error: https://registry.yarnpkg.com/@react-three%2fscissor: Not found

    After trying to install this package, I get the following error-log by Yarn:

    Arguments: /usr/local/bin/node /opt/homebrew/Cellar/yarn/1.22.17_2/libexec/bin/yarn.js add @react-three/scissor

    PATH: /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/opt/homebrew/sbin

    Yarn version: 1.22.17

    Node version: 16.14.0

    Platform: darwin arm64

    Trace: Error: https://registry.yarnpkg.com/@react-three%2fscissor: Not found at Request.params.callback [as _callback] (/opt/homebrew/Cellar/yarn/1.22.17_2/libexec/lib/cli.js:67029:18) at Request.self.callback (/opt/homebrew/Cellar/yarn/1.22.17_2/libexec/lib/cli.js:140883:22) at Request.emit (node:events:520:28) at Request. (/opt/homebrew/Cellar/yarn/1.22.17_2/libexec/lib/cli.js:141855:10) at Request.emit (node:events:520:28) at IncomingMessage. (/opt/homebrew/Cellar/yarn/1.22.17_2/libexec/lib/cli.js:141777:12) at Object.onceWrapper (node:events:639:28) at IncomingMessage.emit (node:events:532:35) at endReadableNT (node:internal/streams/readable:1346:12) at processTicksAndRejections (node:internal/process/task_queues:83:21)

    npm manifest: { "private": true, "version": "0.0.0", "scripts": { "dev": "vite", "build": "vite build", "preview": "vite preview" }, "dependencies": { "@react-three/drei": "^8.10.7", "@react-three/fiber": "^7.0.26", "react": "^17.0.2", "react-dom": "^17.0.2", "three": "^0.138.0" }, "devDependencies": { "@vitejs/plugin-react": "^1.0.7", "vite": "^2.8.0" } }

    How can I install this package? Is it any different?

    opened by eriksachse 1
Owner
Poimandres
Open source developer collective
Poimandres
A simple project to refresh on the usage of js canvas and getContext('2d') to create four interactive squares on the canvas when hovered changes color.

A simple project to refresh on the usage of js canvas and getContext('2d') to create four interactive squares on the canvas when hovered changes color. Can also be clicked to work on mobile devices.

DandaIT04 1 Jan 1, 2022
🇨🇭 A React renderer for Three.js

react-three-fiber react-three-fiber is a React renderer for threejs. npm install three @react-three/fiber Why? Build your scene declaratively with re-

Poimandres 20.9k Jan 9, 2023
An intro to Three.js and React :) Workshop materials and demo from HackTheNorth 2021

?? Speedy 3D - A Quick Intro to Three.js & React This workshop was originally created for Hack The North 2021! My personal motivation was to: learn th

Anson Yu 8 Dec 17, 2021
🧱 Easily extend native three.js materials with modular and composable shader units and effects

three-extended-material Easily extend native three.js materials with modular and composable shader units and effects. Usage npm install three-extended

Leonardo Cavaletti 26 Dec 2, 2022
This is a single page application that includes three pages; Home, Calculator and Quotes. You can do Math Calculations and read quotes.

Math magicians app This is a single page application that includes three pages; Home, Calculator and Quotes. You can do Math Calculations and read quo

Lynette Acholah 12 Jun 7, 2022
This command line helps you create components, pages and even redux implementation for your react project

react-help-create This command line helps you create components, pages and even redux implementation for your react project. How to install it? To ins

Omar 27 Dec 10, 2022
KochSnowFlake - implementation of Koch Snowflake with React+ TS

Koch Snowflake if you just want to play with it, follow, FOLLOW THIS LINK if you are curios about math of this project, FOLLOW THIS LINK installation

Mahyar 1 Mar 13, 2022
Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand.

About Plock ?? Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand. Can I see a demo? ?? The demo

Renato Pozzi 130 Dec 9, 2022
An implementation of React v15.x that optimizes for small script size

react-lite Introduction react-lite is an implementation of React that optimizes for small script size. Note: react-lite dose not support React v16.x n

工业聚 1.7k Dec 10, 2022
An implementation of GitHub's Primer Design System using React

Primer React A React implementation of GitHub's Primer Design System Documentation Our documentation site lives at primer.style/react. You'll be able

Primer 2.2k Dec 26, 2022