Three js and animation library in react
For more info refer to three js docs
- State : The state object is where you store property values that belongs to the component. When the state object changes, the component re-renders.
- Hooks : It allows you to use state and other React features without writing a class. Hooks are the functions which “hook into” React state and lifecycle features from function components.
- Props : React allows us to pass information to a Component using something called props (stands for properties). Props are basically kind of global variable or object.
Canvas
Class of tringular polygonal objects
An efficient way to present lines, mesh, position, face vertex within buffer. It doesnt heavy loads GPU
Appearance of Object, it is renderer independent.
MeshBasicMaterial
MeshStandardMaterial
MeshDepthMaterial
MeshDistanceMaterial
MeshLambertMaterial
MeshMatcapMaterial
MeshNormalMaterial
MeshPhongMaterial
MeshPhysicalMaterial
MeshToonMaterial
LineBasicMaterial
LineDashedMaterial
PointsMaterial
RawShaderMaterial
ShaderMaterial
ShadowMaterial
SpriteMaterial
It is hook which callback after every frame, used for effects , controls, postprocessing. It is a render loop in which you can use internal state as well.
Important: Never use in your Main canvas component or else it’ll go into an infite callback loop
Example :
useFrame(() => (mesh.current.rotation.x = mesh.current.rotation.y += 0.03));
mesh is an reference variable here, not the mesh as mentioned above
castShadow
recieveShadow
MapShadow
shadow-mapSize-width={1024}
shadow-mapSize-height={1024}
shadow-camera-far={50}
shadow-camera-left={-10}
shadow-camera-right={10}
shadow-camera-top={10}
shadow-camera-bottom={-10}Installation
React App Install
Install the dependencies and devDependencies and start the server.
$ npx create-react-app ProjectName
$ yarn add three react-three-fiber react-spring sass drei
$ yarn start
Packages | README |
---|---|
three | [https://www.npmjs.com/package/three] |
react-three-fiber | [https://www.npmjs.com/package/react-three-fiber] |
react-spring | [https://www.npmjs.com/package/react-spring][ |
sass | [https://www.npmjs.com/package/sass] |
drei | [https://www.npmjs.com/package/drei] |