Skip to content

RayanBn/React-Three-Js-Workshop2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

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/

Step 6

Now, using leva, you need to be able to create a single geometric shape on your scene, add physics to it, interact with it and change the shape at any time.
1) Create a dropdown in leva, allowing you to choose the geometric shape.
2) Create a dropdown in leva, allowing you to choose the action to be taken during interaction.
3) Implement the 2 functionalities so that the user can choose a shape and an interaction.

Step 7

To go a step further, a hook often used is the useScroll, which will make your site more dynamic and pleasant. Here's an example of how to use this hook: https://www.gsap.com/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published