项目作者: auralshin

项目描述 :
Three js and animation library in react
高级语言: JavaScript
项目地址: git://github.com/auralshin/react-3D.git
创建时间: 2020-08-06T17:04:07Z
项目社区:https://github.com/auralshin/react-3D

开源协议:

下载


Documentation

For more info refer to three js docs

React Basics :

  • 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

  • Your go to for three js, renders three js elements
  • components : WebGL renderer, camera, scene, etc

Lighting

  • Ambient Light: uniform light , cannot cast shadow
  • Point Light : light emitted from a point
  • Directional Light : Light coming from specific direction, source is at infity rays are parallel

Mesh

Class of tringular polygonal objects

Buffergeometry

An efficient way to present lines, mesh, position, face vertex within buffer. It doesnt heavy loads GPU

Material

Appearance of Object, it is renderer independent.

MeshBasicMaterial
MeshStandardMaterial
MeshDepthMaterial
MeshDistanceMaterial
MeshLambertMaterial
MeshMatcapMaterial
MeshNormalMaterial
MeshPhongMaterial
MeshPhysicalMaterial
MeshToonMaterial
LineBasicMaterial
LineDashedMaterial
PointsMaterial
RawShaderMaterial
ShaderMaterial
ShadowMaterial
SpriteMaterial

useFrame() ( In react three fiber docs useRender)

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 :

  1. useFrame(() => (mesh.current.rotation.x = mesh.current.rotation.y += 0.03));
  2. mesh is an reference variable here, not the mesh as mentioned above

Shadow

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.

  1. $ npx create-react-app ProjectName
  2. $ yarn add three react-three-fiber react-spring sass drei
  3. $ yarn start

Plugins

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]