jw-three-canvas
A react component for canvas, integrated with three.js renderer and animation feature by an integrated animator.
Install
Methods
Method | Parameters | Description |
---|---|---|
getCanvasElement |
retrieve the canvas react component. |
Props
Prop | Description |
---|---|
maintainAspectRatio (optional) |
whether the canvas should keep aspect ratio from the moment it was created. Default: true |
onResize (optional) |
event handler when the canvas is being resized. |
animator (optional) |
the animator object for controlling the animation. If not provided, it will be created from within. |
animate (optional) |
animation method. Parameters: - width : context width- height : context height- timeDiff : time difference between the last animate time (in seconds). |
scene |
A scene from three.js |
camera |
A camera from three.js |
Usage
;;;; { superprops; thisresizeHandler = thisresizeHandler; thisanimate = thisanimate; thisscene = ; thiscamera = 50 1 1 1000; thiscamerapositionz = 60; thisscene; /** And other things you can add in the scene... */ } { const canvas = thismyCanvas; const animator = canvas; /** Start the animation. */ animatorstart; /** Pause the animation. */ animator; /** Resume the animation. */ animator; } { /** ... **/ } { /** ... **/ } { const scene camera = this; return <ThreeCanvas ref= thismyCanvas = myCanvas onResize=thisresizeHandler animate=thisanimate scene=scene camera=camera /> ; } ReactDOM;