General

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/7

flashcard set

Earn XP

Description and Tags

https://react.dev/reference/rsc/use-client

8 Terms

1
New cards

What does ‘use client’ do, why in Three.js?

  • code runs on client for Next.js (every component is a server component by default)

    • server components on server produce HTML, server has no browser

    • can’t use React hooks (useEffect, useRef)

    • no browser APIs (webAPI for window, requestAnimationFrame, mouseEvents)


  • client component has these.


2
New cards

What is a common misunderstanding about client components?

  • They don't render on the server once to produce the first HTML.


3
New cards

What is the point of useRef?

  • Keeps stored variable value outside of re-render of function to prevent erasing.

  • React draws canvas from JSX (<canvas ref={canvasRef}, Three.js needs DOM element to draw into (const renderer = new THREE.WebGLRenderer({canvas}) // canvas = canvasRef.current;

  • In this case, create a empty box for the canvas element to refer to, then draw into it using useEffect(()=>…), then assign once to canvas. Will auto update but keep the same reference


4
New cards

What is the high level process of a tick function?

  1. Define delta = new THREE.Timer() outside of tick function call

  2. Define tick function, where:

  • Mesh updates occur

  • Camera updates occur

  • Renderer updates occur

  • Time update occurs

  • Tick update occurs


5
New cards

Write out the code for a tick function for a basic object spinning, and for the scene?

const delta = new THREE.timer();


const tick = () => {
mesh.rotation.y += 0.1;

renderer.render(scene, camera);

delta.update();

requestAnimationFrame(tick);
};

6
New cards

From a high level perspective, explain the relation of Three.js components to one another.

  • Renderer connects the camera to the scene and also the renderer to the canvas.

  • Meshes and cameras exist within the scene.

  • Tick function, updates, mesh, cameras, renderer, time, and itself.

  • Canvas paints the scene onto itself. Updates occur by tick function.


7
New cards

‘Optionally, add renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)) before setSize for extra sharpness on high-DPI screens.’

What does renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)) do, and why before setSize ?

  • window.devicePixelRatio # of physical pixels in one CSS pixel:

    • monitor: 1, laptops: 2, phone: 3

  • Basically, it's setting a cap of a ratio of two, as most standard laptops have this physical pixel ratio. And also on phones, if set to three, it would tax the GPU heavily. So for monitors, it would take the lowest, which would either be one or if it's a laptop, then it would be two.


8
New cards