builds the final website after writing web code like HTML/CSS/JS.
do the optimizations, cache breaking, source mapping, running a local server, etc.
lots of build tools like Vite, Gulp, Parcel etc
Though the lectures are recorded using Webpack, the config. is the same
npm init -y
npm i vite
npm i three

package.json ์ scripts ๋ณ๊ฒฝ
"scripts": {
"dev" : "vite",
"build" : "vite build"
},
import * as THREE from 'three';
console.log(THREE)
์๋์ฒ๋ผ ๋ค์ํ ํด๋์ค์ ์์ฑ๋ค์ด ์กด์ฌํจ

๋ฒ๋ค๋ฌ๋ ๋ํ๋์, ๊ทธ ์ด๋ค ๋ชจ๋ ์์ด Html๊ณผ JS ๋ง์ผ๋ก three.js๋ฅผ ํ์ฉํด๋ณผ ๊ฒ
scene์ three.js์์ ์ฝํ
์ด๋. Obj, models, particle, lights ๋ฑ์ ๋ด์
// Scene
const scene = new THREE.Scene();
Obj์๋ ๊ธฐ๋ณธ์ ์ธ geometries ๋ถํฐ import๋ model, particles, lights ๋ฑ ๋ฌด์ง๋ฌด์ง ๋ง๋ค
Mesh ๋ geometry(the shape)์ material(how it looks)์ ๊ฒฐํฉ
Mesh๋ฅผ ํตํด ๋์ ๊ฒฐํฉMesh๋ฅผ Scene์ ์ถ๊ฐํ๊ธฐ (scene์ ์ ๋ฃ์ผ๋ฉด ํ์ธ ๋ถ๊ฐ๋ฅ)// Object
const geometry = new THREE.BoxGeometry(1, 1, 1); // width, height, depth
const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);


์นด๋ฉ๋ผ๋ ๋์ ๋ณด์ด์ง ์๊ณ , ์ฌ์ค์ '์์ '์ ๊ฐ๊น์. ์ฌ๋ฌ ๊ฐ์ ์นด๋ฉ๋ผ๋ฅผ ์ธ ์๋ ์๊ณ , ์ฌ๋ฌ ํ์
์ ์นด๋ฉ๋ผ๊ฐ ์กด์ฌ. ์ฌ๊ธฐ์ ์๊ทผ๊ฐ์ด ์๋ perspectiveCamera๋ง ๋ค๋ฃธ
// Sizes
const sizes = {
width: 800,
height: 600
}
// Camera
const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height);
camera.position.z = 3;
scene.add(camera);
๋ ๊ฐ์ง param์ ๊ฐ์ง
Renderer ํ์Renderer์๊ฒ render ์์ฒญํ๋ฉด Renderer๋ ์นด๋ฉ๋ผ ์์ ์์ ๋ณด์ด๋ ๋ชจ์ต์ ์บ๋ฒ์ค ์์ ๊ทธ๋ ค๋Renderer๊ฐ ๊ทธ๋ฆผ์ ๊ทธ๋ฆด canvas๋ฅผ html์ ์ถ๊ฐRenderer์ setSize๋ฉ์๋๋ก ์บ๋ฒ์ค ํฌ๊ธฐ ์กฐ์ render ๋ฉ์๋์ scene๊ณผ camera๋ฅผ param์ผ๋ก ๋๊ฒจ์ฃผ๊ธฐrender the scene seenf rom the camera's point of view
result will be drawn into canvas
// Renderer
const renderer = new THREE.WebGLRenderer({
canvas: canvas
})
renderer.setSize(sizes.width, sizes.height);
// take the picture of the scene, from the camera point of view
renderer.render(scene, camera);
both the obj. and camera are in the default position, the center of the scene
=> cannot see an obj from its inside (๊ธฐ๋ณธ์ ์ผ๋ก object์ ๋ด๋ถ์์๋ ๋ฌผ์ฒด๋ฅผ ํ์ธํ ์ ์์)
๋๋ฌธ์ object์ ์์น๋ฅผ ๋ณ๊ฒฝํด์ฃผ์ด์ผ ํ๋๋ฐ, can transform objs using position, rotation, scale
โญ๏ธ ์ค์ํ ๊ฒ์ render ์ ์ ์์น๋ฅผ ๋ณ๊ฒฝํด์ค์ผํจ!!
< ์ต์
๋ ๊ฐ์ง >
1. Move Mesh forward
2. Move Camera backward



์ฐธ๊ณ :
[9rganizedChaos๋ ๊ฐ์๋
ธํธ](https://velog.io/@9rganizedchaos/Three.js-journey-%EA%B0%95%EC%9D%98%EB%85%B8%ED%8A%B8-01-03
๋ฒ๋ค๋ง(bundle)์ ๋จผ์ ์์์ผ

๋ฒ๋ค
js ํ์ผ๋ค, ์ด๋ฏธ์ง, css ๋ฑ ์ด๋ฐ ๊ฒ๋ค์ ํ๋์ ๋ชจ๋๋ก ๋ณด๊ณ ์ด ๋ชจ๋๋ค์ ๋ฐฐํฌ์ฉ์ผ๋ก ๋ณํฉํ๊ณ ํฌ์ฅํ๋ ์์
๋ฒ๋ค๋ง ์์
์ ์ํํ๋ ํด์ ๋ฒ๋ค๋ฌ๋ผ๊ณ ํจ. ๋ฒ๋ค๋ฌ ์ค์์ Webpack์ด ํ์ฌ ์์ ๊ฐ์ฅ ์ธ๊ธฐ ๋ง์ ์์ด
์ต์ ๋ฌธ๋ฒ์ผ๋ก ๊ฐ๋ฐํ js๋ฅผ ์์ ํ์ผ์์๋ ์ ๋์๊ฐ๋ ํ์ผ๋ก ๋ณํํด์ค(ํธ๋์คํ์ผ๋ฌ)
์นํฉ์ด๋ ๊ฐ์ด ์ฐ๋ฉด ์ข์. ๊ทธ๋์ ๋ฐ๋ฒจ์ ๋ก๋๋ก ๋ถ๋ฌ์์ ๊ฐ์ด ์คํํด์ค
// babel.config.js
module.exports = {
presets: [
['@babel/preset-env', {
targets: {
chrome: '58',
ie: '11',
},
useBuiltIns: 'usage',
corejs: {
version: 3,
}
}]
]
};
// webpack.config.js
const webpackMode = process.env.NODE_ENV || 'development';
module.exports = {
mode: webpackMode,
entry: {
main: './src/main.js',
},
output: {
path: path.resolve('./dist'),
filename: '[name].min.js'
},
// es5๋ก ๋น๋ ํด์ผ ํ ๊ฒฝ์ฐ ์ฃผ์ ์ ๊ฑฐ
// ๋จ, ์ด๊ฑฐ ์ค์ ํ๋ฉด webpack-dev-server 3๋ฒ๋ ๋ฒ์ ์์ live reloading ๋์ ์ํจ
// target: ['web', 'es5'],
devServer: {
liveReload: true
},
optimization: {
minimizer: webpackMode === 'production' ? [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true
}
}
})
] : [],
splitChunks: {
chunks: 'all'
}
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.js$/,
enforce: 'pre',
use: ['source-map-loader'],
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
minify: process.env.NODE_ENV === 'production' ? {
collapseWhitespace: true,
removeComments: true,
} : false
}),
new CleanWebpackPlugin(),
// CopyWebpackPlugin: ๊ทธ๋๋ก ๋ณต์ฌํ ํ์ผ๋ค์ ์ค์ ํ๋ ํ๋ฌ๊ทธ์ธ
// ์๋ patterns์ ์ค์ ํ ํ์ผ/ํด๋๋ ๋น๋ ์ dist ํด๋์ ์๋์ผ๋ก ์์ฑ๋ฉ๋๋ค.
// patterns์ ์ค์ ํ ๊ฒฝ๋ก์ ํด๋น ํ์ผ์ด ์์ผ๋ฉด ์๋ฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
// ์ฌ์ฉํ๋ ํ์ผ์ด๋ ํด๋ ์ด๋ฆ์ด ๋ค๋ฅด๋ค๋ฉด ๋ณ๊ฒฝํด์ฃผ์ธ์.
// ๊ทธ๋๋ก ์ฌ์ฉํ ํ์ผ๋ค์ด ์๋ค๋ฉด CopyWebpackPlugin์ ํต์งธ๋ก ์ฃผ์ ์ฒ๋ฆฌ ํด์ฃผ์ธ์.
new CopyWebpackPlugin({
patterns: [
{ from: "./src/main.css", to: "./main.css" },
{ from: "./src/images", to: "./images" },
],
})
]
};