three js Flashcards

1
Q

What is the npm command to add Three.js to your project?

A

Run

npm install three
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you import all core classes of Three.js using ES modules?

A
import * as THREE from 'three'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create a new scene in Three.js?

A
const scene = new THREE.Scene()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the four essential elements needed to render a basic Three.js scene?

A
  • a scene
  • objects
  • a camera
  • a renderer.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you create a red cube mesh in Three.js?

A
// Create geometry and material
const geometry = new THREE.BoxGeometry(1, 1, 1)
const material = new THREE.MeshBasicMaterial({ color: 0xff0000 })

// Combine to form a mesh and add to the scene
const mesh = new THREE.Mesh(geometry, material)
scene.add(mesh)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you set up a PerspectiveCamera and position it to view the scene?

A
const sizes = { width: 800, height: 600 }
const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height)
camera.position.z = 3  // Move the camera backward
scene.add(camera)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you initialize a WebGL renderer and attach it to a canvas in the HTML?

A
// Get the canvas element
const canvas = document.querySelector('canvas.webgl')

// Create the renderer and set its size
const renderer = new THREE.WebGLRenderer({ canvas: canvas })
renderer.setSize(sizes.width, sizes.height)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you render the scene from the camera’s perspective?

A

Call the render method:

renderer.render(scene, camera)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why might the render show a black screen or only one side of the cube, and how can it be fixed?

A

The camera and object might be at the same position. Moving the camera back (e.g., setting camera.position.z = 3) ensures the object is visible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly