🔆 A React abstraction for the LGL Raycaster

Overview

A React(-three-fiber) abstraction for the LGL-Raytracer.

It does its best to remove all unwanted complexity, you can build your scenes as you always would. This is mostly for photorealistic still-images that can take a while to process but will look absolutely stunning. It is side-effect free, when you unmount it goes back to the default WebGLRenderer.

Demos: [sandbox], [studio-setup]

npm install @react-three/lgl
import { Canvas } from '@react-three/fiber'
import { Raytracer } from '@react-three/lgl'

function App() {
  return (
    <Canvas>
      <Raytracer>
        <mesh>
          <sphereGeometry args={[1, 64, 64]} />
          <meshStandardMateral />
        </mesh>
        ...
      </Raytracer>
    </Canvas>
  )
}

Options

  • samples, How many frames it takes to complete a still-image, 64 by default. Set this to something higher if you want to wait for high-quality images, or Infinity if you want it to go on forever, but keep in mind that raytracing is very expensive!

Otherwise <Raytracer> takes all the LGL raytracer's options: https://lgltracer.com/docs/index.html#/api/LGLTracerRenderer

Lights

LGL ignores threejs lights, it wants to use its own. But in three-fiber you can simply extend, and now the JSX natives will refer to LGL.

import { extend } from '@react-three/fiber'
import { PointLight, RectAreaLight } from 'lgl-tracer'

extend({ PointLight, RectAreaLight })

<rectAreaLight width={2} height={2} position={[3, 3, 3]} />
<pointLight position={[-3, 3, -10]} />

If you plan to switch between renderers you can make lights opt in.

extend({ LglPointLight: PointLight, LglRectAreaLight: RectAreaLight })

<lglPointLight />
<lglRectAreaLight />

Environmental lighting

Simply drop the <Environment> component from drei into your scene, it knows how to work with that ootb, just make sure both the raytracer and the environment are under the same suspense boundary so that they are in sync.

import { Environment } from '@react-three/drei'

<Canvas>
  <Suspense fallback={null}>
    <Rayctracer>
      <Scene />
    </Raytracer>
    <Environment preset="city" />

Movement

Your scene has to be static, it will ignore moving parts. This will never be fast enough for runtime usage but you can get away with some camera movement by lowering your resolution (and your expectations). Do not forget to mark your controls as makeDefault so that the raycaster can react to it. Try something like this for example:

import { OrbitControls } from '@react-three/drei'

<Canvas dpr={1}>
  <Raytracer
    samples={32}
    bounces={3}
    enableTemporalDenoise
    enableSpatialDenoise
    movingDownsampling>
    ...
  </Raytracer>
  <OrbitControls makeDefault />

Screenshots

In order to obtain a screenshot the drawing-buffer has to be preserved, this is a setting in Threejs.

import { Canvas, useThree } from '@react-three/fiber'

<Canvas gl={{ preserveDrawingBuffer: true }}>
  <Raycaster>
    </Scene>
    
...
const gl = useThree(state => state.gl)
...
const link = document.createElement('a')
link.setAttribute('download', 'canvas.png')
link.setAttribute('href', gl.domElement.toDataURL('image/png').replace('image/png', 'image/octet-stream'))
link.click()
You might also like...

React tooltip is a React.JS Component that brings usefull UX and UI information in selected elements of your website.

React Tooltip ✅ React tooltip is a React.JS Component that brings usefull UX and UI information in elements of your website. Installation ⌨️ React Too

Dec 22, 2021

React-Mini-Projects - Simple React mini-applications

React Mini Projects A Fully Responsive React Application contain these mini apps : Todo App Movie App Budget App Flash Card App Factor App This app wa

Jan 1, 2022

React-tutorial - A React tutorial from Udemy (Academind)

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Mar 31, 2022

Airbnb-React - In this project, An Airbnb experience page clone is created to learn and implement React props concepts.

Airbnb-React - In this project, An Airbnb experience page clone is created to learn and implement React props concepts.

Create React Airbnb App In this project An airbnb experience page clone is created to learn and implement React props concepts. Objectives Learn about

Jun 28, 2022

Vtexio-react-apps - Apps react para plafaforma VTEX.

Vtexio-react-apps - Apps react para plafaforma VTEX.

Projeto Modal + Apps Extras Projeto modal setando cookies. Desenvolvido em React + TypeScript para aplicação em e-commerce VTEXIO. 🚨 Este projeto se

Jan 3, 2022

Chrome-extension-react-boilerplate - Simple Chrome extension React boilerplate.

