Coder Social home page Coder Social logo

react-three-lgl's Introduction

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()

react-three-lgl's People

Contributors

drcmda 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

react-three-lgl's Issues

Mobile support by any chances?

This might seems to be a promising library. I would like to know if this is the current limitation at the technology or is this possible to do so?

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?

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'

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.