Simplified Three.JS wrapper for React
The goal of this project is to allow usage of Three.JS in React without modifying Three's API in the conversion process, and to do so without monkey patching React.
Install Using NPM
npm install --save threact
Example Usage
;; Component ... { return <WebGLRenderer physicallyCorrectLights=true gammaInput=true gammaOutput=true shadowMap=enabled: true toneMapping=THREEReinhardToneMapping antialias=true bgColor=0x00a1ff setPixelRatio=windowdevicePixelRatio setSize=windowinnerWidth windowinnerHeight camera=75 1 01 1000 scene=> <PointLight position=0 2 0 color=0xffee88 intensity=1 distance=100 decay=2> <Mesh geometry= 002 16 8 material= emissive: 0xffffee emissiveIntensity: 1 color: 0x000000 position=0 0 0 rotation=- MathPI / 2 0 0/> </PointLight> <HemisphereLight skyColor=0xddeeff groundColor=0x0f0e0d intensity=002 /> <Mesh geometry= 20 20 material= roughness: 08 color: 0xffffff metalness: 02 bumpScale: 00005 rotation=-MathPI / 20 0 0 /> <Mesh geometry= 05 32 32 material= color: 0xffffff roughness: 05 metalness: 10 position=1 05 1 rotation=0 MathPI 0 castShadow=true /> </WebGLRenderer> ; }
Props
Threact will turn each method's parameters into props, so there's no confusion as to how props are mapped. The WEBGLRenderer and Mesh components will also map their instance's writable properties as props. Some of the custom props for handling the Three instances in React are below.
#### WEBGLRenderer
width
: Integer. Sets the canvas and renderer width.height
: Integer. Sets the canvas and renderer height.style
: Object. Sets the canvas style.deferred
: Boolean. Controls whether or notWebGLDeferredRenderer
is used.controls
: Function. Override the default controls scheme. By default, this uses theorbit-controls
package.camera
: Function. Override the default camera scheme. By default, this uses thePerspectiveCamera
.skybox
: Array. Sets the scene background usingCubeTextureLoader
. Expects an array of six image paths.passes
: Array. Loads extra passes for post processing. This uses theEffectComposer
extension.shaders
: Array. Loads extra shaders for post processing. This uses theEffectComposer
extension withShaderPass
.anisotropy
: Integer (1-16) Overrides the default anisotropy setting, which is the renderer's max.stats
: Integer. Adds performance monitoring with thestats.js
package. Valid options include 0 (FPS), 1 (MS), and 2 (RAM).onMouseMove
: Function.onMouseDown
: Function.onResize
: Function.onKeyUp
: Function.onKeyPress
: Function.onKeyDown
: Function.
#### Generic
onMount
: Function. Called after the first render.onAnimate
: Function. Called on each Three render.
Callback parameters include instance
, renderer
, scene
, camera
, and controls
.
Todo
- Write more tests.
- Add a demo.