Raskc / React-Three-Js-Workshop2-edgar-dion

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React-Three-Js-Workshop2

Introduction

In this second workshop session, you will discover the physics with React Three JS.

Step 1

Clone the repo !
git clone git@github.com:RayanBn/React-Three-Js-Workshop2.git

Steps to follow for compiling :

npm install
npm run dev

Step 2

Let's start by discovering how to debug a react three application! Let's start by surrounding our code with a tag to warn you of any problem you may encounter.

root.render(
    <StrictMode>
        <Canvas
            camera={ {
                fov: 45,
                near: 0.1,
                far: 200,
                position: [ - 4, 3, 6 ]
            } }
        >
            <Experience />
        </Canvas>
    </StrictMode>
)

Step 3

Now, it is important to be able to quickly test what we want to do. For this, we will use leva!
To do this, you must first import it:
import { useControls } from 'leva'

Once the module is imported, you will be able to declare several variables with a default value and then modify them in real time on your site:

const { color } = useControls({
    color: '#ff0000',
})
<meshStandardMaterial color={ color } />

Step 4

Now let's go to the physics! For this, we will use a branch of react three called rapier.
import { Physics, RigidBody, Debug } from "@react-three/rapier";

Here is a link to the documentation of rapier. Here the goal will be to create simple objects with physics and to be able to modify their hitbox:
https://github.com/pmndrs/react-three-rapier

Step 5

Thanks to step 4, you will be able to access the properties of each object, to then modify them as you wish. This allows you to make them interact with your scene. Now, let's learn how to load 3D models with react-three/drei. Here is a link to the documentation:
https://github.com/pmndrs/drei#usegltf
Here is a link where you can find several free model dedicated to react three js:
https://market.pmnd.rs/

About


Languages

Language:JavaScript 78.8%Language:HTML 14.6%Language:CSS 6.6%