Simple Chrome extension React boilerplate This is a simple chrome extension boilerplate made in React to use as a default structure for your future pr

May 25, 2022

React-app - Building volume rendering web app with VTK.js,react & HTML Using datasets provided in vtk examples (head for surface rendering and chest for ray casting)

SBE306 Assignment 4 (VTK) data : Directory containing Head and Ankle datasets Description A 3D medical viewer built with vtk-js Team Team Name : team-

Jul 19, 2022

a more intuitive way of defining private, public and common routes for react applications using react-router-dom v6

auth-react-router is a wrapper over react-router-dom v6 that provides a simple API for configuring public, private and common routes (React suspense r

Dec 3, 2022

This is made for those who are learning react and are tired of doing create-react-app and having to delete those unused files

Easy React Pack (ERP) This is made for those who are learning react and are tired of doing create-react-app and having to delete those unused files. H

Jan 12, 2022
Comments
  • Environment map doesn't work with new versions of @react-three/drei and @react-three/fiber

    Environment map doesn't work with new versions of @react-three/drei and @react-three/fiber

    When the latest versions of drei and fiber are used ( e.g "@react-three/drei": "^9.19.7", "@react-three/fiber": "8.3.1"), any environment maps in the scene do not show, and there is the following warnings in the console:

    image

    See https://codesandbox.io/s/lgl-raytracer-forked-8dux92 for an example

    Thankyou!

    opened by davisj147 1
  • Dynamic models

    Dynamic models

    What is you where to have a mesh that could change size/scale dynamically? The raycaster works superb but my model doesn't changes size/shape anymore.. Any available workarounds?

    opened by algopapi 1
  • Module not found: Can't resolve 'lgl-tracer'

    Module not found: Can't resolve 'lgl-tracer'

    ran into this issue...is this a issue on my end or?

    Failed to compile.
    
    ./node_modules/@react-three/lgl/dist/index.js
    Module not found: Can't resolve 'lgl-tracer' in '/node_modules/@react-three/lgl/dist'
    
    
    opened by natarius 1
Owner
Poimandres
Open source developer collective
Poimandres
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

Facebook Experimental 18.2k Jan 8, 2023
React Starter Kit — isomorphic web app boilerplate (Node.js, Express, GraphQL, React.js, Babel, PostCSS, Webpack, Browsersync)

React Starter Kit — "isomorphic" web app boilerplate React Starter Kit is an opinionated boilerplate for web development built on top of Node.js, Expr

Kriasoft 21.7k Dec 30, 2022
📋 React Hooks for forms validation (Web + React Native)

English | 繁中 | 简中 | 日本語 | 한국어 | Français | Italiano | Português | Español | Русский | Deutsch | Türkçe Features Built with performance and DX in mind

React Hook Form 32.4k Dec 29, 2022
:black_medium_small_square:React Move | Beautiful, data-driven animations for React

React-Move Beautiful, data-driven animations for React. Just 3.5kb (gzipped)! Documentation and Examples Features Animate HTML, SVG & React-Native Fin

Steve Hall 6.5k Jan 1, 2023
React features to enhance using Rollbar.js in React Applications

Rollbar React SDK React features to enhance using Rollbar.js in React Applications. This SDK provides a wrapper around the base Rollbar.js SDK in orde

Rollbar 39 Jan 3, 2023
🎉 toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense!

toastify-react-native ?? toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense! De

Zahid Ali 29 Oct 11, 2022
Soft UI Dashboard React - Free Dashboard using React and Material UI

Soft UI Dashboard React Start your Development with an Innovative Admin Template for Material-UI and React. If you like the look & feel of the hottest

Creative Tim 182 Dec 28, 2022
A web application to search all the different countries in the world and get details about them which can include languages, currencies, population, domain e.t.c This application is built with CSS, React, Redux-Toolkit and React-Router.

A web application to search all the different countries in the world and get details about them which can include languages, currencies, population, domain e.t.c This application is built with CSS, React, Redux-Toolkit and React-Router. It also includes a theme switcher from light to dark mode.

Franklin Okolie 4 Jun 5, 2022
Finished code and notes from EFA bonus class on building a React project without create-react-app

React From Scratch Completed Code This is the completed code for the EFA bonus class on building a React project from scratch. Included are also markd

Conor Broaders 3 Oct 11, 2021
Free Open Source High Quality Dashboard based on Bootstrap 4 & React 16: http://dashboards.webkom.co/react/airframe

Airframe React High Quality Dashboard / Admin / Analytics template that works great on any smartphone, tablet or desktop. Available as Open Source as

Mustafa Nabavi 6 Jun 5, 2022