language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
mrdoob
three.js
2b64f57cb1a75d156e7fdc0cf87207adb4cf38d0.json
add translation kr/threejs-offscreencanvas.md
threejs/lessons/kr/threejs-offscreencanvas.md
@@ -0,0 +1,1057 @@ +Title: Three.js OffscreenCanvas +Description: Three.js์—์„œ ์›น ์›Œ์ปค๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฒ•์„ ์•Œ์•„๋ด…๋‹ˆ๋‹ค +TOC: ์›น ์›Œ์ปค์—์„œ OffscreenCanvas ์‚ฌ์šฉํ•˜๊ธฐ + +[`OffscreenCanvas`](https://developer.mozilla.org/ko/docs/Web/API/OffscreenCanvas)๋Š” ๋น„๊ต์  ์ตœ๊ทผ ๋„์ž…๋œ ๋ธŒ๋ผ์šฐ์ € API๋กœ ์•„์ง ํฌ๋กœ๋ฏธ์›€ ๊ธฐ๋ฐ˜ ๋ธŒ๋ผ์šฐ์ €์—์„œ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ๊ฐˆ์ˆ˜๋ก ๋Œ€๋ถ€๋ถ„์˜ ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ด API๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค. `OffscreenCanvas`๋ฅผ ์ด์šฉํ•˜๋ฉด [์›น ์›Œ์ปค(Web Worker)](https://developer.mozilla.org/ko/docs/Web/API/Web_Workers_API)์—์„œ ์บ”๋ฒ„์Šค๋ฅผ ๋ Œ๋”๋งํ•ด ๋ณต์žกํ•œ 3D ์žฅ๋ฉด ๋“ฑ์˜ ๋ฌด๊ฑฐ์šด ์ž‘์—…์„ ๋ณ„๋„ ํ”„๋กœ์„ธ์Šค์—์„œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด ๋ฌด๊ฑฐ์šด ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•  ๋•Œ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๋œ ๋ฒ„๋ฒ…์ด๋„๋ก ํ•  ์ˆ˜ ์žˆ์ฃ . ๋˜ํ•œ ๋ฐ์ดํ„ฐ๋„ ์›Œ์ปค์—์„œ ๋ถˆ๋Ÿฌ์™€ ์ฒ˜๋ฆฌํ•˜๋ฏ€๋กœ ํŽ˜์ด์ง€ ์ดˆ๊ธฐ ๋กœ๋“œ ์‹œ ๋ฒ„๋ฒ…์ž„์„ ํ›จ์”ฌ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +OffscreenCanvas์˜ ๋ฌธ์ œ์  ์ค‘ ํ•˜๋‚˜๋Š” ์›น ์›Œ์ปค๊ฐ€ ์•„์ง ES ๋ชจ๋“ˆ(import, export ํ‚ค์›Œ๋“œ ๋“ฑ)์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒ๋‹ˆ๋‹ค. ๋•Œ๋ฌธ์— ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋‹ฌ๋ฆฌ ์ด ๊ธ€์—์„œ๋Š” ํด๋ž˜์Šค ์Šคํฌ๋ฆฝํŠธ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•  ๊ฒ๋‹ˆ๋‹ค. + +์‚ฌ์šฉ๋ฒ•์€ ๊ฝค๋‚˜ ์ง๊ด€์ ์ž…๋‹ˆ๋‹ค. ๋จผ์ € [๋ฐ˜์‘ํ˜• ๋””์ž์ธ์— ๊ด€ํ•œ ๊ธ€](threejs-responsive.html)์—์„œ ์ผ๋˜ ์˜ˆ์ œ๋ฅผ ๊ฐ€์ ธ์˜ค๋„๋ก ํ•˜์ฃ . + +์ด ์‚ฌ์ดํŠธ ๋Œ€๋ถ€๋ถ„์˜ ์˜ˆ์ œ๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ•ด๋‹น HTML ํŒŒ์ผ์— ์ธ๋ผ์ธ์œผ๋กœ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋ฉด์— ์›Œ์ปค๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ๋ณ„๋„์˜ ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ๋กœ ๋ถ„๋ฆฌํ•ด ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. + +์ด ๊ธ€์—์„œ๋Š” `offscreencanvas-cubes.js`๋ผ๋Š” ๋ณ„๋„ ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด [๋ฐ˜์‘ํ˜• ๋””์ž์ธ์—์„œ ๊ฐ€์ ธ์˜จ ์˜ˆ์ œ](threejs-responsive.html)์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์ „๋ถ€ ๋ณต์‚ฌํ•ด ๋„ฃ์„ ๊ฒ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ๋ฐ”๊ฟ”์•ผํ•  ๋ถ€๋ถ„์„ ๋ฐ”๊ฟ”๋ณด๋„๋ก ํ•˜์ฃ . + +ํ•˜์ง€๋งŒ ์—ฌ์ „ํžˆ HTML ํŒŒ์ผ์— ์•ฝ๊ฐ„์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์บ”๋ฒ„์Šค ์š”์†Œ๋ฅผ ์ฐธ์กฐํ•˜๊ณ  `canvas.transferControlToOffscreen` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด ์บ”๋ฒ„์Šค์˜ ์ œ์–ด๊ถŒ์„ `offscreen`์— ๋„˜๊ฒจ์ค๋‹ˆ๋‹ค. + +```js +function main() { + const canvas = document.querySelector('#c'); + const offscreen = canvas.transferControlToOffscreen(); + + ... +``` + +๊ทธ๋ฆฌ๊ณ  `new Worker(์›Œ์ปค ์Šคํฌ๋ฆฝํŠธ ๊ฒฝ๋กœ)`๋กœ ์›Œ์ปค๋ฅผ ์ƒ์„ฑํ•œ ๋’ค, ์›Œ์ปค์— `offscreen` ๊ฐ์ฒด๋ฅผ ๋„˜๊น๋‹ˆ๋‹ค. + +```js +function main() { + const canvas = document.querySelector('#c'); + const offscreen = canvas.transferControlToOffscreen(); + const worker = new Worker('offscreencanvas-cubes.js'); + worker.postMessage({ type: 'main', canvas: offscreen }, [ offscreen ]); +} +main(); +``` + +์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋”ฐ๋กœ ์จ์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ์›Œ์ปค ์•ˆ์—์„œ๋Š” `DOM`์— ์ ‘๊ทผํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. HTML ์š”์†Œ๋ฅผ ์ฐธ์กฐํ•˜๊ฑฐ๋‚˜ DOM ์š”์†Œ์˜ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์„ ์ˆ˜๋„ ์—†์ฃ . ์ผ๋ฐ˜์ ์œผ๋กœ ๋ฉ”์‹œ์ง€ ์ด๋ฒคํŠธ๋ฅผ ํ†ตํ•ด์„œ๋งŒ ๋‹ค๋ฅธ ์Šคํฌ๋ฆฝํŠธ์™€ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์›Œ์ปค์— ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋ ค๋ฉด [`worker.postMessage`](https://developer.mozilla.org/ko/docs/Web/API/Worker/postMessage)์— ํ•˜๋‚˜ ๋˜๋Š” ๋‘ ๊ฐœ์˜ ์ธ์ž๋ฅผ ๋„˜๊ฒจ์ฃผ์–ด ํ˜ธ์ถœํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ์ธ์ž๋Š” ์›Œ์ปค์— ์ „๋‹ฌํ•  ๊ฐ์ฒด๋กœ, ์ด ๊ฐ์ฒด๋Š” ๊ทธ๋Œ€๋กœ ์ „๋‹ฌ๋˜์ง€ ์•Š๊ณ  [๋ณต์‚ฌ๋ฉ๋‹ˆ๋‹ค](https://developer.mozilla.org/ko/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). ๋‘ ๋ฒˆ์งธ ์ธ์ž๋Š” ์˜ต์…˜์œผ๋กœ ์ฒซ ๋ฒˆ์งธ ์ธ์ž ์ค‘ ๊ทธ๋Œ€๋กœ *์ „๋‹ฌํ•˜๊ธฐ* ์›ํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ๋ฐฐ์—ด๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์— ์ง€์ •ํ•œ ๊ฐ์ฒด๋Š” ๋ณต์‚ฌ๋˜์ง€ ์•Š์ฃ . ๊ทธ๋Œ€๋กœ ์›Œ์ปค์— *์ „๋‹ฌ๋˜์ง€๋งŒ* ๊ฐ์ฒด๋ฅผ ๋ณด๋‚ธ ์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” ๋” ์ด์ƒ ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•ด์ง‘๋‹ˆ๋‹ค. ์ด๊ฒƒ๋„ ๋ชจ๋“  ๊ฐ์ฒด๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ ํŠน์ • ํƒ€์ž…์˜ ๊ฐ์ฒด๋งŒ์„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ์ฃ . ๋‹น์—ฐํ•˜๊ฒŒ๋„ ์ด ์ค‘์—๋Š” `OffscreenCanvas`๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ •๋ฆฌํ•˜์ž๋ฉด `offscreen` ๊ฐ์ฒด๋ฅผ ์ „๋‹ฌํ•˜๊ณ  ๋‚˜๋ฉด ์ด ๊ฐ์ฒด๋Š” ์ด ์Šคํฌ๋ฆฝํŠธ์—์„œ ๋” ์ด์ƒ ์“ธ๋ชจ๊ฐ€ ์—†์–ด์ง‘๋‹ˆ๋‹ค. + +์›Œ์ปค์˜ `message` ์ด๋ฒคํŠธ๋ฅผ ์ด์šฉํ•˜๋ฉด ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. `postMessage`์—์„œ ๋„˜๊ธด ๊ฐ์ฒด๋Š” `event.data`์— ๋‹ด๊ฒจ ๋ฆฌ์Šค๋„ˆ์— ์ „๋‹ฌ๋˜์ฃ . ์•„๊นŒ ์œ„ ์ฝ”๋“œ์—์„œ๋Š” `type: 'main'` ์†์„ฑ์„ ๊ฐ์ฒด์— ์„ ์–ธํ•ด ์›Œ์ปค์— ๋„˜๊ฒจ์คฌ์Šต๋‹ˆ๋‹ค. ์ด `type` ์†์„ฑ์œผ๋กœ ์›Œ์ปค ๋‚ด์— ๋‹ค๋ฅธ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ํ•ด๋ด…์‹œ๋‹ค. ์ด๋Ÿฌ๋ฉด ๋ฉ”์ธ ์Šคํฌ๋ฆฝํŠธ์—์„œ ์›Œ์ปค ๋‚ด์˜ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ๊ฐ€ ํ›จ์”ฌ ์‰ฌ์›Œ์งˆ ๊ฒ๋‹ˆ๋‹ค. + +```js +const handlers = { + main, +}; + +self.onmessage = function(e) { + const fn = handlers[e.data.type]; + if (!fn) { + throw new Error('no handler for type: ' + e.data.type); + } + fn(e.data); +}; +``` + +`type` ๊ฐ’์„ ํ†ตํ•ด ํ˜ธ์ถœํ•  ํ•จ์ˆ˜๋ฅผ ์ฐพ๊ณ , ํ•จ์ˆ˜๊ฐ€ ์žˆ๋‹ค๋ฉด ๋ฉ”์ธ ์Šคํฌ๋ฆฝํŠธ์—์„œ ๋„˜์–ด์˜จ `data`๋ฅผ ์ธ์ž๋กœ ๋„˜๊ฒจ ํ˜ธ์ถœํ•˜๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค. + +์ด์ œ [๋ฐ˜์‘ํ˜• ๋””์ž์ธ์— ๊ด€ํ•œ ๊ธ€](threejs-responsive.html)์—์„œ ๊ฐ€์ ธ์˜จ ์˜ˆ์ œ์˜ `main` ํ•จ์ˆ˜๋ฅผ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +๋ฌผ๋ก  ๊ทธ์ „์— ๋จผ์ € Three.js๋ฅผ `offscreencanvas-cubes.js`์— ๋ถˆ๋Ÿฌ์™€์•ผ๊ฒ ์ฃ . + +```js +importScripts('resources/threejs/r115/build/three.min.js'); +``` + +DOM์—์„œ ์บ”๋ฒ„์Šค์— ์ ‘๊ทผํ•˜๋Š” ๋Œ€์‹  ์ด๋ฒคํŠธ์˜ `data`์—์„œ ์บ”๋ฒ„์Šค๋ฅผ ๋ฐ›์Šต๋‹ˆ๋‹ค. + +```js +-function main() { +- const canvas = document.querySelector('#c'); ++function main(data) { ++ const { canvas } = data; + const renderer = new THREE.WebGLRenderer({ canvas }); + + ... + +``` + +์›Œ์ปค์—์„œ๋Š” DOM์— ์ ‘๊ทผํ•  ์ˆ˜ ์—†๋‹ค๊ณ  ํ–ˆ์—ˆ์ฃ . ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ DOM ์†์„ฑ์ธ `canvas.clientWidth`๋‚˜ `canvas.clientHeight`์—๋„ ์ ‘๊ทผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. `resizeRendererToDisplaySize`๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๊ฒƒ์ด์ฃ . + +```js +function resizeRendererToDisplaySize(renderer) { + const canvas = renderer.domElement; + const width = canvas.clientWidth; + const height = canvas.clientHeight; + const needResize = canvas.width !== width || canvas.height !== height; + if (needResize) { + renderer.setSize(width, height, false); + } + return needResize; +} +``` + +๋Œ€์‹  ์บ”๋ฒ„์Šค ํฌ๊ธฐ๊ฐ€ ๋ณ€๊ฒฝ๋  ๋•Œ๋งˆ๋‹ค ์›Œ์ปค์— ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ผ ๊ฒ๋‹ˆ๋‹ค. ์›Œ์ปค์— ์ „์—ญ ๋ณ€์ˆ˜๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•ด ์—ฌ๊ธฐ์— width์™€ height ๊ฐ’์„ ์ง€์ •ํ•˜๋„๋ก ํ•˜์ฃ . + +```js +const state = { + width: 300, // ์บ”๋ฒ„์Šค ๊ธฐ๋ณธ๊ฐ’ + height: 150, // ์บ”๋ฒ„์Šค ๊ธฐ๋ณธ๊ฐ’ +}; +``` + +๊ทธ๋ฆฌ๊ณ  `size`๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ํ•ด๋‹น ๊ฐ’์„ ์—…๋ฐ์ดํŠธํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js ++function size(data) { ++ state.width = data.width; ++ state.height = data.height; ++} + +const handlers = { + main, ++ size, +}; +``` + +`resizeRendererToDisplaySize`๊ฐ€ `state.width`์™€ `state.height`๋ฅผ ์“ฐ๋„๋ก ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. + +```js +function resizeRendererToDisplaySize(renderer) { + const canvas = renderer.domElement; +- const width = canvas.clientWidth; +- const height = canvas.clientHeight; ++ const width = state.width; ++ const height = state.height; + const needResize = canvas.width !== width || canvas.height !== height; + if (needResize) { + renderer.setSize(width, height, false); + } + return needResize; +} +``` + +๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ข…ํšก๋น„๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ์ฝ”๋“œ๋„ DOM ์†์„ฑ ๋Œ€์‹  `state`๋ฅผ ์“ฐ๋„๋ก ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. + +```js +function render(time) { + time *= 0.001; + + if (resizeRendererToDisplaySize(renderer)) { +- camera.aspect = canvas.clientWidth / canvas.clientHeight; ++ camera.aspect = state.width / state.height; + camera.updateProjectionMatrix(); + } + + ... +``` + +๋ฉ”์ธ ์Šคํฌ๋ฆฝํŠธ๋กœ ๋Œ์•„์™€ ํŽ˜์ด์ง€ ํฌ๊ธฐ๊ฐ€ ๋ฐ”๋€” ๋•Œ๋งˆ๋‹ค ์›Œ์ปค์˜ `size` ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +const worker = new Worker('offscreencanvas-picking.js'); +worker.postMessage({ type: 'main', canvas: offscreen }, [ offscreen ]); + ++function sendSize() { ++ worker.postMessage({ ++ type: 'size', ++ width: canvas.clientWidth, ++ height: canvas.clientHeight, ++ }); ++} ++ ++window.addEventListener('resize', sendSize); ++sendSize(); +``` + +๋˜ํ•œ ์ง์ ‘ ํ˜ธ์ถœํ•ด ์ตœ์ดˆ์— ํ•œ ๋ฒˆ ๊ฐ’์„ ๋ณด๋‚ด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +์—ฌ๋Ÿฌ๋ถ„์˜ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ `OffscreenCanvas`๋ฅผ ์™„๋ฒฝํžˆ ์ง€์›ํ•œ๋‹ค๋ฉด ์ด์ œ ๋ฌธ์ œ ์—†์ด ์ž‘๋™ํ•  ๊ฒ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ฒŒ ๋งŽ์ด ๋ฐ”๊พผ ๊ฒƒ์ด ์—†๋Š”๋ฐ๋„ ๋ง์ด์ฃ . ํ˜น์‹œ ๋ชจ๋ฅด๋‹ˆ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ `OffscreenCanvas`๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋จผ์ € ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•  HTML์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. + +```html +<body> + <canvas id="c"></canvas> ++ <div id="noOffscreenCanvas" style="display:none;"> ++ <div>no OffscreenCanvas support</div> ++ </div> +</body> +``` + +๊ฐ„๋‹จํ•œ ์Šคํƒ€์ผ๋„ ๋„ฃ์–ด์ฃผ๋„๋ก ํ•˜์ฃ . + +```css +#noOffscreenCanvas { + display: flex; + width: 100vw; + height: 100vh; + align-items: center; + justify-content: center; + background: red; + color: white; +} +``` + +๊ทธ๋ฆฌ๊ณ  ์บ”๋ฒ„์Šค ์š”์†Œ์— `transferControlToOffscreen` ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•ด `OffscreenCanvas`์˜ ์ง€์› ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + +```js +function main() { + const canvas = document.querySelector('#c'); ++ if (!canvas.transferControlToOffscreen) { ++ canvas.style.display = 'none'; ++ document.querySelector('#noOffscreenCanvas').style.display = ''; ++ return; ++ } + const offscreen = canvas.transferControlToOffscreen(); + const worker = new Worker('offscreencanvas-picking.js'); + worker.postMessage({ type: 'main', canvas: offscreen }, [ offscreen ]); + + ... +``` + +๋ธŒ๋ผ์šฐ์ €๊ฐ€ `OffscreenCanvas`๋ฅผ ์ง€์›ํ•œ๋‹ค๋ฉด ๋ฌธ์ œ ์—†์ด ์ž‘๋™ํ•  ๊ฒ๋‹ˆ๋‹ค. + +{{{example url="../threejs-offscreencanvas.html" }}} + +ํ•˜์ง€๋งŒ ํ˜„์žฌ ๋ชจ๋“  ๋ธŒ๋ผ์šฐ์ €๊ฐ€ `OffscreenCanvas`๋ฅผ ์ง€์›ํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค. `OffscreenCanvas`๋ฅผ ์ง€์›ํ•  ๊ฒฝ์šฐ์—๋งŒ ์›Œ์ปค๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ํ•˜๊ณ , ๊ทธ๋ ‡์ง€ ์•Š์„ ๊ฒฝ์šฐ์—๋Š” ๊ธฐ์กด์ฒ˜๋Ÿผ ๋ฉ”์ธ ์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ Œ๋”๋ง์„ ์ฒ˜๋ฆฌํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +> OffscreenCanvas๋ฅผ ๋‹จ์ˆœํžˆ ํŽ˜์ด์ง€๋ฅผ ๋ฐ˜์‘ํ˜•์œผ๋กœ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•˜๋Š” ๊ฑด ์˜๋ฏธ์—†์–ด ๋ณด์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฉ”์ธ ์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ฐ˜์‘ํ˜•์„ ์ฒ˜๋ฆฌํ•  ๋•Œ๋ณด๋‹ค ์›Œ์ปค์—์„œ ์ฒ˜๋ฆฌํ•  ๋•Œ ์˜คํžˆ๋ ค ์ž‘์—…์ด ๋” ๋งŽ์ด ๋“ค ์ˆ˜ ์žˆ๊ฑฐ๋“ ์š”. ํ•˜์ง€๋งŒ ๋ฉ”์ธ ์Šคํฌ๋ฆฝํŠธ๋งŒ ์‚ฌ์šฉํ•  ๋•Œ๋ณด๋‹ค ์›Œ์ปค๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ž์›์„ ๋” ๋„‰๋„‰ํ•˜๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑด ๋ถ„๋ช…ํ•ฉ๋‹ˆ๋‹ค. ์ „์ ์œผ๋กœ ์—ฌ๋Ÿฌ๋ถ„์ด ์ƒํ™ฉ์— ๋”ฐ๋ผ ๊ฒฐ์ •ํ•  ๋ฌธ์ œ๋ผ๋Š” ๊ฒƒ์ด์ฃ . + +๋จผ์ € Three.js ๊ด€๋ จ ์ฝ”๋“œ๋ฅผ ๋ถ„๋ฆฌํ•ด ์›Œ์ปค ๊ด€๋ จ ์ฝ”๋“œ์™€ ๊ทธ๋ ‡์ง€ ์•Š์€ ์ฝ”๋“œ๋กœ ๋‚˜๋ˆ ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ๋ฉ”์ธ ์Šคํฌ๋ฆฝํŠธ์™€ ์›Œ์ปค์—์„œ ๋ชจ๋‘ ์“ธ ์ˆ˜ ์žˆ๋„๋ก ๋ง์ด์ฃ . ์•„๋ž˜์™€ ๊ฐ™์ด 3๊ฐœ์˜ ํŒŒ์ผ๋กœ ๋‚˜๋‰  ๊ฒ๋‹ˆ๋‹ค. + +1. html ํŒŒ์ผ. + + `threejs-offscreencanvas-w-fallback.html` + +2. three.js ๊ด€๋ จ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ. + + `shared-cubes.js` + +3. ์›Œ์ปค์šฉ ์Šคํฌ๋ฆฝํŠธ + + `offscreencanvas-worker-cubes.js` + +`shared-cubes.js`์™€ `offscreencanvas-worker-cubes.js`๋Š” ๋‹จ์ˆœํžˆ ์ด์ „ `offscreencanvas-cubes.js` ํŒŒ์ผ์„ ์ชผ๊ฐ  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฉ”์ธ HTML ํŒŒ์ผ์— `main`์ด๋ผ๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ์–ด `main` ํ•จ์ˆ˜๋งŒ `init`์œผ๋กœ ๋ฐ”๊ฟจ์ฃ . + +`offscreencanvas-worker-cubes.js`์˜ ๊ตฌ์กฐ๋Š” ์•„์ฃผ ๋‹จ์ˆœํ•ฉ๋‹ˆ๋‹ค. + +```js +'use strict'; + +/* global importScripts, init, state */ + +importScripts('resources/threejs/r115/build/three.min.js'); ++importScripts('shared-cubes.js'); + +function size(data) { + state.width = data.width; + state.height = data.height; +} + +const handlers = { +- main, ++ init, + size, +}; + +self.onmessage = function(e) { + const fn = handlers[e.data.type]; + if (!fn) { + throw new Error('no handler for type: ' + e.data.type); + } + fn(e.data); +}; +``` + +์œ„ ์ฝ”๋“œ์—์„œ๋Š” Three.js ๊ด€๋ จ ์Šคํฌ๋ฆฝํŠธ์ธ `shared-cubes.js`๋ฅผ ๋ถˆ๋Ÿฌ์™”์Šต๋‹ˆ๋‹ค. + +๋ฉ”์ธ ํŽ˜์ด์ง€์—์„œ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Three.js์™€ `shared-cubes.js`๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```html +<script src="resources/threejs/r115/build/three.min.js"></script> +<script src="shared-cubes.js"><script> +``` + +์ด์ „์— ์ถ”๊ฐ€ํ–ˆ๋˜ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€์šฉ HTML๊ณผ CSS๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. + +```html +<body> + <canvas id="c"></canvas> +- <div id="noOffscreenCanvas" style="display:none;"> +- <div>no OffscreenCanvas support</div> +- </div> +</body> +``` + +```css +-#noOffscreenCanvas { +- display: flex; +- width: 100vw; +- height: 100vh; +- align-items: center; +- justify-content: center; +- background: red; +- color: white; +-} +``` + +๊ทธ๋ฆฌ๊ณ  `OffscreenCanvas`์˜ ์ง€์› ์—ฌ๋ถ€์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +function main() { + const canvas = document.querySelector('#c'); +- if (!canvas.transferControlToOffscreen) { +- canvas.style.display = 'none'; +- document.querySelector('#noOffscreenCanvas').style.display = ''; +- return; +- } +- const offscreen = canvas.transferControlToOffscreen(); +- const worker = new Worker('offscreencanvas-picking.js'); +- worker.postMessage({ type: 'main', canvas: offscreen }, [ offscreen ]); ++ if (canvas.transferControlToOffscreen) { ++ startWorker(canvas); ++ } else { ++ startMainPage(canvas); ++ } + ... +``` + +์›Œ์ปค๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ–ˆ๋˜ ์ฝ”๋“œ๋ฅผ ์ „๋ถ€ `startWorker` ํ•จ์ˆ˜๋กœ ์˜ฎ๊น๋‹ˆ๋‹ค. + +```js +function startWorker(canvas) { + const offscreen = canvas.transferControlToOffscreen(); + const worker = new Worker('offscreencanvas-worker-cubes.js'); + worker.postMessage({type: 'init', canvas: offscreen}, [offscreen]); + + function sendSize() { + worker.postMessage({ + type: 'size', + width: canvas.clientWidth, + height: canvas.clientHeight, + }); + } + + window.addEventListener('resize', sendSize); + sendSize(); + + console.log('using OffscreenCanvas'); +} +``` + +์›Œ์ปค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. + +```js +function startMainPage(canvas) { + init({ canvas }); + + function sendSize() { + state.width = canvas.clientWidth; + state.height = canvas.clientHeight; + } + window.addEventListener('resize', sendSize); + sendSize(); + + console.log('using regular canvas'); +} +``` + +์ด์ œ `OffscreenCanvas๋ฅผ` ์ง€์›ํ•˜๋Š” ๊ฒฝ์šฐ์—๋งŒ `OffscreenCanvas`๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์—๋Š” ๋ฉ”์ธ ์Šค๋ ˆ๋“œ์—์„œ ์ง์ ‘ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. + +{{{example url="../threejs-offscreencanvas-w-fallback.html" }}} + +์–ด๋–ค๊ฐ€์š”? ์ƒ๊ฐํ–ˆ๋˜ ๊ฒƒ๋ณด๋‹ค ์‰ฝ์ง€ ์•Š๋‚˜์š”? ์—ฌ๊ธฐ์— ํ”ผํ‚น(picking)์„ ์ถ”๊ฐ€ํ•ด๋ด…์‹œ๋‹ค. [ํ”ผํ‚น์— ๊ด€ํ•œ ๊ธ€](threejs-picking.html)์˜ `RayCaster` ์˜ˆ์ œ์—์„œ ์ฝ”๋“œ ์ผ๋ถ€๋ฅผ ๊ฐ€์ ธ์˜ค๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +๋จผ์ € `shared-cube.js`์˜ ์ฝ”๋“œ๋ฅผ `shared-picking.js`๋กœ ๋ณต์‚ฌํ•œ ๋’ค, ํ”ผํ‚น ์˜ˆ์ œ์—์„œ `PickHelper`๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. + +```js +class PickHelper { + constructor() { + this.raycaster = new THREE.Raycaster(); + this.pickedObject = null; + this.pickedObjectSavedColor = 0; + } + pick(normalizedPosition, scene, camera, time) { + // ์ด๋ฏธ ๋‹ค๋ฅธ ๋ฌผ์ฒด๋ฅผ ํ”ผํ‚นํ–ˆ๋‹ค๋ฉด ์ƒ‰์„ ๋ณต์›ํ•ฉ๋‹ˆ๋‹ค + if (this.pickedObject) { + this.pickedObject.material.emissive.setHex(this.pickedObjectSavedColor); + this.pickedObject = undefined; + } + + // ์ ˆ๋‘์ฒด ์•ˆ์— ๊ด‘์„ ์„ ์ฉ๋‹ˆ๋‹ค + this.raycaster.setFromCamera(normalizedPosition, camera); + // ๊ด‘์„ ๊ณผ ๊ต์ฐจํ•˜๋Š” ๋ฌผ์ฒด๋“ค์„ ๋ฐฐ์—ด๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค + const intersectedObjects = this.raycaster.intersectObjects(scene.children); + if (intersectedObjects.length) { + // ์ฒซ ๋ฒˆ์งธ ๋ฌผ์ฒด๊ฐ€ ์ œ์ผ ๊ฐ€๊นŒ์šฐ๋ฏ€๋กœ ํ•ด๋‹น ๋ฌผ์ฒด๋ฅผ ๊ณ ๋ฆ…๋‹ˆ๋‹ค + this.pickedObject = intersectedObjects[0].object; + // ๊ธฐ์กด ์ƒ‰์„ ์ €์žฅํ•ด๋‘ก๋‹ˆ๋‹ค + this.pickedObjectSavedColor = this.pickedObject.material.emissive.getHex(); + // emissive ์ƒ‰์„ ๋นจ๊ฐ•/๋…ธ๋ž‘์œผ๋กœ ๋น›๋‚˜๊ฒŒ ๋งŒ๋“ญ๋‹ˆ๋‹ค + this.pickedObject.material.emissive.setHex((time * 8) % 2 > 1 ? 0xFFFF00 : 0xFF0000); + } + } +} + +const pickPosition = { x: 0, y: 0 }; +const pickHelper = new PickHelper(); +``` + +`pickPosition`์€ ๋งˆ์šฐ์Šค ํฌ์ธํ„ฐ์˜ ์ขŒํ‘œ๋ฅผ ๊ธฐ๋กํ•˜๋Š” ์—ญํ• ์ž…๋‹ˆ๋‹ค. ์ด๋ฒคํŠธ๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ์†์„ฑ์„ ์—…๋ฐ์ดํŠธํ•˜๋„๋ก ํ–ˆ์—ˆ์ฃ . + +```js +function getCanvasRelativePosition(event) { + const rect = canvas.getBoundingClientRect(); + return { + x: (event.clientX - rect.left) * canvas.width / rect.width, + y: (event.clientY - rect.top ) * canvas.height / rect.height, + }; +} + +function setPickPosition(event) { + const pos = getCanvasRelativePosition(event); + pickPosition.x = (pos.x / canvas.width ) * 2 - 1; + pickPosition.y = (pos.y / canvas.height) * -2 + 1; // Y์ถ•์„ ๋’ค์ง‘์—ˆ์Œ +} +window.addEventListener('mousemove', setPickPosition); +``` + +์›Œ์ปค๋Š” ํฌ์ธํ„ฐ ์ขŒํ‘œ์— ์ง์ ‘ ์ ‘๊ทผํ•  ์ˆ˜ ์—†๊ธฐ์—, ๋ฐ˜์‘ํ˜• ์ฒ˜๋ฆฌ์— ์‚ฌ์šฉํ–ˆ๋˜ ์ฝ”๋“œ์ฒ˜๋Ÿผ ํฌ์ธํ„ฐ ์ขŒํ‘œ๋ฅผ ๋ฉ”์‹œ์ง€๋กœ ๋ณด๋‚ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋จผ์ € `size` ํ•จ์ˆ˜์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ `mouse` ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด `pickPosition`์„ ์—…๋ฐ์ดํŠธํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +function size(data) { + state.width = data.width; + state.height = data.height; +} + ++function mouse(data) { ++ pickPosition.x = data.x; ++ pickPosition.y = data.y; ++} + +const handlers = { + init, ++ mouse, + size, +}; + +self.onmessage = function(e) { + const fn = handlers[e.data.type]; + if (!fn) { + throw new Error('no handler for type: ' + e.data.type); + } + fn(e.data); +}; +``` + +๊ทธ๋ฆฌ๊ณ  ๋ฉ”์ธ ํŽ˜์ด์ง€์— ๋ถ„๊ธฐ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ์›Œ์ปค ๋˜๋Š” ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ ์ขŒํ‘œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋‚ด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js ++let sendMouse; + +function startWorker(canvas) { + const offscreen = canvas.transferControlToOffscreen(); + const worker = new Worker('offscreencanvas-worker-picking.js'); + worker.postMessage({ type: 'init', canvas: offscreen }, [ offscreen ]); + ++ sendMouse = (x, y) => { ++ worker.postMessage({ ++ type: 'mouse', ++ x, ++ y, ++ }); ++ }; + + function sendSize() { + worker.postMessage({ + type: 'size', + width: canvas.clientWidth, + height: canvas.clientHeight, + }); + } + + window.addEventListener('resize', sendSize); + sendSize(); + + console.log('using OffscreenCanvas'); /* eslint-disable-line no-console */ +} + +function startMainPage(canvas) { + init({ canvas }); + ++ sendMouse = (x, y) => { ++ pickPosition.x = x; ++ pickPosition.y = y; ++ }; + + function sendSize() { + state.width = canvas.clientWidth; + state.height = canvas.clientHeight; + } + window.addEventListener('resize', sendSize); + sendSize(); + + console.log('using regular canvas'); /* eslint-disable-line no-console */ +} + +``` + +๋‹ค์Œ์œผ๋กœ ๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ ๊ด€๋ จ ์ฝ”๋“œ๋ฅผ ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ ์˜ฎ๊ธด ๋’ค `sendMouse` ํ•จ์ˆ˜๋ฅผ ์“ฐ๋„๋ก ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. + +```js +function setPickPosition(event) { + const pos = getCanvasRelativePosition(event); +- pickPosition.x = (pos.x / canvas.clientWidth ) * 2 - 1; +- pickPosition.y = (pos.y / canvas.clientHeight) * -2 + 1; // Y์ถ•์„ ๋’ค์ง‘์—ˆ์Œ ++ sendMouse( ++ (pos.x / canvas.clientWidth ) * 2 - 1, ++ (pos.y / canvas.clientHeight) * -2 + 1); // Y์ถ•์„ ๋’ค์ง‘์—ˆ์Œ +} + +function clearPickPosition() { + /** + * ๋งˆ์šฐ์Šค์˜ ๊ฒฝ์šฐ๋Š” ํ•ญ์ƒ ์œ„์น˜๊ฐ€ ์žˆ์–ด ๊ทธ๋‹ค์ง€ ํฐ + * ์ƒ๊ด€์ด ์—†์ง€๋งŒ, ํ„ฐ์น˜ ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ์†๊ฐ€๋ฝ์„ + * ๋–ผ๋ฉด ํ”ผํ‚น์„ ๋ฉˆ์ถฐ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ง€๊ธˆ์€ ์ผ๋‹จ ์–ด๋–ค ๊ฒƒ๋„ + * ์„ ํƒํ•  ์ˆ˜ ์—†๋Š” ๊ฐ’์œผ๋กœ ์ง€์ •ํ•ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค + **/ +- pickPosition.x = -100000; +- pickPosition.y = -100000; ++ sendMouse(-100000, -100000); +} +window.addEventListener('mousemove', setPickPosition); +window.addEventListener('mouseout', clearPickPosition); +window.addEventListener('mouseleave', clearPickPosition); + +window.addEventListener('touchstart', (event) => { + event.preventDefault(); // ์Šคํฌ๋กค ์ด๋ฒคํŠธ ๋ฐฉ์ง€ + setPickPosition(event.touches[0]); +}, { passive: false }); + +window.addEventListener('touchmove', (event) => { + setPickPosition(event.touches[0]); +}); + +window.addEventListener('touchend', clearPickPosition); +``` + +์ด์ œ `OffscreenCanvas`์—์„œ๋„ ํ”ผํ‚น์ด ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•  ๊ฒ๋‹ˆ๋‹ค. + +{{{example url="../threejs-offscreencanvas-w-picking.html" }}} + +์ข€ ๋” ์š•์‹ฌ์„ ๋‚ด `OrbitControls`๊นŒ์ง€ ์ถ”๊ฐ€ํ•ด๋ด…์‹œ๋‹ค. `OrbitControls`๋Š” DOM์— ๊ฝค ๋‹ค์–‘ํ•˜๊ฒŒ ์ ‘๊ทผํ•˜๊ธฐ์— ์ฒ˜๋ฆฌํ•ด์ค˜์•ผ ํ•  ๊ฒƒ์ด ์ข€ ๋งŽ์Šต๋‹ˆ๋‹ค. ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜๋ ค๋ฉด ๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ, ํ„ฐ์น˜ ์ด๋ฒคํŠธ, ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ๋ฅผ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ด์ค˜์•ผ ํ•˜์ฃ . + +์—ฌํƒœ๊นŒ์ง€๋Š” ์ „์—ญ `state` ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ–ˆ์ง€๋งŒ, `OrbitControls`์˜ ๊ฒฝ์šฐ๋Š” ๊ฐ์ฒด ์†์„ฑ์ด ๋„ˆ๋ฌด ๋งŽ์•„ ๊ทธ๊ฑธ ์ „๋ถ€ ๋‹ค ํ•˜๋“œ ์ฝ”๋”ฉํ•˜๋Š” ๊ฑด ๋„ˆ๋ฌด ๋ฒˆ๊ฑฐ๋กญ์Šต๋‹ˆ๋‹ค. `OrbitControls`๋Š” ํ•„์š”ํ•œ DOM ์ด๋ฒคํŠธ์˜ ๋Œ€๋ถ€๋ถ„์„ ์ธ์ž๋กœ ๋ฐ›๋Š” HTML ์š”์†Œ์— ๋ฐ”์ธ๋”ฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์ด์šฉํ•ด DOM ์š”์†Œ์™€ ๊ฐ™์€ ๊ตฌ์กฐ์˜ ๊ฐ์ฒด๋ฅผ ๋„˜๊ฒจ์ค€๋‹ค๋ฉด ์–ด๋–จ๊นŒ์š”? `OrbitControls`์— ํ•„์š”ํ•œ ๊ธฐ๋Šฅ๋งŒ ์‚ด๋ ค์„œ ๋ง์ด์ฃ . + +[`OrbitControls`์˜ ์†Œ์Šค ์ฝ”๋“œ](https://github.com/gfxfundamentals/threejsfundamentals/blob/master/threejs/resources/threejs/r115/examples/js/controls/OrbitControls.js)๋ฅผ ๋ถ„์„ํ•ด๋ณด๋‹ˆ ์•„๋ž˜์˜ ์ด๋ฒคํŠธ๋งŒ ์ง€์›ํ•˜๋ฉด ๋  ๋“ฏํ•ฉ๋‹ˆ๋‹ค. + +* contextmenu +* mousedown +* mousemove +* mouseup +* touchstart +* touchmove +* touchend +* wheel +* keydown + +๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ ์ค‘ `OrbitControls`๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์†์„ฑ์€ `ctrlKey`, `metaKey`, `shiftKey`, `button`, `clientX`, `clientY`, `pageX`, `pageY`์ด๊ณ , + +keydown ์ด๋ฒคํŠธ์˜ ๊ฒฝ์šฐ๋Š” `ctrlKey`, `metaKey`, `shiftKey`, `keyCode` ์†์„ฑ, + +wheel ์ด๋ฒคํŠธ๋Š” `deltaY` ์†์„ฑ๋งŒ, + +ํ„ฐ์น˜ ์ด๋ฒคํŠธ์˜ ๊ฒฝ์šฐ๋Š” `touches` ์†์„ฑ์˜ `pageX`, `pageY` ์†์„ฑ์ด ํ•„์š”ํ•˜๋„ค์š”. + +์ด๋ฅผ ์ฒ˜๋ฆฌํ•  ๊ฒฝ์œ (proxy) ๊ฐ์ฒด๋ฅผ ํ•œ ์Œ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค. ํ•œ์ชฝ์€ ๋ฉ”์ธ ํŽ˜์ด์ง€์—์„œ ์œ„ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์•„ ํ•„์š”ํ•œ ์†์„ฑ์„ ์›Œ์ปค์— ๋„˜๊ฒจ์ฃผ๋Š” ์—ญํ• ์„ ํ•  ๊ฒ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋‹ค๋ฅธ ํ•œ์ชฝ์€ ์›Œ์ปค ์•ˆ์—์„œ ์ด ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์•„ `OrbitControls`์— ๋„˜๊ฒจ์ค„ ๊ฒ๋‹ˆ๋‹ค. ์ด๋ฒคํŠธ ๊ฐ์ฒด๊ฐ€ DOM ์ด๋ฒคํŠธ์™€ ๊ฐ™์€ ๊ตฌ์กฐ์ด๊ธฐ์— `OrbitControls`๋Š” ์ด ์ด๋ฒคํŠธ๊ฐ€ DOM ์ด๋ฒคํŠธ๊ฐ€ ์•„๋‹ˆ๋ž€ ๊ฑธ ๋ˆˆ์น˜์ฑ„์ง€ ๋ชปํ•˜๊ฒ ์ฃ . + +์•„๋ž˜๋Š” ์›Œ์ปค ์•ˆ์˜ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. + +```js +class ElementProxyReceiver extends THREE.EventDispatcher { + constructor() { + super(); + } + handleEvent(data) { + this.dispatchEvent(data); + } +} +``` + +์œ„ ์ฝ”๋“œ๋Š” ๋‹จ์ˆœํžˆ ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ›์•˜์„ ๋•Œ ๊ทธ๊ฑธ ๋‹ค์‹œ ๋‚ด๋ณด๋‚ด๋Š”(dispatch) ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. ๋ถ€๋ชจ ํด๋ž˜์Šค์ธ `EventDispatcher`๋Š” DOM ์š”์†Œ์ฒ˜๋Ÿผ `addEventListener`๋‚˜ `removeEventListener` ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•˜๊ธฐ์— HTML ์š”์†Œ ๋Œ€์‹  ์ด ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋„˜๊ฒจ์ค˜๋„ ๋ฌธ์ œ์—†์ด ์ž‘๋™ํ•  ๊ฒ๋‹ˆ๋‹ค. + +`ElementProxyReceiver`๋Š” ํ•˜๋‚˜์˜ ์š”์†Œ๋งŒ ๋Œ€์‹ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ์ œ์˜ ๊ฒฝ์šฐ ํ•˜๋‚˜๋งŒ ํ•„์š”ํ•˜๊ธฐ๋Š” ํ•˜๋‚˜ ๋‚˜์ค‘์— ์บ”๋ฒ„์Šค๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์œผ๋‹ˆ ์—ฌ๋Ÿฌ `ElementProxyReceiver`๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +class ProxyManager { + constructor() { + this.targets = {}; + this.handleEvent = this.handleEvent.bind(this); + } + makeProxy(data) { + const { id } = data; + const proxy = new ElementProxyReceiver(); + this.targets[id] = proxy; + } + getProxy(id) { + return this.targets[id]; + } + handleEvent(data) { + this.targets[data.id].handleEvent(data.data); + } +} +``` + +`ProxyManager`์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ  id๊ฐ’๊ณผ ํ•จ๊ป˜ `makeProxy` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ํ•ด๋‹น id์—๋งŒ ์‘๋‹ตํ•˜๋Š” `ElementProxyReceiver`๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. + +์ด์ œ ์ด ํด๋ž˜์Šค๋ฅผ ๊ธฐ์กด ์›Œ์ปค ์ฝ”๋“œ์™€ ์—ฐ๋™ํ•ด๋ด…์‹œ๋‹ค. + +```js +const proxyManager = new ProxyManager(); + +function start(data) { + const proxy = proxyManager.getProxy(data.canvasId); + init({ + canvas: data.canvas, + inputElement: proxy, + }); +} + +function makeProxy(data) { + proxyManager.makeProxy(data); +} + +... + +const handlers = { +- init, +- mouse, ++ start, ++ makeProxy, ++ event: proxyManager.handleEvent, + size, +}; + +self.onmessage = function(e) { + const fn = handlers[e.data.type]; + if (!fn) { + throw new Error('no handler for type: ' + e.data.type); + } + fn(e.data); +}; +``` + +`OrbitControls` ๋ชจ๋“ˆ๋„ ๋ถˆ๋Ÿฌ์™€์•ผ๊ฒ ์ฃ . + +```js +importScripts('resources/threejs/r115/build/three.min/js'); ++importScripts('resources/threejs/r115/examples/js/controls/OrbitControls.js'); +*importScripts('shared-orbitcontrols.js'); +``` + +๊ทธ๋ฆฌ๊ณ  ๊ณตํ†ต Three.js ์ฝ”๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. + +```js +function init(data) { +- const { canvas } = data; ++ const { canvas, inputElement } = data; + const renderer = new THREE.WebGLRenderer({ canvas }); + ++ const controls = new OrbitControls(camera, inputElement); ++ controls.target.set(0, 0, 0); ++ controls.update(); +``` + +์œ„ ์ฝ”๋“œ์—์„œ๋Š” ์ด์ „๊ณผ ๋‹ฌ๋ฆฌ `inputElement`๋กœ ๊ฒฝ์œ  ๊ฐ์ฒด๋ฅผ `OrbitControls`์— ๋„˜๊ฒจ์คฌ์Šต๋‹ˆ๋‹ค. + +ํ•˜๋Š” ๊น€์— ํ”ผํ‚น ์ด๋ฒคํŠธ๋„ ๊ฒฝ์œ  ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. + +```js +function getCanvasRelativePosition(event) { +- const rect = canvas.getBoundingClientRect(); ++ const rect = inputElement.getBoundingClientRect(); + return { + x: event.clientX - rect.left, + y: event.clientY - rect.top, + }; +} + +function setPickPosition(event) { + const pos = getCanvasRelativePosition(event); +- sendMouse( +- (pos.x / canvas.clientWidth ) * 2 - 1, +- (pos.y / canvas.clientHeight) * -2 + 1); // Y์ถ•์„ ๋’ค์ง‘์—ˆ์Œ ++ pickPosition.x = (pos.x / inputElement.clientWidth ) * 2 - 1; ++ pickPosition.y = (pos.y / inputElement.clientHeight) * -2 + 1; // Y์ถ•์„ ๋’ค์ง‘์—ˆ์Œ +} + +function clearPickPosition() { + /** + * ๋งˆ์šฐ์Šค์˜ ๊ฒฝ์šฐ๋Š” ํ•ญ์ƒ ์œ„์น˜๊ฐ€ ์žˆ์–ด ๊ทธ๋‹ค์ง€ ํฐ + * ์ƒ๊ด€์ด ์—†์ง€๋งŒ, ํ„ฐ์น˜ ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ์†๊ฐ€๋ฝ์„ + * ๋–ผ๋ฉด ํ”ผํ‚น์„ ๋ฉˆ์ถฐ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ง€๊ธˆ์€ ์ผ๋‹จ ์–ด๋–ค ๊ฒƒ๋„ + * ์„ ํƒํ•  ์ˆ˜ ์—†๋Š” ๊ฐ’์œผ๋กœ ์ง€์ •ํ•ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค + **/ +- sendMouse(-100000, -100000); ++ pickPosition.x = -100000; ++ pickPosition.y = -100000; +} + +*inputElement.addEventListener('mousemove', setPickPosition); +*inputElement.addEventListener('mouseout', clearPickPosition); +*inputElement.addEventListener('mouseleave', clearPickPosition); + +*inputElement.addEventListener('touchstart', (event) => { + event.preventDefault(); // ์Šคํฌ๋กค ์ด๋ฒคํŠธ ๋ฐฉ์ง€ + setPickPosition(event.touches[0]); +}, { passive: false }); + +*inputElement.addEventListener('touchmove', (event) => { + setPickPosition(event.touches[0]); +}); + +*inputElement.addEventListener('touchend', clearPickPosition); +``` + +๋ฉ”์ธ ํŽ˜์ด์ง€์—์„œ ์œ„์— ์—ด๊ฑฐํ•œ ๋ชจ๋“  ์ด๋ฒคํŠธ๊ฐ€ ์›Œ์ปค๋กœ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +let nextProxyId = 0; +class ElementProxy { + constructor(element, worker, eventHandlers) { + this.id = nextProxyId++; + this.worker = worker; + const sendEvent = (data) => { + this.worker.postMessage({ + type: 'event', + id: this.id, + data, + }); + }; + + // id๋ฅผ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. + worker.postMessage({ + type: 'makeProxy', + id: this.id, + }); + for (const [eventName, handler] of Object.entries(eventHandlers)) { + element.addEventListener(eventName, function(event) { + handler(event, sendEvent); + }); + } + } +} +``` + +`ElementProxy`๋Š” ์ด๋ฒคํŠธ๋ฅผ ์šฐํšŒํ•  ์š”์†Œ(element)๋ฅผ ์ธ์ž๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ณ ์œ  id๋ฅผ ์ƒ์„ฑํ•ด ์›Œ์ปค์— `makeProxy` ๋ฉ”์‹œ์ง€๋กœ id๋ฅผ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์•„๊นŒ ๋งŒ๋“ค์—ˆ๋“ฏ ์›Œ์ปค๋Š” ์ด id์— ์ƒˆ๋กœ์šด `ElementProxyReceiver`๋ฅผ ์ƒ์„ฑํ•˜๊ฒ ์ฃ . + +๋‹ค์Œ์œผ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•  ํ•ธ๋“ค๋Ÿฌ ๋งต(`eventHandlers`)์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด ํ•ด๋‹น ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ๋งŒ ์›Œ์ปค์— ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์ฃ . + +์›Œ์ปค๋ฅผ ์ƒ์„ฑํ•  ๋•Œ `ElementProxy`์— ์ด ํ•ธ๋“ค๋Ÿฌ ๋งต์„ ๋„˜๊ฒจ ์ƒˆ ์šฐํšŒ ์š”์†Œ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +```js +function startWorker(canvas) { + const offscreen = canvas.transferControlToOffscreen(); + const worker = new Worker('offscreencanvas-worker-orbitcontrols.js'); + ++ const eventHandlers = { ++ contextmenu: preventDefaultHandler, ++ mousedown: mouseEventHandler, ++ mousemove: mouseEventHandler, ++ mouseup: mouseEventHandler, ++ touchstart: touchEventHandler, ++ touchmove: touchEventHandler, ++ touchend: touchEventHandler, ++ wheel: wheelEventHandler, ++ keydown: filteredKeydownEventHandler, ++ }; ++ const proxy = new ElementProxy(canvas, worker, eventHandlers); + worker.postMessage({ + type: 'start', + canvas: offscreen, ++ canvasId: proxy.id, + }, [ offscreen ]); + console.log('using OffscreenCanvas'); /* eslint-disable-line no-console */ +} +``` + +ํ•ธ๋“ค๋Ÿฌ ๋งต์˜ ํ•ธ๋“ค๋Ÿฌ๋Š” ๋„˜๊ฒจ ๋ฐ›์€ ์ด๋ฒคํŠธ์˜ ์†์„ฑ ์ค‘ ๋„˜๊ฒจ ๋ฐ›์€ ํ‚ค ๋ฐฐ์—ด์— ํ•ด๋‹นํ•˜๋Š” ์†์„ฑ๋งŒ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  `ElementProxy`์—์„œ ๋„˜๊ฒจ ๋ฐ›์€ `sendEvent` ํ•จ์ˆ˜๋ฅผ ๋ณต์‚ฌํ•œ ๋ฐ์ดํ„ฐ์™€ ํ•จ๊ป˜ ํ˜ธ์ถœํ•˜์ฃ . ๊ทธ๋Ÿฌ๋ฉด `sendEvent` ํ•จ์ˆ˜๋Š” ํ•ด๋‹นํ•˜๋Š” id์™€ ๋ฐ์ดํ„ฐ๋ฅผ ์›Œ์ปค์— ๋ณด๋ƒ…๋‹ˆ๋‹ค. + +```js +const mouseEventHandler = makeSendPropertiesHandler([ + 'ctrlKey', + 'metaKey', + 'shiftKey', + 'button', + 'clientX', + 'clientY', + 'pageX', + 'pageY', +]); +const wheelEventHandlerImpl = makeSendPropertiesHandler([ + 'deltaX', + 'deltaY', +]); +const keydownEventHandler = makeSendPropertiesHandler([ + 'ctrlKey', + 'metaKey', + 'shiftKey', + 'keyCode', +]); + +function wheelEventHandler(event, sendFn) { + event.preventDefault(); + wheelEventHandlerImpl(event, sendFn); +} + +function preventDefaultHandler(event) { + event.preventDefault(); +} + +function copyProperties(src, properties, dst) { + for (const name of properties) { + dst[name] = src[name]; + } +} + +function makeSendPropertiesHandler(properties) { + return function sendProperties(event, sendFn) { + const data = { type: event.type }; + copyProperties(event, properties, data); + sendFn(data); + }; +} + +function touchEventHandler(event, sendFn) { + const touches = []; + const data = { type: event.type, touches }; + for (let i = 0; i < event.touches.length; ++i) { + const touch = event.touches[i]; + touches.push({ + pageX: touch.pageX, + pageY: touch.pageY, + }); + } + sendFn(data); +} + +// ํ‚ค๋ณด๋“œ์˜ ํ™”์‚ดํ‘œ ํ‚ค +const orbitKeys = { + '37': true, // ์™ผ์ชฝ + '38': true, // ์œ„์ชฝ + '39': true, // ์˜ค๋ฅธ์ชฝ + '40': true, // ์•„๋ž˜์ชฝ +}; +function filteredKeydownEventHandler(event, sendFn) { + const { keyCode } = event; + if (orbitKeys[keyCode]) { + event.preventDefault(); + keydownEventHandler(event, sendFn); + } +} +``` + +๊ฑฐ์˜ ๋‹ค ๋œ ๋“ฏํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์‹ค์ œ๋กœ ์˜ˆ์ œ๋ฅผ ์‹คํ–‰ํ•ด๋ณด๋‹ˆ ์•„์ง ์ฒ˜๋ฆฌํ•ด์ค˜์•ผ ํ•  ๊ฒƒ๋“ค์ด ๋ช‡ ๊ฐœ ๋” ์žˆ๋„ค์š”. + +`OrbitControls`๋Š” `element.focus` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์›Œ์ปค์—์„œ ๊ทธ๋‹ค์ง€ ์“ธ๋ชจ๊ฐ€ ์—†์œผ๋‹ˆ ๋นˆ ํ•จ์ˆ˜๋กœ ๋Œ€์ฒดํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +class ElementProxyReceiver extends THREE.EventDispatcher { + constructor() { + super(); + } + handleEvent(data) { + this.dispatchEvent(data); + } ++ focus() { ++ // ๋นˆ ํ•จ์ˆ˜(no-operation) ++ } +} +``` + +`event.preventDefault`์™€ `event.stopPropagation`๋„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ด๋ฏธ ๋ฉ”์ธ ํŽ˜์ด์ง€์—์„œ ์ฒ˜๋ฆฌํ–ˆ์œผ๋‹ˆ ์ด ์—ญ์‹œ ๋นˆ ํ•จ์ˆ˜๋กœ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค. + +```js ++function noop() { ++} + +class ElementProxyReceiver extends THREE.EventDispatcher { + constructor() { + super(); + } + handleEvent(data) { ++ data.preventDefault = noop; ++ data.stopPropagation = noop; + this.dispatchEvent(data); + } + focus() { + // ๋นˆ ํ•จ์ˆ˜(no-operation) + } +} +``` + +๋˜ `clientWidth`์™€ `clientHeight`๋„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด์ „์—๋Š” ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ๊ฐ’์„ ๋”ฐ๋กœ ๋„˜๊ฒจ์คฌ์—ˆ๋Š”๋ฐ, ๊ฒฝ์œ  ๊ฐ์ฒด๋“ค์ด ์ด ๊ฐ’๋„ ์ฃผ๊ณ ๋ฐ›๋„๋ก ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +์›Œ์ปค์˜ ๊ฒฝ์šฐ ๋‹ค์Œ์ฒ˜๋Ÿผ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +class ElementProxyReceiver extends THREE.EventDispatcher { + constructor() { + super(); + } ++ get clientWidth() { ++ return this.width; ++ } ++ get clientHeight() { ++ return this.height; ++ } ++ getBoundingClientRect() { ++ return { ++ left: this.left, ++ top: this.top, ++ width: this.width, ++ height: this.height, ++ right: this.left + this.width, ++ bottom: this.top + this.height, ++ }; ++ } + handleEvent(data) { ++ if (data.type === 'size') { ++ this.left = data.left; ++ this.top = data.top; ++ this.width = data.width; ++ this.height = data.height; ++ return; ++ } + data.preventDefault = noop; + data.stopPropagation = noop; + this.dispatchEvent(data); + } + focus() { + // ๋นˆ ํ•จ์ˆ˜(no-operation) + } +} +``` + +์ด์ œ ๋ฉ”์ธ ํŽ˜์ด์ง€์—์„œ ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ์™€ ์œ„์น˜ ์ขŒํ‘œ๋ฅผ ๋„˜๊ฒจ์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. ํ•˜๋‚˜ ์–ธ๊ธ‰ํ•˜๊ณ  ์‹ถ์€ ๊ฑด ์˜ˆ์ œ์—์„œ๋Š” ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ๊ฐ€ ๋ฐ”๋€Œ๋Š” ๊ฒฝ์šฐ๋งŒ ๊ฐ€์ •ํ–ˆ์ง€, ์บ”๋ฒ„์Šค๊ฐ€ ์›€์ง์ด๋Š” ๊ฒฝ์šฐ๋Š” ๊ฐ€์ •ํ•˜์ง€ ์•Š์•˜๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. ์บ”๋ฒ„์Šค๊ฐ€ ์›€์ง์ด๋Š” ๊ฒฝ์šฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋ ค๋ฉด ์บ”๋ฒ„์Šค๊ฐ€ ์›€์ง์˜€์„ ๋•Œ `sendSize`๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. + +```js +class ElementProxy { + constructor(element, worker, eventHandlers) { + this.id = nextProxyId++; + this.worker = worker; + const sendEvent = (data) => { + this.worker.postMessage({ + type: 'event', + id: this.id, + data, + }); + }; + + // id๋ฅผ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. + worker.postMessage({ + type: 'makeProxy', + id: this.id, + }); ++ sendSize(); + for (const [eventName, handler] of Object.entries(eventHandlers)) { + element.addEventListener(eventName, function(event) { + handler(event, sendEvent); + }); + } + ++ function sendSize() { ++ const rect = element.getBoundingClientRect(); ++ sendEvent({ ++ type: 'size', ++ left: rect.left, ++ top: rect.top, ++ width: element.clientWidth, ++ height: element.clientHeight, ++ }); ++ } ++ ++ window.addEventListener('resize', sendSize); + } +} +``` + +์ด์ œ ๊ณตํ†ต Three.js ์ฝ”๋“œ์—์„œ `state` ์ „์—ญ ๋ณ€์ˆ˜๋ฅผ ์“ฐ์ง€ ์•Š์œผ๋‹ˆ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค. + +```js +-const state = { +- width: 300, // ์บ”๋ฒ„์Šค ๊ธฐ๋ณธ๊ฐ’ +- height: 150, // ์บ”๋ฒ„์Šค ๊ธฐ๋ณธ๊ฐ’ +-}; + +... + +function resizeRendererToDisplaySize(renderer) { + const canvas = renderer.domElement; +- const width = state.width; +- const height = state.height; ++ const width = inputElement.clientWidth; ++ const height = inputElement.clientHeight; + const needResize = canvas.width !== width || canvas.height !== height; + if (needResize) { + renderer.setSize(width, height, false); + } + return needResize; +} + +function render(time) { + time *= 0.001; + + if (resizeRendererToDisplaySize(renderer)) { +- camera.aspect = state.width / state.height; ++ camera.aspect = inputElement.clientWidth / inputElement.clientHeight; + camera.updateProjectionMatrix(); + } + + ... +``` + +`OrbitControls`๋Š” ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ๋ฅผ ๊ฐ์ง€ํ•˜๊ธฐ ์œ„ํ•ด `window`์— ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ๋ฅผ ๋ฐ”์ธ๋”ฉํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒŒ ์ข‹์€ ๋ฐฉ์‹์ธ์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ, ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์ง์ ‘ ์ˆ˜์ •ํ•˜์ง€ ์•Š๋Š” ํ•œ ์ด ๋™์ž‘์„ ๊ณ ์น  ์ˆ˜๋Š” ์—†์Šต๋‹ˆ๋‹ค. ์›Œ์ปค์—๋Š” `window` ๊ฐ์ฒด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๊ฑฐ๋“ ์š”. + +๋˜ `document`์˜ `mousemove`์™€ `mouseup` ์ด๋ฒคํŠธ๋„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ๋งˆ์šฐ์Šค๊ฐ€ ์ฐฝ ๋ฐ–์œผ๋กœ ๋‚˜๊ฐ„๋‹ค๋“ ๊ฐ€ ํ•˜๋Š” ๊ฒฝ์šฐ์—๋„ ๋งˆ์šฐ์Šค์˜ ์›€์ง์ž„์„ ๊ฐ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ๊ฒƒ์ด์ง€๋งŒ, `window`์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์›Œ์ปค์—๋Š” `document` ๊ฐ์ฒด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. + +๊ฑฐ๊ธฐ๋‹ค `OrbitControls`์— ๋„˜๊ฒจ์ค€ ์š”์†Œ๊ฐ€ `document`์™€ ์ผ์น˜ํ•˜๋Š”์ง€์˜ ์—ฌ๋ถ€๋„ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค. + +์ด ๋ฌธ์ œ๋Š” ๊ฐ„๋‹จํ•œ ํŽธ๋ฒ•(hack)์„ ์จ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ•œ ๋ฒˆ ์›Œ์ปค์˜ ๊ฒฝ์œ  ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•˜๋„๋ก ํ•˜์ฃ . + +```js +function start(data) { + const proxy = proxyManager.getProxy(data.canvasId); ++ self.window = proxy; // HACK! ++ self.document = { // HACK! ++ addEventListener: proxy.addEventListener.bind(proxy), ++ removeEventListener: proxy.removeEventListener.bind(proxy), ++ }; + init({ + canvas: data.canvas, + inputElement: proxy, + }); +} +``` + +์ด๋Ÿฌ๋ฉด `OrbitControls`๊ฐ€ ์—๋Ÿฌ๋ฅผ ๋˜์ง€์ง€ ์•Š์„ ๊ฒ๋‹ˆ๋‹ค. + +์˜ˆ์ œ๊ฐ€ ๋ณต์žกํ•ด ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ค์› ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋™์ž‘์„ ์š”์•ฝํ•˜์ž๋ฉด `ElementProxy`๊ฐ€ ๋ฉ”์ธ ํŽ˜์ด์ง€์˜ DOM ์ด๋ฒคํŠธ๋ฅผ ์›Œ์ปค์˜ `ElementProxyReceiver`์— ๋„˜๊ธฐ๊ณ , `ElementProxyReceiver`๋Š” `HTMLElement`๋ฅผ ๊ฐ€์žฅํ•ด `OrbitControls`์™€ ๊ณตํ†ต ์ฝ”๋“œ์—์„œ ์“ธ ์ˆ˜ ์žˆ๋Š” ๋Œ€์ฒด DOM ์š”์†Œ๋กœ ๊ธฐ๋Šฅํ•ฉ๋‹ˆ๋‹ค. + +๋งˆ์ง€๋ง‰์œผ๋กœ `OffscreenCanvas`๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์˜ ์˜ˆ์™ธ ์ฝ”๋“œ๋งŒ ์ˆ˜์ •ํ•ด์ฃผ๋ฉด ๋์ž…๋‹ˆ๋‹ค. ๊ฐ„๋‹จํžˆ `inputElement`์— ์บ”๋ฒ„์Šค ์š”์†Œ์ž์ฒด๋ฅผ ๋„˜๊ฒจ์ฃผ๊ธฐ๋งŒ ํ•˜๋ฉด ๋˜์ฃ . + +```js +function startMainPage(canvas) { +- init({ canvas }); ++ init({ canvas, inputElement: canvas }); + console.log('using regular canvas'); +} +``` + +์ด์ œ `OffscreenCanvas`์—์„œ๋„ `OrbitControls`๊ฐ€ ์ž˜ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. + +{{{example url="../threejs-offscreencanvas-w-orbitcontrols.html" }}} + +์•„๋งˆ ์ด ์˜ˆ์ œ๊ฐ€ ์ด ์‹œ๋ฆฌ์ฆˆ๋ฅผ ํ†ตํ‹€์–ด ๊ฐ€์žฅ ๋ณต์žกํ•œ ์˜ˆ์ œ์ผ ๊ฒ๋‹ˆ๋‹ค. ๊ฐ ์˜ˆ์ œ๋งˆ๋‹ค HTML ํŒŒ์ผ, ์›Œ์ปค ํŒŒ์ผ, ๊ณตํ†ต Three.js ์ฝ”๋“œ ํŒŒ์ผ, ์ด๋ ‡๊ฒŒ ํŒŒ์ผ 3๊ฐœ๊ฐ€ ์„œ๋กœ ์—ฐ๋™๋˜๋‹ˆ ๊ทธ๋Ÿด๋งŒ ํ•˜์ฃ . + +์ด ๊ธ€์ด ๋„ˆ๋ฌด ์–ด๋ ต๊ฒŒ ๋А๊ปด์ง€์ง€ ์•Š์•˜๋‹ค๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ Three.js์—์„œ OffscreenCanvas์™€ ์›น ์›Œ์ปค๋ฅผ ํ™œ์šฉํ•˜๋Š” ์ข‹์€ ์˜ˆ๊ฐ€ ๋˜์—ˆ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.
false
Other
mrdoob
three.js
633dbb61bdfd242077b4c012fce7468c1e707c1a.json
add translation kr/threejs-rendering-on-demand.md add translation kr/threejs-transparency.md update translation kr/threejs-prerequisites.md add translation kr/threejs-multiple-scenes.md add translation kr/threejs-picking.md fix typo & add translation kr/threejs-post-processing.md add translation kr/threejs-post-processing-3dlut.md
threejs/lessons/kr/threejs-multiple-scenes.md
@@ -0,0 +1,696 @@ +Title: Three.js๋กœ ์บ”๋ฒ„์Šค, ์žฅ๋ฉด ์—ฌ๋Ÿฌ ๊ฐœ ๋งŒ๋“ค๊ธฐ +Description: THREE.js๋กœ ๋‹ค์ˆ˜์˜ ์žฅ๋ฉด์„ ๋ Œ๋”๋งํ•ด๋ด…๋‹ˆ๋‹ค +TOC: ๋‹ค์ค‘ ์บ”๋ฒ„์Šค, ๋‹ค์ค‘ ์žฅ๋ฉด ๋งŒ๋“ค๊ธฐ + +์‚ฌ๋žŒ๋“ค์ด ์ž์ฃผ ํ•˜๋Š” ์งˆ๋ฌธ ์ค‘ ํ•˜๋‚˜๋Š” Three.js๋กœ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์บ”๋ฒ„์Šค(canvas)๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๋ฉด +์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋‚˜์š”?"์ž…๋‹ˆ๋‹ค. ์‡ผํ•‘๋ชฐ ์‚ฌ์ดํŠธ๋‚˜ 3D ๋„ํ‘œ๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐœ ์žˆ๋Š” ์›น ํŽ˜์ด์ง€๋ฅผ +์ œ์ž‘ํ•œ๋‹ค๊ณ  ํ•ด๋ด…์‹œ๋‹ค. ์–ผํ• ๊ทธ๋ฆฌ ์–ด๋ ค์šธ ๊ฑด ์—†์–ด ๋ณด์ž…๋‹ˆ๋‹ค. ๊ทธ๋ƒฅ ๋„ํ‘œ๊ฐ€ ๋“ค์–ด๊ฐˆ ๊ณณ๋งˆ๋‹ค +๊ฐ๊ฐ ์บ”๋ฒ„์Šค๋ฅผ ๋งŒ๋“ค๊ณ , ๊ฐ ์บ”๋ฒ„์Šค๋งˆ๋‹ค `Renderer`๋ฅผ ์ƒ์„ฑํ•˜๋ฉด ๋˜์ง€ ์•Š์„๊นŒ์š”? + +ํ•˜์ง€๋งŒ ์ด ๋ฐฉ๋ฒ•์„ ์ ์šฉํ•˜์ž๋งˆ์ž ๋ฌธ์ œ๊ฐ€ ์ƒ๊น๋‹ˆ๋‹ค. + +1. ๋ธŒ๋ผ์šฐ์ €์˜ WebGL ์ปจํ…์ŠคํŠธ(context)๋Š” ์ œํ•œ์ ์ด๋‹ค. + + ์ผ๋ฐ˜์ ์œผ๋กœ ์•ฝ 8๊ฐœ๊ฐ€ ์ตœ๋Œ€์ž…๋‹ˆ๋‹ค. 9๋ฒˆ์งธ ์ปจํ…์ŠคํŠธ๋ฅผ ๋งŒ๋“ค๋ฉด ์ œ์ผ ์ฒ˜์Œ์— ๋งŒ๋“ค์—ˆ๋˜ + ์ปจํ…์ŠคํŠธ๊ฐ€ ์‚ฌ๋ผ์ง€์ฃ . + +2. WebGL ์ž์›์€ ์ปจํ…์ŠคํŠธ๋ผ๋ฆฌ ๊ณต์œ ํ•  ์ˆ˜ ์—†๋‹ค. + + 10MB์งœ๋ฆฌ ๋ชจ๋ธ์„ ์บ”๋ฒ„์Šค ๋‘ ๊ฐœ์—์„œ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋ชจ๋ธ์„ ๊ฐ๊ฐ ์ด ๋‘ ๋ฒˆ ๋กœ๋“œํ•ด์•ผ ํ•˜๊ณ , + ์›๋ž˜์˜ ๋‘ ๋ฐฐ์ธ 20MB์˜ ์ž์›์„ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค. ์ปจํ…์ŠคํŠธ๋ผ๋ฆฌ๋Š” ์–ด๋–ค ๊ฒƒ๋„ ๊ณต์œ ํ•  + ์ˆ˜ ์—†์ฃ . ๋˜ํ•œ ์ดˆ๊ธฐํ™”๋„ ๋‘ ๋ฒˆ, ์‰์ด๋” ์ปดํŒŒ์ผ๋„ ๋‘ ๋ฒˆ, ๊ฐ™์€ ๋™์ž‘์€ ๋ชจ๋‘ ๋‘ ๋ฒˆ์”ฉ + ์‹คํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์บ”๋ฒ„์Šค์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋งŽ์•„์งˆ์ˆ˜๋ก ์„ฑ๋Šฅ์— ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ๊ฒ ์ฃ . + +๊ทธ๋ ‡๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ• ๊นŒ์š”? + +๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜๋Š” ์บ”๋ฒ„์Šค ํ•˜๋‚˜๋กœ ํ™”๋ฉด ์ „์ฒด๋ฅผ ์ฑ„์šฐ๊ณ , ๊ฐ "๊ฐ€์ƒ" ์บ”๋ฒ„์Šค๋ฅผ ๋Œ€์‹ ํ•  HTML ์š”์†Œ(element)๋ฅผ +๋‘๋Š” ๊ฒ๋‹ˆ๋‹ค. `Renderer`๋Š” ํ•˜๋‚˜๋งŒ ๋งŒ๋“ค๋˜ ๊ฐ€์ƒ ์บ”๋ฒ„์Šค์— ๊ฐ๊ฐ `Scene`์„ ๋งŒ๋“œ๋Š” ๊ฑฐ์ฃ . ๊ทธ๋ฆฌ๊ณ  +๊ฐ€์ƒ HTML ์š”์†Œ์˜ ์ขŒํ‘œ๋ฅผ ๊ณ„์‚ฐํ•ด ์š”์†Œ๊ฐ€ ํ™”๋ฉด์— ๋ณด์ธ๋‹ค๋ฉด Three.js๊ฐ€ ํ•ด๋‹น ์žฅ๋ฉด(scene)์„ ๊ฐ€์ƒ +์š”์†Œ์˜ ์ขŒํ‘œ์— ๋งž์ถฐ ๋ Œ๋”๋งํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +์ด ๋ฐฉ๋ฒ•์€ ์บ”๋ฒ„์Šค๋ฅผ ํ•˜๋‚˜๋งŒ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ์œ„ 1๋ฒˆ๊ณผ 2๋ฒˆ ๋ฌธ์ œ ๋ชจ๋‘ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ปจํ…์ŠคํŠธ๋ฅผ +ํ•˜๋‚˜๋งŒ ์‚ฌ์šฉํ•˜๋‹ˆ WebGL ์ปจํ…์ŠคํŠธ ์ œํ•œ์„ ๊ฑฑ์ •ํ•  ์ผ๋„ ์—†๊ณ , ์ž์›์„ ๋ช‡ ๋ฐฐ์”ฉ ๋” ์‚ฌ์šฉํ•  ์ผ๋„ ์—†์ฃ . + +2๊ฐœ์˜ ์žฅ๋ฉด๋งŒ ๋งŒ๋“ค์–ด ๊ฐ„๋‹จํžˆ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋จผ์ € HTML์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. + +```html +<canvas id="c"></canvas> +<p> + <span id="box" class="diagram left"></span> + I love boxes. Presents come in boxes. + When I find a new box I'm always excited to find out what's inside. +</p> +<p> + <span id="pyramid" class="diagram right"></span> + When I was a kid I dreamed of going on an expedition inside a pyramid + and finding a undiscovered tomb full of mummies and treasure. +</p> +``` + +๋‹ค์Œ์œผ๋กœ CSS๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. + +```css +#c { + position: fixed; + left: 0; + top: 0; + width: 100vw; + height: 100vh; + display: block; + z-index: -1; +} +.diagram { + display: inline-block; + width: 5em; + height: 3em; + border: 1px solid black; +} +.left { + float: left; + margin-right: .25em; +} +.right { + float: right; + margin-left: .25em; +} +``` + +์บ”๋ฒ„์Šค๊ฐ€ ํ™”๋ฉด ์ „์ฒด๋ฅผ ์ฑ„์šฐ๋„๋ก ํ•˜๊ณ  `z-index`๋ฅผ -1๋กœ ์„ค์ •ํ•ด ๋‹ค๋ฅธ ์š”์†Œ ๋’ค๋กœ ๊ฐ€๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค. +๊ฐ€์ƒ ์š”์†Œ์— ์ปจํ…์ธ ๊ฐ€ ์—†์–ด ํฌ๊ธฐ๊ฐ€ 0์ด๋‹ˆ ๋ณ„๋„์˜ width์™€ height๋„ ์ง€์ •ํ•ด์คฌ์Šต๋‹ˆ๋‹ค. + +์ด์ œ ๊ฐ๊ฐ์˜ ์นด๋ฉ”๋ผ์™€ ์กฐ๋ช…์ด ์žˆ๋Š” ์žฅ๋ฉด 2๊ฐœ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ํ•˜๋‚˜์—๋Š” ์ •์œก๋ฉด์ฒด, ๋‹ค๋ฅธ ํ•˜๋‚˜์—๋Š” +๋‹ค์ด์•„๋ชฌ๋“œ ๋ชจ์–‘์„ ๋„ฃ์„ ๊ฒ๋‹ˆ๋‹ค. + +```js +function makeScene(elem) { + const scene = new THREE.Scene(); + + const fov = 45; + const aspect = 2; // ์บ”๋ฒ„์Šค ๊ธฐ๋ณธ๊ฐ’ + const near = 0.1; + const far = 5; + const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); + camera.position.z = 2; + camera.position.set(0, 1, 2); + camera.lookAt(0, 0, 0); + + { + const color = 0xFFFFFF; + const intensity = 1; + const light = new THREE.DirectionalLight(color, intensity); + light.position.set(-1, 2, 4); + scene.add(light); + } + + return { scene, camera, elem }; +} + +function setupScene1() { + const sceneInfo = makeScene(document.querySelector('#box')); + const geometry = new THREE.BoxBufferGeometry(1, 1, 1); + const material = new THREE.MeshPhongMaterial({color: 'red'}); + const mesh = new THREE.Mesh(geometry, material); + sceneInfo.scene.add(mesh); + sceneInfo.mesh = mesh; + return sceneInfo; +} + +function setupScene2() { + const sceneInfo = makeScene(document.querySelector('#pyramid')); + const radius = .8; + const widthSegments = 4; + const heightSegments = 2; + const geometry = new THREE.SphereBufferGeometry(radius, widthSegments, heightSegments); + const material = new THREE.MeshPhongMaterial({ + color: 'blue', + flatShading: true, + }); + const mesh = new THREE.Mesh(geometry, material); + sceneInfo.scene.add(mesh); + sceneInfo.mesh = mesh; + return sceneInfo; +} + +const sceneInfo1 = setupScene1(); +const sceneInfo2 = setupScene2(); +``` + +์ด์ œ ๊ฐ ์š”์†Œ๊ฐ€ ํ™”๋ฉด์— ๋ณด์ผ ๋•Œ๋งŒ ์žฅ๋ฉด์„ ๋ Œ๋”๋งํ•  ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. `Renderer.setScissorTest`๋ฅผ +ํ˜ธ์ถœํ•ด *๊ฐ€์œ„(scissor)* ํ…Œ์ŠคํŠธ๋ฅผ ํ™œ์„ฑํ™”ํ•˜๋ฉด Three.js๊ฐ€ ์บ”๋ฒ„์Šค์˜ ํŠน์ • ๋ถ€๋ถ„๋งŒ ๋ Œ๋”๋งํ•˜๋„๋ก +ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  `Renderer.setScissor`๋กœ ๊ฐ€์œ„๋ฅผ ์„ค์ •ํ•œ ๋’ค `Renderer.setViewport`๋กœ +์žฅ๋ฉด์˜ ์ขŒํ‘œ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. + +```js +function renderSceneInfo(sceneInfo) { + const { scene, camera, elem } = sceneInfo; + + // ํ•ด๋‹น ์š”์†Œ์˜ ํ™”๋ฉด ๋Œ€๋น„ ์ขŒํ‘œ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค + const { left, right, top, bottom, width, height } = + elem.getBoundingClientRect(); + + const isOffscreen = + bottom < 0 || + top > renderer.domElement.clientHeight || + right < 0 || + left > renderer.domElement.clientWidth; + + if (isOffscreen) { + return; + } + + camera.aspect = width / height; + camera.updateProjectionMatrix(); + + const positiveYUpBottom = canvasRect.height - bottom; + renderer.setScissor(left, positiveYUpBottom, width, height); + renderer.setViewport(left, positiveYUpBottom, width, height); + + renderer.render(scene, camera); +} +``` + +๋‹ค์Œ์œผ๋กœ `render` ํ•จ์ˆ˜ ์•ˆ์—์„œ ๋จผ์ € ์บ”๋ฒ„์Šค ์ „์ฒด๋ฅผ ๋น„์šด ๋’ค ๊ฐ ์žฅ๋ฉด์„ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. + +```js +function render(time) { + time *= 0.001; + + resizeRendererToDisplaySize(renderer); + + renderer.setScissorTest(false); + renderer.clear(true, true); + renderer.setScissorTest(true); + + sceneInfo1.mesh.rotation.y = time * .1; + sceneInfo2.mesh.rotation.y = time * .1; + + renderSceneInfo(sceneInfo1); + renderSceneInfo(sceneInfo2); + + requestAnimationFrame(render); +} +``` + +๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ด๋ณผ๊นŒ์š”? + +{{{example url="../threejs-multiple-scenes-v1.html" }}} + +์ฒซ ๋ฒˆ์งธ `<span>` ์š”์†Œ๊ฐ€ ์žˆ๋Š” ๊ณณ์—๋Š” ๋นจ๊ฐ„ ์ •์œก๋ฉด์ฒด๊ฐ€, ๋‘ ๋ฒˆ์งธ `<span>` ์š”์†Œ๊ฐ€ ์žˆ๋Š” ๊ณณ์—๋Š” +ํŒŒ๋ž€ ๋‹ค์ด์•„๋ชฌ๋“œ๊ฐ€ ๋ณด์ผ ๊ฒ๋‹ˆ๋‹ค. + +## ๋™๊ธฐํ™”ํ•˜๊ธฐ + +์œ„ ์ฝ”๋“œ๋Š” ๋‚˜์˜์ง€ ์•Š์ง€๋งŒ ์ž‘์€ ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณต์žกํ•œ ์žฅ๋ฉด ๋“ฑ ๋ฌด์Šจ ์ด์œ ๋ผ๋„ ๋ Œ๋”๋งํ•˜๋Š” +๋ฐ ์‹œ๊ฐ„์ด ์˜ค๋ž˜ ๊ฑธ๋ฆฐ๋‹ค๋ฉด, ์žฅ๋ฉด์˜ ์ขŒํ‘œ๋Š” ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์ปจํ…์ธ ์— ๋น„ํ•ด ๋”๋””๊ฒŒ ๋‚ด๋ ค์˜ฌ ๊ฒ๋‹ˆ๋‹ค. + +๊ฐ ๊ฐ€์ƒ ์š”์†Œ์— ํ…Œ๋‘๋ฆฌ๋ฅผ ๋„ฃ๊ณ  + +```css +.diagram { + display: inline-block; + width: 5em; + height: 3em; ++ border: 1px solid black; +} +``` + +๊ฐ ์žฅ๋ฉด์— ๋ฐฐ๊ฒฝ์ƒ‰๋„ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. + +```js +const scene = new THREE.Scene(); ++scene.background = new THREE.Color('red'); +``` + +๊ทธ๋Ÿฐ ๋‹ค์Œ <a href="../threejs-multiple-scenes-v2.html" target="_blank">๋น ๋ฅด๊ฒŒ ์Šคํฌ๋กค์„ ์œ„์•„๋ž˜๋กœ ๋ฐ˜๋ณตํ•ด๋ณด๋ฉด</a> +๋ฌธ์ œ๊ฐ€ ๋ณด์ผ๊ฒ๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ์Šคํฌ๋กค ์• ๋‹ˆ๋ฉ”์ด์…˜ ์บก์ณ๋ณธ์˜ ์†๋„๋ฅผ 10๋ฐฐ ๋‚ฎ์ถ˜ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค. + +<div class="threejs_center"><img class="border" src="resources/images/multi-view-skew.gif"></div> + +์ถ”๊ฐ€๋กœ ์ฒ˜๋ฆฌํ•ด์ค˜์•ผ ํ•  ๊ฒƒ์ด ์žˆ๊ธด ํ•˜์ง€๋งŒ, ์บ”๋ฒ„์Šค์˜ CSS๋ฅผ `position: fixed`์—์„œ `position: absolute`๋กœ +๋ฐ”๊ฟ” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```css +#c { +- position: fixed; ++ position: absolute; +``` + +๊ทธ๋ฆฌ๊ณ  ํŽ˜์ด์ง€ ์Šคํฌ๋กค์— ์ƒ๊ด€ ์—†์ด ์บ”๋ฒ„์Šค๊ฐ€ ํ•ญ์ƒ ํ™”๋ฉด์˜ ์ƒ๋‹จ์— ์œ„์น˜ํ•  ์ˆ˜ ์žˆ๋„๋ก ์บ”๋ฒ„์Šค์— +transform ์Šคํƒ€์ผ์„ ์ง€์ •ํ•ด์ค๋‹ˆ๋‹ค. + +```js +function render(time) { + ... + + const transform = `translateY(${ window.scrollY }px)`; + renderer.domElement.style.transform = transform; + +``` + +์บ”๋ฒ„์Šค์— `position: fixed`๋ฅผ ์ ์šฉํ•˜๋ฉด ์บ”๋ฒ„์Šค๋Š” ์Šคํฌ๋กค์˜ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š์Šต๋‹ˆ๋‹ค. `position: absolute`๋ฅผ +์ ์šฉํ•˜๋ฉด ๋ Œ๋”๋งํ•˜๋Š” ๋ฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๋”๋ผ๋„ ์ผ๋‹จ ๋‹ค๋ฅธ ํŽ˜์ด์ง€์™€ ๊ฐ™์ด ์Šคํฌ๋กค์ด ๋˜๊ฒ ์ฃ . ๊ทธ๋ฆฌ๊ณ  +๋ Œ๋”๋งํ•˜๊ธฐ ์ „์— ์บ”๋ฒ„์Šค๋ฅผ ๋‹ค์‹œ ์›€์ง์—ฌ ํ™”๋ฉด ์ „์ฒด์— ๋งž์ถ˜ ๋’ค ์บ”๋ฒ„์Šค๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ๊ฒ๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด +ํ™”๋ฉด์˜ ๊ฐ€์žฅ์ž๋ฆฌ์— ์‚ด์ง ๋ Œ๋”๋ง๋˜์ง€ ์•Š์€ ๋ถ€๋ถ„์ด ๋ณด์ผ ์ˆ˜๋Š” ์žˆ์–ด๋„ ๋‚˜๋จธ์ง€ ํŽ˜์ด์ง€์— ์žˆ๋Š” ์š”์†Œ๋Š” +๋ฒ„๋ฒ…์ด์ง€ ์•Š๊ณ  ์ œ์ž๋ฆฌ์— ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ์ ์šฉํ•œ ํ™”๋ฉด์˜ ์บก์ณ๋ณธ์„ ์•„๊นŒ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ +10๋ฐฐ ๋А๋ฆฌ๊ฒŒ ๋งŒ๋“  ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +<div class="threejs_center"><img class="border" src="resources/images/multi-view-fixed.gif"></div> + +## ํ™•์žฅํ•˜๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ธฐ + +์—ฌ๋Ÿฌ ์žฅ๋ฉด์„ ๊ตฌํ˜„ํ–ˆ์œผ๋‹ˆ ์ด์ œ ์ด ์˜ˆ์ œ๋ฅผ ์ข€ ๋” ํ™•์žฅํ•˜๊ธฐ ์‰ฝ๊ฒŒ ๋งŒ๋“ค์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +๋จผ์ € ๊ธฐ์กด์ฒ˜๋Ÿผ ์บ”๋ฒ„์Šค ์ „์ฒด๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” `render` ํ•จ์ˆ˜๋ฅผ ๋‘๊ณ , ๊ฐ ์žฅ๋ฉด์— ํ•ด๋‹นํ•˜๋Š” ๊ฐ€์ƒ ์š”์†Œ, +ํ•ด๋‹น ์žฅ๋ฉด์„ ๋ Œ๋”๋งํ•˜๋Š” ํ•จ์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ ๊ฐ์ฒด์˜ ๋ฐฐ์—ด์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. `render` ํ•จ์ˆ˜์—์„œ ๊ฐ€์ƒ ์š”์†Œ๊ฐ€ +ํ™”๋ฉด์— ๋ณด์ด๋Š”์ง€ ํ™•์ธํ•œ ๋’ค, ๊ฐ€์ƒ ์š”์†Œ๊ฐ€ ํ™”๋ฉด์— ๋ณด์ธ๋‹ค๋ฉด ์ƒ์‘ํ•˜๋Š” ๋ Œ๋”๋ง ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด +ํ™•์žฅ์„ฑ์€ ๋ฌผ๋ก  ๊ฐ ์žฅ๋ฉด์˜ ๋ Œ๋”๋ง ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•  ๋•Œ๋„ ์ „์ฒด๋ฅผ ์‹ ๊ฒฝ์“ธ ํ•„์š”๊ฐ€ ์—†์ฃ . + +์•„๋ž˜๋Š” ์ „์ฒด๋ฅผ ๋‹ด๋‹นํ•˜๋Š” `render` ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. + +```js +const sceneElements = []; +function addScene(elem, fn) { + sceneElements.push({ elem, fn }); +} + +function render(time) { + time *= 0.001; + + resizeRendererToDisplaySize(renderer); + + renderer.setScissorTest(false); + renderer.setClearColor(clearColor, 0); + renderer.clear(true, true); + renderer.setScissorTest(true); + + const transform = `translateY(${ window.scrollY }px)`; + renderer.domElement.style.transform = transform; + + for (const { elem, fn } of sceneElements) { + // ํ•ด๋‹น ์š”์†Œ์˜ ํ™”๋ฉด ๋Œ€๋น„ ์ขŒํ‘œ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค + const rect = elem.getBoundingClientRect(); + const {left, right, top, bottom, width, height} = rect; + + const isOffscreen = + bottom < 0 || + top > renderer.domElement.clientHeight || + right < 0 || + left > renderer.domElement.clientWidth; + + if (!isOffscreen) { + const positiveYUpBottom = renderer.domElement.clientHeight - bottom; + renderer.setScissor(left, positiveYUpBottom, width, height); + renderer.setViewport(left, positiveYUpBottom, width, height); + + fn(time, rect); + } + } + + requestAnimationFrame(render); +} +``` + +`render` ํ•จ์ˆ˜๋Š” `elem`๊ณผ `fn` ์†์„ฑ์˜ ๊ฐ์ฒด๋กœ ์ด๋ฃจ์–ด์ง„ `sceneElements` ๋ฐฐ์—ด์„ ์ˆœํšŒํ•ฉ๋‹ˆ๋‹ค. + +๊ทธ๋ฆฌ๊ณ  ๊ฐ ์š”์†Œ๊ฐ€ ํ™”๋ฉด์— ๋ณด์ด๋Š”์ง€ ํ™•์ธํ•˜๊ณ , ํ™”๋ฉด์— ๋ณด์ธ๋‹ค๋ฉด `fn`์— ํ•ด๋‹น ์žฅ๋ฉด์ด ๋“ค์–ด๊ฐ€์•ผํ•  +์‚ฌ๊ฐ ์ขŒํ‘œ์™€ ํ˜„์žฌ ์‹œ๊ฐ„๊ฐ’์„ ๋„˜๊ฒจ์ฃผ์–ด ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. + +์ด์ œ ๊ฐ ์žฅ๋ฉด์„ ๋งŒ๋“ค๊ณ  ์ƒ์‘ํ•˜๋Š” ์š”์†Œ์™€ ๋ Œ๋”๋ง ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +{ + const elem = document.querySelector('#box'); + const { scene, camera } = makeScene(); + const geometry = new THREE.BoxBufferGeometry(1, 1, 1); + const material = new THREE.MeshPhongMaterial({ color: 'red' }); + const mesh = new THREE.Mesh(geometry, material); + scene.add(mesh); + addScene(elem, (time, rect) => { + camera.aspect = rect.width / rect.height; + camera.updateProjectionMatrix(); + mesh.rotation.y = time * .1; + renderer.render(scene, camera); + }); +} + +{ + const elem = document.querySelector('#pyramid'); + const { scene, camera } = makeScene(); + const radius = .8; + const widthSegments = 4; + const heightSegments = 2; + const geometry = new THREE.SphereBufferGeometry(radius, widthSegments, heightSegments); + const material = new THREE.MeshPhongMaterial({ + color: 'blue', + flatShading: true, + }); + const mesh = new THREE.Mesh(geometry, material); + scene.add(mesh); + addScene(elem, (time, rect) => { + camera.aspect = rect.width / rect.height; + camera.updateProjectionMatrix(); + mesh.rotation.y = time * .1; + renderer.render(scene, camera); + }); +} +``` + +`sceneInfo1`, `sceneInfo2`๋Š” ๋” ์ด์ƒ ํ•„์š” ์—†์œผ๋‹ˆ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. ๋Œ€์‹  ๊ฐ mesh์˜ ํšŒ์ „์€ ํ•ด๋‹น +์žฅ๋ฉด์—์„œ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +{{{example url="../threejs-multiple-scenes-generic.html" }}} + +## HTML Dataset ์‚ฌ์šฉํ•˜๊ธฐ + +HTML์˜ [dataset](https://developer.mozilla.org/ko/docs/Web/API/HTMLElement/dataset)์„ +์ด์šฉํ•˜๋ฉด ์ข€ ๋” ํ™•์žฅํ•˜๊ธฐ ์‰ฌ์šด ํ™˜๊ฒฝ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. `id="..."` ๋Œ€์‹  `data-diagram="..."`์„ +์ด์šฉํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์ง์ ‘ HTML ์š”์†Œ์— ์ง€์ •ํ•˜๋Š” ๊ฑฐ์ฃ . + +```html +<canvas id="c"></canvas> +<p> +- <span id="box" class="diagram left"></span> ++ <span data-diagram="box" class="left"></span> + I love boxes. Presents come in boxes. + When I find a new box I'm always excited to find out what's inside. +</p> +<p> +- <span id="pyramid" class="diagram left"></span> ++ <span data-diagram="pyramid" class="right"></span> + When I was a kid I dreamed of going on an expedition inside a pyramid + and finding a undiscovered tomb full of mummies and treasure. +</p> +``` + +์š”์†Œ์˜ id๋ฅผ ์ œ๊ฑฐํ–ˆ์œผ๋‹ˆ CSS ์…€๋ ‰ํ„ฐ๋„ ๋‹ค์Œ์ฒ˜๋Ÿผ ๋ฐ”๊พธ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +```css +-.diagram ++*[data-diagram] { + display: inline-block; + width: 5em; + height: 3em; +} +``` + +๋˜ํ•œ ๊ฐ ์žฅ๋ฉด์„ ๋งŒ๋“œ๋Š” ์ฝ”๋“œ๋ฅผ *scene initialization functions*๋ผ๋Š” ๋งต์œผ๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค. +์ด ๋งต์€ ํ‚ค๊ฐ’์— ๋Œ€์‘ํ•˜๋Š” *์žฅ๋ฉด ๋ Œ๋”๋ง ํ•จ์ˆ˜*๋ฅผ ๋ฐ˜ํ™˜ํ•  ๊ฒ๋‹ˆ๋‹ค. + +```js +const sceneInitFunctionsByName = { + 'box': () => { + const { scene, camera } = makeScene(); + const geometry = new THREE.BoxBufferGeometry(1, 1, 1); + const material = new THREE.MeshPhongMaterial({color: 'red'}); + const mesh = new THREE.Mesh(geometry, material); + scene.add(mesh); + return (time, rect) => { + mesh.rotation.y = time * .1; + camera.aspect = rect.width / rect.height; + camera.updateProjectionMatrix(); + renderer.render(scene, camera); + }; + }, + 'pyramid': () => { + const { scene, camera } = makeScene(); + const radius = .8; + const widthSegments = 4; + const heightSegments = 2; + const geometry = new THREE.SphereBufferGeometry(radius, widthSegments, heightSegments); + const material = new THREE.MeshPhongMaterial({ + color: 'blue', + flatShading: true, + }); + const mesh = new THREE.Mesh(geometry, material); + scene.add(mesh); + return (time, rect) => { + mesh.rotation.y = time * .1; + camera.aspect = rect.width / rect.height; + camera.updateProjectionMatrix(); + renderer.render(scene, camera); + }; + }, +}; +``` + +๊ทธ๋ฆฌ๊ณ  `querySelectorAll`๋กœ ๊ฐ€์ƒ ์š”์†Œ๋ฅผ ์ „๋ถ€ ๋ถˆ๋Ÿฌ์™€ ํ•ด๋‹น ์š”์†Œ์— ์ƒ์‘ํ•˜๋Š” ๋ Œ๋”๋ง ํ•จ์ˆ˜๋ฅผ +์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. + +```js +document.querySelectorAll('[data-diagram]').forEach((elem) => { + const sceneName = elem.dataset.diagram; + const sceneInitFunction = sceneInitFunctionsByName[sceneName]; + const sceneRenderFunction = sceneInitFunction(elem); + addScene(elem, sceneRenderFunction); +}); +``` + +์ด์ œ ์ฝ”๋“œ๋ฅผ ํ™•์žฅํ•˜๊ธฐ๊ฐ€ ํ•œ๊ฒฐ ํŽธํ•ด์กŒ์Šต๋‹ˆ๋‹ค. + +{{{examples url="../threejs-multiple-scenes-selector.html" }}} + +## ๊ฐ ์š”์†Œ์— ์•ก์…˜ ์ถ”๊ฐ€ํ•˜๊ธฐ + +์‚ฌ์šฉ์ž ์•ก์…˜, ์˜ˆ๋ฅผ ๋“ค์–ด `TrackballControls`๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฑด ์•„์ฃผ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. ๋จผ์ € ์Šคํฌ๋ฆฝํŠธ๋ฅผ +๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค. + +```js +import { TrackballControls } from './resources/threejs/r115/examples/jsm/controls/TrackballControls.js'; +``` + +๊ทธ๋ฆฌ๊ณ  ๊ฐ ์žฅ๋ฉด์— ๋Œ€์‘ํ•˜๋Š” ์š”์†Œ์— `TrackballControls`๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +-function makeScene() { ++function makeScene(elem) { + const scene = new THREE.Scene(); + + const fov = 45; + const aspect = 2; // ์บ”๋ฒ„์Šค ๊ธฐ๋ณธ๊ฐ’ + const near = 0.1; + const far = 5; + const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); + camera.position.set(0, 1, 2); + camera.lookAt(0, 0, 0); ++ scene.add(camera); + ++ const controls = new TrackballControls(camera, elem); ++ controls.noZoom = true; ++ controls.noPan = true; + + { + const color = 0xFFFFFF; + const intensity = 1; + const light = new THREE.DirectionalLight(color, intensity); + light.position.set(-1, 2, 4); +- scene.add(light); ++ camera.add(light); + } + +- return { scene, camera }; ++ return { scene, camera, controls }; +} +``` + +์œ„ ์ฝ”๋“œ์—์„œ๋Š” ์นด๋ฉ”๋ผ๋ฅผ ์žฅ๋ฉด์— ์ถ”๊ฐ€ํ•˜๊ณ , ์นด๋ฉ”๋ผ์— ์กฐ๋ช…์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด ์กฐ๋ช…์ด ์นด๋ฉ”๋ผ๋ฅผ +๋”ฐ๋ผ๋‹ค๋‹ˆ๊ฒ ์ฃ . `TrackballControls`๋Š” ์นด๋ฉ”๋ผ๋ฅผ ์กฐ์ •ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ ‡๊ฒŒ ํ•ด์•ผ ๋น›์ด ๊ณ„์† ์šฐ๋ฆฌ๊ฐ€ +๋ฐ”๋ผ๋ณด๋Š” ๋ฐฉํ–ฅ์—์„œ ๋‚˜๊ฐ‘๋‹ˆ๋‹ค. + +๋˜ํ•œ ์ปจํŠธ๋กค์„ ๋ Œ๋”๋ง ํ•จ์ˆ˜์—์„œ ์—…๋ฐ์ดํŠธํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +```js +const sceneInitFunctionsByName = { +- 'box': () => { +- const {scene, camera} = makeScene(); ++ 'box': (elem) => { ++ const { scene, camera, controls } = makeScene(elem); + const geometry = new THREE.BoxBufferGeometry(1, 1, 1); + const material = new THREE.MeshPhongMaterial({color: 'red'}); + const mesh = new THREE.Mesh(geometry, material); + scene.add(mesh); + return (time, rect) => { + mesh.rotation.y = time * .1; + camera.aspect = rect.width / rect.height; + camera.updateProjectionMatrix(); ++ controls.handleResize(); ++ controls.update(); + renderer.render(scene, camera); + }; + }, +- 'pyramid': () => { +- const { scene, camera } = makeScene(); ++ 'pyramid': (elem) => { ++ const { scene, camera, controls } = makeScene(elem); + const radius = .8; + const widthSegments = 4; + const heightSegments = 2; + const geometry = new THREE.SphereBufferGeometry(radius, widthSegments, heightSegments); + const material = new THREE.MeshPhongMaterial({ + color: 'blue', + flatShading: true, + }); + const mesh = new THREE.Mesh(geometry, material); + scene.add(mesh); + return (time, rect) => { + mesh.rotation.y = time * .1; + camera.aspect = rect.width / rect.height; + camera.updateProjectionMatrix(); ++ controls.handleResize(); ++ controls.update(); + renderer.render(scene, camera); + }; + }, +}; +``` + +์ด์ œ ๊ฐ ๋ฌผ์ฒด๋ฅผ ์ž์œ ๋กญ๊ฒŒ ํšŒ์ „์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-multiple-scenes-controls.html" }}} + +์ด ๊ธฐ๋ฒ•์€ ์ด ์‚ฌ์ดํŠธ ์ „์ฒด์— ์‚ฌ์šฉํ•œ ๊ธฐ๋ฒ•์ž…๋‹ˆ๋‹ค. [์›์‹œ ๋ชจ๋ธ์— ๊ด€ํ•œ ๊ธ€](threejs-primitives.html)๊ณผ +[์žฌ์งˆ์— ๊ด€ํ•œ ๊ธ€](threejs-materials.html)์—์„œ ๋‹ค์–‘ํ•œ ์˜ˆ์‹œ๋ฅผ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ–ˆ์ฃ . + +๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ๋Š” ํ™”๋ฉด ๋ฐ–์˜ ์บ”๋ฒ„์Šค์—์„œ ์žฅ๋ฉด์„ ๋ Œ๋”๋งํ•ด ๊ฐ ์š”์†Œ์— 2D ์บ”๋ฒ„์Šค ํ˜•ํƒœ๋กœ ๋„˜๊ฒจ์ฃผ๋Š” +๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ฐฉ๋ฒ•์˜ ์žฅ์ ์€ ๊ฐ ์˜์—ญ์„ ์–ด๋–ป๊ฒŒ ๋ถ„๋ฆฌํ• ์ง€ ๊ณ ๋ฏผํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค๋Š” ๊ฒƒ์ด์ฃ . +์œ„์—์„œ ์‚ดํŽด๋ณธ ๋ฐฉ๋ฒ•์€ ์บ”๋ฒ„์Šค๋ฅผ ํ™”๋ฉด ์ „์ฒด์˜ ๋ฐฐ๊ฒฝ์œผ๋กœ ์จ์•ผ ํ•˜์ง€๋งŒ, ์ด ๋ฐฉ๋ฒ•์€ ์ผ๋ฐ˜ HTML ํ˜•ํƒœ๋กœ +์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +ํ•˜์ง€๋งŒ ์ด ๋ฐฉ๋ฒ•์€ ๊ฐ ์˜์—ญ์„ ๋ณต์‚ฌํ•˜๋Š” ๊ฒƒ์ด๊ธฐ์— ์„ฑ๋Šฅ์ด ๋” ๋А๋ฆฝ๋‹ˆ๋‹ค. ์–ผ๋งˆ๋‚˜ ๋А๋ฆด์ง€๋Š” ๋ธŒ๋ผ์šฐ์ €์™€ +GPU ์„ฑ๋Šฅ์— ๋”ฐ๋ผ ๋‹ค๋ฅด์ฃ . + +๋ฐ”๊ฟ”์•ผ ํ•˜๋Š” ๊ฑด ์ƒ๊ฐ๋ณด๋‹ค ๋งŽ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +๋จผ์ € ๋ฐฐ๊ฒฝ์—์„œ ์บ”๋ฒ„์Šค ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. + +```html +<body> +- <canvas id="c"></canvas> + ... +</body> +``` + +CSS๋„ ๋ฐ”๊ฟ”์ค๋‹ˆ๋‹ค. + +```css +-#c { +- position: absolute; +- left: 0; +- top: 0; +- width: 100vw; +- height: 100vh; +- display: block; +- z-index: -1; +-} +canvas { + width: 100%; + height: 100%; + display: block; +} +*[data-diagram] { + display: inline-block; + width: 5em; + height: 3em; +} +``` + +์บ”๋ฒ„์Šค ์š”์†Œ๊ฐ€ ๋ถ€๋ชจ์— ๊ฝ‰ ์ฐจ๋„๋ก ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค. + +์ด์ œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋ณ€๊ฒฝํ•ด๋ด…์‹œ๋‹ค. ๋จผ์ € ์บ”๋ฒ„์Šค๋ฅผ ์ฐธ์กฐํ•  ํ•„์š”๊ฐ€ ์—†์œผ๋‹ˆ ๋Œ€์‹  ์บ”๋ฒ„์Šค ์š”์†Œ๋ฅผ +์ƒˆ๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋˜ํ•œ ๊ฐ€์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์ฒ˜์Œ์— ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค. + +```js +function main() { +- const canvas = document.querySelector('#c'); ++ const canvas = document.createElement('canvas'); + const renderer = new THREE.WebGLRenderer({canvas, alpha: true}); ++ renderer.setScissorTest(true); + + ... +``` + +๋‹ค์Œ์œผ๋กœ ๊ฐ ์žฅ๋ฉด์— 2D ๋ Œ๋”๋ง ์ปจํ…์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žฅ๋ฉด์— ๋Œ€์‘ํ•˜๋Š” ์š”์†Œ์— ์บ”๋ฒ„์Šค๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +const sceneElements = []; +function addScene(elem, fn) { ++ const ctx = document.createElement('canvas').getContext('2d'); ++ elem.appendChild(ctx.canvas); +- sceneElements.push({ elem, fn }); ++ sceneElements.push({ elem, ctx, fn }); +} +``` + +๋งŒ์•ฝ ๋ Œ๋”๋ง ์‹œ ๋ Œ๋”๋ง์šฉ ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ๊ฐ€ ์žฅ๋ฉด์˜ ํฌ๊ธฐ๋ณด๋‹ค ์ž‘์„ ๊ฒฝ์šฐ, ๋ Œ๋”๋ง์šฉ ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ๋ฅผ +ํ‚ค์›๋‹ˆ๋‹ค. ๋˜ํ•œ 2D ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ๊ฐ€ ๋ถ€๋ชจ ์š”์†Œ์™€ ๋‹ค๋ฅด๋‹ค๋ฉด 2D ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค. ๋งˆ์ง€๋ง‰์œผ๋กœ +๊ฐ€์œ„์™€ ํ™”๋ฉด์„ ์„ค์ •ํ•˜๊ณ , ํ•ด๋‹น ์žฅ๋ฉด์„ ๋ Œ๋”๋งํ•œ ๋’ค, ์š”์†Œ์˜ ์บ”๋ฒ„์Šค๋กœ ๋ Œ๋”๋ง ๊ฒฐ๊ณผ๋ฌผ์„ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค. + +```js +function render(time) { + time *= 0.001; + +- resizeRendererToDisplaySize(renderer); +- +- renderer.setScissorTest(false); +- renderer.setClearColor(clearColor, 0); +- renderer.clear(true, true); +- renderer.setScissorTest(true); +- +- const transform = `translateY(${ window.scrollY }px)`; +- renderer.domElement.style.transform = transform; + +- for (const { elem, fn } of sceneElements) { ++ for (const { elem, fn, ctx } of sceneElements) { + // ํ•ด๋‹น ์š”์†Œ์˜ ํ™”๋ฉด ๋Œ€๋น„ ์ขŒํ‘œ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค + const rect = elem.getBoundingClientRect(); + const { left, right, top, bottom, width, height } = rect; ++ const rendererCanvas = renderer.domElement; + + const isOffscreen = + bottom < 0 || +- top > renderer.domElement.clientHeight || ++ top > window.innerHeight || + right < 0 || +- left > renderer.domElement.clientWidth; ++ left > window.innerWidth; + + if (!isOffscreen) { +- const positiveYUpBottom = renderer.domElement.clientHeight - bottom; +- renderer.setScissor(left, positiveYUpBottom, width, height); +- renderer.setViewport(left, positiveYUpBottom, width, height); + ++ // ๋ Œ๋”๋ง์šฉ ์บ”๋ฒ„์Šค ํฌ๊ธฐ ์กฐ์ • ++ if (rendererCanvas.width < width || rendererCanvas.height < height) { ++ renderer.setSize(width, height, false); ++ } ++ ++ // 2D ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ๊ฐ€ ์š”์†Œ์˜ ํฌ๊ธฐ์™€ ๊ฐ™๋„๋ก ์กฐ์ • ++ if (ctx.canvas.width !== width || ctx.canvas.height !== height) { ++ ctx.canvas.width = width; ++ ctx.canvas.height = height; ++ } ++ ++ renderer.setScissor(0, 0, width, height); ++ renderer.setViewport(0, 0, width, height); + + fn(time, rect); + ++ // ๋ Œ๋”๋ง๋œ ์žฅ๋ฉด์„ 2D ์บ”๋ฒ„์Šค์— ๋ณต์‚ฌ ++ ctx.globalCompositeOperation = 'copy'; ++ ctx.drawImage( ++ rendererCanvas, ++ 0, rendererCanvas.height - height, width, height, // ์›๋ณธ ์‚ฌ๊ฐ ์ขŒํ‘œ ++ 0, 0, width, height); // ๊ฒฐ๊ณผ๋ฌผ ์‚ฌ๊ฐ ์ขŒํ‘œ + } + } + + requestAnimationFrame(render); +} +``` + +๊ฒฐ๊ณผ๋ฌผ์€ ์œ„์™€ ๋‹ค๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-multiple-scenes-copy-canvas.html" }}} + +์ด ๊ธฐ๋ฒ•์˜ ๋‹ค๋ฅธ ์žฅ์ ์€ [`OffscreenCanvas`](https://developer.mozilla.org/ko/docs/Web/API/OffscreenCanvas) +์›น ์›Œ์ปค๋ฅผ ์ด์šฉํ•ด ์ด ๊ธฐ๋Šฅ์„ ๋ณ„๋„ ์Šค๋ ˆ๋“œ์—์„œ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์•„์‰ฝ๊ฒŒ๋„ +2020๋…„ 7์›”์„ ๊ธฐ์ค€์œผ๋กœ `OffscreenCanvas`๋Š” ์•„์ง ํฌ๋กœ๋ฏธ์›€ ๊ธฐ๋ฐ˜ ๋ธŒ๋ผ์šฐ์ €์—์„œ๋งŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. \ No newline at end of file
true
Other
mrdoob
three.js
633dbb61bdfd242077b4c012fce7468c1e707c1a.json
add translation kr/threejs-rendering-on-demand.md add translation kr/threejs-transparency.md update translation kr/threejs-prerequisites.md add translation kr/threejs-multiple-scenes.md add translation kr/threejs-picking.md fix typo & add translation kr/threejs-post-processing.md add translation kr/threejs-post-processing-3dlut.md
threejs/lessons/kr/threejs-picking.md
@@ -0,0 +1,417 @@ +Title: Three.js ํ”ผํ‚น(Picking) +Description: Three.js์—์„œ ๋งˆ์šฐ์Šค๋กœ ์š”์†Œ๋ฅผ ์„ ํƒํ•˜๋Š” ๋ฒ•์„ ์•Œ์•„๋ด…๋‹ˆ๋‹ค +TOC: ๋ฌผ์ฒด๋ฅผ ๋งˆ์šฐ์Šค๋กœ ํ”ผํ‚นํ•˜๊ธฐ + +*ํ”ผํ‚น(picking)*์ด๋ž€ ์‚ฌ์šฉ์ž๊ฐ€ ํด๋ฆญ ๋˜๋Š” ํ„ฐ์น˜ํ•œ ๋ฌผ์ฒด๋ฅผ ๊ฐ€๋ ค๋‚ด๋Š” ์ž‘์—…์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ํ”ผํ‚น์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์ˆ˜์—†์ด ๋งŽ์ง€๋งŒ, ๊ฐ์ž ๋‹จ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๊ธ€์—์„œ๋Š” ์ด ๋ฐฉ๋ฒ• ์ค‘ ํ”ํžˆ ์‚ฌ์šฉํ•˜๋Š” 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•๋งŒ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +์•„๋งˆ *ํ”ผํ‚น*์„ ๊ตฌํ˜„ํ•˜๋Š” ๊ฐ€์žฅ ํ”ํ•œ ๋ฐฉ๋ฒ•์€ ๊ด‘์„  ํˆฌ์‚ฌ(ray casting)์ผ ๊ฒ๋‹ˆ๋‹ค. ๊ด‘์„  ํˆฌ์‚ฌ๋ž€ ํฌ์ธํ„ฐ(์ปค์„œ)์—์„œ ์žฅ๋ฉด์˜ ์ ˆ๋‘์ฒด๋กœ ๊ด‘์„ ์„ ์ด ๊ด‘์„ ์ด ๋‹ฟ๋Š” ๋ฌผ์ฒด๋ฅผ ๊ฐ์ง€ํ•˜๋Š” ๊ธฐ๋ฒ•์„ ๋งํ•˜์ฃ . ์ด๋ก ์ ์œผ๋กœ ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. + +๋จผ์ € ํฌ์ธํ„ฐ์˜ ์ขŒํ‘œ๋ฅผ ๊ตฌํ•œ ๋’ค, ์ด ์ขŒํ‘œ๋ฅผ ์นด๋ฉ”๋ผ์˜ ์‹œ์„ ๊ณผ ๋ฐฉํ–ฅ์— ๋”ฐ๋ผ 3D ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  near ๋ฉด์—์„œ far ๋ฉด๊นŒ์ง€์˜ ๊ด‘์„ ์„ ๊ตฌํ•ด ์ด ๊ด‘์„ ์ด ์žฅ๋ฉด ์•ˆ ๊ฐ ๋ฌผ์ฒด์˜ ์‚ผ๊ฐํ˜•๊ณผ ๊ต์ฐจํ•˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์žฅ๋ฉด ์•ˆ์— 1000๊ฐœ์˜ ์‚ผ๊ฐํ˜•์„ ๊ฐ€์ง„ ๋ฌผ์ฒด๊ฐ€ 1000๊ฐœ ์žˆ๋‹ค๋ฉด ๋ฐฑ๋งŒ ๊ฐœ์˜ ์‚ผ๊ฐํ˜•์„ ์ผ์ผ์ด ํ™•์ธํ•ด์•ผ ํ•˜๋Š” ์…ˆ์ด์ฃ . + +์ด๋ฅผ ์ตœ์ ํ™”ํ•˜๋ ค๋ฉด ๋ช‡ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์„ ์‹œ๋„ํ•ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜๋‚˜๋Š” ๋จผ์ € ๋ฌผ์ฒด๋ฅผ ๊ฐ์‹ผ ๊ฒฝ๊ณ„(bounding) ์ขŒํ‘œ๊ฐ€ ๊ด‘์„ ๊ณผ ๊ต์ฐจํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ณ , ๊ต์ฐจํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ํ•ด๋‹น ๋ฌผ์ฒด์˜ ์‚ผ๊ฐํ˜•์„ ํ™•์ธํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด์ฃ . + +Three.js์—๋Š” ์ด๋Ÿฐ ์ž‘์—…์„ ๋Œ€์‹ ํ•ด์ฃผ๋Š” `RayCaster` ํด๋ž˜์Šค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. + +ํ•œ๋ฒˆ ๋ฌผ์ฒด 100๊ฐœ๊ฐ€ ์žˆ๋Š” ์žฅ๋ฉด์„ ๋งŒ๋“ค์–ด ์—ฌ๊ธฐ์„œ ํ”ผํ‚น์„ ๊ตฌํ˜„ํ•ด๋ด…์‹œ๋‹ค. ์˜ˆ์ œ๋Š” [๋ฐ˜์‘ํ˜• ๋””์ž์ธ](threejs-responsive.html)์—์„œ ์ผ๋˜ ์˜ˆ์ œ๋ฅผ ๊ฐ€์ ธ์™€ ์‚ฌ์šฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +์šฐ์„  ์นด๋ฉ”๋ผ๋ฅผ ๋ณ„๋„ `Object3D`์˜ ์ž์‹์œผ๋กœ ์ถ”๊ฐ€ํ•ด ์นด๋ฉ”๋ผ๊ฐ€ ์…€์นด๋ด‰์ฒ˜๋Ÿผ ์žฅ๋ฉด ์ฃผ์œ„๋ฅผ ๋Œ ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +*const fov = 60; +const aspect = 2; // ์บ”๋ฒ„์Šค ๊ธฐ๋ณธ๊ฐ’ +const near = 0.1; +*const far = 200; +const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); +*camera.position.z = 30; + +const scene = new THREE.Scene(); ++scene.background = new THREE.Color('white'); + ++// ์นด๋ฉ”๋ผ๋ฅผ ๋ด‰(pole)์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ++// ์ด๋Ÿฌ๋ฉด ๋ด‰์„ ํšŒ์ „์‹œ์ผœ ์นด๋ฉ”๋ผ๊ฐ€ ์žฅ๋ฉด ์ฃผ์œ„๋ฅผ ๋Œ๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค ++const cameraPole = new THREE.Object3D(); ++scene.add(cameraPole); ++cameraPole.add(camera); +``` + +๊ทธ๋ฆฌ๊ณ  `render` ํ•จ์ˆ˜ ์•ˆ์—์„œ ์นด๋ฉ”๋ผ ๋ด‰์„ ๋Œ๋ฆฝ๋‹ˆ๋‹ค. + +```js +cameraPole.rotation.y = time * .1; +``` + +๋˜ํ•œ ์นด๋ฉ”๋ผ์— ์กฐ๋ช…์„ ์ถ”๊ฐ€ํ•ด ์กฐ๋ช…์ด ์นด๋ฉ”๋ผ์™€ ๊ฐ™์ด ์›€์ง์ด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +-scene.add(light); ++camera.add(light); +``` + +์ •์œก๋ฉด์ฒด 100๊ฐœ์˜ ์œ„์น˜, ๋ฐฉํ–ฅ, ํฌ๊ธฐ๋ฅผ ๋ฌด์ž‘์œ„๋กœ ์„ค์ •ํ•ด ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +```js +const boxWidth = 1; +const boxHeight = 1; +const boxDepth = 1; +const geometry = new THREE.BoxGeometry(boxWidth, boxHeight, boxDepth); + +function rand(min, max) { + if (max === undefined) { + max = min; + min = 0; + } + return min + (max - min) * Math.random(); +} + +function randomColor() { + return `hsl(${ rand(360) | 0 }, ${ rand(50, 100) | 0 }%, 50%)`; +} + +const numObjects = 100; +for (let i = 0; i < numObjects; ++i) { + const material = new THREE.MeshPhongMaterial({ + color: randomColor(), + }); + + const cube = new THREE.Mesh(geometry, material); + scene.add(cube); + + cube.position.set(rand(-20, 20), rand(-20, 20), rand(-20, 20)); + cube.rotation.set(rand(Math.PI), rand(Math.PI), 0); + cube.scale.set(rand(3, 6), rand(3, 6), rand(3, 6)); +} +``` + +์ด์ œ ํ”ผํ‚น์„ ๊ตฌํ˜„ํ•ด๋ด…์‹œ๋‹ค. + +ํ”ผํ‚น์„ ๊ด€๋ฆฌํ•  ๊ฐ„๋‹จํ•œ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +class PickHelper { + constructor() { + this.raycaster = new THREE.Raycaster(); + this.pickedObject = null; + this.pickedObjectSavedColor = 0; + } + pick(normalizedPosition, scene, camera, time) { + // ์ด๋ฏธ ๋‹ค๋ฅธ ๋ฌผ์ฒด๋ฅผ ํ”ผํ‚นํ–ˆ๋‹ค๋ฉด ์ƒ‰์„ ๋ณต์›ํ•ฉ๋‹ˆ๋‹ค + if (this.pickedObject) { + this.pickedObject.material.emissive.setHex(this.pickedObjectSavedColor); + this.pickedObject = undefined; + } + + // ์ ˆ๋‘์ฒด ์•ˆ์— ๊ด‘์„ ์„ ์ฉ๋‹ˆ๋‹ค + this.raycaster.setFromCamera(normalizedPosition, camera); + // ๊ด‘์„ ๊ณผ ๊ต์ฐจํ•˜๋Š” ๋ฌผ์ฒด๋“ค์„ ๋ฐฐ์—ด๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค + const intersectedObjects = this.raycaster.intersectObjects(scene.children); + if (intersectedObjects.length) { + // ์ฒซ ๋ฒˆ์งธ ๋ฌผ์ฒด๊ฐ€ ์ œ์ผ ๊ฐ€๊นŒ์šฐ๋ฏ€๋กœ ํ•ด๋‹น ๋ฌผ์ฒด๋ฅผ ๊ณ ๋ฆ…๋‹ˆ๋‹ค + this.pickedObject = intersectedObjects[0].object; + // ๊ธฐ์กด ์ƒ‰์„ ์ €์žฅํ•ด๋‘ก๋‹ˆ๋‹ค + this.pickedObjectSavedColor = this.pickedObject.material.emissive.getHex(); + // emissive ์ƒ‰์„ ๋นจ๊ฐ•/๋…ธ๋ž‘์œผ๋กœ ๋น›๋‚˜๊ฒŒ ๋งŒ๋“ญ๋‹ˆ๋‹ค + this.pickedObject.material.emissive.setHex((time * 8) % 2 > 1 ? 0xFFFF00 : 0xFF0000); + } + } +} +``` + +์œ„ ํด๋ž˜์Šค๋Š” ๋จผ์ € `RayCaster` ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ  `pick` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์žฅ๋ฉด์— ๊ด‘์„ ์„ ์  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ด‘์„ ์— ๋งž๋Š” ์š”์†Œ๊ฐ€ ์žˆ์œผ๋ฉด ํ•ด๋‹น ์š”์†Œ ์ค‘ ๊ฐ€์žฅ ์ฒซ ๋ฒˆ์งธ ์š”์†Œ์˜ ์ƒ‰์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. + +์‚ฌ์šฉ์ž๊ฐ€ ๋งˆ์šฐ์Šค๋ฅผ ๋ˆŒ๋ €์„ ๋•Œ(down)๋งŒ ์ด ํ•จ์ˆ˜๊ฐ€ ์ž‘๋™ํ•˜๋„๋ก ํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ์˜ˆ์ œ์—์„œ๋Š” ๋งˆ์šฐ์Šค ํฌ์ธํ„ฐ ์•„๋ž˜์˜ ์žˆ๋Š” ์š”์†Œ๋ฅผ ํ”ผํ‚นํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด ๋จผ์ € ํฌ์ธํ„ฐ๋ฅผ ์ถ”์ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +```js +const pickPosition = { x: 0, y: 0 }; +clearPickPosition(); + +... + +function getCanvasRelativePosition(event) { + const rect = canvas.getBoundingClientRect(); + return { + x: (event.clientX - rect.left) * canvas.width / rect.width, + y: (event.clientY - rect.top ) * canvas.height / rect.height, + }; +} + +function setPickPosition(event) { + const pos = getCanvasRelativePosition(event); + pickPosition.x = (pos.x / canvas.width ) * 2 - 1; + pickPosition.y = (pos.y / canvas.height) * -2 + 1; // Y ์ถ•์„ ๋’ค์ง‘์—ˆ์Œ +} + +function clearPickPosition() { + /** + * ๋งˆ์šฐ์Šค์˜ ๊ฒฝ์šฐ๋Š” ํ•ญ์ƒ ์œ„์น˜๊ฐ€ ์žˆ์–ด ๊ทธ๋‹ค์ง€ ํฐ + * ์ƒ๊ด€์ด ์—†์ง€๋งŒ, ํ„ฐ์น˜ ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ์†๊ฐ€๋ฝ์„ + * ๋–ผ๋ฉด ํ”ผํ‚น์„ ๋ฉˆ์ถฐ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ง€๊ธˆ์€ ์ผ๋‹จ ์–ด๋–ค ๊ฒƒ๋„ + * ์„ ํƒํ•  ์ˆ˜ ์—†๋Š” ๊ฐ’์œผ๋กœ ์ง€์ •ํ•ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค + **/ + pickPosition.x = -100000; + pickPosition.y = -100000; +} + +window.addEventListener('mousemove', setPickPosition); +window.addEventListener('mouseout', clearPickPosition); +window.addEventListener('mouseleave', clearPickPosition); +``` + +์œ„ ์˜ˆ์ œ์—์„œ๋Š” ๋งˆ์šฐ์Šค์˜ ์ขŒํ‘œ๋ฅผ ์ •๊ทœํ™”(normalize)ํ–ˆ์Šต๋‹ˆ๋‹ค. ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ์™€ ์ƒ๊ด€์—†์ด ์™ผ์ชฝ ๋์ด -1, ์˜ค๋ฅธ์ชฝ ๋์ด +1์ธ ๋ฒกํ„ฐ๊ฐ’์ด ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด์ฃ . ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์•„๋ž˜์ชฝ ๋์€ -1, ์œ„์ชฝ ๋์€ +1์ž…๋‹ˆ๋‹ค. + +๋ชจ๋ฐ”์ผ๋„ ํ™˜๊ฒฝ๋„ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•ด ๋ฆฌ์Šค๋„ˆ๋ฅผ ๋” ์ถ”๊ฐ€ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +window.addEventListener('touchstart', (event) => { + event.preventDefault(); // ์Šคํฌ๋กค ์ด๋ฒคํŠธ ๋ฐฉ์ง€ + setPickPosition(event.touches[0]); +}, { passive: false }); + +window.addEventListener('touchmove', (event) => { + setPickPosition(event.touches[0]); +}); + +window.addEventListener('touchend', clearPickPosition); +``` + +๋งˆ์ง€๋ง‰์œผ๋กœ `render` ํ•จ์ˆ˜์—์„œ `PickHelper`์˜ `pick` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. + +```js ++const pickHelper = new PickHelper(); + +function render(time) { + time *= 0.001; // ์ดˆ ๋‹จ์œ„๋กœ ๋ณ€ํ™˜ + + ... + ++ pickHelper.pick(pickPosition, scene, camera, time); + + renderer.render(scene, camera); + + ... +``` + +๊ฒฐ๊ณผ๋ฅผ ๋ณผ๊นŒ์š”? + +{{{example url="../threejs-picking-raycaster.html" }}} + +๋”ฑํžˆ ๋ฌธ์ œ๋Š” ์—†์–ด ๋ณด์ž…๋‹ˆ๋‹ค. ์‹ค์ œ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋„ ๋Œ€๋ถ€๋ถ„ ๋ฌธ์ œ ์—†์ด ์ž˜ ๋˜๊ฒ ์ง€๋งŒ, ์ด ๋ฐฉ๋ฒ•์—๋Š” ๋ช‡ ๊ฐ€์ง€ ๋ฌธ์ œ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. + +1. CPU์˜ ์ž์›์„ ์‚ฌ์šฉํ•œ๋‹ค + + ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์—”์ง„์€ ๊ฐ ์š”์†Œ๋ฅผ ๋Œ๋ฉฐ ๊ด‘์„ ์ด ์š”์†Œ์˜ ๊ฒฝ๊ณ„ ์ขŒํ‘œ ์•ˆ์— ๊ต์ฐจํ•˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๊ต์ฐจํ•  ๊ฒฝ์šฐ, ํ•ด๋‹น ์š”์†Œ์˜ ์‚ผ๊ฐํ˜•์„ ์ „๋ถ€ ๋Œ๋ฉฐ ๊ด‘์„ ๊ณผ ๊ต์ฐจํ•˜๋Š” ์‚ผ๊ฐํ˜•์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + + ์ด ๋ฐฉ์‹์˜ ์žฅ์ ์€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๊ฐ€ ๊ต์ฐจํ•˜๋Š” ์ง€์ ์„ ์ •ํ™•ํžˆ ๊ณ„์‚ฐํ•ด ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฅผ ๋„˜๊ฒจ์ค„ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๊ต์ฐจ๊ฐ€ ๋ฐœ์ƒํ•œ ์ง€์ ์— ํŠน์ • ํ‘œ์‹œ๋ฅผ ํ•  ์ˆ˜ ์žˆ๊ฒ ์ฃ . + + ๋Œ€์‹  CPU๊ฐ€ ํ•  ์ผ์ด ๋” ๋Š˜์–ด๋‚œ๋‹ค๋Š” ์ ์ด ๋‹จ์ ์ž…๋‹ˆ๋‹ค. ์š”์†Œ๊ฐ€ ๊ฐ€์ง„ ์‚ผ๊ฐํ˜•์ด ๋งŽ์„์ˆ˜๋ก ๋” ๋А๋ ค์ง€๊ฒ ์ฃ . + +2. ํŠน์ดํ•œ ๋ฐฉ์‹์˜ ์‰์ด๋”๋‚˜ ๋ณ€์ด๋ฅผ ๊ฐ์ง€ํ•˜์ง€ ๋ชปํ•œ๋‹ค + + ๋งŒ์•ฝ ์žฅ๋ฉด์—์„œ geometry๋ฅผ ๋ณ€ํ˜•ํ•˜๋Š” ์‰์ด๋”๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์ด ๋ณ€ํ˜•์„ ๊ฐ์ง€ํ•˜์ง€ ๋ชปํ•˜๊ธฐ์— ์ž˜๋ชป๋œ ๊ฐ’์„ ๋‚ด๋†“์„ ๊ฒ๋‹ˆ๋‹ค. ์ œ๊ฐ€ ํ…Œ์ŠคํŠธํ•ด๋ณธ ๊ฒฐ๊ณผ ์Šคํ‚จ์ด ์ ์šฉ๋œ ์š”์†Œ์—๋Š” ์ด ๋ฐฉ๋ฒ•์ด ๋จนํžˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +3. ์š”์†Œ์˜ ํˆฌ๋ช…ํ•œ ๊ตฌ๋ฉ์„ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ•œ๋‹ค. + +์˜ˆ์ œ๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด๋ณด์ฃ . ์•„๋ž˜์™€ ๊ฐ™์€ ํ…์Šค์ฒ˜๋ฅผ ์ •์œก๋ฉด์ฒด์— ์ ์šฉํ•ด๋ด…์‹œ๋‹ค. + +<div class="threejs_center"><img class="checkerboard" src="../resources/images/frame.png"></div> + +๊ทธ๋‹ค์ง€ ์ถ”๊ฐ€ํ•  ๊ฑด ๋งŽ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +```js ++const loader = new THREE.TextureLoader(); ++const texture = loader.load('resources/images/frame.png'); + +const numObjects = 100; +for (let i = 0; i < numObjects; ++i) { + const material = new THREE.MeshPhongMaterial({ + color: randomColor(), + +map: texture, + +transparent: true, + +side: THREE.DoubleSide, + +alphaTest: 0.1, + }); + + const cube = new THREE.Mesh(geometry, material); + scene.add(cube); + + ... +``` + +์˜ˆ์ œ๋ฅผ ์‹คํ–‰์‹œํ‚ค๋ฉด ๋ฐ”๋กœ ๋ฌธ์ œ๊ฐ€ ๋ณด์ผ ๊ฒ๋‹ˆ๋‹ค. + +{{{example url="../threejs-picking-raycaster-transparency.html" }}} + +์ •์œก๋ฉด์ฒด์˜ ๋นˆ ๊ณต๊ฐ„์„ ํ†ตํ•ด ๋ฌด์–ธ๊ฐ€๋ฅผ ์„ ํƒํ•  ์ˆ˜๊ฐ€ ์—†์ฃ . + +<div class="threejs_center"><img src="resources/images/picking-transparent-issue.jpg" style="width: 635px;"></div> + +์ด๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๊ฐ€ ํ…์Šค์ฒ˜๋‚˜ ์žฌ์งˆ์„ ๋ณด๊ณ  ํ•ด๋‹น ์š”์†Œ๊ฐ€ ํˆฌ๋ช…ํ•œ์ง€ ํŒ๋‹จํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. + +์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๋ฉด GPU ๊ธฐ๋ฐ˜ ํ”ผํ‚น์„ ๊ตฌํ˜„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ก ์ ์œผ๋กœ๋Š” ๊ฐ„๋‹จํ•˜์ง€๋งŒ ์œ„์—์„œ ์‚ฌ์šฉํ•œ ๊ด‘์„  ํˆฌ์‚ฌ๋ฒ•๋ณด๋‹ค๋Š” ์ข€ ๋” ๋ณต์žกํ•˜์ฃ . + +GPU ํ”ผํ‚น์„ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด ๊ฐ ์š”์†Œ๋ฅผ ๋ณ„๋„์˜ ํ™”๋ฉด์—์„œ ๊ณ ์œ ํ•œ ์ƒ‰์ƒ์œผ๋กœ ๋ Œ๋”๋งํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํฌ์ธํ„ฐ ์•„๋ž˜์— ์žˆ๋Š” ํ”ฝ์…€์˜ ์ƒ‰์„ ๊ฐ€์ ธ์™€ ํ•ด๋‹น ์š”์†Œ๊ฐ€ ์„ ํƒ๋๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๊ฑฐ์ฃ . + +์ด๋Ÿฌ๋ฉด ์œ„์—์„œ ์–ธ๊ธ‰ํ•œ ๋ฌธ์ œ์  2, 3๋ฒˆ์ด ํ•ด๊ฒฐ๋ฉ๋‹ˆ๋‹ค. 1๋ฒˆ, ์„ฑ๋Šฅ์˜ ๊ฒฝ์šฐ๋Š” ์ƒํ™ฉ์— ๋”ฐ๋ผ ์ฒœ์ฐจ๋งŒ๋ณ„์ด์ฃ . ๋ˆˆ์— ๋ณด์ด๋Š” ํ™”๋ฉด์„ ์œ„ํ•ด ํ•œ ๋ฒˆ, ํ”ผํ‚น์„ ์œ„ํ•ด ํ•œ ๋ฒˆ, ์ด๋ ‡๊ฒŒ ๋งค ์š”์†Œ๋ฅผ ์ด ๋‘ ๋ฒˆ์”ฉ ๋ Œ๋”๋งํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋” ๋ณต์žกํ•œ ํ•ด๊ฒฐ์ฑ…์„ ์“ฐ๋ฉด ๋ Œ๋”๋ง์„ ํ•œ ๋ฒˆ๋งŒ ํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ์ด ๊ธ€์—์„œ๋Š” ์ผ๋‹จ ๋” ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +์„ฑ๋Šฅ ์ตœ์ ํ™”๋ฅผ ์œ„ํ•ด ์‹œ๋„ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ํ•˜๋‚˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์–ด์ฐจํ”ผ ํ”ฝ์…€์„ ํ•˜๋‚˜๋งŒ ์ฝ์„ ๊ฒƒ์ด๋‹ˆ, ์นด๋ฉ”๋ผ๋ฅผ ํ”ฝ์…€ ํ•˜๋‚˜๋งŒ ๋ Œ๋”๋งํ•˜๋„๋ก ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด์ฃ . `PerspectiveCamera.setViewOffset` ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์นด๋ฉ”๋ผ์˜ ํŠน์ • ๋ถ€๋ถ„๋งŒ ๋ Œ๋”๋งํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด ์„ฑ๋Šฅ ํ–ฅ์ƒ์— ์กฐ๊ธˆ์ด๋‚˜๋งˆ ๋„์›€์ด ๋˜๊ฒ ์ฃ . + +ํ˜„์žฌ Three.js์—์„œ ์ด ๊ธฐ๋ฒ•์„ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด ์žฅ๋ฉด 2๊ฐœ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ํ•˜๋‚˜๋Š” ๊ธฐ์กด mesh๋ฅผ ๊ทธ๋Œ€๋กœ ์“ฐ๊ณ , ๋‚˜๋จธ์ง€ ํ•˜๋‚˜๋Š” ํ”ผํ‚น์šฉ ์žฌ์งˆ์„ ์ ์šฉํ•œ mesh๋ฅผ ์“ธ ๊ฒ๋‹ˆ๋‹ค. + +๋จผ์ € ๋‘ ๋ฒˆ์งธ ์žฅ๋ฉด์„ ์ถ”๊ฐ€ํ•˜๊ณ  ๋ฐฐ๊ฒฝ์„ ๊ฒ€์ •์œผ๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. + +```js +const scene = new THREE.Scene(); +scene.background = new THREE.Color('white'); +const pickingScene = new THREE.Scene(); +pickingScene.background = new THREE.Color(0); +``` + +๊ฐ ์ •์œก๋ฉด์ฒด๋ฅผ ์žฅ๋ฉด์— ์ถ”๊ฐ€ํ•  ๋•Œ `pickingScene`์˜ ๊ฐ™์€ ์œ„์น˜์— "ํ”ผํ‚น์šฉ ์ •์œก๋ฉด์ฒด"๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ ํ”ผํ‚น์šฉ ์ •์œก๋ฉด์ฒด์—๋Š” id๋กœ ์“ธ ๊ณ ์œ  ์ƒ‰์ƒ๊ฐ’์„ ์ง€์ •ํ•œ ๋’ค, ์ด id ์ƒ‰์ƒ๊ฐ’์œผ๋กœ ์žฌ์งˆ์„ ๋งŒ๋“ค์–ด ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. id ์ƒ‰์ƒ๊ฐ’์„ ์ •์œก๋ฉด์ฒด์˜ ํ‚ค๊ฐ’์œผ๋กœ ๋งคํ•‘ํ•ด ๋†“์œผ๋ฉด ๋‚˜์ค‘์— ์ƒ์‘ํ•˜๋Š” ์ •์œก๋ฉด์ฒด๋ฅผ ๋ฐ”๋กœ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๊ฒ ์ฃ . + +```js +const idToObject = {}; ++const numObjects = 100; +for (let i = 0; i < numObjects; ++i) { ++ const id = i + 1; + const material = new THREE.MeshPhongMaterial({ + color: randomColor(), + map: texture, + transparent: true, + side: THREE.DoubleSide, + alphaTest: 0.1, + }); + + const cube = new THREE.Mesh(geometry, material); + scene.add(cube); ++ idToObject[id] = cube; + + cube.position.set(rand(-20, 20), rand(-20, 20), rand(-20, 20)); + cube.rotation.set(rand(Math.PI), rand(Math.PI), 0); + cube.scale.set(rand(3, 6), rand(3, 6), rand(3, 6)); + ++ const pickingMaterial = new THREE.MeshPhongMaterial({ ++ emissive: new THREE.Color(id), ++ color: new THREE.Color(0, 0, 0), ++ specular: new THREE.Color(0, 0, 0), ++ map: texture, ++ transparent: true, ++ side: THREE.DoubleSide, ++ alphaTest: 0.5, ++ blending: THREE.NoBlending, ++ }); ++ const pickingCube = new THREE.Mesh(geometry, pickingMaterial); ++ pickingScene.add(pickingCube); ++ pickingCube.position.copy(cube.position); ++ pickingCube.rotation.copy(cube.rotation); ++ pickingCube.scale.copy(cube.scale); +} +``` + +์œ„ ์ฝ”๋“œ์—์„œ๋Š” `MeshPhongMaterial`๋กœ ํŽธ๋ฒ•์„ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. `emissive` ์†์„ฑ์„ id ์ƒ‰์ƒ๊ฐ’์œผ๋กœ, `color`์™€ `specular` ์†์„ฑ์„ 0์œผ๋กœ ์„ค์ •ํ•˜๋ฉด ํ…์Šค์ฒ˜์˜ ์•ŒํŒŒ๊ฐ’์ด `alphaTest`๋ณด๋‹ค ํฐ ๋ถ€๋ถ„๋งŒ id ์ƒ‰์ƒ๊ฐ’์œผ๋กœ ๋ณด์ด๊ฒ ์ฃ . ๋˜ `blending` ์†์„ฑ์„ `THREE.NoBlending`์œผ๋กœ ์„ค์ •ํ•ด id ์ƒ‰์ƒ๊ฐ’์ด ์•ŒํŒŒ๊ฐ’์˜ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค. + +์ œ๊ฐ€ ์‚ฌ์šฉํ•œ ํŽธ๋ฒ•์ด ์ตœ์ ์˜ ํ•ด๊ฒฐ์ฑ…์€ ์•„๋‹™๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์˜ต์…˜์„ ๊ป๋‹ค๊ณ  ํ•ด๋„ ์—ฌ์ „ํžˆ ์กฐ๋ช… ๊ด€๋ จ ์—ฐ์‚ฐ์„ ์‹คํ–‰ํ•  ํ…Œ๋‹ˆ๊นŒ์š”. ์ฝ”๋“œ๋ฅผ ๋” ์ตœ์ ํ™”ํ•˜๋ ค๋ฉด `alphaTest` ๊ฐ’๋ณด๋‹ค ๋†’์€ ๊ฒฝ์šฐ์—๋งŒ id ์ƒ‰์ƒ์„ ๋ Œ๋”๋งํ•˜๋Š” ์‰์ด๋”๋ฅผ ์ง์ ‘ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +๊ด‘์„  ํˆฌ์‚ฌ๋ฒ•์„ ์“ธ ๋•Œ์™€ ๋‹ฌ๋ฆฌ ํ”ฝ์…€์„ ํ•˜๋‚˜๋งŒ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ์œ„์น˜๊ฐ’์ด ํ”ฝ์…€ ํ•˜๋‚˜๋งŒ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. + +```js +function setPickPosition(event) { + const pos = getCanvasRelativePosition(event); +- pickPosition.x = (pos.x / canvas.clientWidth ) * 2 - 1; +- pickPosition.y = (pos.y / canvas.clientHeight) * -2 + 1; // Y ์ถ•์„ ๋’ค์ง‘์—ˆ์Œ ++ pickPosition.x = pos.x; ++ pickPosition.y = pos.y; +} +``` + +`PickHelper` ํด๋ž˜์Šค๋„ `GPUPickHelper`๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. [๋ Œ๋” ํƒ€๊ฒŸ(render target)์— ๊ด€ํ•œ ๊ธ€](threejs-rendertargets.html)์—์„œ ๋‹ค๋ฃฌ `WebGLRenderTarget`์„ ์จ ๊ตฌํ˜„ํ•˜๋˜, ์ด๋ฒˆ ๋ Œ๋” ํƒ€๊ฒŸ์˜ ํฌ๊ธฐ๋Š” 1x1, 1ํ”ฝ์…€์ž…๋‹ˆ๋‹ค. + +```js +-class PickHelper { ++class GPUPickHelper { + constructor() { +- this.raycaster = new THREE.Raycaster(); ++ // 1x1 ํ”ฝ์…€ ํฌ๊ธฐ์˜ ๋ Œ๋” ํƒ€๊ฒŸ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค ++ this.pickingTexture = new THREE.WebGLRenderTarget(1, 1); ++ this.pixelBuffer = new Uint8Array(4); + this.pickedObject = null; + this.pickedObjectSavedColor = 0; + } + pick(cssPosition, scene, camera, time) { ++ const {pickingTexture, pixelBuffer} = this; + + // ๊ธฐ์กด์— ์„ ํƒ๋œ ์š”์†Œ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ์ƒ‰์„ ๋ณต์›ํ•ฉ๋‹ˆ๋‹ค + if (this.pickedObject) { + this.pickedObject.material.emissive.setHex(this.pickedObjectSavedColor); + this.pickedObject = undefined; + } + ++ // view offset์„ ๋งˆ์šฐ์Šค ํฌ์ธํ„ฐ ์•„๋ž˜ 1ํ”ฝ์…€๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค ++ const pixelRatio = renderer.getPixelRatio(); ++ camera.setViewOffset( ++ renderer.getContext().drawingBufferWidth, // ์ „์ฒด ๋„ˆ๋น„ ++ renderer.getContext().drawingBufferHeight, // ์ „์ฒด ๋†’์ด ++ cssPosition.x * pixelRatio | 0, // ์‚ฌ๊ฐ x ์ขŒํ‘œ ++ cssPosition.y * pixelRatio | 0, // ์‚ฌ๊ฐ y ์ขŒํ‘œ ++ 1, // ์‚ฌ๊ฐ ์ขŒํ‘œ width ++ 1, // ์‚ฌ๊ฐ ์ขŒํ‘œ height ++ ); ++ // ์žฅ๋ฉด์„ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค ++ renderer.setRenderTarget(pickingTexture) ++ renderer.render(scene, camera); ++ renderer.setRenderTarget(null); ++ ++ // view offset์„ ์ •์ƒ์œผ๋กœ ๋Œ๋ ค ์›๋ž˜์˜ ํ™”๋ฉด์„ ๋ Œ๋”๋งํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค ++ camera.clearViewOffset(); ++ // ํ”ฝ์…€์„ ๊ฐ์ง€ํ•ฉ๋‹ˆ๋‹ค ++ renderer.readRenderTargetPixels( ++ pickingTexture, ++ 0, // x ++ 0, // y ++ 1, // width ++ 1, // height ++ pixelBuffer); ++ ++ const id = ++ (pixelBuffer[0] << 16) | ++ (pixelBuffer[1] << 8) | ++ (pixelBuffer[2] ); + + // ์ ˆ๋‘์ฒด ์•ˆ์— ๊ด‘์„ ์„ ์ฉ๋‹ˆ๋‹ค +- this.raycaster.setFromCamera(normalizedPosition, camera); + // ๊ด‘์„ ๊ณผ ๊ต์ฐจํ•˜๋Š” ๋ฌผ์ฒด๋“ค์„ ๋ฐฐ์—ด๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค +- const intersectedObjects = this.raycaster.intersectObjects(scene.children); +- if (intersectedObjects.length) { + // ์ฒซ ๋ฒˆ์งธ ๋ฌผ์ฒด๊ฐ€ ์ œ์ผ ๊ฐ€๊นŒ์šฐ๋ฏ€๋กœ ํ•ด๋‹น ๋ฌผ์ฒด๋ฅผ ๊ณ ๋ฆ…๋‹ˆ๋‹ค +- this.pickedObject = intersectedObjects[0].object; + ++ const intersectedObject = idToObject[id]; ++ if (intersectedObject) { + // ์ฒซ ๋ฒˆ์งธ ๋ฌผ์ฒด๊ฐ€ ์ œ์ผ ๊ฐ€๊นŒ์šฐ๋ฏ€๋กœ ํ•ด๋‹น ๋ฌผ์ฒด๋ฅผ ๊ณ ๋ฆ…๋‹ˆ๋‹ค ++ this.pickedObject = intersectedObject; + // ๊ธฐ์กด ์ƒ‰์„ ์ €์žฅํ•ด๋‘ก๋‹ˆ๋‹ค + this.pickedObjectSavedColor = this.pickedObject.material.emissive.getHex(); + // emissive ์ƒ‰์„ ๋นจ๊ฐ•/๋…ธ๋ž‘์œผ๋กœ ๋น›๋‚˜๊ฒŒ ๋งŒ๋“ญ๋‹ˆ๋‹ค + this.pickedObject.material.emissive.setHex((time * 8) % 2 > 1 ? 0xFFFF00 : 0xFF0000); + } + } +} +``` + +์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“œ๋Š” ์ชฝ๋„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. + +```js +-const pickHelper = new PickHelper(); ++const pickHelper = new GPUPickHelper(); +``` + +`pick` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ `scene` ๋Œ€์‹  `pickScene`์„ ๋„˜๊ฒจ์ค๋‹ˆ๋‹ค. + +```js +- pickHelper.pick(pickPosition, scene, camera, time); ++ pickHelper.pick(pickPosition, pickScene, camera, time); +``` + +์ด์ œ ํˆฌ๋ช…ํ•œ ๋ถ€๋ถ„์„ ๊ด€ํ†ตํ•ด ์š”์†Œ๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-picking-gpu.html" }}} + +์ด ๊ธ€์ด ํ”ผํ‚น์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜์—ˆ์œผ๋ฉด ์ข‹๊ฒ ๋„ค์š”. ๋‚˜์ค‘์— ์š”์†Œ๋ฅผ ๋งˆ์šฐ์Šค๋กœ ์กฐ์ž‘ํ•˜๋Š” ๋ฒ•์— ๋Œ€ํ•ด์„œ๋„ ํ•œ ๋ฒˆ ์จ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. \ No newline at end of file
true
Other
mrdoob
three.js
633dbb61bdfd242077b4c012fce7468c1e707c1a.json
add translation kr/threejs-rendering-on-demand.md add translation kr/threejs-transparency.md update translation kr/threejs-prerequisites.md add translation kr/threejs-multiple-scenes.md add translation kr/threejs-picking.md fix typo & add translation kr/threejs-post-processing.md add translation kr/threejs-post-processing-3dlut.md
threejs/lessons/kr/threejs-post-processing-3dlut.md
@@ -0,0 +1,502 @@ +Title: 3DLUT๋กœ ํ›„์ฒ˜๋ฆฌํ•˜๊ธฐ +Description: Three.js์—์„œ 3DLUT๋กœ ํ›„์ฒ˜๋ฆฌํ•˜๋Š” ๋ฒ•์„ ์•Œ์•„๋ด…๋‹ˆ๋‹ค +TOC: LUT ํŒŒ์ผ๋กœ ํ›„์ฒ˜๋ฆฌ ํšจ๊ณผ ์ ์šฉํ•˜๊ธฐ + +์ด์ „ ๊ธ€์—์„œ๋Š” [ํ›„์ฒ˜๋ฆฌ(Post processing)](threejs-post-processing.html)์— ๊ด€ํ•ด ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค. ๋ณดํ†ต ํ›„์ฒ˜๋ฆฌ๋Š” LUT ๋˜๋Š” 3DLUT๋ผ๊ณ  ๋ถ€๋ฅด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. LUT๋Š” ๋ฃฉ์—… ํ…Œ์ด๋ธ”(Look-Up Table, ์ˆœ๋žŒํ‘œ)์˜ ์ค„์ž„๋ง์ด๊ณ , 3DLUT๋Š” 3์ฐจ์› ๋ฃฉ์—… ํ…Œ์ด๋ธ”์˜ ์ค„์ž„๋ง์ž…๋‹ˆ๋‹ค. + +3DLUT๋Š” 2D ์ด๋ฏธ์ง€๋ฅผ ํŠน์ •ํ•œ ์ƒ‰์ƒ ์ •์œก๋ฉด์ฒด๋ฅผ ๋งคํ•‘ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ์‰ฝ์Šต๋‹ˆ๋‹ค. ๋จผ์ € ์›๋ณธ ์ด๋ฏธ์ง€์˜ ์ƒ‰์ƒ์„ ์ •์œก๋ฉด์ฒด์˜ ์ธ๋ฑ์Šค ๊ฐ’๊ณผ ๋งค์นญ์‹œํ‚ต๋‹ˆ๋‹ค. ์›๋ณธ ์ด๋ฏธ์ง€์˜ ํ”ฝ์…€ ํ•˜๋‚˜๋‹น ํ•ด๋‹น ํ”ฝ์…€ ์ƒ‰์ƒ์˜ ๋นจ๊ฐ•(red), ์ดˆ๋ก(green), ํŒŒ๋ž‘(blue) ๊ฐ’์„ ์ด์šฉํ•ด ์ •์œก๋ฉด์ฒด์˜ ํŠน์ • ์ง€์ ์„ ๊ฐ€๋ฆฌํ‚ค๋Š”(look-up) 3D ๋ฒกํ„ฐ ์ธ๋ฑ์Šค๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด์ฃ . ์ด ์ธ๋ฑ์Šค๋ฅผ ํ†ตํ•ด 3DLUT์—์„œ ๋ฝ‘์•„๋‚ธ ๊ฐ’์„ ์ƒˆ๋กœ์šด ์ƒ‰์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒ๋‹ˆ๋‹ค. + +์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ๊ฒฝ์šฐ ์•„๋ž˜์ฒ˜๋Ÿผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. RGB ๊ฐ ์ƒ‰์ƒ๊ฐ’์„ 0๋ถ€ํ„ฐ 255์˜ ์ •์ˆ˜๋กœ ํ‘œํ˜„ํ•œ 3์ฐจ์› 256x256x256 ๋ฐฐ์—ด๋กœ ๋ฃฉ์—… ํ…Œ์ด๋ธ”์„ ๊ตฌํ˜„ํ•˜๊ณ , ์ด ๋ฃฉ์—… ํ…Œ์ด๋ธ”์—์„œ RGB ์ƒ‰์ƒ๊ฐ’์„ ์ด์šฉํ•ด ์ƒˆ๋กœ์šด ์ƒ‰์ƒ๊ฐ’์„ ์„ ํƒํ•˜๋Š” ๊ฑฐ์ฃ . + +```js +const newColor = lut[origColor.red][origColor.green][origColor.blue] +``` + +๋ฌผ๋ก  256x256x256 ๋ฐฐ์—ด์€ ํฐ ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค. [ํ…์Šค์ฒ˜์— ๊ด€ํ•œ ๊ธ€](threejs-textures.html)์—์„œ ๋ฐฐ์› ๋“ฏ ํ…์Šค์ฒ˜๋Š” ํฌ๊ธฐ์— ์ƒ๊ด€ ์—†์ด 0.0์—์„œ 1.0๋กœ ๊ฐ’์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. + +8x8x8 ์ •์œก๋ฉด์ฒด๋ฅผ ์˜ˆ๋กœ ๋“ค์–ด๋ณด์ฃ . + +<div class="threejs_center"><img src="resources/images/3dlut-rgb.svg" class="noinvertdark" style="width: 500px"></div> + +๋จผ์ € 0,0,0 ๋ถ€๋ถ„์„ ๊ฒ€์ •์ƒ‰์œผ๋กœ ์ฑ„์›๋‹ˆ๋‹ค. ๋งž์€ํŽธ์˜ 1,1,1 ๋ถ€๋ถ„์€ ํ•˜์–€์ƒ‰, 1,0,0 ๋ถ€๋ถ„์€ <span style="color:red;">๋นจ๊ฐ•</span>, 0,1,0์€ <span style="color:green;">์ดˆ๋ก</span>, 0,0,1์€ <span style="color:blue;">ํŒŒ๋ž‘</span>์œผ๋กœ ์ฑ„์›๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/3dlut-axis.svg" class="noinvertdark" style="width: 500px"></div> + +๊ทธ๋ฆฌ๊ณ  ๊ฐ ์ถ•์„ ๋”ฐ๋ผ ์ƒ‰์„ ์ฑ„์›Œ๋„ฃ์Šต๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/3dlut-edges.svg" class="noinvertdark" style="width: 500px"></div> + +๋นˆ ๋ชจ์„œ๋ฆฌ๋ฅผ 2๊ฐœ ์ด์ƒ์˜ ์ƒ‰์ƒ ์ฑ„๋„์„ ์‚ฌ์šฉํ•˜๋Š” ์ƒ‰์œผ๋กœ ์ฑ„์›๋‹ˆ๋‹ค(์ดˆ๋ก + ๋นจ๊ฐ•, ํŒŒ๋ž‘ + ๋นจ๊ฐ• ๋“ฑ). + +<div class="threejs_center"><img src="resources/images/3dlut-standard.svg" class="noinvertdark" style="width: 500px"></div> + +๋งˆ์ง€๋ง‰์œผ๋กœ ๋นˆ ๊ณต๊ฐ„์„ ์ฑ„์›๋‹ˆ๋‹ค. ์ด ํ˜•ํƒœ๊ฐ€ 3DLUT ๊ธฐ๋ณธ ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค. ์ง€๊ธˆ์€ ํšจ๊ณผ๋ฅผ ์ฃผ๊ธฐ ์ „๊ณผ ํ›„์˜ ์ฐจ์ด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์ƒ‰์ƒ๊ฐ’์„ ์ธ๋ฑ์Šค๋กœ ์‚ฌ์šฉํ•ด ์ƒˆ๋กœ์šด ์ƒ‰์ƒ๊ฐ’์„ ์„ ํƒํ•˜๋ฉด, ์ •ํ™•ํžˆ ๊ฐ™์€ ์ƒ‰์ƒ๊ฐ’์ด ๋‚˜์˜ค๊ธฐ ๋•Œ๋ฌธ์ด์ฃ . + +<div class="threejs_center"><object type="image/svg+xml" data="resources/images/3dlut-standard-lookup.svg" class="noinvertdark" data-diagram="lookup" style="width: 600px"></object></div> + +์ด ์ •์œก๋ฉด์ฒด๋ฅผ ํ˜ธ๋ฐ•์ƒ‰ ์‰์ด๋“œ๋กœ ๋ฐ”๊พธ๋ฉด ๊ฐ™์€ ์ธ๋ฑ์Šค๋ฅผ ์ฐธ์กฐํ•˜์ง€๋งŒ ์ „ํ˜€ ๋‹ค๋ฅธ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค. + +<div class="threejs_center"><object type="image/svg+xml" data="resources/images/3dlut-amber-lookup.svg" class="noinvertdark" data-diagram="lookup" style="width: 600px"></object></div> + +์ด ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฃฉ์—… ํ…Œ์ด๋ธ”์„ ๊ต์ฒดํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋งŽ์€ ํšจ๊ณผ๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒ‰์ƒ ๊ณ„์‚ฐ ๊ธฐ๋ฐ˜์˜ ํšจ๊ณผ๋Š” ๋Œ€๋ถ€๋ถ„ ํ•˜๋‚˜์˜ ์ƒ‰์ƒ๊ฐ’๋งŒ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ƒ‰์ƒ, ๋Œ€๋น„, ์ฑ„๋„, ์ปฌ๋Ÿฌ ์บ์ŠคํŠธ(color cast), ํ‹ดํŠธ(tint), ๋ฐ๊ธฐ, ๋…ธ์ถœ๋„, ๋ ˆ๋ฒจ, ์ปค๋ธŒ, ํฌ์Šคํ„ฐํ™”, ๊ทธ๋ฆผ์ž, ๊ฐ•์กฐ, ๋“ฑ ๊ฑฐ์˜ ๋ชจ๋“  ํšจ๊ณผ๋ฅผ ์ƒ‰์ƒ๊ฐ’ ๊ณ„์‚ฐ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ตฌํ˜„ํ•˜์ฃ . ๋˜ ์ด ๋ชจ๋“  ํšจ๊ณผ๋ฅผ ํ•˜๋‚˜์˜ ๋ฃฉ์—… ํ…Œ์ด๋ธ”๋กœ ํ•ฉ์น  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. + +๋ฃฉ์—… ํ…Œ์ด๋ธ”์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋จผ์ € ์ ์šฉํ•  ์žฅ๋ฉด์ด ํ•„์š”ํ•˜๋‹ˆ ๊ฐ„๋‹จํ•œ ์žฅ๋ฉด์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. [glTF ๋ถˆ๋Ÿฌ์˜ค๊ธฐ](threejs-load-gltf.html)์—์„œ ๋ฐฐ์› ๋“ฏ glTF ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์™€ ์‚ฌ์šฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์˜ˆ์ œ์— ์‚ฌ์šฉํ•  ๋ชจ๋ธ์€ [The Ice Wolves](https://sketchfab.com/sarath.irn.kat005)์˜ [์ž‘ํ’ˆ](https://sketchfab.com/models/a1d315908e9f45e5a3bc618bdfd2e7ee)์ž…๋‹ˆ๋‹ค. + +[๋ฐฐ๊ฒฝ๊ณผ ํ•˜๋Š˜ ์ƒ์ž](threejs-backgrounds.html)์—์„œ ๋ฐฐ์› ๋˜ ๋Œ€๋กœ ๋ฐฐ๊ฒฝ๋„ ์ถ”๊ฐ€ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-postprocessing-3dlut-prep.html" }}} + +์ด์ œ ์žฅ๋ฉด์„ ๊ตฌํ˜„ํ–ˆ์œผ๋‹ˆ 3DLUT๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ 3DLUT๋Š” 2x2x2 identity LUT๋กœ, ์—ฌ๊ธฐ์„œ *identity(๋™์ผํ•œ)*์€ ์•„๋ฌด๋Ÿฐ ๋ณ€ํ™”๋„ ์—†์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. 1์„ ๊ณฑํ•˜๊ฑฐ๋‚˜ ์•„๋ฌด๊ฒƒ๋„ ์•ˆ ํ•˜๋Š” ๊ฒฝ์šฐ์™€ ๊ฐ™์ฃ . LUT ์•ˆ์˜ ์ƒ‰์ƒ๊ฐ’์„ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ํ•ด๋„ ์ž…๋ ฅ๋œ ๊ฐ’๊ณผ ์ •ํ™•ํžˆ ๊ฐ™์€ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•  ํ…Œ๋‹ˆ๊นŒ์š”. + +<div class="threejs_center"><img src="resources/images/3dlut-standard-2x2.svg" class="noinvertdark" style="width: 200px"></div> + +WebGL1์€ 3D ํ…์Šค์ณ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 3D ํ…์Šค์ฒ˜๋ฅผ ์ฐ์–ด ํŽผ์ณ ๋†“์€ ํ˜•ํƒœ์˜ 4x2์งœ๋ฆฌ 2D ํ…์Šค์ฒ˜๋ฅผ ๋Œ€์‹  ์‚ฌ์šฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +์•„๋ž˜๋Š” 4x2 2D ํ…์Šค์ฒ˜๋กœ identity LUT๋ฅผ ๊ตฌํ˜„ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +```js +const makeIdentityLutTexture = function() { + const identityLUT = new Uint8Array([ + 0, 0, 0, 255, // black + 255, 0, 0, 255, // red + 0, 0, 255, 255, // blue + 255, 0, 255, 255, // magenta + 0, 255, 0, 255, // green + 255, 255, 0, 255, // yellow + 0, 255, 255, 255, // cyan + 255, 255, 255, 255, // white + ]); + + return function(filter) { + const texture = new THREE.DataTexture(identityLUT, 4, 2, THREE.RGBAFormat); + texture.minFilter = filter; + texture.magFilter = filter; + texture.needsUpdate = true; + texture.flipY = false; + return texture; + }; +}(); +``` + +ํ•„ํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐ„ ๊ฒƒ, ์•ˆ ๋“ค์–ด๊ฐ„ ๊ฒƒ ์ด 2๊ฐœ๋ฅผ ๋งŒ๋“ค๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +const lutTextures = [ + { name: 'identity', size: 2, texture: makeIdentityLutTexture(THREE.LinearFilter) }, + { name: 'identity not filtered', size: 2, texture: makeIdentityLutTexture(THREE.NearestFilter) }, +]; +``` + +[ํ›„์ฒ˜๋ฆฌ์— ๊ด€ํ•œ ๊ธ€](threejs-post-processing.html)์—์„œ ์ž‘์„ฑํ–ˆ๋˜ ์ฝ”๋“œ๋ฅผ ๊ฐ€์ ธ์™€ ์ด ์‰์ด๋”๋“ค์„ ๋Œ€์‹  ์“ฐ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +const lutShader = { + uniforms: { + tDiffuse: { value: null }, + lutMap: { value: null }, + lutMapSize: { value: 1, }, + }, + vertexShader: ` + varying vec2 vUv; + void main() { + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + } + `, + fragmentShader: ` + #include <common> + + #define FILTER_LUT true + + uniform sampler2D tDiffuse; + uniform sampler2D lutMap; + uniform float lutMapSize; + + varying vec2 vUv; + + vec4 sampleAs3DTexture(sampler2D tex, vec3 texCoord, float size) { + float sliceSize = 1.0 / size; // space of 1 slice + float slicePixelSize = sliceSize / size; // space of 1 pixel + float width = size - 1.0; + float sliceInnerSize = slicePixelSize * width; // space of size pixels + float zSlice0 = floor( texCoord.z * width); + float zSlice1 = min( zSlice0 + 1.0, width); + float xOffset = slicePixelSize * 0.5 + texCoord.x * sliceInnerSize; + float yRange = (texCoord.y * width + 0.5) / size; + float s0 = xOffset + (zSlice0 * sliceSize); + + #ifdef FILTER_LUT + + float s1 = xOffset + (zSlice1 * sliceSize); + vec4 slice0Color = texture2D(tex, vec2(s0, yRange)); + vec4 slice1Color = texture2D(tex, vec2(s1, yRange)); + float zOffset = mod(texCoord.z * width, 1.0); + return mix(slice0Color, slice1Color, zOffset); + + #else + + return texture2D(tex, vec2( s0, yRange)); + + #endif + } + + void main() { + vec4 originalColor = texture2D(tDiffuse, vUv); + gl_FragColor = sampleAs3DTexture(lutMap, originalColor.xyz, lutMapSize); + } + `, +}; + +const lutNearestShader = { + uniforms: Object.assign( {}, lutShader.uniforms ), + vertexShader: lutShader.vertexShader, + fragmentShader: lutShader.fragmentShader.replace('#define FILTER_LUT', '//'), +}; +``` + +fragment ์‰์ด๋”์˜ ๋‹ค์Œ ์ฝ”๋“œ๋Š” + +```glsl +#define FILTER_LUT true +``` + +์ฃผ์„ ์ฒ˜๋ฆฌํ–ˆ๋˜ ๋‘ ๋ฒˆ์งธ ์‰์ด๋”๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +๊ทธ๋ฆฌ๊ณ  ๊ฐ ์‰์ด๋”๋กœ `Pass`๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. + +```js +const effectLUT = new THREE.ShaderPass(lutShader); +effectLUT.renderToScreen = true; +const effectLUTNearest = new THREE.ShaderPass(lutNearestShader); +effectLUTNearest.renderToScreen = true; +``` + +๊ธฐ์กด์— ๋ฐฐ๊ฒฝ๊ณผ glTF๋ฅผ ๋ณ„๋„ ์žฅ๋ฉด์œผ๋กœ ๋ถ„๋ฆฌํ–ˆ์œผ๋ฏ€๋กœ ๊ฐ ์žฅ๋ฉด์˜ `RenderPass`๋ฅผ ๋”ฐ๋กœ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +```js +const renderModel = new THREE.RenderPass(scene, camera); +renderModel.clear = false; // ๋ฐฐ๊ฒฝ์„ ์ง€์šฐ์ง€ ์•Š๋„๋ก ํ•ฉ๋‹ˆ๋‹ค +const renderBG = new THREE.RenderPass(sceneBG, cameraBG); +``` + +๋‹ค์Œ์œผ๋กœ ์‚ฌ์šฉํ•  pass*๋ฅผ `EffectComposer`์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +โ€ป ํŽธ์˜์ƒ `Pass` ์ธ์Šคํ„ด์Šค๋ฅผ pass๋กœ ๋ฒˆ์—ญํ•ฉ๋‹ˆ๋‹ค. + +```js +const rtParameters = { + minFilter: THREE.LinearFilter, + magFilter: THREE.LinearFilter, + format: THREE.RGBFormat, +}; +const composer = new THREE.EffectComposer(renderer, new THREE.WebGLRenderTarget(1, 1, rtParameters)); + +composer.addPass(renderBG); +composer.addPass(renderModel); +composer.addPass(effectLUT); +composer.addPass(effectLUTNearest); +``` + +GUI๋ฅผ ๋งŒ๋“ค์–ด LUT๋ฅผ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +const lutNameIndexMap = {}; +lutTextures.forEach((info, ndx) => { + lutNameIndexMap[info.name] = ndx; +}); + +const lutSettings = { + lut: lutNameIndexMap.identity, +}; +const gui = new GUI({ width: 300 }); +gui.add(lutSettings, 'lut', lutNameIndexMap); +``` + +๋งˆ์ง€๋ง‰์œผ๋กœ ํ•„ํ„ฐ๋ง ์—ฌ๋ถ€์— ๋”ฐ๋ผ ํšจ๊ณผ๊ฐ€ ๋ฐ”๋€Œ๋„๋ก ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. LUT๊ฐ€ ์„ ํƒํ•œ ํ…์Šค์ฒ˜๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ํ•˜๊ณ , `EffectComposer`๋กœ ๋ Œ๋”๋ง ํ•ฉ๋‹ˆ๋‹ค. + +```js +const lutInfo = lutTextures[lutSettings.lut]; + +const effect = lutInfo.filter ? effectLUT : effectLUTNearest; +effectLUT.enabled = lutInfo.filter; +effectLUTNearest.enabled = !lutInfo.filter; + +const lutTexture = lutInfo.texture; +effect.uniforms.lutMap.value = lutTexture; +effect.uniforms.lutMapSize.value = lutInfo.size; + +composer.render(delta); +``` + +identity 3DLUT๋ฅผ ์„ ํƒํ–ˆ์„ ๋•Œ๋Š” ์•„๋ฌด๋Ÿฐ ๋ณ€ํ™”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-postprocessing-3dlut-identity.html" }}} + +ํ•˜์ง€๋งŒ ํ•„ํ„ฐ๊ฐ€ identity not filtered LUT๋ฅผ ์„ ํƒํ•˜๋ฉด ์žฌ๋ฏธ์žˆ๋Š” ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/unfiltered-3dlut.jpg" style="width: 500px"></div> + +์™œ ์ด๋Ÿฐ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜จ ๊ฑธ๊นŒ์š”? ํ•„ํ„ฐ๋ง์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ(linear), GPU๋Š” ์„ ํ˜•์ ์œผ๋กœ ์ƒ‰์ƒ๊ฐ’์„ ์ฑ„์›Œ๋„ฃ์Šต๋‹ˆ๋‹ค. ํ•„ํ„ฐ๋ง์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ(nearest), ์•Œ์•„์„œ ์ƒ‰์ƒ๊ฐ’์„ ์ฑ„์›Œ๋„ฃ์ง€ ์•Š๊ธฐ์— 3DLUT์—์„œ(๊ทผ์ฒ˜์˜) ์ƒ‰์ƒ๊ฐ’์ด ์žˆ๋Š” ๊ณณ์„ ์ฐพ์•„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด์ฃ . + +์–ด๋А์ •๋„ ์ดํ•ดํ–ˆ๋‹ค๋ฉด ๋” ๋‹ค์–‘ํ•œ 3DLUT๋ฅผ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค. + +๋จผ์ € ๋ฃฉ์—… ํ…Œ์ด๋ธ”์˜ ํ•ด์ƒ๋„๋ฅผ ์ •ํ•˜๊ณ  ๊ฐ„๋‹จํ•œ ์ฝ”๋“œ๋ฅผ ๋งŒ๋“ค์–ด ๋ฃฉ์—… ํ…Œ์ด๋ธ” ์ •์œก๋ฉด์ฒด์˜ ๊ฐ ๋ฉด์„ ๋งŒ๋“ค๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +const ctx = document.querySelector('canvas').getContext('2d'); + +function drawColorCubeImage(ctx, size) { + const canvas = ctx.canvas; + canvas.width = size * size; + canvas.height = size; + + for (let zz = 0; zz < size; ++zz) { + for (let yy = 0; yy < size; ++yy) { + for (let xx = 0; xx < size; ++xx) { + const r = Math.floor(xx / (size - 1) * 255); + const g = Math.floor(yy / (size - 1) * 255); + const b = Math.floor(zz / (size - 1) * 255); + ctx.fillStyle = `rgb(${ r },${ g },${ b })`; + ctx.fillRect(zz * size + xx, yy, 1, 1); + } + } + } + document.querySelector('#width').textContent = canvas.width; + document.querySelector('#height').textContent = canvas.height; +} + +drawColorCubeImage(ctx, 8); +``` + +์บ”๋ฒ„์Šค ์š”์†Œ๋„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. + +```html +<canvas></canvas> +``` + +์ด์ œ ์–ด๋–ค identity 3D ๋ฃฉ์—… ํ…Œ์ด๋ธ”์ด๋“  ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +{{{example url="../3dlut-base-cube-maker.html" }}} + +ํ•ด์ƒ๋„๊ฐ€ ๋†’์„์ˆ˜๋ก ๋” ์„ธ๋ฐ€ํ•œ ํšจ๊ณผ๋ฅผ ์ค„ ์ˆ˜ ์žˆ์ง€๋งŒ ์ •์œก๋ฉด์ฒดํ˜• ๋ฐ์ดํ„ฐ์˜ ํฌ๊ธฐ๋Š” ๊ธฐํ•˜๊ธ‰์ˆ˜์ ์œผ๋กœ ๋Š˜์–ด๋‚ฉ๋‹ˆ๋‹ค. ํฌ๊ธฐ 8x8 ์ •์œก๋ฉด์ฒด๋Š” 2kb ์ •๋„์ง€๋งŒ 64x64 ์ •์œก๋ฉด์ฒด๋Š” ์•ฝ 1mb๋‚˜ ๋˜์ฃ . ๊ทธ๋Ÿฌ๋‹ˆ ์ถฉ๋ถ„ํžˆ ํšจ๊ณผ๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋Š” ๋งŒํผ๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค. + +์‚ฌ์ด์ฆˆ๋ฅผ 16์œผ๋กœ ์„ค์ •ํ•˜๊ณ  `Save...` ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ํŒŒ์ผ์ด ๋‚˜์˜ต๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/identity-lut-s16.png"></div> + +๊ทธ๋ฆฌ๊ณ  LUT๋ฅผ ์ ์šฉํ•  ํ™”๋ฉด์„ ์บก์ณํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ์—๋Š” ์ด์ „์— ๋งŒ๋“  ์žฅ๋ฉด์— ์•„๋ฌด๋Ÿฐ ํšจ๊ณผ๋ฅผ ์ฃผ์ง€ ์•Š์€ ํ™”๋ฉด์ด๊ฒ ์ฃ . ๋Œ€๊ฒŒ ์œ„ ์˜ˆ์ œ๋ฅผ ์˜ค๋ฅธ์ชฝ ํด๋ฆญํ•ด "๋‹ค๋ฅธ ์ด๋ฆ„์œผ๋กœ ์ €์žฅ..."์„ ํด๋ฆญํ•˜๋ฉด ๋˜์ง€๋งŒ, OS์— ๋”ฐ๋ผ ๋งˆ์šฐ์Šค ์šฐํด๋ฆญ์ด ๋™์ž‘ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ œ ๊ฒฝ์šฐ OS์— ๋‚ด์žฅ๋œ ์Šคํฌ๋ฆฐ์ƒท ๊ธฐ๋Šฅ์„ ์ด์šฉํ•ด ํ™”๋ฉด์„ ์บก์ณํ–ˆ์Šต๋‹ˆ๋‹ค*. + +โ€ป Windows 10 RS5(๋ ˆ๋“œ์Šคํ†ค 5) ์ด์ƒ์ด๋ผ๋ฉด `Windows + Shift + S`๋ฅผ ๋ˆŒ๋Ÿฌ ํ™”๋ฉด์„ ์บก์ณํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์—ญ์ฃผ. + +<div class="threejs_center"><img src="resources/images/3dlut-screen-capture.jpg" style="width: 600px"></div> + +์บก์ณ๋ณธ์„ ์ด๋ฏธ์ง€ ์—๋””ํ„ฐ์—์„œ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค. ์ €๋Š” ํฌํ† ์ƒต์„ ์‚ฌ์šฉํ•ด ์ƒ˜ํ”Œ ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ณ , ํ•œ์ชฝ ๊ท€ํ‰์ด์— 3DLUT๋ฅผ ๋ถ™์—ฌ ๋„ฃ์—ˆ์Šต๋‹ˆ๋‹ค. + +> ์ฐธ๊ณ : ์ œ ๊ฒฝ์šฐ ํฌํ† ์ƒต์—์„œ ์บก์ณ๋ณธ ์œ„์— lut ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๋ ค๊ณ  ํ–ˆ์„ ๋•Œ ์ด๋ฏธ์ง€๊ฐ€ ๋‘ ๋ฐฐ ๋” ์ปค์กŒ์Šต๋‹ˆ๋‹ค. ์•„๋งˆ DPI๋ฅผ ๋งž์ถ”๊ฑฐ๋‚˜ ํ•˜๋Š” ์ด์œ  ๋•Œ๋ฌธ์— ๊ทธ๋Ÿฐ ๊ฑฐ๊ฒ ์ฃ . lut ํŒŒ์ผ์„ ๋ณ„๋„ ํƒญ์— ๋ถˆ๋Ÿฌ์™€ ์บก์ณ๋ณธ ์œ„์— ๋ณต์‚ฌ ๋ถ™์—ฌ ๋„ฃ๊ธฐ ํ•˜๋‹ˆ ์ •์ƒ์ ์œผ๋กœ ๋ถˆ๋Ÿฌ์™€์ง€๋”๊ตฐ์š”. + +<div class="threejs_center"><img src="resources/images/3dlut-photoshop-before.jpg" style="width: 600px"></div> + +๊ทธ๋ฆฌ๊ณ  ์ด๋ฏธ์ง€์— ๋ถ€์—ฌํ•˜๊ณ  ์‹ถ์€ ์ƒ‰์ƒ ํšจ๊ณผ๋ฅผ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค. ํฌํ† ์ƒต์˜ ๊ฒฝ์šฐ ๋Œ€๋ถ€๋ถ„์˜ ํšจ๊ณผ๋Š” ์ด๋ฏธ์ง€(Image)->์กฐ์ •(Adjustments) ๋ฉ”๋‰ด์— ์žˆ์Šต๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/3dlut-photoshop-after.jpg" style="width: 600px"></div> + +์ƒ‰์ƒ์„ ์กฐ์ •ํ•˜๋ฉด 3DLUT ์ด๋ฏธ์ง€์—๋„ ๊ฐ™์€ ํšจ๊ณผ๊ฐ€ ์ ์šฉ๋  ๊ฒ๋‹ˆ๋‹ค. + +์ž ๊ทธ๋Ÿผ ์ด์ œ ์ด๊ฑธ ์–ด๋–ป๊ฒŒ ์“ธ ์ˆ˜ ์žˆ์„๊นŒ์š”? + +๋จผ์ € ์ €๋Š” 3DLUT ์ด๋ฏธ์ง€๋ฅผ `3dlut-red-only-s16.png`๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ์ €์žฅํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์•„๋ผ๋ ค๋ฉด ์ด๋ฏธ์ง€๋ฅผ LUT ๋ถ€๋ถ„๋งŒ ์ž˜๋ผ 16x256๋กœ ๋งž์ถ”๋Š” ๊ฒƒ์ด ์ข‹์ง€๋งŒ, ๊ทธ๋ƒฅ ์žฌ๋ฏธ์‚ผ์•„ ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜จ ์ดํ›„ ์ž๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค*. ์ด ๋ฐฉ๋ฒ•์˜ ์žฅ์ ์€ ๊ท€์ฐฎ๊ฒŒ ์ด๋ฏธ์ง€๋ฅผ ์ž๋ฅด๋Š” ๊ณผ์ • ์—†์ด ํšจ๊ณผ๋ฅผ ์ ์šฉํ•ด๋ณด๊ณ  ์‹ถ์€ ๋Œ€๋กœ ๋ฐ”๋กœ๋ฐ”๋กœ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด์ฃ . ๋ฌผ๋ก  ๋Œ€์—ญํญ์„ ๋‚ญ๋น„ํ•œ๋‹ค๋Š” ๊ฒŒ ๋‹จ์ ์ž…๋‹ˆ๋‹ค. + +โ€ป ํฌํ† ์ƒต CC ์ดํ›„ ๋ฒ„์ ผ์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋ ˆ์ด์–ด๋ฅผ ์˜ค๋ฅธ์ชฝ ํด๋ฆญํ•ด `PNG๋กœ ๋น ๋ฅด๊ฒŒ ๋‚ด๋ณด๋‚ด๊ธฐ` ๋ฉ”๋‰ด๋กœ ํ•ด๋‹น ๊ทธ๋ฃน ๋˜๋Š” ๋ ˆ์ด์–ด๋งŒ .png ํŒŒ์ผ๋กœ ๋‚ด๋ณด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฏธ์ง€๋ฅผ ๊ท€์ฐฎ๊ฒŒ ์ž๋ฅด๋Š” ๊ณผ์ • ์—†์ด .png ํŒŒ์ผ์„ ๋ฐ”๋กœ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์ฃ . ์—ญ์ฃผ. + +์•„๋ž˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. ์‹ค์ œ ์ฝ”๋“œ์—์„œ๋Š” ํ…์Šค์ฒ˜๋ฅผ ๋ถˆ๋Ÿฌ์™”์„ ๋•Œ ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก identity lut๋ฅผ ๋จผ์ € ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ๋‹ค์Œ ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์™€ 3DLUT ๋ถ€๋ถ„๋งŒ ์บ”๋ฒ„์Šค์— ๋ณต์‚ฌํ•˜๊ณ , ์บ”๋ฒ„์Šค์—์„œ ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์Šค์ฒ˜์— ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ํ…์Šค์ฒ˜๊ฐ€ ๋ฐ”๋€Œ์—ˆ์„ ๋•Œ ๋ฐ”๋กœ ์ ์šฉํ•˜๋„๋ก `needsUpdate` ์†์„ฑ๋„ true๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. + +```js +const makeLUTTexture = function() { + const imgLoader = new THREE.ImageLoader(); + const ctx = document.createElement('canvas').getContext('2d'); + + return function(info) { + const texture = makeIdentityLutTexture( + info.filter ? THREE.LinearFilter : THREE.NearestFilter); + + if (info.url) { + const lutSize = info.size; + + /** + * ํฌ๊ธฐ๋ฅผ 2(identity LUT์˜ ํฌ๊ธฐ)๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ด ํฌ๊ธฐ๋Š” ๋‚˜์ค‘์— ์ด๋ฏธ์ง€๋ฅผ + * ๋ถˆ๋Ÿฌ์˜จ ๋’ค ๋ณต์›ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด lut๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ๋Š” ์ด๋ฏธ์ง€์˜ ์ ์šฉ ์—ฌ๋ถ€๋ฅผ + * ์‹ ๊ฒฝ์“ฐ์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค. + **/ + info.size = 2; + + imgLoader.load(info.url, function(image) { + const width = lutSize * lutSize; + const height = lutSize; + info.size = lutSize; + ctx.canvas.width = width; + ctx.canvas.height = height; + ctx.drawImage(image, 0, 0); + const imageData = ctx.getImageData(0, 0, width, height); + + texture.image.data = new Uint8Array(imageData.data.buffer); + texture.image.width = width; + texture.image.height = height; + texture.needsUpdate = true; + }); + } + + return texture; + }; +}(); +``` + +๊ธฐ์กด ์ฝ”๋“œ๊ฐ€ LUT png ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋„๋ก ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. + +```js +const lutTextures = [ + { name: 'identity', size: 2, filter: true , }, + { name: 'identity no filter', size: 2, filter: false, }, ++ { name: 'custom', url: 'resources/images/lut/3dlut-red-only-s16.png' }, +]; + ++lutTextures.forEach((info) => { ++ // ์‚ฌ์ด์ฆˆ๊ฐ’์ด ์—†๋‹ค๋ฉด ์‚ฌ์ด์ฆˆ ์ •๋ณด๋ฅผ ํŒŒ์ผ ์ด๋ฆ„์—์„œ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. ++ if (!info.size) { ++ /** ++ * ํŒŒ์ผ ์ด๋ฆ„์ด '-s<์ˆซ์ž>[n]' ์ด๋ ‡๊ฒŒ ๋๋‚œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. ++ * <์ˆซ์ž>๋Š” 3DLUT ์ •์œก๋ฉด์ฒด์˜ ํฌ๊ธฐ์ž…๋‹ˆ๋‹ค. ++ * [n]์€ 'ํ•„ํ„ฐ๋ง ์—†์Œ' ๋˜๋Š” 'nearest'๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ++ * ++ * ์˜ˆ์‹œ: ++ * 'foo-s16.png' = ํฌ๊ธฐ:16, ํ•„ํ„ฐ: true ++ * 'bar-s8n.png' = ํฌ๊ธฐ:8, ํ•„ํ„ฐ: false ++ **/ ++ const m = /-s(\d+)(n*)\.[^.]+$/.exec(info.url); ++ if (m) { ++ info.size = parseInt(m[1]); ++ info.filter = info.filter === undefined ? m[2] !== 'n' : info.filter; ++ } ++ } ++ ++ info.texture = makeLUTTexture(info); ++}); +``` + +์œ„ ์ฝ”๋“œ๊ฐ€ LUT์˜ ์‚ฌ์ด์ฆˆ๋ฅผ ํŒŒ์ผ ์ด๋ฆ„์— ์ธ์ฝ”๋”ฉํ•œ ์˜ˆ์ž…๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด png๋กœ LUT๋ฅผ ๋ฐ”๊พธ๊ธฐ๊ฐ€ ํ›จ์”ฌ ์‰ฝ์ฃ . + +๊ทธ๋ƒฅ์€ ์ข€ ์‹ฌ์‹ฌํ•˜๋‹ˆ lut png ํŒŒ์ผ์„ ๋” ๋งŽ์ด ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค. + +```js +const lutTextures = [ + { name: 'identity', size: 2, filter: true , }, + { name: 'identity no filter', size: 2, filter: false, }, + { name: 'custom', url: 'resources/images/lut/3dlut-red-only-s16.png' }, ++ { name: 'monochrome', url: 'resources/images/lut/monochrome-s8.png' }, ++ { name: 'sepia', url: 'resources/images/lut/sepia-s8.png' }, ++ { name: 'saturated', url: 'resources/images/lut/saturated-s8.png', }, ++ { name: 'posterize', url: 'resources/images/lut/posterize-s8n.png', }, ++ { name: 'posterize-3-rgb', url: 'resources/images/lut/posterize-3-rgb-s8n.png', }, ++ { name: 'posterize-3-lab', url: 'resources/images/lut/posterize-3-lab-s8n.png', }, ++ { name: 'posterize-4-lab', url: 'resources/images/lut/posterize-4-lab-s8n.png', }, ++ { name: 'posterize-more', url: 'resources/images/lut/posterize-more-s8n.png', }, ++ { name: 'inverse', url: 'resources/images/lut/inverse-s8.png', }, ++ { name: 'color negative', url: 'resources/images/lut/color-negative-s8.png', }, ++ { name: 'high contrast', url: 'resources/images/lut/high-contrast-bw-s8.png', }, ++ { name: 'funky contrast', url: 'resources/images/lut/funky-contrast-s8.png', }, ++ { name: 'nightvision', url: 'resources/images/lut/nightvision-s8.png', }, ++ { name: 'thermal', url: 'resources/images/lut/thermal-s8.png', }, ++ { name: 'b/w', url: 'resources/images/lut/black-white-s8n.png', }, ++ { name: 'hue +60', url: 'resources/images/lut/hue-plus-60-s8.png', }, ++ { name: 'hue +180', url: 'resources/images/lut/hue-plus-180-s8.png', }, ++ { name: 'hue -60', url: 'resources/images/lut/hue-minus-60-s8.png', }, ++ { name: 'red to cyan', url: 'resources/images/lut/red-to-cyan-s8.png' }, ++ { name: 'blues', url: 'resources/images/lut/blues-s8.png' }, ++ { name: 'infrared', url: 'resources/images/lut/infrared-s8.png' }, ++ { name: 'radioactive', url: 'resources/images/lut/radioactive-s8.png' }, ++ { name: 'goolgey', url: 'resources/images/lut/googley-s8.png' }, ++ { name: 'bgy', url: 'resources/images/lut/bgy-s8.png' }, +]; +``` + +์•„๋ž˜ ์˜ˆ์ œ์—์„œ ์—ฌ๋Ÿฌ lut๋ฅผ ์‹œํ—˜ํ•ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-postprocessing-3dlut.html" }}} + +์ถ”๊ฐ€๋กœ ํ•œ ๊ฐ€์ง€ ๋ง๋ถ™์ด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ธํ„ฐ๋„ท์„ ๋’ค์ ธ๋ณด๋‹ˆ Adobe์—์„œ ๋งŒ๋“  ํ‘œ์ค€ LUT ํ˜•์‹์ด ์žˆ๋”๊ตฐ์š”. [์ธํ„ฐ๋„ท์—์„œ ๊ฒ€์ƒ‰](https://www.google.com/search?q=lut+files)ํ•ด๋ณด๋ฉด ์ด๋Ÿฐ LUT ํ˜•์‹์˜ ํŒŒ์ผ์„ ์‰ฝ๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค. + +์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋กœ๋”๋ฅผ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด 4๊ฐ€์ง€ ํ˜•์‹์ด ์žˆ๋‹ค๊ณ ๋Š” ํ•˜๋‚˜, ์ œ๊ฐ€ ์ฐพ์€ ํ˜•์‹์€ ํ•˜๋‚˜๋ฟ์ด๋ผ ๋ชจ๋“  ํ˜•์‹์—์„œ ํ…Œ์ŠคํŠธํ•˜์ง„ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. + +์—ฌ๊ธฐ์— ๊ฐ„๋‹จํ•œ ๋“œ๋ž˜๊ทธ-์•ค-๋“œ๋กญ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์ด ๋‘ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•ด ์—ฌ๋Ÿฌ๋ถ„์ด ์ง์ ‘ LUT ํŒŒ์ผ์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ง์ด์ฃ . + +๋จผ์ € ์•ž์„œ ๋งŒ๋“  ๋‘ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋ถˆ๋Ÿฌ์˜จ ๋’ค + +```js +import * as lutParser from './resources/lut-reader.js'; +import * as dragAndDrop from './resources/drag-and-drop.js'; +``` + +์•„๋ž˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +```js +dragAndDrop.setup({ msg: 'Drop LUT File here' }); +dragAndDrop.onDropFile(readLUTFile); + +function readLUTFile(file) { + const reader = new FileReader(); + reader.onload = (e) => { + const lut = lutParser.lutTo2D3Drgb8(lutParser.parse(e.target.result)); + const {size, data, name} = lut; + const texture = new THREE.DataTexture(data, size * size, size, THREE.RGBFormat); + texture.minFilter = THREE.LinearFilter; + texture.needsUpdate = true; + texture.flipY = false; + const lutTexture = { + name: (name && name.toLowerCase().trim() !== 'untitled') + ? name + : file.name, + size: size, + filter: true, + texture, + }; + lutTextures.push(lutTexture); + lutSettings.lut = lutTextures.length - 1; + updateGUI(); + }; + + reader.readAsText(file); +} +``` + +GUI๊ฐ€ ์ƒˆ๋กœ ๋ถˆ๋Ÿฌ์˜จ ํŒŒ์ผ์„ ๋ฐ˜์˜ํ•˜๋„๋ก ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +const lutSettings = { + lut: lutNameIndexMap.thermal, +}; +const gui = new GUI({ width: 300 }); +gui.addFolder('Choose LUT or Drag&Drop LUT File(s)'); + +let lutGUI; +function updateGUI() { + makeLutNameIndexMap(); + if (lutGUI) { + gui.remove(lutGUI); + } + lutGUI = gui.add(lutSettings, 'lut', lutNameIndexMap); +} +updateGUI(); +``` + +์ด์ œ [Adobe LUT ํŒŒ์ผ](https://www.google.com/search?q=lut+files)์„ ๋‹ค์šดํ•ด ์•„๋ž˜ ์˜ˆ์ œ์— ๋“œ๋ž˜๊ทธ-์•ค-๋“œ๋กญ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค. + +{{{example url="../threejs-postprocessing-3dlut-w-loader.html" }}} + +๋‹ค๋งŒ Adobe LUT๋Š” ์˜จ๋ผ์ธ ํ™˜๊ฒฝ์— ์ตœ์ ํ™”๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ํŒŒ์ผ ์šฉ๋Ÿ‰์ด ๊ฝค ํฐ ํŽธ์ด์ฃ . ์•„๋ž˜ ์˜ˆ์ œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์šฉ๋Ÿ‰์„ ์ข€ ๋” ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋“œ๋ž˜๊ทธ-์•ค-๋“œ๋กญ์œผ๋กœ ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๊ณ  ํฌ๊ธฐ๋ฅผ ์„ ํƒํ•œ ๋’ค "Save..." ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ๋˜์ฃ . + +์•„๋ž˜ ์˜ˆ์ œ๋Š” ๋‹จ์ˆœํžˆ ์œ„์—์„œ ์ผ๋˜ ์˜ˆ์ œ๋ฅผ ์กฐ๊ธˆ ์ˆ˜์ •ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. glFT ํŒŒ์ผ ์—†์ด ๋ฐฐ๊ฒฝ๋งŒ ๋ Œ๋”๋งํ•œ ๊ฒƒ์ด์ฃ . ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋Š” ์•„๊นŒ ๋ณธ ์Šคํฌ๋ฆฝํŠธ๋กœ ๋งŒ๋“  identity lut ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์— LUT ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์™€ ํ•ด๋‹น LUT ํŒŒ์ผ์„ PNG๋กœ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด์ฃ . + +{{{example url="../threejs-postprocessing-adobe-lut-to-png-converter.html" }}} + +์ด ๊ธ€์—์„œ๋Š” ์‰์ด๋”๊ฐ€ ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋Š”์ง€์— ๋Œ€ํ•ด์„œ๋Š” ์•„์˜ˆ ์„ค๋ช…ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ๋‚˜์ค‘์— GLSL์— ๋Œ€ํ•ด ๋” ๋‹ค๋ฃฐ ๊ธฐํšŒ๊ฐ€ ์žˆ์—ˆ์œผ๋ฉด ์ข‹๊ฒ ๋„ค์š”. ์‰์ด๋”์˜ ์ž‘๋™ ๋ฐฉ์‹์„ ์•Œ๊ณ  ์‹ถ๋‹ค๋ฉด [ํ›„์ฒ˜๋ฆฌ์— ๊ด€ํ•œ ๊ธ€](threejs-post-processing.html)์— ์žˆ๋Š” ๋งํฌ ๋˜๋Š” [์ด ์œ ํŠœ๋ธŒ ์˜์ƒ](https://www.youtube.com/watch?v=rfQ8rKGTVlg#t=24m30s)์„ ์ฐธ๊ณ ํ•˜๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. + +<script type="module" src="../resources/threejs-post-processing-3dlut.js"></script>
true
Other
mrdoob
three.js
633dbb61bdfd242077b4c012fce7468c1e707c1a.json
add translation kr/threejs-rendering-on-demand.md add translation kr/threejs-transparency.md update translation kr/threejs-prerequisites.md add translation kr/threejs-multiple-scenes.md add translation kr/threejs-picking.md fix typo & add translation kr/threejs-post-processing.md add translation kr/threejs-post-processing-3dlut.md
threejs/lessons/kr/threejs-post-processing.md
@@ -0,0 +1,254 @@ +Title: Three.js ํ›„์ฒ˜๋ฆฌ +Description: Three.js๋กœ ํ›„์ฒ˜๋ฆฌํ•˜๋Š” ๋ฒ•์„ ์•Œ์•„๋ด…๋‹ˆ๋‹ค +TOC: ํ›„์ฒ˜๋ฆฌ + +*ํ›„์ฒ˜๋ฆฌ(post processing)*๋ž€ ๋ณดํ†ต 2D ์ด๋ฏธ์ง€์— ์–ด๋–ค ํšจ๊ณผ๋‚˜ ํ•„ํ„ฐ๋ฅผ ๋„ฃ๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. Three.js๋Š” ๋‹ค์–‘ํ•œ mesh๋กœ ์ด๋ฃจ์–ด์ง„ ์žฅ๋ฉด์„ 2D ์ด๋ฏธ์ง€๋กœ ๋ Œ๋”๋งํ•˜์ฃ . ์ผ๋ฐ˜์ ์œผ๋กœ ์ด ์ด๋ฏธ์ง€๋Š” ๋ฐ”๋กœ ์บ”๋ฒ„์Šค๋ฅผ ํ†ตํ•ด ๋ธŒ๋ผ์šฐ์ € ํ™”๋ฉด์— ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋Œ€์‹  ์ด ์ด๋ฏธ์ง€๋ฅผ [๋ Œ๋” ํƒ€๊ฒŸ์— ๋ Œ๋”๋งํ•˜๊ณ ](threejs-rendertargets.html) ์บ”๋ฒ„์Šค์— ๋ณด๋‚ด๊ธฐ ์ „ ์ž„์˜์˜ *ํ›„์ฒ˜๋ฆฌ* ํšจ๊ณผ๋ฅผ ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์ธ์Šคํƒ€๊ทธ๋žจ ํ•„ํ„ฐ, ํฌํ† ์ƒต ํ•„ํ„ฐ ๋“ฑ์ด ํ›„์ฒ˜๋ฆฌ์˜ ์ข‹์€ ์˜ˆ์ด์ฃ . + +Three.js์—๋Š” ํ›„์ฒ˜๋ฆฌ๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์ฃผ๋Š” ๋ชจ๋ฒ” ํด๋ž˜์Šค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ผ๋‹จ `EffectComposer`์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์—ฌ๊ธฐ์— `Pass` ๊ฐ์ฒด(ํšจ๊ณผ, ํ•„ํ„ฐ)๋“ค์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  `EffectComposer.render` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ํ˜„์žฌ ์žฅ๋ฉด์„ [๋ Œ๋” ํƒ€๊ฒŸ](threejs-rendertargets.html)์— ๋ Œ๋”๋งํ•œ ๋’ค ๊ฐ pass*๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. + +โ€ป ํŽธ์˜์ƒ `Pass` ์ธ์Šคํ„ด์Šค๋ฅผ pass๋กœ ๋ฒˆ์—ญํ•ฉ๋‹ˆ๋‹ค. + +์ด pass๋Š” ๋น„๋„ท(vignette), ํ๋ฆผ(blur), ๋ธ”๋ฃธ(bloom), ํ•„๋ฆ„ ๊ทธ๋ ˆ์ธ(film grain) ํšจ๊ณผ ๋˜๋Š” hue, ์ฑ„๋„(saturation), ๋Œ€๋น„(contrast) ์กฐ์ • ๋“ฑ์˜ ํ›„์ฒ˜๋ฆฌ ํšจ๊ณผ๋กœ, ์ด ํšจ๊ณผ๋ฅผ ๋ชจ๋‘ ์ ์šฉํ•œ ๊ฒฐ๊ณผ๋ฌผ์„ ์ตœ์ข…์ ์œผ๋กœ ์บ”๋ฒ„์Šค์— ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. + +์—ฌ๊ธฐ์„œ ์–ด๋А ์ •๋„ `EffectComposer`์˜ ์›๋ฆฌ๋ฅผ ์ดํ•ดํ•  ํ•„์š”๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. `EffectComposer`๋Š” ๋‘ ๊ฐœ์˜ [๋ Œ๋” ํƒ€๊ฒŸ](threejs-rendertargets.html)์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ํŽธ์˜์ƒ ์ด ๋‘˜์„ **rtA**, **rtB**๋ผ๊ณ  ๋ถ€๋ฅด๋„๋ก ํ•˜์ฃ . + +`EffectComposer.addPass`๋ฅผ ๊ฐ pass๋ฅผ ์ ์šฉํ•  ์ˆœ์„œ๋Œ€๋กœ ํ˜ธ์ถœํ•˜๊ณ  `EffectComposer.render`๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด pass*๋Š” ์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์€ ์ˆœ์„œ๋กœ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/threejs-postprocessing.svg" style="width: 600px"></div> + +๋จผ์ € `RenderPass`์— ๋„˜๊ธด ์žฅ๋ฉด์„ **rtA**์— ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  **rtA**๋ฅผ ๋‹ค์Œ pass์— ๋„˜๊ฒจ์ฃผ๋ฉด ํ•ด๋‹น pass๋Š” **rtA**์— pass๋ฅผ ์ ์šฉํ•œ ๊ฒฐ๊ณผ๋ฅผ **rtB**์— ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ **rtB**๋ฅผ ๋‹ค์Œ pass๋กœ ๋„˜๊ฒจ ์ ์šฉํ•œ ๊ฒฐ๊ณผ๋ฅผ **rtA**์—, **rtA**์— pass๋ฅผ ์ ์šฉํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋‹ค์‹œ **rtB**์—, ์ด๋Ÿฐ ์‹์œผ๋กœ ๋ชจ๋“  pass๊ฐ€ ๋๋‚  ๋•Œ๊นŒ์ง€ ๊ณ„์† ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค. + +`Pass`์—๋Š” ๊ณตํ†ต์ ์œผ๋กœ 4๊ฐ€์ง€ ์˜ต์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค. + +## `enabled` + +์ด pass๋ฅผ ์‚ฌ์šฉํ• ์ง€์˜ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค. + +## `needsSwap` + +์ด pass๋ฅผ ์ ์šฉํ•œ ํ›„ `rtA`์™€ `rtB`๋ฅผ ๋ฐ”๊ฟ€์ง€์˜ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค. + +## `clear` + +์ด pass๋ฅผ ์ ์šฉํ•˜๊ธฐ ์ „์— ํ™”๋ฉด์„ ์ดˆ๊ธฐํ™”ํ• ์ง€์˜ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค. + +## `renderToScreen` + +์ง€์ •ํ•œ ๋ Œ๋” ํƒ€๊ฒŸ์ด ์•„๋‹Œ ์บ”๋ฒ„์Šค์— ๋ Œ๋”๋งํ• ์ง€์˜ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค. ๋ณดํ†ต `EffectComposer`์— ์ถ”๊ฐ€ํ•˜๋Š” ๋งˆ์ง€๋ง‰ pass์— ์ด ์˜ต์…˜์„ true๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. + +๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค. [๋ฐ˜์‘ํ˜• ๋””์ž์ธ์— ๊ด€ํ•œ ๊ธ€](threejs-responsive.html)์—์„œ ์ผ๋˜ ์˜ˆ์ œ๋ฅผ ๊ฐ€์ ธ์˜ค๊ฒ ์Šต๋‹ˆ๋‹ค. + +์ถ”๊ฐ€๋กœ ๋จผ์ € `EffectComposer` ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +```js +const composer = new EffectComposer(renderer); +``` + +๋‹ค์Œ์œผ๋กœ `RenderPass`๋ฅผ ์ฒซ pass๋กœ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ์ด pass๋Š” ๋„˜๊ฒจ ๋ฐ›์€ ์žฅ๋ฉด์„ ์ฒซ ๋ Œ๋” ํƒ€๊ฒŸ์— ๋ Œ๋”๋งํ•  ๊ฒ๋‹ˆ๋‹ค. + +```js +composer.addPass(new RenderPass(scene, camera)); +``` + +๋‹ค์Œ์œผ๋กœ `BloomPass`๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. `BloomPass`๋Š” ์žฅ๋ฉด์„ ์›๋ž˜์˜ ์žฅ๋ฉด๋ณด๋‹ค ์ž‘๊ฒŒ ๋ Œ๋”๋งํ•ด ํ๋ฆผ(blur) ํšจ๊ณผ๋ฅผ ์ค๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํšจ๊ณผ๊ฐ€ ์ ์šฉ๋œ ์žฅ๋ฉด์„ ์›๋ž˜ ์žฅ๋ฉด์— ๋ฎ์–ด ์”Œ์šฐ๋Š” ์‹์œผ๋กœ *๋ธ”๋ฃธ* ํšจ๊ณผ๋ฅผ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค. + +```js +const bloomPass = new BloomPass( + 1, // ๊ฐ•๋„ + 25, // ์ปค๋„(kernel) ํฌ๊ธฐ + 4, // ์‹œ๊ทธ๋งˆ ? + 256, // ๋ Œ๋” ํƒ€๊ฒŸ์˜ ํ•ด์ƒ๋„๋ฅผ ๋‚ฎ์ถค +); +composer.addPass(bloomPass); +``` + +๋งˆ์ง€๋ง‰์œผ๋กœ ์›๋ณธ ์žฅ๋ฉด์— ๋…ธ์ด์ฆˆ์™€ ์Šค์บ”๋ผ์ธ(scanline)์„ ์ถ”๊ฐ€ํ•˜๋Š” `FilmPass`๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +const filmPass = new FilmPass( + 0.35, // ๋…ธ์ด์ฆˆ ๊ฐ•๋„ + 0.025, // ์Šค์บ”๋ผ์ธ ๊ฐ•๋„ + 648, // ์Šค์บ”๋ผ์ธ ๊ฐœ์ˆ˜ + false, // ํ‘๋ฐฑ +); +filmPass.renderToScreen = true; +composer.addPass(filmPass); +``` + +`filmPass`๊ฐ€ ๋งˆ์ง€๋ง‰ pass์ด๊ธฐ์— ์บ”๋ฒ„์Šค์— ๊ฒฐ๊ณผ๋ฅผ ๋ฐ”๋กœ ๋ Œ๋”๋งํ•˜๋„๋ก `renderToScreen` ์˜ต์…˜์„ true๋กœ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ์˜ต์…˜์„ ์„ค์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ์บ”๋ฒ„์Šค๊ฐ€ ์•„๋‹Œ ๋‹ค์Œ ๋ Œ๋” ํƒ€๊ฒŸ์— ์žฅ๋ฉด์„ ๋ Œ๋”๋งํ•  ๊ฑฐ์˜ˆ์š”. + +๋˜ ์ด ํด๋ž˜์Šค๋“ค์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์—ฌ๋Ÿฌ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋ถˆ๋Ÿฌ์™€์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +```js +import { EffectComposer } from './resources/threejs/r115/examples/jsm/postprocessing/EffectComposer.js'; +import { RenderPass } from './resources/threejs/r115/examples/jsm/postprocessing/RenderPass.js'; +import { BloomPass } from './resources/threejs/r115/examples/jsm/postprocessing/BloomPass.js'; +import { FilmPass } from './resources/threejs/r115/examples/jsm/postprocessing/FilmPass.js'; +``` + +๋Œ€๋ถ€๋ถ„์˜ ํ›„์ฒ˜๋ฆฌ์—๋Š” `EffectComposer.js`์™€ `RenderPass.js`๊ฐ€ ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค. + +์ด์ œ `WebGLRenderer.render` ๋Œ€์‹  `EffectComposer.render`๋ฅผ ์‚ฌ์šฉ*ํ•˜๊ณ * `EffectComposer`๊ฐ€ ๊ฒฐ๊ณผ๋ฌผ์„ ์บ”๋ฒ„์Šค์˜ ํฌ๊ธฐ์— ๋งž์ถ”๋„๋ก ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +```js +-function render(now) { +- time *= 0.001; ++let then = 0; ++function render(now) { ++ now *= 0.001; // ์ดˆ ๋‹จ์œ„๋กœ ๋ณ€ํ™˜ ++ const deltaTime = now - then; ++ then = now; + + if (resizeRendererToDisplaySize(renderer)) { + const canvas = renderer.domElement; + camera.aspect = canvas.clientWidth / canvas.clientHeight; + camera.updateProjectionMatrix(); ++ composer.setSize(canvas.width, canvas.height); + } + + cubes.forEach((cube, ndx) => { + const speed = 1 + ndx * .1; +- const rot = time * speed; ++ const rot = now * speed; + cube.rotation.x = rot; + cube.rotation.y = rot; + }); + +- renderer.render(scene, camera); ++ composer.render(deltaTime); + + requestAnimationFrame(render); +} +``` + +`EffectComposer.render` ๋ฉ”์„œ๋“œ๋Š” ์ธ์ž๋กœ ๋งˆ์ง€๋ง‰ ํ”„๋ ˆ์ž„์„ ๋ Œ๋”๋งํ•œ ์ดํ›„์˜ ์‹œ๊ฐ„๊ฐ’์ธ `deltaTime`์„ ์ธ์ž๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค. pass์— ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ํ•„์š”ํ•  ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•ด ์ด ๊ฐ’์„ ๋„˜๊ฒจ์ฃผ๊ธฐ ์œ„ํ•ด์„œ์ด์ฃ . ์˜ˆ์ œ์˜ ๊ฒฝ์šฐ์—๋Š” `FilmPass`์— ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-postprocessing.html" }}} + +๋Ÿฐํƒ€์ž„์— ํšจ๊ณผ์˜ ์†์„ฑ์„ ๋ณ€๊ฒฝํ•  ๋•Œ๋Š” ๋ณดํ†ต uniform์˜ value ๊ฐ’์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. GUI๋ฅผ ์ถ”๊ฐ€ํ•ด ์ด ์†์„ฑ์„ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์–ด๋ณด์ฃ . ์–ด๋–ค ์†์„ฑ์„ ์–ด๋–ป๊ฒŒ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ๋Š”์ง€๋Š” ํ•ด๋‹น ํšจ๊ณผ์˜ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์—ด์–ด๋ด์•ผ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +[`BloomPass.js`](https://github.com/mrdoob/three.js/blob/master/examples/js/postprocessing/BloomPass.js)์—์„œ +์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค. + +```js +this.copyUniforms[ "opacity" ].value = strength; +``` + +์•„๋ž˜์ฒ˜๋Ÿผ ํ•˜๋ฉด ๊ฐ•๋„๋ฅผ ๋Ÿฐํƒ€์ž„์— ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”. + +```js +bloomPass.copyUniforms.opacity.value = someValue; +``` + +๋งˆ์ฐฌ๊ฐ€์ง€๋กœ [`FilmPass.js`](https://github.com/mrdoob/three.js/blob/master/examples/js/postprocessing/FilmPass.js)์—์„œ +์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค. + +```js +if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale; +if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity; +if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity; +if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount; +``` + +์ด์ œ ์–ด๋–ป๊ฒŒ ๊ฐ’์„ ์ง€์ •ํ•ด์•ผ ํ•˜๋Š”์ง€ ์•Œ์•˜์œผ๋‹ˆ ์ด ๊ฐ’์„ ์กฐ์ž‘ํ•˜๋Š” GUI๋ฅผ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค. + +```js +import { GUI } from '../3rdparty/dat.gui.module.js'; +``` + +์ผ๋‹จ ๋ชจ๋“ˆ์„ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค. + +```js +const gui = new GUI(); +{ + const folder = gui.addFolder('BloomPass'); + folder.add(bloomPass.copyUniforms.opacity, 'value', 0, 2).name('strength'); + folder.open(); +} +{ + const folder = gui.addFolder('FilmPass'); + folder.add(filmPass.uniforms.grayscale, 'value').name('grayscale'); + folder.add(filmPass.uniforms.nIntensity, 'value', 0, 1).name('noise intensity'); + folder.add(filmPass.uniforms.sIntensity, 'value', 0, 1).name('scanline intensity'); + folder.add(filmPass.uniforms.sCount, 'value', 0, 1000).name('scanline count'); + folder.open(); +} +``` + +์ด์ œ ๊ฐ ์„ค์ •์„ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-postprocessing-gui.html" }}} + +์—ฌ๊ธฐ๊นŒ์ง€ ์ž˜ ๋”ฐ๋ผ์™”๋‹ค๋ฉด ์ด์ œ ํšจ๊ณผ๋ฅผ ์ง์ ‘ ๋งŒ๋“ค์–ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +ํ›„์ฒ˜๋ฆฌ ํšจ๊ณผ๋Š” ์‰์ด๋”๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์‰์ด๋”๋Š” [GLSL (Graphics Library Shading Language)](https://www.khronos.org/files/opengles_shading_language.pdf)์ด๋ผ๋Š” ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ฃ . ์–ธ์–ด๊ฐ€ ๋ฐฉ๋Œ€ํ•ด ์ด ๊ธ€์—์„œ ์ „๋ถ€ ๋‹ค๋ฃจ๊ธฐ๋Š” ์–ด๋ ต์Šต๋‹ˆ๋‹ค. ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์•Œ์•„๋ณด๊ณ  ์‹ถ๋‹ค๋ฉด [์ด ๊ธ€](https://webglfundamentals.org/webgl/lessons/ko/webgl-shaders-and-glsl.html)๊ณผ [์‰์ด๋”๋ž€ ๋ฌด์—‡์ธ๊ฐ€(The Book of Shaders)](https://thebookofshaders.com/)๋ฅผ ์ฝ์–ด๋ณด๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. + +์ง์ ‘ ์˜ˆ์ œ๋ฅผ ๋งŒ๋“ค์–ด๋ณด๋Š” ๊ฒŒ ๋„์›€์ด ๋  ํ…Œ๋‹ˆ ๊ฐ„๋‹จํ•œ GLSL ํ›„์ฒ˜๋ฆฌ ์‰์ด๋”๋ฅผ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค. ์ด๋ฏธ์ง€์— ํŠน์ • ์ƒ‰์„ ํ˜ผํ•ฉํ•˜๋Š” ์‰์ด๋”๋ฅผ ๋งŒ๋“ค ๊ฒ๋‹ˆ๋‹ค. + +Three.js์—๋Š” ํ›„์ฒ˜๋ฆฌ๋ฅผ ๋„์™€์ฃผ๋Š” `ShaderPass` ํ—ฌํผ ํด๋ž˜์Šค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ธ์ž๋กœ vertex ์‰์ด๋”, fragment ์‰์ด๋”, ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๊ฐ์ฒด๋ฅผ ๋ฐ›์ฃ . ์ด ํด๋ž˜์Šค๋Š” ์ด์ „ pass์˜ ๊ฒฐ๊ณผ๋ฌผ์—์„œ ์–ด๋–ค ํ…์Šค์ฒ˜๋ฅผ ์ฝ์„์ง€, ๊ทธ๋ฆฌ๊ณ  `EffectComposer`์˜ ๋ Œ๋” ํƒ€๊ฒŸ๊ณผ ์บ”๋ฒ„์Šค ์ค‘ ์–ด๋””์— ๋ Œ๋”๋งํ• ์ง€๋ฅผ ๊ฒฐ์ •ํ•  ๊ฒ๋‹ˆ๋‹ค. + +์•„๋ž˜๋Š” ์ด์ „ pass์˜ ๊ฒฐ๊ณผ๋ฌผ์— ํŠน์ • ์ƒ‰์„ ํ˜ผํ•ฉํ•˜๋Š” ๊ฐ„๋‹จํ•œ ํ›„์ฒ˜๋ฆฌ ์‰์ด๋”์ž…๋‹ˆ๋‹ค. + +```js +const colorShader = { + uniforms: { + tDiffuse: { value: null }, + color: { value: new THREE.Color(0x88CCFF) }, + }, + vertexShader: ` + varying vec2 vUv; + void main() { + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1); + } + `, + fragmentShader: ` + varying vec2 vUv; + uniform sampler2D tDiffuse; + uniform vec3 color; + void main() { + vec4 previousPassColor = texture2D(tDiffuse, vUv); + gl_FragColor = vec4( + previousPassColor.rgb * color, + previousPassColor.a); + } + `, +}; +``` + +์œ„ ์ฝ”๋“œ์—์„œ `tDiffuse`๋Š” ์ด์ „ pass์˜ ๊ฒฐ๊ณผ๋ฌผ์„ ๋ฐ›์•„์˜ค๊ธฐ ์œ„ํ•œ ๊ฒƒ์œผ๋กœ ๊ฑฐ์˜ ๋ชจ๋“  ๊ฒฝ์šฐ์— ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ ๋ฐ”๋กœ ๋ฐ‘์— `color` ์†์„ฑ์„ Three.js์˜ `Color`๋กœ ์„ ์–ธํ–ˆ์Šต๋‹ˆ๋‹ค. + +๋‹ค์Œ์œผ๋กœ vertex ์‰์ด๋”๋ฅผ ์ž‘์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์œ„ ์ฝ”๋“œ์—์„œ ์ž‘์„ฑํ•œ vertex ์‰์ด๋”๋Š” ํ›„์ฒ˜๋ฆฌ์—์„œ ๊ฑฐ์˜ ํ‘œ์ค€์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ๋กœ, ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ๋ฐ”๊ฟ€ ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๋ญ”๊ฐ€ ๋งŽ์ด ์„ค์ •ํ•œ ๊ฒฝ์šฐ(์•„๊นŒ ์–ธ๊ธ‰ํ•œ ๋งํฌ ์ฐธ์กฐ)๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด `uv`, `projectionMatrix`, `modelViewMatrix`, `position` ๋ณ€์ˆ˜๋Š” Three.js๊ฐ€ ์•Œ์•„์„œ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. + +๋งˆ์ง€๋ง‰์œผ๋กœ fragment ์‰์ด๋”๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋กœ ์ด์ „ pass์—์„œ ๋„˜๊ฒจ์ค€ ๊ฒฐ๊ณผ๋ฌผ์˜ ํ”ฝ์…€ ์ƒ‰์ƒ๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```glsl +vec4 previousPassColor = texture2D(tDiffuse, vUv); +``` + +์—ฌ๊ธฐ์— ์ง€์ •ํ•œ ์ƒ‰์ƒ์„ ๊ณฑํ•ด `gl_FragColor`์— ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. + +```glsl +gl_FragColor = vec4( + previousPassColor.rgb * color, + previousPassColor.a); +``` + +์ถ”๊ฐ€๋กœ ๊ฐ„๋‹จํ•œ GUI๋ฅผ ๋งŒ๋“ค์–ด rgb์˜ ๊ฐ ์ƒ‰์ƒ๊ฐ’์„ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +const gui = new GUI(); +gui.add(colorPass.uniforms.color.value, 'r', 0, 4).name('red'); +gui.add(colorPass.uniforms.color.value, 'g', 0, 4).name('green'); +gui.add(colorPass.uniforms.color.value, 'b', 0, 4).name('blue'); +``` + +์ƒ‰์„ ํ˜ผํ•ฉํ•˜๋Š” ๊ฐ„๋‹จํ•œ ํ›„์ฒ˜๋ฆฌ ์‰์ด๋”๋ฅผ ์™„์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-postprocessing-custom.html" }}} + +์–ธ๊ธ‰ํ–ˆ๋“ฏ ์ด ๊ธ€์—์„œ GLSL์˜ ์ž‘์„ฑ๋ฒ•๊ณผ ์‚ฌ์šฉ์ž ์ง€์ • ์‰์ด๋”๋ฅผ ๋งŒ๋“œ๋Š” ๋ฒ•์„ ๋ชจ๋‘ ๋‹ค๋ฃจ๊ธฐ๋Š” ๋ฌด๋ฆฌ์ž…๋‹ˆ๋‹ค. WebGL์ด ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•˜๋Š”์ง€ ์•Œ๊ณ  ์‹ถ๋‹ค๋ฉด [์ด ์‹œ๋ฆฌ์ฆˆ](https://webglfundamentals.org)๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”. [Three.js์˜ ํ›„์ฒ˜๋ฆฌ ์‰์ด๋” ์†Œ์Šค ์ฝ”๋“œ](https://github.com/mrdoob/three.js/tree/master/examples/js/shaders)๋ฅผ ๋ถ„์„ํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์€ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ์ƒ๋Œ€์ ์œผ๋กœ ๋ณต์žกํ•œ ์‰์ด๋”๋„ ์žˆ์ง€๋งŒ ์ž‘์€ ๊ฒƒ๋ถ€ํ„ฐ ์ฐจ๊ทผ์ฐจ๊ทผ ์‚ดํŽด๋ณธ๋‹ค๋ฉด ์–ธ์  ๊ฐ€ ์ „์ฒด๋ฅผ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์„ ๊ฑฐ์˜ˆ์š”. + +์•„์‰ฝ๊ฒŒ๋„ Three.js์˜ ํ›„์ฒ˜๋ฆฌ ํšจ๊ณผ ๋Œ€๋ถ€๋ถ„์€ ๊ณต์‹ ๋ฌธ์„œ๊ฐ€ ์—†์–ด [์˜ˆ์ œ๋ฅผ ์ฐธ๊ณ ํ•˜๊ฑฐ๋‚˜](https://github.com/mrdoob/three.js/tree/master/examples) [ํ›„์ฒ˜๋ฆฌ ํšจ๊ณผ์˜ ์†Œ์Šค ์ฝ”๋“œ](https://github.com/mrdoob/three.js/tree/master/examples/js/postprocessing)๋ฅผ ์ง์ ‘ ๋ถ„์„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ถ€๋”” ์ด ๊ธ€๊ณผ ์ด ์‹œ๋ฆฌ์ฆˆ์˜ [๋ Œ๋” ํƒ€๊ฒŸ์— ๊ด€ํ•œ ๊ธ€](threejs-rendertargets.html)์ด ์ข‹์€ ์ถœ๋ฐœ์ ์„ ๋งˆ๋ จํ•ด์ฃผ์—ˆ์œผ๋ฉด ์ข‹๊ฒ ๋„ค์š”.
true
Other
mrdoob
three.js
633dbb61bdfd242077b4c012fce7468c1e707c1a.json
add translation kr/threejs-rendering-on-demand.md add translation kr/threejs-transparency.md update translation kr/threejs-prerequisites.md add translation kr/threejs-multiple-scenes.md add translation kr/threejs-picking.md fix typo & add translation kr/threejs-post-processing.md add translation kr/threejs-post-processing-3dlut.md
threejs/lessons/kr/threejs-prerequisites.md
@@ -148,12 +148,50 @@ ES5์—์„œ ๋ฐฐ์—ด์— [`forEach`](https://developer.mozilla.org/ko/docs/Web/JavaSc ๊ธฐ์กด ๋ฐฉ๋ฒ• - const width = dims.width; - const height = dims.height; +```js +const width = dims.width; +const height = dims.height; +``` + +์ƒˆ๋กœ์šด ๋ฐฉ๋ฒ• + +```js +const { width, height } = dims; +``` + +๊ตฌ์กฐ๋ถ„ํ•ดํ• ๋‹น์€ ๋ฐฐ์—ด์—๋„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. `const position = [1, 2, 3, 4]`. +์ด๋Ÿฐ ๋ฐฐ์—ด์ด ์žˆ๋‹ค๊ณ  ํ•ด๋ณด์ฃ . + +๊ธฐ์กด ๋ฐฉ๋ฒ• + +```js +const x = position[2]; +const y = position[1]; +``` ์ƒˆ๋กœ์šด ๋ฐฉ๋ฒ• - const { width, height } = dims; +```js +const [ , y, x ] = position; +``` + +๋˜ํ•œ ๋งค๊ฐœ๋ณ€์ˆ˜์—๋„ ๊ตฌ์กฐ๋ถ„ํ•ดํ• ๋‹น์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```js +const dims = { width: 300, height: 150 }; +const position = [1, 2, 3, 4]; + +function distFromOrig([x, y]) { + return Math.sqrt(x * x + y * y); +} + +const dist = distFromOrig(position); // dist = 2.236... + +function area({ width, height }) { + return width * height; +} +const a = area(dims); // a = 45000 +``` ### ๊ฐ์ฒด ์„ ์–ธ ์‹œ ์ถ•์•ฝ ๋ฌธ๋ฒ• ์‚ฌ์šฉ @@ -193,7 +231,7 @@ ES5์—์„œ ๋ฐฐ์—ด์— [`forEach`](https://developer.mozilla.org/ko/docs/Web/JavaSc function log(className, ...args) { const elem = document.createElement('div'); elem.className = className; - elem.textContent = [...args].join(' '); + elem.textContent = args.join(' '); document.body.appendChild(elem); } ``` @@ -205,6 +243,22 @@ const position = [1, 2, 3]; somemesh.position.set(...position); ``` +๋ฐฐ์—ด์„ ์–•์€ ๋ณต์‚ฌํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๊ณ  + +```js +const copiedPositionArray = [...position]; +copiedPositionArray.push(4); // [1,2,3,4] +console.log(position); // [1,2,3] ๊ธฐ์กด ๋ฐฐ์—ด์€ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š์Œ +``` + +๊ฐ์ฒด๋ฅผ ํ•ฉ์น  ๋•Œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์ฃ . + +``` +const a = { abc: 123 }; +const b = { def: 456 }; +const c = { ...a, ...b }; // c = { abc: 123, def: 456 } +``` + ### `class` ์‚ฌ์šฉํ•˜๊ธฐ ES5 ์ดํ•˜์˜ ๋ฌธ๋ฒ•์œผ๋กœ ํด๋ž˜์Šค ์Šคํƒ€์ผ์˜ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋“ค์—๊ฒŒ ๋‚ฏ์„  ์š”์†Œ
true
Other
mrdoob
three.js
633dbb61bdfd242077b4c012fce7468c1e707c1a.json
add translation kr/threejs-rendering-on-demand.md add translation kr/threejs-transparency.md update translation kr/threejs-prerequisites.md add translation kr/threejs-multiple-scenes.md add translation kr/threejs-picking.md fix typo & add translation kr/threejs-post-processing.md add translation kr/threejs-post-processing-3dlut.md
threejs/lessons/kr/threejs-rendering-on-demand.md
@@ -0,0 +1,227 @@ +Title: ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง ์—†์• ๊ธฐ +Description: ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค +TOC: ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง ์—†์• ๊ธฐ + +๋Œ€๋ถ€๋ถ„์˜ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ์ด ์ฃผ์ œ๋Š” ๋„ˆ๋ฌด ๋ป”ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ํ•„์š”ํ•œ ๋ˆ„๊ตฐ๊ฐ€๋ฅผ ์œ„ํ•ด +๊ธ€์„ ์จ๋ณด๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ Three.js ์˜ˆ์ œ๋Š” ๋ Œ๋”๋ง ๊ณผ์ •์„ ๊ณ„์† ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค. +๊ทธ๋Ÿฌ๋‹ˆ๊นŒ ์•„๋ž˜์™€ ๊ฐ™์ด ์žฌ๊ท€์ ์œผ๋กœ `requestAnimationFrame` ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” +๊ฑฐ์ฃ . + +```js +function render() { + ... + requestAnimationFrame(render); +} +requestAnimationFrame(render); +``` + +๊ณ„์† ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์žˆ๋Š” ๊ฒฝ์šฐ์—์•ผ ๋ณ„ ์ƒ๊ด€์ด ์—†์ง€๋งŒ, ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์—†๋Š” ๊ฒฝ์šฐ๋ผ๋ฉด +์–ด๋–จ๊นŒ์š”? ์ด ๊ฒฝ์šฐ ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง์„ ๋ฐ˜๋ณตํ•˜๋Š” ๊ฒƒ์€ ์—ฐ์‚ฐ ๋‚ญ๋น„์ผ ๋ฟ๋”๋Ÿฌ ์‚ฌ์šฉ +ํ™˜๊ฒฝ์ด ๋ชจ๋ฐ”์ผ์ด๋ผ๋ฉด ์‚ฌ์šฉ์ž์˜ ๋ฐฐํ„ฐ๋ฆฌ๊นŒ์ง€ ๋‚ญ๋น„ํ•˜๋Š” ์…ˆ์ž…๋‹ˆ๋‹ค. + +์ฒ˜์Œ ํ•œ ๋ฒˆ๋งŒ ๋ Œ๋”๋งํ•˜๊ณ , ๊ทธ ํ›„์— ๋ณ€ํ™”๊ฐ€ ์žˆ์„ ๋•Œ๋งŒ ๋ Œ๋”๋งํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ์ •ํ™•ํ•œ +ํ•ด๊ฒฐ์ฑ…์ผ ๊ฒ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ๋ณ€ํ™”๋ž€ ํ…์Šค์ฒ˜๋‚˜ ๋ชจ๋ธ์˜ ๋กœ๋”ฉ์ด ๋๋‚ฌ์„ ๋•Œ, ์™ธ๋ถ€์—์„œ +๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•˜์„ ๋•Œ, ์‚ฌ์šฉ์ž๊ฐ€ ์นด๋ฉ”๋ผ๋ฅผ ์กฐ์ •ํ•˜๊ฑฐ๋‚˜, ์„ค์ •์„ ๋ฐ”๊พธ๊ฑฐ๋‚˜, ์ธํ’‹ ๊ฐ’์ด +๋ณ€๊ฒฝ๋œ ๊ฒฝ์šฐ ๋“ฑ ๋‹ค์–‘ํ•˜๊ฒ ์ฃ . + +[๋ฐ˜์‘ํ˜• ๋””์ž์ธ์— ๊ด€ํ•œ ๊ธ€](threejs-responsive.html)์—์„œ ์ผ๋˜ ์˜ˆ์ œ๋ฅผ ์ˆ˜์ •ํ•ด +ํ•„์š”์— ๋”ฐ๋ฅธ ๋ Œ๋”๋ง์„ ๊ตฌํ˜„ํ•ด๋ด…์‹œ๋‹ค. + +๋จผ์ € ๋ญ”๊ฐ€ ๋ณ€ํ™”๋ฅผ ์ผ์œผํ‚ฌ ์ˆ˜ ์žˆ๋Š” ์š”์†Œ๊ฐ€ ํ•„์š”ํ•˜๋‹ˆ `OrbitControls`๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +import * as THREE from './resources/three/r115/build/three.module.js'; ++import { OrbitControls } from './resources/threejs/r115/examples/jsm/controls/OrbitControls.js'; + +... + +const fov = 75; +const aspect = 2; // canvas ๊ธฐ๋ณธ๊ฐ’ +const near = 0.1; +const far = 5; +const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); +camera.position.z = 2; + ++const controls = new OrbitControls(camera, canvas); ++controls.target.set(0, 0, 0); ++controls.update(); +``` + +์ •์œก๋ฉด์ฒด์— ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋„ฃ์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ˆ ์ด๋“ค์„ ์ฐธ์กฐํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. + +```js +-const cubes = [ +- makeInstance(geometry, 0x44aa88, 0), +- makeInstance(geometry, 0x8844aa, -2), +- makeInstance(geometry, 0xaa8844, 2), +-]; ++makeInstance(geometry, 0x44aa88, 0); ++makeInstance(geometry, 0x8844aa, -2); ++makeInstance(geometry, 0xaa8844, 2); +``` + +์• ๋‹ˆ๋ฉ”์ด์…˜๊ณผ `requestAnimationFrame` ๊ด€๋ จ ์ฝ”๋“œ๋„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. + +```js +-function render(time) { +- time *= 0.001; ++function render() { + + if (resizeRendererToDisplaySize(renderer)) { + const canvas = renderer.domElement; + camera.aspect = canvas.clientWidth / canvas.clientHeight; + camera.updateProjectionMatrix(); + } + +- cubes.forEach((cube, ndx) => { +- const speed = 1 + ndx * .1; +- const rot = time * speed; +- cube.rotation.x = rot; +- cube.rotation.y = rot; +- }); + + renderer.render(scene, camera); + +- requestAnimationFrame(render); +} + +-requestAnimationFrame(render); +``` + +๊ทธ๋ฆฌ๊ณ  `render` ํ•จ์ˆ˜๋ฅผ ์ง์ ‘ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. + +```js +render(); +``` + +์ด์ œ `OrbitControls`๊ฐ€ ์นด๋ฉ”๋ผ ์„ค์ •์„ ๋ฐ”๊ฟ€ ๋•Œ๋งˆ๋‹ค ์ง์ ‘ `render` ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด์•ผ +ํ•ฉ๋‹ˆ๋‹ค. ๋ญ”๊ฐ€ ๋ณต์žกํ•  ๊ฒƒ ๊ฐ™์ง€๋งŒ ๋‹คํ–‰ํžˆ `OrbitControls`์—๋Š” `change` ์ด๋ฒคํŠธ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. + +```js +controls.addEventListener('change', render); +``` + +๋˜ํ•œ ์ฐฝ ํฌ๊ธฐ๊ฐ€ ๋ฐ”๋€” ๋•Œ์˜ ๋™์ž‘๋„ ์ง์ ‘ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. `render` ํ•จ์ˆ˜๋ฅผ ๊ณ„์† ํ˜ธ์ถœํ•  +๋•Œ๋Š” ํ•ด๋‹น ๋™์ž‘์„ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ–ˆ์ง€๋งŒ, ์ง€๊ธˆ์€ `render` ํ•จ์ˆ˜๋ฅผ ์ˆ˜๋™์œผ๋กœ ํ˜ธ์ถœํ•˜๋ฏ€๋กœ +์ฐฝ์˜ ํฌ๊ธฐ๊ฐ€ ๋ฐ”๋€” ๋•Œ `render` ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +window.addEventListener('resize', render); +``` + +์ด์ œ ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง์„ ๋ฐ˜๋ณตํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-render-on-demand.html" }}} + +`OrbitControls`์—๋Š” ๊ด€์„ฑ(inertia) ์˜ต์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค. `enableDamping` ์†์„ฑ์„ ture๋กœ +์„ค์ •ํ•˜๋ฉด ๋™์ž‘์ด ์ข€ ๋” ๋ถ€๋“œ๋Ÿฌ์›Œ์ง€์ฃ . + +โ€ป damping: ๊ฐ์‡ . + +```js +controls.enableDamping = true; +``` + +๋˜ํ•œ `OrbitControls`๊ฐ€ ๋ถ€๋“œ๋Ÿฌ์šด ๋™์ž‘์„ ๊ตฌํ˜„ํ•  ๋•Œ ๋ณ€๊ฒฝ๋œ ์นด๋ฉ”๋ผ ๊ฐ’์„ ๊ณ„์† ๋„˜๊ฒจ์ฃผ๋„๋ก +`render` ํ•จ์ˆ˜ ์•ˆ์—์„œ `controls.update` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด +`change` ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ `render` ํ•จ์ˆ˜๊ฐ€ ๋ฌดํ•œ์ • ํ˜ธ์ถœ๋  ๊ฒ๋‹ˆ๋‹ค. controls๊ฐ€ `change` +์ด๋ฒคํŠธ๋ฅผ ๋ณด๋‚ด๋ฉด `render` ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜๊ณ , `render` ํ•จ์ˆ˜๋Š” `controls.update` ๋ฉ”์„œ๋“œ๋ฅผ +ํ˜ธ์ถœํ•ด ๋‹ค์‹œ `change` ์ด๋ฒคํŠธ๋ฅผ ๋ณด๋‚ด๊ฒŒ ๋งŒ๋“ค ํ…Œ๋‹ˆ๊นŒ์š”. + +`requestAnimationFrame`์ด ์ง์ ‘ `render` ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ํ•˜๋ฉด ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ ํ•  ์ˆ˜ +์žˆ์Šต๋‹ˆ๋‹ค. ๋„ˆ๋ฌด ๋งŽ์€ ํ”„๋ ˆ์ž„์„ ๋ง‰๊ธฐ ์œ„ํ•ด ๋ณ€์ˆ˜ ํ•˜๋‚˜๋ฅผ ๋‘์–ด ์š”์ฒญํ•œ ํ”„๋ ˆ์ž„์ด ์—†์„ ๊ฒฝ์šฐ์—๋งŒ +ํ”„๋ ˆ์ž„์„ ์š”์ฒญํ•˜๋„๋ก ํ•˜๋ฉด ๋˜๊ฒ ๋„ค์š”. + +```js ++let renderRequested = false; + +function render() { ++ renderRequested = false; + + if (resizeRendererToDisplaySize(renderer)) { + const canvas = renderer.domElement; + camera.aspect = canvas.clientWidth / canvas.clientHeight; + camera.updateProjectionMatrix(); + } + ++ controls.update(); + renderer.render(scene, camera); +} +render(); + ++function requestRenderIfNotRequested() { ++ if (!renderRequested) { ++ renderRequested = true; ++ requestAnimationFrame(render); ++ } ++} + +-controls.addEventListener('change', render); ++controls.addEventListener('change', requestRenderIfNotRequested); +``` + +์ฐฝ ํฌ๊ธฐ ๋ณ€ํ™”๊ฐ€ ์ผ์–ด๋‚ฌ์„ ๋•Œ๋„ `requestRenderIfNotRequested`๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +```js +-window.addEventListener('resize', render); ++window.addEventListener('resize', requestRenderIfNotRequested); +``` + +์ฐจ์ด์ ์„ ๋А๋ผ๊ธฐ ์–ด๋ ค์šธ์ง€๋„ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ™”์‚ดํ‘œ ํ‚ค๋ฅผ ์“ฐ๊ฑฐ๋‚˜ ์˜ˆ์ œ๋ฅผ ๋“œ๋ž˜๊ทธํ•ด ๋ณด๊ณ  +๋‹ค์‹œ ์œ„ ์˜ˆ์ œ๋ฅผ ์ด๋ฆฌ์ €๋ฆฌ ๋Œ๋ ค๋ณด์„ธ์š”. ์ฐจ์ด์ ์ด ๋А๊ปด์งˆ ๊ฑฐ์˜ˆ์š”. ์œ„ ์˜ˆ์ œ๋Š” ํ™”์‚ดํ‘œ ํ‚ค๋ฅผ +๋ˆŒ๋ €์„ ๋•Œ ์ผ์ • ๊ฑฐ๋ฆฌ๋งŒํผ ์ˆœ๊ฐ„์ด๋™ํ•˜์ง€๋งŒ ์•„๋ž˜์˜ ์˜ˆ์ œ๋Š” ์•ฝ๊ฐ„ ๋ฏธ๋„๋Ÿฌ์ง‘๋‹ˆ๋‹ค. + +{{{example url="../threejs-render-on-demand-w-damping.html" }}} + +๊ฐ„๋‹จํ•œ dat.GUI๋ฅผ ์ถ”๊ฐ€ํ•ด ๋ฐ˜๋ณต ๋ Œ๋”๋ง ์—ฌ๋ถ€๋ฅผ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +import * as THREE from './resources/three/r115/build/three.module.js'; +import { OrbitControls } from './resources/threejs/r115/examples/jsm/controls/OrbitControls.js'; ++import { GUI } from '../3rdparty/dat.gui.module.js'; +``` + +๋จผ์ € ๊ฐ ์ •์œก๋ฉด์ฒด์˜ ์ƒ‰๊ณผ x์ถ• ์Šค์ผ€์ผ์„ ์กฐ์ •ํ•˜๋Š” GUI๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. [์กฐ๋ช…์— ๊ด€ํ•œ ๊ธ€](threejs-lights.html)์—์„œ +์ผ๋˜ `ColorGUIHelper`๋ฅผ ๊ฐ€์ ธ์™€ ์“ฐ๋„๋ก ํ•˜์ฃ . + +๋จผ์ € GUI๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +```js +const gui = new GUI(); +``` + +๊ทธ๋ฆฌ๊ณ  ๊ฐ ์ •์œก๋ฉด์ฒด์— `material.color`, `cube.scale.x` ์„ค์ •์„ ํด๋”๋กœ ๋ฌถ์–ด +์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +function makeInstance(geometry, color, x) { + const material = new THREE.MeshPhongMaterial({color}); + + const cube = new THREE.Mesh(geometry, material); + scene.add(cube); + + cube.position.x = x; + ++ const folder = gui.addFolder(`Cube${ x }`); ++ folder.addColor(new ColorGUIHelper(material, 'color'), 'value') ++ .name('color') ++ .onChange(requestRenderIfNotRequested); ++ folder.add(cube.scale, 'x', .1, 1.5) ++ .name('scale x') ++ .onChange(requestRenderIfNotRequested); ++ folder.open(); + + return cube; +} +``` + +dat.GUI ์ปจํŠธ๋กค(control)์˜ `onChange` ๋ฉ”์„œ๋“œ์— ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ๋„˜๊ฒจ์ฃผ๋ฉด GUI ๊ฐ’์ด ๋ฐ”๋€” +๋•Œ๋งˆ๋‹ค ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์ œ์˜ ๊ฒฝ์šฐ์—๋Š” ๋‹จ์ˆœํžˆ `requestRenderIfNotRequested` +ํ•จ์ˆ˜๋ฅผ ๋„˜๊ฒจ์ฃผ๋ฉด ๋˜์ฃ . ๊ทธ๋ฆฌ๊ณ  `folder.open` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด ํด๋”๋ฅผ ์—ด์–ด ๋‘ก๋‹ˆ๋‹ค. + +{{{example url="../threejs-render-on-demand-w-gui.html" }}} + +์ด ๊ธ€์ด ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง ์ œ๊ฑฐ์— ๋Œ€ํ•œ ๊ฐœ๋…์„ ์กฐ๊ธˆ์ด๋ผ๋„ ์žก์•„์ฃผ์—ˆ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๋ณดํ†ต +Three.js๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ์ด๋ ‡๊ฒŒ ๋ Œ๋”๋ง ๋ฃจํ”„๋ฅผ ์ œ์–ดํ•  ์ผ์ด ์—†์Šต๋‹ˆ๋‹ค. ๋Œ€๊ฒŒ ๊ฒŒ์ž„ ๋˜๋Š” +์• ๋‹ˆ๋ฉ”์ด์…˜์ด ๋“ค์–ด๊ฐ„ 3D ์ปจํ…์ธ ์ด๊ธฐ ๋•Œ๋ฌธ์ด์ฃ . ํ•˜์ง€๋งŒ ์ง€๋„๋‚˜, 3D ์—๋””ํ„ฐ, 3D ๊ทธ๋ž˜ํ”„, +์ƒํ’ˆ ๋ชฉ๋ก ๋“ฑ์—์„œ๋Š” ์ด๋Ÿฐ ๊ธฐ๋ฒ•์ด ํ•„์š”ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
true
Other
mrdoob
three.js
633dbb61bdfd242077b4c012fce7468c1e707c1a.json
add translation kr/threejs-rendering-on-demand.md add translation kr/threejs-transparency.md update translation kr/threejs-prerequisites.md add translation kr/threejs-multiple-scenes.md add translation kr/threejs-picking.md fix typo & add translation kr/threejs-post-processing.md add translation kr/threejs-post-processing-3dlut.md
threejs/lessons/kr/threejs-transparency.md
@@ -0,0 +1,396 @@ +Title: Three.js ํˆฌ๋ช…๋„ +Description: Three.js์—์„œ ํˆฌ๋ช…๋„๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฒ•์„ ์•Œ์•„๋ด…๋‹ˆ๋‹ค +TOC: ๋ฌผ์ฒด์˜ ํˆฌ๋ช…๋„ ์„ค์ •ํ•˜๊ธฐ + +Three.js์—์„œ ํˆฌ๋ช…๋„๋Š” ๊ฐ„๋‹จํ•˜์ง€๋งŒ ๋™์‹œ์— ๊นŒ๋‹ค๋กœ์šด ์ฃผ์ œ์ž…๋‹ˆ๋‹ค. + +๋จผ์ € ์‰ฌ์šด ๊ฒƒ๋ถ€ํ„ฐ ์•Œ์•„๋ณด์ฃ . ์˜ˆ์ œ๋กœ ์ •์œก๋ฉด์ฒด 8๊ฐœ๋ฅผ 2x2x2 ๊ทธ๋ฆฌ๋“œ์— ๋งž์ถ˜ ์žฅ๋ฉด์„ +๋งŒ๋“ค์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +[๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง ์ œ๊ฑฐํ•˜๊ธฐ](threejs-rendering-on-demand.html)์—์„œ ์ผ๋˜ +์˜ˆ์ œ๋ฅผ ๊ฐ€์ ธ์™€ ์ •์œก๋ฉด์ฒด 3๊ฐœ๋ฅผ 8๊ฐœ๋กœ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. ๋จผ์ € `makeInstance` ํ•จ์ˆ˜๊ฐ€ +x, y, z ๊ฐ’์„ ๋ฐ›๋„๋ก ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +-function makeInstance(geometry, color) { ++function makeInstance(geometry, color, x, y, z) { + const material = new THREE.MeshPhongMaterial({color}); + + const cube = new THREE.Mesh(geometry, material); + scene.add(cube); + +- cube.position.x = x; ++ cube.position.set(x, y, z); + + return cube; +} +``` + +๊ทธ๋ฆฌ๊ณ  ์ •์œก๋ฉด์ฒด 8๊ฐœ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. + +```js ++function hsl(h, s, l) { ++ return (new THREE.Color()).setHSL(h, s, l); ++} + +-makeInstance(geometry, 0x44aa88, 0); +-makeInstance(geometry, 0x8844aa, -2); +-makeInstance(geometry, 0xaa8844, 2); + ++{ ++ const d = 0.8; ++ makeInstance(geometry, hsl(0 / 8, 1, .5), -d, -d, -d); ++ makeInstance(geometry, hsl(1 / 8, 1, .5), d, -d, -d); ++ makeInstance(geometry, hsl(2 / 8, 1, .5), -d, d, -d); ++ makeInstance(geometry, hsl(3 / 8, 1, .5), d, d, -d); ++ makeInstance(geometry, hsl(4 / 8, 1, .5), -d, -d, d); ++ makeInstance(geometry, hsl(5 / 8, 1, .5), d, -d, d); ++ makeInstance(geometry, hsl(6 / 8, 1, .5), -d, d, d); ++ makeInstance(geometry, hsl(7 / 8, 1, .5), d, d, d); ++} +``` + +์นด๋ฉ”๋ผ๋„ ์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค. + +```js +const fov = 75; +const aspect = 2; // canvas ๊ธฐ๋ณธ๊ฐ’ +const near = 0.1; +-const far = 5; ++const far = 25; +const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); +-camera.position.z = 4; ++camera.position.z = 2; +``` + +๋ฐฐ๊ฒฝ์ƒ‰์€ ํ•˜์–€์ƒ‰์œผ๋กœ ๋ฐ”๊ฟ”์ฃผ๊ณ  + +```js +const scene = new THREE.Scene(); ++scene.background = new THREE.Color('white'); +``` + +์ •์œก๋ฉด์ฒด์˜ ์˜†๋ฉด๋„ ๋น›์„ ๋ฐ›๋„๋ก ์กฐ๋ช…์„ ํ•˜๋‚˜ ๋” ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +-{ ++function addLight(...pos) { + const color = 0xFFFFFF; + const intensity = 1; + const light = new THREE.DirectionalLight(color, intensity); +- light.position.set(-1, 2, 4); ++ light.position.set(...pos); + scene.add(light); +} ++addLight(-1, 2, 4); ++addLight( 1, -1, -2); +``` + +์ •์œก๋ฉด์ฒด๋ฅผ ํˆฌ๋ช…ํ•˜๊ฒŒ ๋งŒ๋“ค๋ ค๋ฉด [`transparent`](Material.transparent) ์†์„ฑ์„ +์ผœ๊ณ  [`opacity`](Material.opacity) ์†์„ฑ์„ ์„ค์ •ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค(CSS์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ +0์€ ์™„์ „ํžˆ ํˆฌ๋ช…ํ•จ, 1์€ ์™„์ „ํžˆ ๋ถˆํˆฌ๋ช…ํ•จ์„ ์˜๋ฏธ). + +```js +function makeInstance(geometry, color, x, y, z) { +- const material = new THREE.MeshPhongMaterial({color}); ++ const material = new THREE.MeshPhongMaterial({ ++ color, ++ opacity: 0.5, ++ transparent: true, ++ }); + + const cube = new THREE.Mesh(geometry, material); + scene.add(cube); + + cube.position.set(x, y, z); + + return cube; +} +``` + +์ด์ œ 8๊ฐœ์˜ ๋ฐ˜ํˆฌ๋ช…ํ•œ ์ •์œก๋ฉด์ฒด๊ฐ€ ์ƒ๊ฒผ์Šต๋‹ˆ๋‹ค. + +{{{example url="../threejs-transparency.html"}}} + +์˜ˆ์ œ๋ฅผ ๋“œ๋ž˜๊ทธํ•˜๋ฉด ํ™”๋ฉด์„ ํšŒ์ „์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์™„๋ฒฝํ•œ๋ฐ์š”, ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค๋ฉด ์ข€ ๋” ์ž์„ธํžˆ ๋ณด์„ธ์š”. ์ •์œก๋ฉด์ฒด์˜ ๋’ท๋ฉด์ด ํ•˜๋‚˜๋„ +๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/transparency-cubes-no-backs.png" style="width: 416px;"></div> +<div class="threejs_center">๋’ท๋ฉด์ด ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค</div> + +์ด์ „์— [์žฌ์งˆ(material)์— ๊ด€ํ•ด](threejs-materials.html) ๋ฐฐ์šธ ๋•Œ [`side`](Material.side) +์†์„ฑ์— ๋Œ€ํ•ด ๋ฐฐ์› ์—ˆ์ฃ . ์ด ์†์„ฑ์„ `THREE.DoubleSide`๋กœ ์„ค์ •ํ•ด ์ •์œก๋ฉด์ฒด์˜ +์–‘๋ฉด์ด ๋ชจ๋‘ ๋ณด์ด๋„๋ก ํ•ด๋ด…์‹œ๋‹ค. + +```js +const material = new THREE.MeshPhongMaterial({ + color, + map: loader.load(url), + opacity: 0.5, + transparent: true, ++ side: THREE.DoubleSide, +}); +``` + +{{{example url="../threejs-transparency-doubleside.html" }}} + +์˜ˆ์ œ๋ฅผ ๋Œ๋ ค๋ณด์„ธ์š”. ๋ญ”๊ฐ€ ํ•ด๊ฒฐ๋œ ๋“ฏ ํ•˜์ง€๋งŒ ์ž์„ธํžˆ ๋ณด๋ฉด ๊ฐ€๋” ๋’ท๋ฉด ๋˜๋Š” ๋’ท๋ฉด์˜ +์ผ๋ถ€๊ฐ€ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/transparency-cubes-some-backs.png" style="width: 368px;"></div> +<div class="threejs_center">์ •์œก๋ฉด์ฒด์˜ ์™ผ์ชฝ ๋’ท๋ฉด์ด ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค</div> + +์ด๋Š” 3D ์š”์†Œ๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ์‹ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. WebGL์€ ๊ฐ geometry์˜ ์‚ผ๊ฐํ˜•์„ +ํ•œ ๋ฒˆ์— ํ•˜๋‚˜์”ฉ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์‚ผ๊ฐํ˜•์˜ ํ”ฝ์…€ ํ•˜๋‚˜๋ฅผ ๋ Œ๋”๋งํ•  ๋•Œ๋งˆ๋‹ค +2๊ฐœ์˜ ์ •๋ณด๋ฅผ ๊ธฐ๋กํ•˜๋Š”๋ฐ, ํ•˜๋‚˜๋Š” ํ•ด๋‹น ํ”ฝ์…€์˜ ์ƒ‰์ด๊ณ  ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ํ”ฝ์…€์˜ +๊นŠ์ด(depth)์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ ์‚ผ๊ฐํ˜•์„ ๊ทธ๋ฆด ๋•Œ ํ•ด๋‹น ํ”ฝ์…€์ด ์ด๋ฏธ ๊ทธ๋ ค์ง„ ํ”ฝ์…€๋ณด๋‹ค +๊นŠ์ด๊ฐ€ ๊นŠ๋‹ค๋ฉด ํ•ด๋‹น ํ”ฝ์…€์„ ๋ Œ๋”๋งํ•˜์ง€ ์•Š์ฃ . + +์ด๋Š” ๋ถˆํˆฌ๋ช…ํ•œ ๋ฌผ์ฒด์—์„œ๋Š” ๋ฌธ์ œ๊ฐ€ ๋˜์ง€ ์•Š์•˜์ง€๋งŒ ํˆฌ๋ช…ํ•œ ๋ฌผ์ฒด์—์„œ๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. + +์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๋ฉด ํˆฌ๋ช…ํ•œ ๋ฌผ์ฒด๋ฅผ ๋ถ„๋ฅ˜ํ•ด ๋’ค์— ์žˆ๋Š” ๋ฌผ์ฒด๋ฅผ ์•ž์— ์žˆ๋Š” ๋ฌผ์ฒด๋ณด๋‹ค +๋จผ์ € ๋ Œ๋”๋งํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. `Mesh` ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” Three.js๊ฐ€ ์ž๋™์œผ๋กœ ์ด๋ฅผ ์ฒ˜๋ฆฌํ•ด์ฃผ์ฃ . +๋งŒ์•ฝ ๊ทธ๋Ÿฌ์ง€ ์•Š์•˜๋‹ค๋ฉด ์ œ์ผ ์ฒซ ๋ฒˆ์งธ ์˜ˆ์ œ์—์„œ ๋’ค์— ์žˆ๋Š” ์ •์œก๋ฉด์ฒด๋ฅผ ์•„์˜ˆ ๋ณผ ์ˆ˜ +์—†์—ˆ์„ ๊ฒ๋‹ˆ๋‹ค. + +์ •์œก๋ฉด์ฒด์—๋Š” ํ•œ ๋ฉด์— 2๊ฐœ, ์ด 12๊ฐœ์˜ ์‚ผ๊ฐํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ ์‚ผ๊ฐํ˜•์˜ ๋ Œ๋”๋ง ์ˆœ์„œ๋Š” +[geometry์— ๊ด€ํ•œ ๊ธ€์—์„œ ๋ดค๋˜ ๊ฒƒ](threejs-custom-buffergeometry.html)๊ณผ ๊ฐ™์ฃ . +์‹œ์„ ์— ๋”ฐ๋ผ ์นด๋ฉ”๋ผ์—์„œ ๊ฐ€๊นŒ์šด ์‚ผ๊ฐํ˜•์„ ๋จผ์ € ๋ Œ๋”๋งํ•  ๊ฒ๋‹ˆ๋‹ค. ์•ž๋ฉด์„ ๋’ท๋ฉด๋ณด๋‹ค ๋จผ์ € +๋ Œ๋”๋งํ•˜๋‹ˆ, ๋•Œ๋•Œ๋กœ ๋’ท๋ฉด์ด ๋ณด์ด์ง€ ์•Š์„ ์ˆ˜๋ฐ–์— ์—†์ฃ . + +๊ตฌ์ฒด๋‚˜ ์ •์œก๋ฉด์ฒด ๋“ฑ ๋ณผ๋ก ๋ฌผ์ฒด(convex object)์˜ ๊ฒฝ์šฐ, ๋ชจ๋“  ๋ฌผ์ฒด๋ฅผ ํ•œ ๋ฒˆ์”ฉ ๋” ๋ Œ๋”๋งํ•ด +๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜๋‚˜๋Š” ์•ˆ์ชฝ๋ฉด ์‚ผ๊ฐํ˜•๋งŒ ๋ Œ๋”๋งํ•˜๊ณ , ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ๋ฐ”๊นฅ์ชฝ +์‚ผ๊ฐํ˜•๋งŒ ๋ Œ๋”๋งํ•˜๋„๋ก ๋งŒ๋“œ๋Š” ๊ฒƒ์ด์ฃ . + +```js +function makeInstance(geometry, color, x, y, z) { ++ [THREE.BackSide, THREE.FrontSide].forEach((side) => { + const material = new THREE.MeshPhongMaterial({ + color, + opacity: 0.5, + transparent: true, ++ side, + }); + + const cube = new THREE.Mesh(geometry, material); + scene.add(cube); + + cube.position.set(x, y, z); ++ }); +} +``` + +์–ด์ฐŒ์–ด์ฐŒ ํ•ด๊ฒฐ๋œ *๊ฒƒ์ฒ˜๋Ÿผ* ๋ณด์ž…๋‹ˆ๋‹ค. + +{{{example url="../threejs-transparency-doubleside-hack.html" }}} + +Three.js์˜ ๋ถ„๋ฅ˜ ๊ธฐ์ค€์€ ๊ณ ์ •์ ์ธ ๋“ฏํ•ฉ๋‹ˆ๋‹ค. `side: THREE.BackSide` mesh๋ฅผ ๋จผ์ € +๋„ฃ๊ณ , ๊ทธ ๋‹ค์Œ ์ •ํ™•ํžˆ ๊ฐ™์€ ์œ„์น˜์— `side: THREE.FrontSide` mesh๋ฅผ ๋„ฃ์—ˆ์œผ๋‹ˆ๊นŒ์š”. + +์ด๋ฒˆ์—๋Š” ํ‰๋ฉด 2๊ฐœ๋ฅผ ๊ต์ฐจ๋กœ ๋ฐฐ์น˜ํ•ด๋ด…์‹œ๋‹ค(์ •์œก๋ฉด์ฒด ๊ด€๋ จ ์ฝ”๋“œ๋ฅผ ์ „๋ถ€ ์ง€์šด ๋’ค). +๊ฐ ํ‰๋ฉด์—๋Š” ๋‹ค๋ฅธ ํ…์Šค์ฒ˜๋ฅผ ๋„ฃ์„ ๊ฒ๋‹ˆ๋‹ค. + +```js +const planeWidth = 1; +const planeHeight = 1; +const geometry = new THREE.PlaneBufferGeometry(planeWidth, planeHeight); + +const loader = new THREE.TextureLoader(); + +function makeInstance(geometry, color, rotY, url) { + const texture = loader.load(url, render); + const material = new THREE.MeshPhongMaterial({ + color, + map: texture, + opacity: 0.5, + transparent: true, + side: THREE.DoubleSide, + }); + + const mesh = new THREE.Mesh(geometry, material); + scene.add(mesh); + + mesh.rotation.y = rotY; +} + +makeInstance(geometry, 'pink', 0, 'resources/images/happyface.png'); +makeInstance(geometry, 'lightblue', Math.PI * 0.5, 'resources/images/hmmmface.png'); +``` + +ํ‰๋ฉด์€ ํ•œ ๋ฒˆ์— ํ•œ ๋ฉด๋ฐ–์— ๋ณด์ง€ ๋ชปํ•˜๋‹ˆ, `side: THREE.DoubleSide`๋กœ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ +ํ…์Šค์ฒ˜๋ฅผ ์ „๋ถ€ ๋ถˆ๋Ÿฌ์™”์„ ๋•Œ ์žฅ๋ฉด์„ ๋‹ค์‹œ ๋ Œ๋”๋งํ•˜๋„๋ก `render` ํ•จ์ˆ˜๋ฅผ `loader.load` +๋ฉ”์„œ๋“œ์— ๋„˜๊ฒจ์คฌ์Šต๋‹ˆ๋‹ค. ์ด๋Š” [ํ•„์š”์— ๋”ฐ๋ฅธ ๋ Œ๋”๋ง](threejs-rendering-on-demand.html)์„ +๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ๊ฒƒ์ด์ฃ . + +{{{example url="../threejs-transparency-intersecting-planes.html"}}} + +์•„๊นŒ์™€ ๋น„์Šทํ•œ ๋ฌธ์ œ๊ฐ€ ๋ณด์ž…๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/transparency-planes.png" style="width: 408px;"></div> +<div class="threejs_center">๋ฉด์˜ ๋ฐ˜์ชฝ์ด ์‚ฌ๋ผ์กŒ๋‹ค</div> + +ํ‰๋ฉด์„ ๋‘˜๋กœ ์ชผ๊ฐœ ์‹ค์ œ๋กœ๋Š” ๊ต์ฐจํ•˜์ง€ ์•Š๊ฒŒ๋” ๋งŒ๋“ค๋ฉด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +```js +function makeInstance(geometry, color, rotY, url) { ++ const base = new THREE.Object3D(); ++ scene.add(base); ++ base.rotation.y = rotY; + ++ [-1, 1].forEach((x) => { + const texture = loader.load(url, render); ++ texture.offset.x = x < 0 ? 0 : 0.5; ++ texture.repeat.x = .5; + const material = new THREE.MeshPhongMaterial({ + color, + map: texture, + opacity: 0.5, + transparent: true, + side: THREE.DoubleSide, + }); + + const mesh = new THREE.Mesh(geometry, material); +- scene.add(mesh); ++ base.add(mesh); + +- mesh.rotation.y = rotY; ++ mesh.position.x = x * .25; + }); +} +``` + +์ €๊ฑธ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ• ์ง€๋Š” ์—ฌ๋Ÿฌ๋ถ„์˜ ์„ ํƒ์ž…๋‹ˆ๋‹ค. [๋ธ”๋ Œ๋”(Blender)](https://blender.org) +๊ฐ™์€ 3D ์—๋””ํ„ฐ๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค๋ฉด ํ…์Šค์ฒ˜ ์ขŒํ‘œ๋ฅผ ์ง์ ‘ ์ˆ˜์ •ํ–ˆ๊ฒ ์ฃ . ์˜ˆ์ œ์˜ ๊ฒฝ์šฐ์—๋Š” +`PlaneBufferGeometry`๋ฅผ ์ผ์Šต๋‹ˆ๋‹ค. [์ด์ „์— ๋‹ค๋ค˜๋“ฏ](threejs-textures.html) +์ด geometry๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ํ…์Šค์ฒ˜๋ฅผ ํฌ๊ธฐ์— ๋งž์ถฐ ๋Š˜๋ฆฝ๋‹ˆ๋‹ค. [`texture.repeat`](Texture.repeat) +์†์„ฑ๊ณผ [`texture.offset`](Texture.offset) ์†์„ฑ์„ ์กฐ์ •ํ•ด ๊ฐ ๋ฉด์— ์ ์ ˆํ•œ +ํ…์Šค์ฒ˜๋ฅผ ์ž…ํ˜€์ค„ ์ˆ˜ ์žˆ์ฃ . + +์œ„ ์ฝ”๋“œ์—์„œ๋Š” `Object3D`๋ฅผ ๋งŒ๋“ค์–ด ๋‘ ํ‰๋ฉด์˜ ๋ถ€๋ชจ๋กœ ์ง€์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ +ํ•˜๋ฉด ๋ณต์žกํ•œ ๊ณ„์‚ฐ ์—†์ด ๊ฐ„๋‹จํ•˜๊ฒŒ `Object3D`๋งŒ ๋Œ๋ ค์„œ ๋‘ ํ‰๋ฉด ๋‹ค ํšŒ์ „์‹œํ‚ฌ +์ˆ˜ ์žˆ์ฃ . + +{{{example url="../threejs-transparency-intersecting-planes-fixed.html"}}} + +์ด ๋ฐฉ๋ฒ•์€ ๊ต์ฐจ์ ์ด ๋ณ€ํ•˜์ง€ ์•Š๋Š” ์ •๋ง ๊ฐ„๋‹จํ•œ ๊ฒฝ์šฐ์—๋งŒ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + +ํ…์Šค์ฒ˜๊ฐ€ ๋“ค์–ด๊ฐ„ ์š”์†Œ๋Š” ์•ŒํŒŒ ํ…Œ์ŠคํŠธ(alpha test)๋ฅผ ํ™œ์„ฑํ™”ํ•ด ์ด๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ +์žˆ์ฃ . + +์•ŒํŒŒ ํ…Œ์ŠคํŠธ๋ž€ Three.js๊ฐ€ ํ”ฝ์…€์„ ๋ Œ๋”๋งํ•˜์ง€ ์•Š๋Š” ํŠน์ • *์•ŒํŒŒ* ๋‹จ๊ณ„๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. +๋งŒ์•ฝ ์•„๋ฌด๊ฒƒ๋„ ๊ทธ๋ฆฌ์ง€ ์•Š๊ฒŒ ์„ค์ •ํ•œ๋‹ค๋ฉด ์œ„์™€ ๊ฐ™์€ ๋ฌธ์ œ๋Š” ์‚ฌ๋ผ์ง€๊ฒ ์ฃ . ์ƒ๋Œ€์ ์œผ๋กœ +๊ฒฝ๊ณ„๊ฐ€ ๋ถ„๋ช…ํ•œ ํ…์Šค์ฒ˜, ๋‚˜๋ญ‡์žŽ, ์ž”๋”” ๋“ฑ์˜ ๊ฒฝ์šฐ ์ด๋Š” ๊ฝค ์ž˜ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. + +์ด๋ฒˆ์—๋„ 2๊ฐœ์˜ ๋ฉด์„ ๋งŒ๋“ค์–ด ํ…Œ์ŠคํŠธํ•ด๋ณด๋„๋ก ํ•ฉ์‹œ๋‹ค. ์•„๊นŒ๋Š” ํ…์Šค์ฒ˜๊ฐ€ ์ „๋ถ€ ๋ถˆํˆฌ๋ช…ํ–ˆ์ฃ . +์ด๋ฒˆ์—๋Š” ๊ฐ ๋ฉด์—๋Š” ๊ฐ๊ฐ ๋‹ค๋ฅธ, ๋ถ€๋ถ„์ ์œผ๋กœ ํˆฌ๋ช…ํ•œ ํ…์Šค์ฒ˜๋ฅผ ์‚ฌ์šฉํ•  ๊ฒ๋‹ˆ๋‹ค. + +<div class="spread"> + <div><img class="checkerboard" src="../resources/images/tree-01.png"></div> + <div><img class="checkerboard" src="../resources/images/tree-02.png"></div> +</div> + +์•„๊นŒ ํ‰๋ฉด 2๊ฐœ๋ฅผ ๊ต์ฐจํ•ด๋†“์•˜๋˜(๋ฐ˜์œผ๋กœ ๊ฐ€๋ฅด๊ธฐ ์ „) ์˜ˆ์ œ๋ฅผ ๊ฐ€์ ธ์™€ ์ด ํ…์Šค์ฒ˜์— +[`alphaTest`](Material.alphaTest) ์†์„ฑ์„ ์ง€์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +```js +function makeInstance(geometry, color, rotY, url) { + const texture = loader.load(url, render); + const material = new THREE.MeshPhongMaterial({ + color, + map: texture, +- opacity: 0.5, + transparent: true, ++ alphaTest: 0.5, + side: THREE.DoubleSide, + }); + + const mesh = new THREE.Mesh(geometry, material); + scene.add(mesh); + + mesh.rotation.y = rotY; +} + +-makeInstance(geometry, 'pink', 0, 'resources/images/happyface.png'); +-makeInstance(geometry, 'lightblue', Math.PI * 0.5, 'resources/images/hmmmface.png'); ++makeInstance(geometry, 'white', 0, 'resources/images/tree-01.png'); ++makeInstance(geometry, 'white', Math.PI * 0.5, 'resources/images/tree-02.png'); +``` + +์ด๋Œ€๋กœ ์‹คํ–‰ํ•ด๋„ ๋˜์ง€๋งŒ, ๊ฐ„๋‹จํ•œ UI๋ฅผ ๋งŒ๋“ค์–ด `alphaTest`์™€ `transparent` ์†์„ฑ์„ +๊ฐ–๊ณ  ๋†€ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. [์”ฌ ๊ทธ๋ž˜ํ”„์— ๊ด€ํ•œ ๊ธ€](threejs-scenegraph.html)์—์„œ +์†Œ๊ฐœํ–ˆ๋˜ dat.GUI๋ฅผ ์จ์„œ์š”. + +๋จผ์ € dat.GUI์— ์ง€์ •ํ•  ํ—ฌํผ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด ํ—ฌํผ ํด๋ž˜์Šค๋Š” ์žฅ๋ฉด ์•ˆ ๋ชจ๋“  +์žฌ์งˆ์„ ํ•ด๋‹น ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝํ•  ๊ฒ๋‹ˆ๋‹ค. + +```js +class AllMaterialPropertyGUIHelper { + constructor(prop, scene) { + this.prop = prop; + this.scene = scene; + } + get value() { + const { scene, prop } = this; + let v; + scene.traverse((obj) => { + if (obj.material && obj.material[prop] !== undefined) { + v = obj.material[prop]; + } + }); + return v; + } + set value(v) { + const { scene, prop } = this; + scene.traverse((obj) => { + if (obj.material && obj.material[prop] !== undefined) { + obj.material[prop] = v; + obj.material.needsUpdate = true; + } + }); + } +} +``` + +๋‹ค์Œ์œผ๋กœ GUI๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. + +```js +const gui = new GUI(); +gui.add(new AllMaterialPropertyGUIHelper('alphaTest', scene), 'value', 0, 1) + .name('alphaTest') + .onChange(requestRenderIfNotRequested); +gui.add(new AllMaterialPropertyGUIHelper('transparent', scene), 'value') + .name('transparent') + .onChange(requestRenderIfNotRequested); +``` + +๋ฌผ๋ก  dat.GUI ๋ชจ๋“ˆ๋„ ๋ถˆ๋Ÿฌ์™€์•ผ์ฃ . + +```js +import * as THREE from './resources/three/r115/build/three.module.js'; +import { OrbitControls } from './resources/threejs/r115/examples/jsm/controls/OrbitControls.js'; ++import { GUI } from '../3rdparty/dat.gui.module.js'; +``` + +{{{example url="../threejs-transparency-intersecting-planes-alphatest.html"}}} + +์˜ˆ์ œ๋ฅผ ํ™•๋Œ€ํ•ด๋ณด๋ฉด ํ‰๋ฉด์— ํ•˜์–€ ํ…Œ๋‘๋ฆฌ๊ฐ€ ๋ณด์ผ ๊ฒ๋‹ˆ๋‹ค. + +<div class="threejs_center"><img src="resources/images/transparency-alphatest-issues.png" style="width: 532px;"></div> + +์ด๋Š” ์•ž์„œ ๋ดค๋˜ ์˜ˆ์ œ์™€ ๊ฐ™์€ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ํ•˜์–€ ํ…Œ๋‘๋ฆฌ๋ฅผ ๊ฐ€์ง„ ์š”์†Œ๊ฐ€ ๋จผ์ € ๊ทธ๋ ค์ ธ +๋’ค์— ์žˆ๋Š” ์š”์†Œ๊ฐ€ ์ผ๋ถ€ ๊ฐ€๋ ค์ง„ ๊ฒƒ์ด์ฃ . ์™„๋ฒฝํ•œ ํ•ด๊ฒฐ์ฑ…์€ ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๋•Œ๊ทธ๋•Œ ์ƒํ™ฉ์— +๋”ฐ๋ผ `alphaTest`๋‚˜ `transparent` ์˜ต์…˜์„ ์กฐ์ •ํ•ด์„œ ์ƒํ™ฉ์— ๋งž๋Š” ํ•ด๊ฒฐ์ฑ…์„ ์ฐพ์•„์•ผ +ํ•˜์ฃ . + +๊ฒฐ๊ตญ ์ด ๊ธ€์˜ ์ฃผ์ œ๋Š” "์™„๋ฒฝํ•œ ํˆฌ๋ช…๋„๋Š” ๊ตฌํ˜„ํ•˜๊ธฐ ํž˜๋“ค๋‹ค"๊ฐ€ ๋˜๊ฒ ๋„ค์š”. ์›ฌ๋งŒํ•œ ๋ฐฉ๋ฒ•์—๋Š” +๋ชจ๋‘ ๋ฌธ์ œ์™€, ํƒ€ํ˜‘์ , ํŽธ๋ฒ• ๋“ฑ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. + +์ž๋™์ฐจ์˜ ๊ฒฝ์šฐ๋ฅผ ์˜ˆ๋กœ ๋“ค์–ด๋ณด์ฃ . ์ž๋™์ฐจ๋Š” ๋ณดํ†ต 4๋ฉด์— ์œ ๋ฆฌ์ฐฝ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ Œ๋”๋ง ์ˆœ์„œ๋ฅผ +์ œ๋Œ€๋กœ ์ ์šฉํ•˜๋ ค๋ฉด ๊ฐ๊ฐ์˜ ์ฐฝ๋ฌธ์„ ๋ณ„๋„์˜ ์š”์†Œ๋กœ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ํ•˜๋‚˜์˜ ์š”์†Œ๋ผ๋ฉด +Three.js๊ฐ€ ๋ Œ๋”๋ง ์ˆœ์„œ๋ฅผ ์ œ๋Œ€๋กœ ๊ฒฐ์ •ํ•  ์ˆ˜ ์—†๊ฒ ์ฃ . + +์‹๋ฌผ์ด๋‚˜ ์ž”๋”” ๋“ฑ์„ ๊ตฌํ˜„ํ•  ๋•Œ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ์•ŒํŒŒ ํ…Œ์ŠคํŠธ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +์–ด๋–ค ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ• ์ง€๋Š” ์ „์ ์œผ๋กœ ์ƒํ™ฉ๊ณผ ์—ฌ๋Ÿฌ๋ถ„์˜ ํŒ๋‹จ์— ๋‹ฌ๋ ค ์žˆ์ฃ .
true
Other
mrdoob
three.js
a0656c6b5a207629127a856da0fc4a6ef5dc0a0f.json
Fix mismatch info I should have sent pull request together, but I discovered this later. same as previous, `light` should be child of `camera` not `scene`.
threejs/threejs-multiple-scenes-copy-canvas.html
@@ -80,7 +80,7 @@ const intensity = 1; const light = new THREE.DirectionalLight(color, intensity); light.position.set(-1, 2, 4); - scene.add(light); + camera.add(light); } return {scene, camera, controls};
false
Other
mrdoob
three.js
c17cb2587d863518ca27074135dcffe4f94c2099.json
Fix mismatch info (#88) light should be added to `camera` not `scene`
threejs/threejs-multiple-scenes-controls.html
@@ -82,7 +82,7 @@ const intensity = 1; const light = new THREE.DirectionalLight(color, intensity); light.position.set(-1, 2, 4); - scene.add(light); + camera.add(light); } return {scene, camera, controls};
false
Other
mrdoob
three.js
ca306c07511a63a257d07f505e6a0a7ef4dbc5a6.json
Add version to glslang.
examples/jsm/libs/glslang.js
@@ -1,7 +1,7 @@ - +// 0.0.15 var Module = (function() { var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; - + return ( function(Module) { Module = Module || {};
false
Other
mrdoob
three.js
0f5de4f5da1014f81c00d309f93b1a1e709341e4.json
Fix ReDos in Color.js
src/math/Color.js
@@ -169,14 +169,14 @@ class Color { let color; const name = m[ 1 ]; - const components = m[ 2 ]; + const components = m[ 2 ].replace(/^\s*/, ''); switch ( name ) { case 'rgb': case 'rgba': - if ( color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) { + if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) { // rgb(255,0,0) rgba(255,0,0,0.5) this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
false
Other
mrdoob
three.js
341b2e863a97932dd9705947b2327f4aee159156.json
Handle empty cases in Sphere.union (#24701)
src/math/Sphere.js
@@ -195,6 +195,18 @@ class Sphere { union( sphere ) { + // handle empty sphere cases + if ( sphere.isEmpty() ) { + + return; + + } else if ( this.isEmpty() ) { + + this.copy( sphere ); + return; + + } + // from https://github.com/juj/MathGeoLib/blob/2940b99b99cfe575dd45103ef20f4019dee15b54/src/Geometry/Sphere.cpp#L759-L769 // To enclose another sphere into this sphere, we only need to enclose two points:
false
Other
mrdoob
three.js
fa6899ae485cda3f5fceef325acf8bb2d9fc592f.json
Minimize glActiveTexture calls (#24492) * Don't set activetexture for textures that won't be bound * Fix texture state update of a previously bound texture * Combine bindTexture and bindTextureToSlot into a single function
src/renderers/webgl/WebGLState.js
@@ -880,25 +880,40 @@ function WebGLState( gl, extensions, capabilities ) { } - function bindTexture( webglType, webglTexture ) { + function bindTexture( webglType, webglTexture, webglSlot ) { - if ( currentTextureSlot === null ) { + if ( webglSlot === undefined ) { - activeTexture(); + if ( currentTextureSlot === null ) { + + webglSlot = gl.TEXTURE0 + maxTextures - 1; + + } else { + + webglSlot = currentTextureSlot; + + } } - let boundTexture = currentBoundTextures[ currentTextureSlot ]; + let boundTexture = currentBoundTextures[ webglSlot ]; if ( boundTexture === undefined ) { boundTexture = { type: undefined, texture: undefined }; - currentBoundTextures[ currentTextureSlot ] = boundTexture; + currentBoundTextures[ webglSlot ] = boundTexture; } if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) { + if ( currentTextureSlot !== webglSlot ) { + + gl.activeTexture( webglSlot ); + currentTextureSlot = webglSlot; + + } + gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] ); boundTexture.type = webglType;
true
Other
mrdoob
three.js
fa6899ae485cda3f5fceef325acf8bb2d9fc592f.json
Minimize glActiveTexture calls (#24492) * Don't set activetexture for textures that won't be bound * Fix texture state update of a previously bound texture * Combine bindTexture and bindTextureToSlot into a single function
src/renderers/webgl/WebGLTextures.js
@@ -460,8 +460,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, } - state.activeTexture( _gl.TEXTURE0 + slot ); - state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture ); + state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); } @@ -476,8 +475,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, } - state.activeTexture( _gl.TEXTURE0 + slot ); - state.bindTexture( _gl.TEXTURE_2D_ARRAY, textureProperties.__webglTexture ); + state.bindTexture( _gl.TEXTURE_2D_ARRAY, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); } @@ -492,8 +490,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, } - state.activeTexture( _gl.TEXTURE0 + slot ); - state.bindTexture( _gl.TEXTURE_3D, textureProperties.__webglTexture ); + state.bindTexture( _gl.TEXTURE_3D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); } @@ -508,8 +505,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, } - state.activeTexture( _gl.TEXTURE0 + slot ); - state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture ); + state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); } @@ -681,13 +677,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, const forceUpload = initTexture( textureProperties, texture ); const source = texture.source; - state.activeTexture( _gl.TEXTURE0 + slot ); - state.bindTexture( textureType, textureProperties.__webglTexture ); + state.bindTexture( textureType, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); const sourceProperties = properties.get( source ); if ( source.version !== sourceProperties.__version || forceUpload === true ) { + state.activeTexture( _gl.TEXTURE0 + slot ); + _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY ); _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha ); _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment ); @@ -1042,13 +1039,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, const forceUpload = initTexture( textureProperties, texture ); const source = texture.source; - state.activeTexture( _gl.TEXTURE0 + slot ); - state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture ); + state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); const sourceProperties = properties.get( source ); if ( source.version !== sourceProperties.__version || forceUpload === true ) { + state.activeTexture( _gl.TEXTURE0 + slot ); + _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY ); _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha ); _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
true
Other
mrdoob
three.js
24f2d651f46ec3af5e63ea949fa93ac9eb81e5f2.json
Simplify calls to lookAt() (#24909) * Simplify calls to lookAt() * Clean up
examples/jsm/loaders/3DMLoader.js
@@ -15,7 +15,6 @@ import { PointLight, SpotLight, RectAreaLight, - Vector3, Sprite, SpriteMaterial, CanvasTexture, @@ -625,7 +624,7 @@ class Rhino3dmLoader extends Loader { light.position.set( geometry.location[ 0 ] - ( height / 2 ), geometry.location[ 1 ], geometry.location[ 2 ] - ( width / 2 ) ); light.height = height; light.width = width; - light.lookAt( new Vector3( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] ) ); + light.lookAt( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] ); break;
true
Other
mrdoob
three.js
24f2d651f46ec3af5e63ea949fa93ac9eb81e5f2.json
Simplify calls to lookAt() (#24909) * Simplify calls to lookAt() * Clean up
examples/webgl_animation_skinning_morph.html
@@ -71,7 +71,7 @@ camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 100 ); camera.position.set( - 5, 3, 10 ); - camera.lookAt( new THREE.Vector3( 0, 2, 0 ) ); + camera.lookAt( 0, 2, 0 ); scene = new THREE.Scene(); scene.background = new THREE.Color( 0xe0e0e0 );
true
Other
mrdoob
three.js
24f2d651f46ec3af5e63ea949fa93ac9eb81e5f2.json
Simplify calls to lookAt() (#24909) * Simplify calls to lookAt() * Clean up
src/cameras/CubeCamera.js
@@ -1,6 +1,5 @@ import { NoToneMapping } from '../constants.js'; import { Object3D } from '../core/Object3D.js'; -import { Vector3 } from '../math/Vector3.js'; import { PerspectiveCamera } from './PerspectiveCamera.js'; const fov = 90, aspect = 1; @@ -18,37 +17,37 @@ class CubeCamera extends Object3D { const cameraPX = new PerspectiveCamera( fov, aspect, near, far ); cameraPX.layers = this.layers; cameraPX.up.set( 0, - 1, 0 ); - cameraPX.lookAt( new Vector3( 1, 0, 0 ) ); + cameraPX.lookAt( 1, 0, 0 ); this.add( cameraPX ); const cameraNX = new PerspectiveCamera( fov, aspect, near, far ); cameraNX.layers = this.layers; cameraNX.up.set( 0, - 1, 0 ); - cameraNX.lookAt( new Vector3( - 1, 0, 0 ) ); + cameraNX.lookAt( - 1, 0, 0 ); this.add( cameraNX ); const cameraPY = new PerspectiveCamera( fov, aspect, near, far ); cameraPY.layers = this.layers; cameraPY.up.set( 0, 0, 1 ); - cameraPY.lookAt( new Vector3( 0, 1, 0 ) ); + cameraPY.lookAt( 0, 1, 0 ); this.add( cameraPY ); const cameraNY = new PerspectiveCamera( fov, aspect, near, far ); cameraNY.layers = this.layers; cameraNY.up.set( 0, 0, - 1 ); - cameraNY.lookAt( new Vector3( 0, - 1, 0 ) ); + cameraNY.lookAt( 0, - 1, 0 ); this.add( cameraNY ); const cameraPZ = new PerspectiveCamera( fov, aspect, near, far ); cameraPZ.layers = this.layers; cameraPZ.up.set( 0, - 1, 0 ); - cameraPZ.lookAt( new Vector3( 0, 0, 1 ) ); + cameraPZ.lookAt( 0, 0, 1 ); this.add( cameraPZ ); const cameraNZ = new PerspectiveCamera( fov, aspect, near, far ); cameraNZ.layers = this.layers; cameraNZ.up.set( 0, - 1, 0 ); - cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) ); + cameraNZ.lookAt( 0, 0, - 1 ); this.add( cameraNZ ); }
true
Other
mrdoob
three.js
a13c6a3e106b1a3b2add618599175bd58f71259f.json
Introduce scene.backgroundIntensity (#24876)
docs/api/en/scenes/Scene.html
@@ -40,6 +40,11 @@ <h3>[property:Float backgroundBlurriness]</h3> Sets the blurriness of the background. Only influences environment maps assigned to [page:Scene.background]. Valid input is a float between *0* and *1*. Default is *0*. </p> + <h3>[property:Float backgroundIntensity]</h3> + <p> + Attenuates the color of the background. Only applies to background textures. Default is *1*. + </p> + <h3>[property:Texture environment]</h3> <p> Sets the environment map for all physical materials in the scene.
true
Other
mrdoob
three.js
a13c6a3e106b1a3b2add618599175bd58f71259f.json
Introduce scene.backgroundIntensity (#24876)
src/renderers/shaders/ShaderLib.js
@@ -218,6 +218,7 @@ const ShaderLib = { uniforms: { uvTransform: { value: /*@__PURE__*/ new Matrix3() }, t2D: { value: null }, + backgroundIntensity: { value: 1 } }, vertexShader: ShaderChunk.background_vert, @@ -230,7 +231,8 @@ const ShaderLib = { uniforms: { envMap: { value: null }, flipEnvMap: { value: - 1 }, - backgroundBlurriness: { value: 0 } + backgroundBlurriness: { value: 0 }, + backgroundIntensity: { value: 1 } }, vertexShader: ShaderChunk.backgroundCube_vert,
true
Other
mrdoob
three.js
a13c6a3e106b1a3b2add618599175bd58f71259f.json
Introduce scene.backgroundIntensity (#24876)
src/renderers/shaders/ShaderLib/background.glsl.js
@@ -13,21 +13,26 @@ void main() { export const fragment = /* glsl */` uniform sampler2D t2D; +uniform float backgroundIntensity; varying vec2 vUv; void main() { - gl_FragColor = texture2D( t2D, vUv ); + vec4 texColor = texture2D( t2D, vUv ); #ifdef DECODE_VIDEO_TEXTURE // inline sRGB decode (TODO: Remove this code when https://crbug.com/1256340 is solved) - gl_FragColor = vec4( mix( pow( gl_FragColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), gl_FragColor.rgb * 0.0773993808, vec3( lessThanEqual( gl_FragColor.rgb, vec3( 0.04045 ) ) ) ), gl_FragColor.w ); + texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w ); #endif + texColor.rgb *= backgroundIntensity; + + gl_FragColor = texColor; + #include <tonemapping_fragment> #include <encodings_fragment>
true
Other
mrdoob
three.js
a13c6a3e106b1a3b2add618599175bd58f71259f.json
Introduce scene.backgroundIntensity (#24876)
src/renderers/shaders/ShaderLib/backgroundCube.glsl.js
@@ -29,6 +29,7 @@ export const fragment = /* glsl */` uniform float flipEnvMap; uniform float backgroundBlurriness; +uniform float backgroundIntensity; varying vec3 vWorldDirection; @@ -50,6 +51,8 @@ void main() { #endif + texColor.rgb *= backgroundIntensity; + gl_FragColor = texColor; #include <tonemapping_fragment>
true
Other
mrdoob
three.js
a13c6a3e106b1a3b2add618599175bd58f71259f.json
Introduce scene.backgroundIntensity (#24876)
src/renderers/webgl/WebGLBackground.js
@@ -105,6 +105,7 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha, boxMesh.material.uniforms.envMap.value = background; boxMesh.material.uniforms.flipEnvMap.value = ( background.isCubeTexture && background.isRenderTargetTexture === false ) ? - 1 : 1; boxMesh.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness; + boxMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity; if ( currentBackground !== background || currentBackgroundVersion !== background.version || @@ -159,6 +160,7 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha, } planeMesh.material.uniforms.t2D.value = background; + planeMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity; if ( background.matrixAutoUpdate === true ) {
true
Other
mrdoob
three.js
a13c6a3e106b1a3b2add618599175bd58f71259f.json
Introduce scene.backgroundIntensity (#24876)
src/scenes/Scene.js
@@ -15,6 +15,7 @@ class Scene extends Object3D { this.fog = null; this.backgroundBlurriness = 0; + this.backgroundIntensity = 1; this.overrideMaterial = null; @@ -35,6 +36,7 @@ class Scene extends Object3D { if ( source.fog !== null ) this.fog = source.fog.clone(); this.backgroundBlurriness = source.backgroundBlurriness; + this.backgroundIntensity = source.backgroundIntensity; if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone(); @@ -50,6 +52,7 @@ class Scene extends Object3D { if ( this.fog !== null ) data.object.fog = this.fog.toJSON(); if ( this.backgroundBlurriness > 0 ) data.backgroundBlurriness = this.backgroundBlurriness; + if ( this.backgroundIntensity !== 1 ) data.backgroundIntensity = this.backgroundIntensity; return data;
true
Other
mrdoob
three.js
065f2c3f1763c6bbf2b4d7398aa38b078116fe41.json
Fix typos in fundamentals.html (#24901) * Fix typo in en/fundamentals.html Word `be` was repeated. * Remove extra "a"
manual/en/fundamentals.html
@@ -176,7 +176,7 @@ <h1>Fundamentals</h1> <p><img src="../resources/frustum-3d.svg" width="500" class="threejs_center"></p> <p>The height of the near and far planes are determined by the field of view. The width of both planes is determined by the field of view and the aspect.</p> -<p>Anything inside the defined frustum will be be drawn. Anything outside +<p>Anything inside the defined frustum will be drawn. Anything outside will not.</p> <p>The camera defaults to looking down the -Z axis with +Y up. We'll put our cube at the origin so we need to move the camera back a little from the origin @@ -209,7 +209,7 @@ <h1>Fundamentals</h1> <pre class="prettyprint showlinemods notranslate lang-js" translate="no">const material = new THREE.MeshBasicMaterial({color: 0x44aa88}); </pre> <p>We then create a <a href="/docs/#api/en/objects/Mesh"><code class="notranslate" translate="no">Mesh</code></a>. A <a href="/docs/#api/en/objects/Mesh"><code class="notranslate" translate="no">Mesh</code></a> in three represents the combination -of a three things</p> +of three things</p> <ol> <li>A <code class="notranslate" translate="no">Geometry</code> (the shape of the object)</li> <li>A <a href="/docs/#api/en/materials/Material"><code class="notranslate" translate="no">Material</code></a> (how to draw the object, shiny or flat, what color, what texture(s) to apply. Etc.)</li> @@ -461,4 +461,4 @@ <h3>es6 modules, three.js, and folder structure</h3> -</body></html> \ No newline at end of file +</body></html>
false
Other
mrdoob
three.js
b361e9b2f4c3d9a574612972c9749477787f1685.json
Fix Chinese typos on page responsive.html (#24884) Co-authored-by: xiaoke <xiaoke@micous.com>
manual/zh/responsive.html
@@ -1,49 +1,53 @@ -<!DOCTYPE html><html lang="zh"><head> - <meta charset="utf-8"> - <title>ๅ“ๅบ”ๅผ่ฎพ่ฎก</title> - <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> - <meta name="twitter:card" content="summary_large_image"> - <meta name="twitter:site" content="@threejs"> - <meta name="twitter:title" content="Three.js โ€“ ๅ“ๅบ”ๅผ่ฎพ่ฎก"> - <meta property="og:image" content="https://threejs.org/files/share.png"> - <link rel="shortcut icon" href="/files/favicon_white.ico" media="(prefers-color-scheme: dark)"> - <link rel="shortcut icon" href="/files/favicon.ico" media="(prefers-color-scheme: light)"> - - <link rel="stylesheet" href="/manual/resources/lesson.css"> - <link rel="stylesheet" href="/manual/resources/lang.css"> -<!-- Import maps polyfill --> -<!-- Remove this when import maps will be widely supported --> -<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script> - -<script type="importmap"> +<!DOCTYPE html> +<html lang="zh"> + +<head> + <meta charset="utf-8"> + <title>ๅ“ๅบ”ๅผ่ฎพ่ฎก</title> + <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> + <meta name="twitter:card" content="summary_large_image"> + <meta name="twitter:site" content="@threejs"> + <meta name="twitter:title" content="Three.js โ€“ ๅ“ๅบ”ๅผ่ฎพ่ฎก"> + <meta property="og:image" content="https://threejs.org/files/share.png"> + <link rel="shortcut icon" href="/files/favicon_white.ico" media="(prefers-color-scheme: dark)"> + <link rel="shortcut icon" href="/files/favicon.ico" media="(prefers-color-scheme: light)"> + + <link rel="stylesheet" href="/manual/resources/lesson.css"> + <link rel="stylesheet" href="/manual/resources/lang.css"> + <!-- Import maps polyfill --> + <!-- Remove this when import maps will be widely supported --> + <script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script> + + <script type="importmap"> { "imports": { "three": "../../build/three.module.js" } } </script> - <link rel="stylesheet" href="/manual/zh/lang.css"> - </head> - <body> - <div class="container"> - <div class="lesson-title"> - <h1>ๅ“ๅบ”ๅผ่ฎพ่ฎก</h1> - </div> - <div class="lesson"> - <div class="lesson-main"> - <p>่ฟ™ๆ˜ฏthree.js็ณปๅˆ—ๆ–‡็ซ ็š„็ฌฌไบŒ็ฏ‡ใ€‚ -็ฌฌไธ€็ฏ‡ๆ˜ฏ<a href="fundamentals.html">ๅ…ณไบŽๅŸบ็ก€</a>ใ€‚ -ๅฆ‚ๆžœไฝ ่ฟ˜ๆฒกๆœ‰้˜…่ฏป็ฌฌไธ€็ฏ‡้‚ฃไฝ ๅบ”่ฏฅไปŽ็ฌฌไธ€็ฏ‡ๅผ€ๅง‹ใ€‚</p> -<p>ๆœฌ็ฏ‡ๆ–‡็ซ ๆ˜ฏๅ…ณไบŽๅฆ‚ไฝ•่ฎฉไฝ ็š„three.jsๅบ”็”จ่‡ช้€‚ๅบ”ๅ„็งๆƒ…ๅ†ตใ€‚ -็ฝ‘้กต็š„ๅ“ๅบ”ๅผๆ˜ฏๆŒ‡่ฎฉๅ…ถๅœจๆกŒ้ขใ€ๅนณๆฟๅŠๆ‰‹ๆœบ็ญ‰ไธๅŒๅฐบๅฏธ็š„ๅฑๅน•ไธŠๆ˜พ็คบ่‰ฏๅฅฝใ€‚</p> -<p>ๅฏนthree.jsๆฅ่ฏดๆœ‰ๆ›ดๅคš็š„ๆƒ…ๅ†ต่ฆ่€ƒ่™‘ใ€‚ไพ‹ๅฆ‚๏ผŒๆˆ‘ไปฌๅฏ่ƒฝ้œ€่ฆๅค„็†ๆŽงไปถๅœจๅทฆไพงใ€ๅณไพงใ€้กถ้ƒจๆˆ–ๅบ•้ƒจ็š„ไธ‰็ปด็ผ–่พ‘ๅ™จใ€‚ๆœฌๆ–‡็š„ไธญ้—ด้ƒจๅˆ†ๅฑ•็คบไบ†ๅฆไธ€ไธชไพ‹ๅญใ€‚</p> -<p>ไธŠไธ€ไธชไพ‹ๅญไธญๆˆ‘ไปฌไฝฟ็”จไบ†ไธ€ไธชๆฒกๆœ‰่ฎพ็ฝฎๆ ทๅผๅ’Œๅฐบๅฏธ็š„ใ€‚</p> -<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;canvas id="c"&gt;&lt;/canvas&gt; + <link rel="stylesheet" href="/manual/zh/lang.css"> +</head> + +<body> + <div class="container"> + <div class="lesson-title"> + <h1>ๅ“ๅบ”ๅผ่ฎพ่ฎก</h1> + </div> + <div class="lesson"> + <div class="lesson-main"> + <p>่ฟ™ๆ˜ฏthree.js็ณปๅˆ—ๆ–‡็ซ ็š„็ฌฌไบŒ็ฏ‡ใ€‚ + ็ฌฌไธ€็ฏ‡ๆ˜ฏ<a href="fundamentals.html">ๅ…ณไบŽๅŸบ็ก€</a>ใ€‚ + ๅฆ‚ๆžœไฝ ่ฟ˜ๆฒกๆœ‰้˜…่ฏป็ฌฌไธ€็ฏ‡้‚ฃไฝ ๅบ”่ฏฅไปŽ็ฌฌไธ€็ฏ‡ๅผ€ๅง‹ใ€‚</p> + <p>ๆœฌ็ฏ‡ๆ–‡็ซ ๆ˜ฏๅ…ณไบŽๅฆ‚ไฝ•่ฎฉไฝ ็š„three.jsๅบ”็”จ่‡ช้€‚ๅบ”ๅ„็งๆƒ…ๅ†ตใ€‚ + ็ฝ‘้กต็š„ๅ“ๅบ”ๅผๆ˜ฏๆŒ‡่ฎฉๅ…ถๅœจๆกŒ้ขใ€ๅนณๆฟๅŠๆ‰‹ๆœบ็ญ‰ไธๅŒๅฐบๅฏธ็š„ๅฑๅน•ไธŠๆ˜พ็คบ่‰ฏๅฅฝใ€‚</p> + <p>ๅฏนthree.jsๆฅ่ฏดๆœ‰ๆ›ดๅคš็š„ๆƒ…ๅ†ต่ฆ่€ƒ่™‘ใ€‚ไพ‹ๅฆ‚๏ผŒๆˆ‘ไปฌๅฏ่ƒฝ้œ€่ฆๅค„็†ๆŽงไปถๅœจๅทฆไพงใ€ๅณไพงใ€้กถ้ƒจๆˆ–ๅบ•้ƒจ็š„ไธ‰็ปด็ผ–่พ‘ๅ™จใ€‚ๆœฌๆ–‡็š„ไธญ้—ด้ƒจๅˆ†ๅฑ•็คบไบ†ๅฆไธ€ไธชไพ‹ๅญใ€‚</p> + <p>ไธŠไธ€ไธชไพ‹ๅญไธญๆˆ‘ไปฌไฝฟ็”จไบ†ไธ€ไธชๆฒกๆœ‰่ฎพ็ฝฎๆ ทๅผๅ’Œๅฐบๅฏธ็š„ใ€‚</p> + <pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;canvas id="c"&gt;&lt;/canvas&gt; </pre> -<p>้‚ฃไธชcanvas้ป˜่ฎค300x150ๅƒ็ด ใ€‚</p> -<p>ๅœจwebๅนณๅฐๆŽจ่ไฝฟ็”จCSSๆฅ่ฎพ็ฝฎ็‰ฉไฝ“็š„ๅฐบๅฏธใ€‚</p> -<p>ๆˆ‘ไปฌ้€š่ฟ‡ๆทปๅŠ CSSๆฅ่ฎฉcanvasๅกซๅ……ๆ•ดไธช้กต้ขใ€‚</p> -<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;style&gt; + <p>้‚ฃไธชcanvas้ป˜่ฎค300x150ๅƒ็ด ใ€‚</p> + <p>ๅœจwebๅนณๅฐๆŽจ่ไฝฟ็”จCSSๆฅ่ฎพ็ฝฎ็‰ฉไฝ“็š„ๅฐบๅฏธใ€‚</p> + <p>ๆˆ‘ไปฌ้€š่ฟ‡ๆทปๅŠ CSSๆฅ่ฎฉcanvasๅกซๅ……ๆ•ดไธช้กต้ขใ€‚</p> + <pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;style&gt; html, body { margin: 0; height: 100%; @@ -55,30 +59,36 @@ <h1>ๅ“ๅบ”ๅผ่ฎพ่ฎก</h1> } &lt;/style&gt; </pre> -<p>HTMLไธญ็š„body้ป˜่ฎคๆœ‰5ไธชๅƒ็ด ็š„marginๅ€ผๆ‰€ไปฅ่ฎพ็ฝฎmarginไธบ0ๆฅ็งป้™คmarginๅ€ผใ€‚ -่ฎพ็ฝฎhtmlๅ’Œbody็š„้ซ˜ๅบฆไธบ100%่ฎฉไป–ไปฌๅ……ๆปกๆ•ดไธช็ช—ๅฃใ€‚ไธ็„ถ็š„่ฏไป–ไปฌ็š„ๅคงๅฐๅชไผš -ๅ’Œๅกซๅ……ไป–ไปฌ็š„ๅ†…ๅฎนไธ€ๆ ทใ€‚</p> -<p>็„ถๅŽๆˆ‘ไปฌ่ฎฉ<code class="notranslate" translate="no">id=c</code>็š„ๅ…ƒ็ด ็š„ๅฐบๅฏธๆ˜ฏๅฎนๅ™จ็š„100%่ฟ™้‡Œๆ˜ฏbodyๆ ‡็ญพใ€‚ </p> -<p>ๆœ€ๅŽๆˆ‘ไปฌ่ฎพ็ฝฎๅฎƒ็š„<code class="notranslate" translate="no">display</code>ไธบ<code class="notranslate" translate="no">block</code>ใ€‚canvas็š„display้ป˜่ฎคไธบ -<code class="notranslate" translate="no">inline</code>ใ€‚่กŒๅ†…ๅ…ƒ็ด ็š„ๆœซๅฐพไผšๆœ‰็ฉบๆ ผใ€‚ -้€š่ฟ‡่ฎพ็ฝฎcanvasไธบๅ—็บงๅ…ƒ็ด ๅฐฑ่ƒฝๆถˆ้™ค่ฟ™ไธช็ฉบๆ ผใ€‚</p> -<p>่ฟ™้‡Œๆ˜ฏ็ป“ๆžœใ€‚</p> -<p></p><div translate="no" class="threejs_example_container notranslate"> - <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-no-resize.html"></iframe></div> - <a class="threejs_center" href="/manual/examples/responsive-no-resize.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> -</div> - -<p></p> -<p>ไฝ ๅฏไปฅ็œ‹ๅˆฐcanvasๅ……ๆปกไบ†ๆ•ดไธช้กต้ข๏ผŒไฝ†ๆ˜ฏๆœ‰ไธคไธช้—ฎ้ข˜ใ€‚ -็ฌฌไธ€ๆ˜ฏๆˆ‘ไปฌ็š„็ซ‹ๆ–นไฝ“่ขซๆ‹‰ไผธไบ†ใ€‚ไป–ไปฌไธๆ˜ฏ็ซ‹ๆ–นไฝ“ไบ†ๆ›ดๅƒๆ˜ฏไธช็›’ๅญ๏ผŒๅคช้ซ˜ๆˆ–่€…ๅคชๅฎฝใ€‚ ๅœจๆ–ฐๆ ‡็ญพไธญๆ‰“ๅผ€ๅฎƒ็„ถๅŽๆ”นๅ˜ๅฐบๅฏธไฝ ๅฐฑ่ƒฝ็œ‹ๅˆฐ็ซ‹ๆ–นไฝ“ๆ˜ฏๆ€Žไนˆๅœจๅฎฝ้ซ˜ไธŠ่ขซๆ‹‰ไผธ็š„ใ€‚</p> -<p><img src="../resources/images/resize-incorrect-aspect.png" width="407" class="threejs_center nobg"></p> -<p>ๅฆไธ€ไธช้—ฎ้ข˜ๆ˜ฏ็ซ‹ๆ–นไฝ“็œ‹่ตทๆฅๅˆ†่พจ็އๅคชไฝŽๆˆ–่€…่ฏดๅ—็ŠถๅŒ–ๆˆ–่€…ๆœ‰็‚นๆจก็ณŠใ€‚ -ๅฐ†็ช—ๅฃๆ‹‰ไผธ็š„้žๅธธๅคงไฝ ๅฐฑ่ƒฝ็œ‹ๅˆฐ้—ฎ้ข˜ใ€‚</p> -<p><img src="../resources/images/resize-low-res.png" class="threejs_center nobg"></p> -<p>ๆˆ‘ไปฌๅ…ˆ่งฃๅ†ณๆ‹‰ไผธ็š„้—ฎ้ข˜ใ€‚ไธบๆญคๆˆ‘ไปฌ่ฆๅฐ†็›ธๆœบ็š„ๅฎฝ้ซ˜ๆฏ”่ฎพ็ฝฎไธบcanvas็š„ๅฎฝ้ซ˜ๆฏ”ใ€‚ -ๆˆ‘ไปฌๅฏไปฅ้€š่ฟ‡canvas็š„<code class="notranslate" translate="no">clientWidth</code>ๅ’Œ<code class="notranslate" translate="no">clientHeight</code>ๅฑžๆ€งๆฅๅฎž็Žฐใ€‚</p> -<p>ๆˆ‘ไปฌ้œ€่ฆๅฐ†ๆธฒๆŸ“ๅพช็Žฏๅ˜ๆˆ่ฟ™ๆ ทใ€‚</p> -<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function render(time) { + <p>HTMLไธญ็š„body้ป˜่ฎคๆœ‰5ไธชๅƒ็ด ็š„marginๅ€ผๆ‰€ไปฅ่ฎพ็ฝฎmarginไธบ0ๆฅ็งป้™คmarginๅ€ผใ€‚ + ่ฎพ็ฝฎhtmlๅ’Œbody็š„้ซ˜ๅบฆไธบ100%่ฎฉไป–ไปฌๅ……ๆปกๆ•ดไธช็ช—ๅฃใ€‚ไธ็„ถ็š„่ฏไป–ไปฌ็š„ๅคงๅฐๅชไผš + ๅ’Œๅกซๅ……ไป–ไปฌ็š„ๅ†…ๅฎนไธ€ๆ ทใ€‚</p> + <p>็„ถๅŽๆˆ‘ไปฌ่ฎฉ<code class="notranslate" translate="no">id=c</code>็š„ๅ…ƒ็ด ็š„ๅฐบๅฏธๆ˜ฏๅฎนๅ™จ็š„100%่ฟ™้‡Œๆ˜ฏbodyๆ ‡็ญพใ€‚ </p> + <p>ๆœ€ๅŽๆˆ‘ไปฌ่ฎพ็ฝฎๅฎƒ็š„<code class="notranslate" translate="no">display</code>ไธบ<code class="notranslate" + translate="no">block</code>ใ€‚canvas็š„display้ป˜่ฎคไธบ + <code class="notranslate" translate="no">inline</code>ใ€‚่กŒๅ†…ๅ…ƒ็ด ็š„ๆœซๅฐพไผšๆœ‰็ฉบๆ ผใ€‚ + ้€š่ฟ‡่ฎพ็ฝฎcanvasไธบๅ—็บงๅ…ƒ็ด ๅฐฑ่ƒฝๆถˆ้™ค่ฟ™ไธช็ฉบๆ ผใ€‚ + </p> + <p>่ฟ™้‡Œๆ˜ฏ็ป“ๆžœใ€‚</p> + <p></p> + <div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " + src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-no-resize.html"></iframe> + </div> + <a class="threejs_center" href="/manual/examples/responsive-no-resize.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> + </div> + + <p></p> + <p>ไฝ ๅฏไปฅ็œ‹ๅˆฐcanvasๅ……ๆปกไบ†ๆ•ดไธช้กต้ข๏ผŒไฝ†ๆ˜ฏๆœ‰ไธคไธช้—ฎ้ข˜ใ€‚ + ็ฌฌไธ€ๆ˜ฏๆˆ‘ไปฌ็š„็ซ‹ๆ–นไฝ“่ขซๆ‹‰ไผธไบ†ใ€‚ไป–ไปฌไธๆ˜ฏ็ซ‹ๆ–นไฝ“ไบ†ๆ›ดๅƒๆ˜ฏไธช็›’ๅญ๏ผŒๅคช้ซ˜ๆˆ–่€…ๅคชๅฎฝใ€‚ ๅœจๆ–ฐๆ ‡็ญพไธญๆ‰“ๅผ€ๅฎƒ็„ถๅŽๆ”นๅ˜ๅฐบๅฏธไฝ ๅฐฑ่ƒฝ็œ‹ๅˆฐ็ซ‹ๆ–นไฝ“ๆ˜ฏๆ€Žไนˆๅœจๅฎฝ้ซ˜ไธŠ่ขซๆ‹‰ไผธ็š„ใ€‚</p> + <p><img src="../resources/images/resize-incorrect-aspect.png" width="407" class="threejs_center nobg"></p> + <p>ๅฆไธ€ไธช้—ฎ้ข˜ๆ˜ฏ็ซ‹ๆ–นไฝ“็œ‹่ตทๆฅๅˆ†่พจ็އๅคชไฝŽๆˆ–่€…่ฏดๅ—็ŠถๅŒ–ๆˆ–่€…ๆœ‰็‚นๆจก็ณŠใ€‚ + ๅฐ†็ช—ๅฃๆ‹‰ไผธ็š„้žๅธธๅคงไฝ ๅฐฑ่ƒฝ็œ‹ๅˆฐ้—ฎ้ข˜ใ€‚</p> + <p><img src="../resources/images/resize-low-res.png" class="threejs_center nobg"></p> + <p>ๆˆ‘ไปฌๅ…ˆ่งฃๅ†ณๆ‹‰ไผธ็š„้—ฎ้ข˜ใ€‚ไธบๆญคๆˆ‘ไปฌ่ฆๅฐ†็›ธๆœบ็š„ๅฎฝ้ซ˜ๆฏ”่ฎพ็ฝฎไธบcanvas็š„ๅฎฝ้ซ˜ๆฏ”ใ€‚ + ๆˆ‘ไปฌๅฏไปฅ้€š่ฟ‡canvas็š„<code class="notranslate" translate="no">clientWidth</code>ๅ’Œ<code class="notranslate" + translate="no">clientHeight</code>ๅฑžๆ€งๆฅๅฎž็Žฐใ€‚</p> + <p>ๆˆ‘ไปฌ้œ€่ฆๅฐ†ๆธฒๆŸ“ๅพช็Žฏๅ˜ๆˆ่ฟ™ๆ ทใ€‚</p> + <pre class="prettyprint showlinemods notranslate lang-js" translate="no">function render(time) { time *= 0.001; + const canvas = renderer.domElement; @@ -87,30 +97,35 @@ <h1>ๅ“ๅบ”ๅผ่ฎพ่ฎก</h1> ... </pre> -<p>็Žฐๅœจ็ซ‹ๆ–นไฝ“ๅบ”่ฏฅไธไผšๅ˜ๅฝขไบ†ใ€‚</p> -<p></p><div translate="no" class="threejs_example_container notranslate"> - <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-update-camera.html"></iframe></div> - <a class="threejs_center" href="/manual/examples/responsive-update-camera.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> -</div> - -<p></p> -<p>ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€ไพ‹ๅญไฝ ๅบ”่ฏฅ่ƒฝ็œ‹ๅˆฐ็ซ‹ๆ–นไฝ“็š„ๅฎฝ้ซ˜ไธไผšๅ†่ขซๆ‹‰ไผธไบ†ใ€‚ -ไป–ไปฌ้ƒฝไผšไฟๆŒๆญฃ็กฎ็š„ๆฏ”ไพ‹ไธ็ฎก็ช—ๅฃ็š„ๅฐบๅฏธๅฆ‚ไฝ•ใ€‚</p> -<p><img src="../resources/images/resize-correct-aspect.png" width="407" class="threejs_center nobg"></p> -<p>ๆˆ‘ไปฌ็Žฐๅœจๆฅ่งฃๅ†ณๅ—็ŠถๅŒ–็š„้—ฎ้ข˜ใ€‚</p> -<p>canvasๅ…ƒ็ด ๆœ‰ไธคไธชๅฐบๅฏธใ€‚ไธ€ไธชๆ˜ฏcanvasๅœจ้กต้ขไธŠ็š„ๆ˜พ็คบๅฐบๅฏธ๏ผŒ -ๆ˜ฏๆˆ‘ไปฌ็”จCSSๆฅ่ฎพ็ฝฎ็š„ใ€‚ๅฆไธ€ไธชๅฐบๅฏธๆ˜ฏcanvasๆœฌ่บซๅƒ็ด ็š„ๆ•ฐ้‡ใ€‚่ฟ™ๅ’Œๅ›พ็‰‡ไธ€ๆ ทใ€‚ -ๆฏ”ๅฆ‚ๆˆ‘ไปฌๆœ‰ไธ€ไธช128x64ๅƒ็ด ็š„ๅ›พ็‰‡็„ถๅŽๆˆ‘ไปฌๅฏไปฅ้€š่ฟ‡CSS่ฎฉๅฎƒๆ˜พ็คบไธบ -400x200ๅƒ็ด ใ€‚</p> -<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;img src="some128x64image.jpg" style="width:400px; height:200px"&gt; + <p>็Žฐๅœจ็ซ‹ๆ–นไฝ“ๅบ”่ฏฅไธไผšๅ˜ๅฝขไบ†ใ€‚</p> + <p></p> + <div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " + src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-update-camera.html"></iframe> + </div> + <a class="threejs_center" href="/manual/examples/responsive-update-camera.html" + target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> + </div> + + <p></p> + <p>ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€ไพ‹ๅญไฝ ๅบ”่ฏฅ่ƒฝ็œ‹ๅˆฐ็ซ‹ๆ–นไฝ“็š„ๅฎฝ้ซ˜ไธไผšๅ†่ขซๆ‹‰ไผธไบ†ใ€‚ + ไป–ไปฌ้ƒฝไผšไฟๆŒๆญฃ็กฎ็š„ๆฏ”ไพ‹ไธ็ฎก็ช—ๅฃ็š„ๅฐบๅฏธๅฆ‚ไฝ•ใ€‚</p> + <p><img src="../resources/images/resize-correct-aspect.png" width="407" class="threejs_center nobg"></p> + <p>ๆˆ‘ไปฌ็Žฐๅœจๆฅ่งฃๅ†ณๅ—็ŠถๅŒ–็š„้—ฎ้ข˜ใ€‚</p> + <p>canvasๅ…ƒ็ด ๆœ‰ไธคไธชๅฐบๅฏธใ€‚ไธ€ไธชๆ˜ฏcanvasๅœจ้กต้ขไธŠ็š„ๆ˜พ็คบๅฐบๅฏธ๏ผŒ + ๆ˜ฏๆˆ‘ไปฌ็”จCSSๆฅ่ฎพ็ฝฎ็š„ใ€‚ๅฆไธ€ไธชๅฐบๅฏธๆ˜ฏcanvasๆœฌ่บซๅƒ็ด ็š„ๆ•ฐ้‡ใ€‚่ฟ™ๅ’Œๅ›พ็‰‡ไธ€ๆ ทใ€‚ + ๆฏ”ๅฆ‚ๆˆ‘ไปฌๆœ‰ไธ€ไธช128x64ๅƒ็ด ็š„ๅ›พ็‰‡็„ถๅŽๆˆ‘ไปฌๅฏไปฅ้€š่ฟ‡CSS่ฎฉๅฎƒๆ˜พ็คบไธบ + 400x200ๅƒ็ด ใ€‚</p> + <pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;img src="some128x64image.jpg" style="width:400px; height:200px"&gt; </pre> -<p>ไธ€ไธชcanvas็š„ๅ†…้ƒจๅฐบๅฏธ๏ผŒๅฎƒ็š„ๅˆ†่พจ็އ๏ผŒ้€šๅธธ่ขซๅซๅš็ป˜ๅ›พ็ผ“ๅ†ฒๅŒบ(drawingbuffer)ๅฐบๅฏธใ€‚ -ๅœจthree.jsไธญๆˆ‘ไปฌๅฏไปฅ้€š่ฟ‡่ฐƒ็”จ<code class="notranslate" translate="no">renderer.setSize</code>ๆฅ่ฎพ็ฝฎcanvas็š„็ป˜ๅ›พ็ผ“ๅ†ฒๅŒบใ€‚ -ๆˆ‘ไปฌๅบ”่ฏฅ้€‰ๆ‹ฉไป€ไนˆๅฐบๅฏธ? ๆœ€ๆ˜พ่€Œๆ˜“่ง็š„ๆ˜ฏ"ๅ’Œcanvas็š„ๆ˜พ็คบๅฐบๅฏธไธ€ๆ ท"ใ€‚ -ๅณๅฏไปฅ็›ดๆŽฅ็”จcanvas็š„<code class="notranslate" translate="no">clientWidth</code>ๅ’Œ<code class="notranslate" translate="no">clientHeight</code>ๅฑžๆ€งใ€‚</p> -<p>ๆˆ‘ไปฌๅ†™ไธ€ไธชๅ‡ฝๆ•ฐๆฅๆฃ€ๆŸฅๆธฒๆŸ“ๅ™จ็š„canvasๅฐบๅฏธๆ˜ฏไธๆ˜ฏๅ’Œcanvas็š„ๆ˜พ็คบๅฐบๅฏธไธไธ€ๆ ท -ๅฆ‚ๆžœไธไธ€ๆ ทๅฐฑ่ฎพ็ฝฎๅฎƒใ€‚</p> -<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function resizeRendererToDisplaySize(renderer) { + <p>ไธ€ไธชcanvas็š„ๅ†…้ƒจๅฐบๅฏธ๏ผŒๅฎƒ็š„ๅˆ†่พจ็އ๏ผŒ้€šๅธธ่ขซๅซๅš็ป˜ๅ›พ็ผ“ๅ†ฒๅŒบ(drawingbuffer)ๅฐบๅฏธใ€‚ + ๅœจthree.jsไธญๆˆ‘ไปฌๅฏไปฅ้€š่ฟ‡่ฐƒ็”จ<code class="notranslate" translate="no">renderer.setSize</code>ๆฅ่ฎพ็ฝฎcanvas็š„็ป˜ๅ›พ็ผ“ๅ†ฒๅŒบใ€‚ + ๆˆ‘ไปฌๅบ”่ฏฅ้€‰ๆ‹ฉไป€ไนˆๅฐบๅฏธ? ๆœ€ๆ˜พ่€Œๆ˜“่ง็š„ๆ˜ฏ"ๅ’Œcanvas็š„ๆ˜พ็คบๅฐบๅฏธไธ€ๆ ท"ใ€‚ + ๅณๅฏไปฅ็›ดๆŽฅ็”จcanvas็š„<code class="notranslate" translate="no">clientWidth</code>ๅ’Œ<code class="notranslate" + translate="no">clientHeight</code>ๅฑžๆ€งใ€‚</p> + <p>ๆˆ‘ไปฌๅ†™ไธ€ไธชๅ‡ฝๆ•ฐๆฅๆฃ€ๆŸฅๆธฒๆŸ“ๅ™จ็š„canvasๅฐบๅฏธๆ˜ฏไธๆ˜ฏๅ’Œcanvas็š„ๆ˜พ็คบๅฐบๅฏธไธไธ€ๆ ท + ๅฆ‚ๆžœไธไธ€ๆ ทๅฐฑ่ฎพ็ฝฎๅฎƒใ€‚</p> + <pre class="prettyprint showlinemods notranslate lang-js" translate="no">function resizeRendererToDisplaySize(renderer) { const canvas = renderer.domElement; const width = canvas.clientWidth; const height = canvas.clientHeight; @@ -121,17 +136,18 @@ <h1>ๅ“ๅบ”ๅผ่ฎพ่ฎก</h1> return needResize; } </pre> -<p>ๆณจๆ„ๆˆ‘ไปฌๆฃ€ๆŸฅไบ†canvasๆ˜ฏๅฆ็œŸ็š„้œ€่ฆ่ฐƒๆ•ดๅคงๅฐใ€‚ -่ฐƒๆ•ด็”ปๅธƒๅคงๅฐๆ˜ฏcanvas่ง„่Œƒ็š„ไธ€ไธชๆœ‰่ถฃ้ƒจๅˆ†๏ผŒๅฆ‚ๆžœๅฎƒๅทฒ็ปๆ˜ฏๆˆ‘ไปฌๆƒณ่ฆ็š„ๅคงๅฐ๏ผŒๆœ€ๅฅฝไธ่ฆ่ฎพ็ฝฎ็›ธๅŒ็š„ๅคงๅฐ.</p> -<p>ไธ€ๆ—ฆๆˆ‘ไปฌ็Ÿฅ้“ไบ†ๆ˜ฏๅฆ้œ€่ฆ่ฐƒๆ•ดๅคงๅฐๆˆ‘ไปฌๅฐฑ่ฐƒ็”จ<code class="notranslate" translate="no">renderer.setSize</code>็„ถๅŽ -ไผ ๅ…ฅๆ–ฐ็š„ๅฎฝ้ซ˜ใ€‚ๅœจๆœซๅฐพไผ ๅ…ฅ<code class="notranslate" translate="no">false</code>ๅพˆ้‡่ฆใ€‚ -<code class="notranslate" translate="no">render.setSize</code>้ป˜่ฎคไผš่ฎพ็ฝฎcanvas็š„CSSๅฐบๅฏธไฝ†่ฟ™ๅนถไธๆ˜ฏๆˆ‘ไปฌๆƒณ่ฆ็š„ใ€‚ -ๆˆ‘ไปฌๅธŒๆœ›ๆต่งˆๅ™จ่ƒฝ็ปง็ปญๅทฅไฝœๅฐฑๅƒๅ…ถไป–ไฝฟ็”จCSSๆฅๅฎšไน‰ๅฐบๅฏธ็š„ๅ…ถไป–ๅ…ƒ็ด ใ€‚ๆˆ‘ไปฌไธๅธŒๆœ› -three.jsไฝฟ็”จcanvasๅ’Œๅ…ถไป–ๅ…ƒ็ด ไธไธ€ๆ ทใ€‚</p> -<p>ๆณจๆ„ๅฆ‚ๆžœๆˆ‘ไปฌ็š„canvasๅคงๅฐ่ขซ่ฐƒๆ•ดไบ†้‚ฃๅ‡ฝๆ•ฐไผš่ฟ”ๅ›žtrueใ€‚ๆˆ‘ไปฌๅฏไปฅๅˆฉ็”จ -่ฟ™ไธชๆฅๆฃ€ๆŸฅๆ˜ฏๅฆๆœ‰ๅ…ถไป–็š„ไธœ่ฅฟๅบ”่ฏฅๆ›ดๆ–ฐใ€‚ๆˆ‘ไปฌไฟฎๆ”นๆธฒๆŸ“ๅพช็Žฏ -ๆฅไฝฟ็”จๆˆ‘ไปฌ็š„ๆ–ฐๅ‡ฝๆ•ฐใ€‚</p> -<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function render(time) { + <p>ๆณจๆ„ๆˆ‘ไปฌๆฃ€ๆŸฅไบ†canvasๆ˜ฏๅฆ็œŸ็š„้œ€่ฆ่ฐƒๆ•ดๅคงๅฐใ€‚ + ่ฐƒๆ•ด็”ปๅธƒๅคงๅฐๆ˜ฏcanvas่ง„่Œƒ็š„ไธ€ไธชๆœ‰่ถฃ้ƒจๅˆ†๏ผŒๅฆ‚ๆžœๅฎƒๅทฒ็ปๆ˜ฏๆˆ‘ไปฌๆƒณ่ฆ็š„ๅคงๅฐ๏ผŒๆœ€ๅฅฝไธ่ฆ่ฎพ็ฝฎ็›ธๅŒ็š„ๅคงๅฐ.</p> + <p>ไธ€ๆ—ฆๆˆ‘ไปฌ็Ÿฅ้“ไบ†ๆ˜ฏๅฆ้œ€่ฆ่ฐƒๆ•ดๅคงๅฐๆˆ‘ไปฌๅฐฑ่ฐƒ็”จ<code class="notranslate" translate="no">renderer.setSize</code>็„ถๅŽ + ไผ ๅ…ฅๆ–ฐ็š„ๅฎฝ้ซ˜ใ€‚ๅœจๆœซๅฐพไผ ๅ…ฅ<code class="notranslate" translate="no">false</code>ๅพˆ้‡่ฆใ€‚ + <code class="notranslate" translate="no">render.setSize</code>้ป˜่ฎคไผš่ฎพ็ฝฎcanvas็š„CSSๅฐบๅฏธไฝ†่ฟ™ๅนถไธๆ˜ฏๆˆ‘ไปฌๆƒณ่ฆ็š„ใ€‚ + ๆˆ‘ไปฌๅธŒๆœ›ๆต่งˆๅ™จ่ƒฝ็ปง็ปญๅทฅไฝœๅฐฑๅƒๅ…ถไป–ไฝฟ็”จCSSๆฅๅฎšไน‰ๅฐบๅฏธ็š„ๅ…ถไป–ๅ…ƒ็ด ใ€‚ๆˆ‘ไปฌไธๅธŒๆœ› + three.jsไฝฟ็”จcanvasๅ’Œๅ…ถไป–ๅ…ƒ็ด ไธไธ€ๆ ทใ€‚ + </p> + <p>ๆณจๆ„ๅฆ‚ๆžœๆˆ‘ไปฌ็š„canvasๅคงๅฐ่ขซ่ฐƒๆ•ดไบ†้‚ฃๅ‡ฝๆ•ฐไผš่ฟ”ๅ›žtrueใ€‚ๆˆ‘ไปฌๅฏไปฅๅˆฉ็”จ + ่ฟ™ไธชๆฅๆฃ€ๆŸฅๆ˜ฏๅฆๆœ‰ๅ…ถไป–็š„ไธœ่ฅฟๅบ”่ฏฅๆ›ดๆ–ฐใ€‚ๆˆ‘ไปฌไฟฎๆ”นๆธฒๆŸ“ๅพช็Žฏ + ๆฅไฝฟ็”จๆˆ‘ไปฌ็š„ๆ–ฐๅ‡ฝๆ•ฐใ€‚</p> + <pre class="prettyprint showlinemods notranslate lang-js" translate="no">function render(time) { time *= 0.001; + if (resizeRendererToDisplaySize(renderer)) { @@ -142,53 +158,64 @@ <h1>ๅ“ๅบ”ๅผ่ฎพ่ฎก</h1> ... </pre> -<p>ๅ› ไธบๅชๆœ‰canvas็š„ๆ˜พ็คบๅฐบๅฏธๅ˜ๅŒ–ๆ—ถๅฎฝ้ซ˜ๆฏ”ๆ‰ๅ˜ๅŒ–ๆ‰€ไปฅๆˆ‘ไปฌ -ๅชๅœจ<code class="notranslate" translate="no">resizeRendererToDisplaySize</code>ๅ‡ฝๆ•ฐ่ฟ”ๅ›ž<code class="notranslate" translate="no">true</code>ๆ—ถๆ‰่ฎพ็ฝฎๆ‘„ๅƒๆœบ็š„ๅฎฝ้ซ˜ๆฏ”ใ€‚</p> -<p></p><div translate="no" class="threejs_example_container notranslate"> - <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/responsive.html"></iframe></div> - <a class="threejs_center" href="/manual/examples/responsive.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> -</div> - -<p></p> -<p>็ŽฐๅœจๆธฒๆŸ“็š„ๅˆ†่พจ็އๅบ”่ฏฅๆ˜ฏๅ’Œcanvas็š„ๆ˜พ็คบๅฐบๅฏธไธ€ๆ ท็š„ใ€‚</p> -<p>ไธบไบ†่ฏดๆธ…ๆฅš่ฎฉCSSๅค„็†่ฐƒๆ•ดๅฐบๅฏธๆˆ‘ไปฌๅฐ†ไปฃ็ ๆ”พ่ฟ›<a href="../examples/threejs-responsive.js">ไธ€ไธชๅ•็‹ฌ็š„jsๆ–‡ไปถ</a>ใ€‚ -่ฟ™้‡Œ่ฟ˜ๆœ‰ไธ€ไบ›ไพ‹ๅญๆˆ‘ไปฌ่ฎฉCSSๅ†ณๅฎšๅฐบๅฏธ็š„ๅคงๅฐๅนถไธ”ๆณจๆ„ๆˆ‘ไปฌๅนถๆฒกๆœ‰ๆ”นๅ˜ไปปไฝ• -ไปฃ็ ๆฅ่ฎฉไป–ไปฌๅทฅไฝœใ€‚</p> -<p>ๆˆ‘ไปฌๅฐ†็ซ‹ๆ–นไฝ“ๆ”พๅœจๆ–‡ๅญ—ๆฎต่ฝ็š„ไธญ้—ดใ€‚</p> -<p></p><div translate="no" class="threejs_example_container notranslate"> - <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-paragraph.html&amp;startPane=html"></iframe></div> - <a class="threejs_center" href="/manual/examples/responsive-paragraph.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> -</div> - -<p></p> -<p>่ฟ™ๆ˜ฏๆˆ‘ไปฌๅœจ็ผ–่พ‘ๅ™จๆ ทๅผๅธƒๅฑ€ไธญไฝฟ็”จ็š„็›ธๅŒไปฃ็ ๏ผŒๅณไพง็š„ๆŽงๅˆถๅŒบๅŸŸๅฏไปฅ่ฐƒๆ•ดๅคงๅฐใ€‚</p> -<p></p><div translate="no" class="threejs_example_container notranslate"> - <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-editor.html&amp;startPane=html"></iframe></div> - <a class="threejs_center" href="/manual/examples/responsive-editor.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> -</div> - -<p></p> -<p>้‡็‚นๆณจๆ„ๆˆ‘ไปฌ็š„ไปฃ็ ๅนถๆฒกๆœ‰ๆ”นๅ˜๏ผŒๅชๆœ‰ๆˆ‘ไปฌ็š„HTMLๅ’ŒCSSๅ˜ไบ†ใ€‚</p> -<h2 id="-hd-dpi-">ๅบ”ๅฏนHD-DPIๆ˜พ็คบๅ™จ</h2> -<p>HD-DPIไปฃ่กจๆฏ่‹ฑๅฏธ้ซ˜ๅฏ†ๅบฆ็‚นๆ˜พ็คบๅ™จ(่ง†็ฝ‘่†œๆ˜พ็คบๅ™จ)ใ€‚ๅฎƒๆŒ‡็š„ๆ˜ฏๅฝ“ไปŠๅคงๅคšๆ•ฐ็š„Macๅ’Œwindowsๆœบๅ™จไปฅๅŠๅ‡ ไนŽๆ‰€ๆœ‰็š„ๆ™บ่ƒฝๆ‰‹ๆœบใ€‚</p> -<p>ๆต่งˆๅ™จไธญ็š„ๅทฅไฝœๆ–นๅผๆ˜ฏไธ็ฎกๅฑๅน•็š„ๅˆ†่พจ็އๆœ‰ๅคš้ซ˜ไฝฟ็”จCSSๅƒ็ด ่ฎพ็ฝฎๅฐบๅฏธไผš่ขซ่ฎคไธบๆ˜ฏไธ€ๆ ท็š„ใ€‚ -ๅŒๆ ท็š„็‰ฉ็†ๅฐบๅฏธๆต่งˆๅ™จไผšๆธฒๆŸ“ๅ‡บๅญ—ไฝ“็š„ๆ›ดๅคš็ป†่Š‚ใ€‚</p> -<p>ไฝฟ็”จthree.jsๆœ‰ๅคš็งๆ–นๆณ•ๆฅๅบ”ๅฏนHD-DPIใ€‚</p> -<p>็ฌฌไธ€็งๅฐฑๆ˜ฏไธๅšไปปไฝ•็‰นๅˆซ็š„ไบ‹ๆƒ…ใ€‚่ฟ™ๅฏไปฅ่ฏดๆ˜ฏๆœ€ๅธธ่ง็š„ใ€‚ -ๆธฒๆŸ“ไธ‰็ปดๅ›พๅฝข้œ€่ฆๅคง้‡็š„GPUๅค„็†่ƒฝๅŠ›ใ€‚็งปๅŠจ็ซฏ็š„GPU่ƒฝๅŠ›ๆฏ”ๆกŒ้ข็ซฏ็š„่ฆๅผฑใ€‚่‡ณๅฐ‘ๆˆชๆญขๅˆฐ2018ๅนด, -ๆ‰‹ๆœบ้ƒฝๆœ‰้žๅธธ้ซ˜็š„ๅˆ†่พจ็އๆ˜พ็คบๅ™จใ€‚ -็›ฎๅ‰ๆœ€ๅฅฝ็š„ๆ‰‹ๆœบ็š„HD-DPIๆฏ”ไพ‹ไธบ3x๏ผŒๆ„ๆ€ๆ˜ฏ้ž้ซ˜ๅฏ†ๅบฆ็‚นๆ˜พ็คบๅ™จไธŠ็š„ไธ€ไธชๅƒ็ด ๅœจ้ซ˜ๅฏ†ๅบฆๆ˜พ็คบๅ™จไธŠๆ˜ฏ9ไธชๅƒ็ด ใ€‚ -ๆ„ๅ‘ณ็€้œ€่ฆ9ๅ€็š„ๆธฒๆŸ“ใ€‚</p> -<p>่ฎก็ฎ—9ๅ€็š„ๅƒ็ด ๆ˜ฏไธชๅคงๅทฅ็จ‹ๆ‰€ไปฅๅฆ‚ๆžœไฟๆŒไปฃ็ ไธๅ˜ๆˆ‘ไปฌๅฐ†่ฎก็ฎ—ไธ€ไธชๅƒ็ด ็„ถๅŽๆต่งˆๅ™จๅฐ†ไปฅไธ‰ๅ€ๅคงๅฐ็ป˜ๅˆถ(3x3=9ๅƒ็ด )ใ€‚</p> -<p>ๅฏนไบŽๅคงๅž‹็š„three.jsๅบ”็”จๆฅ่ฏดไธŠ้ขๅฐฑๆ˜ฏไฝ ๆƒณ่ฆ็š„ๅฆไพงไฝ ็š„ๅธง้€Ÿ็އไผšๅพˆไฝŽใ€‚</p> -<p>ๅฐฝ็ฎกๅฆ‚ๆญคๅฆ‚ๆžœไฝ ็กฎๅฎžๆƒณ็”จ่ฎพๅค‡็š„ๅˆ†่พจ็އๆฅๆธฒๆŸ“๏ผŒthree.jsไธญๆœ‰ไธค็งๆ–นๆณ•ๆฅๅฎž็Žฐใ€‚</p> -<p>ไธ€็งๆ˜ฏไฝฟ็”จrenderer.setPixelRatioๆฅๅ‘Š่ฏ‰three.jsๅˆ†่พจ็އ็š„ๅ€ๆ•ฐใ€‚ -่ฎฟ้—ฎๆต่งˆๅ™จไปŽCSSๅƒ็ด ๅˆฐ่ฎพๅค‡ๅƒ็ด ็š„ๅ€ๆ•ฐ็„ถๅŽไผ ็ป™three.jsใ€‚</p> -<pre class="prettyprint showlinemods notranslate notranslate" translate="no"> renderer.setPixelRatio(window.devicePixelRatio); -</pre><p>ไน‹ๅŽไปปไฝ•ๅฏน<code class="notranslate" translate="no">renderer.setSize</code>็š„่ฐƒ็”จ้ƒฝไผš็ฅžๅฅ‡ๅœฐไฝฟ็”จๆ‚จ่ฏทๆฑ‚็š„ๅคงๅฐไน˜ไปฅๆ‚จไผ ๅ…ฅ็š„ๅƒ็ด ๆฏ”ไพ‹. -<strong>ๅผบ็ƒˆไธๅปบ่ฎฎ่ฟ™ๆ ท</strong>ใ€‚ ็œ‹ไธ‹้ขใ€‚</p> -<p>ๅฆไธ€็งๆ–นๆณ•ๆ˜ฏๅœจ่ฐƒๆ•ดcanvas็š„ๅคงๅฐๆ—ถ่‡ชๅทฑๅค„็†ใ€‚</p> -<pre class="prettyprint showlinemods notranslate lang-js" translate="no"> function resizeRendererToDisplaySize(renderer) { + <p>ๅ› ไธบๅชๆœ‰canvas็š„ๆ˜พ็คบๅฐบๅฏธๅ˜ๅŒ–ๆ—ถๅฎฝ้ซ˜ๆฏ”ๆ‰ๅ˜ๅŒ–ๆ‰€ไปฅๆˆ‘ไปฌ + ๅชๅœจ<code class="notranslate" translate="no">resizeRendererToDisplaySize</code>ๅ‡ฝๆ•ฐ่ฟ”ๅ›ž<code class="notranslate" + translate="no">true</code>ๆ—ถๆ‰่ฎพ็ฝฎๆ‘„ๅƒๆœบ็š„ๅฎฝ้ซ˜ๆฏ”ใ€‚</p> + <p></p> + <div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " + src="/manual/examples/resources/editor.html?url=/manual/examples/responsive.html"></iframe></div> + <a class="threejs_center" href="/manual/examples/responsive.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> + </div> + + <p></p> + <p>็ŽฐๅœจๆธฒๆŸ“็š„ๅˆ†่พจ็އๅบ”่ฏฅๆ˜ฏๅ’Œcanvas็š„ๆ˜พ็คบๅฐบๅฏธไธ€ๆ ท็š„ใ€‚</p> + <p>ไธบไบ†่ฏดๆธ…ๆฅš่ฎฉCSSๅค„็†่ฐƒๆ•ดๅฐบๅฏธๆˆ‘ไปฌๅฐ†ไปฃ็ ๆ”พ่ฟ›<a href="../examples/threejs-responsive.js">ไธ€ไธชๅ•็‹ฌ็š„jsๆ–‡ไปถ</a>ใ€‚ + ่ฟ™้‡Œ่ฟ˜ๆœ‰ไธ€ไบ›ไพ‹ๅญๆˆ‘ไปฌ่ฎฉCSSๅ†ณๅฎšๅฐบๅฏธ็š„ๅคงๅฐๅนถไธ”ๆณจๆ„ๆˆ‘ไปฌๅนถๆฒกๆœ‰ๆ”นๅ˜ไปปไฝ• + ไปฃ็ ๆฅ่ฎฉไป–ไปฌๅทฅไฝœใ€‚</p> + <p>ๆˆ‘ไปฌๅฐ†็ซ‹ๆ–นไฝ“ๆ”พๅœจๆ–‡ๅญ—ๆฎต่ฝ็š„ไธญ้—ดใ€‚</p> + <p></p> + <div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " + src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-paragraph.html&amp;startPane=html"></iframe> + </div> + <a class="threejs_center" href="/manual/examples/responsive-paragraph.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> + </div> + + <p></p> + <p>่ฟ™ๆ˜ฏๆˆ‘ไปฌๅœจ็ผ–่พ‘ๅ™จๆ ทๅผๅธƒๅฑ€ไธญไฝฟ็”จ็š„็›ธๅŒไปฃ็ ๏ผŒๅณไพง็š„ๆŽงๅˆถๅŒบๅŸŸๅฏไปฅ่ฐƒๆ•ดๅคงๅฐใ€‚</p> + <p></p> + <div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " + src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-editor.html&amp;startPane=html"></iframe> + </div> + <a class="threejs_center" href="/manual/examples/responsive-editor.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> + </div> + + <p></p> + <p>้‡็‚นๆณจๆ„ๆˆ‘ไปฌ็š„ไปฃ็ ๅนถๆฒกๆœ‰ๆ”นๅ˜๏ผŒๅชๆœ‰ๆˆ‘ไปฌ็š„HTMLๅ’ŒCSSๅ˜ไบ†ใ€‚</p> + <h2 id="-hd-dpi-">ๅบ”ๅฏนHD-DPIๆ˜พ็คบๅ™จ</h2> + <p>HD-DPIไปฃ่กจๆฏ่‹ฑๅฏธ้ซ˜ๅฏ†ๅบฆ็‚นๆ˜พ็คบๅ™จ(่ง†็ฝ‘่†œๆ˜พ็คบๅ™จ)ใ€‚ๅฎƒๆŒ‡็š„ๆ˜ฏๅฝ“ไปŠๅคงๅคšๆ•ฐ็š„Macๅ’Œwindowsๆœบๅ™จไปฅๅŠๅ‡ ไนŽๆ‰€ๆœ‰็š„ๆ™บ่ƒฝๆ‰‹ๆœบใ€‚</p> + <p>ๆต่งˆๅ™จไธญ็š„ๅทฅไฝœๆ–นๅผๆ˜ฏไธ็ฎกๅฑๅน•็š„ๅˆ†่พจ็އๆœ‰ๅคš้ซ˜ไฝฟ็”จCSSๅƒ็ด ่ฎพ็ฝฎๅฐบๅฏธไผš่ขซ่ฎคไธบๆ˜ฏไธ€ๆ ท็š„ใ€‚ + ๅŒๆ ท็š„็‰ฉ็†ๅฐบๅฏธๆต่งˆๅ™จไผšๆธฒๆŸ“ๅ‡บๅญ—ไฝ“็š„ๆ›ดๅคš็ป†่Š‚ใ€‚</p> + <p>ไฝฟ็”จthree.jsๆœ‰ๅคš็งๆ–นๆณ•ๆฅๅบ”ๅฏนHD-DPIใ€‚</p> + <p>็ฌฌไธ€็งๅฐฑๆ˜ฏไธๅšไปปไฝ•็‰นๅˆซ็š„ไบ‹ๆƒ…ใ€‚่ฟ™ๅฏไปฅ่ฏดๆ˜ฏๆœ€ๅธธ่ง็š„ใ€‚ + ๆธฒๆŸ“ไธ‰็ปดๅ›พๅฝข้œ€่ฆๅคง้‡็š„GPUๅค„็†่ƒฝๅŠ›ใ€‚็งปๅŠจ็ซฏ็š„GPU่ƒฝๅŠ›ๆฏ”ๆกŒ้ข็ซฏ็š„่ฆๅผฑใ€‚่‡ณๅฐ‘ๆˆชๆญขๅˆฐ2018ๅนด, + ๆ‰‹ๆœบ้ƒฝๆœ‰้žๅธธ้ซ˜็š„ๅˆ†่พจ็އๆ˜พ็คบๅ™จใ€‚ + ็›ฎๅ‰ๆœ€ๅฅฝ็š„ๆ‰‹ๆœบ็š„HD-DPIๆฏ”ไพ‹ไธบ3x๏ผŒๆ„ๆ€ๆ˜ฏ้ž้ซ˜ๅฏ†ๅบฆ็‚นๆ˜พ็คบๅ™จไธŠ็š„ไธ€ไธชๅƒ็ด ๅœจ้ซ˜ๅฏ†ๅบฆๆ˜พ็คบๅ™จไธŠๆ˜ฏ9ไธชๅƒ็ด ใ€‚ + ๆ„ๅ‘ณ็€้œ€่ฆ9ๅ€็š„ๆธฒๆŸ“ใ€‚</p> + <p>่ฎก็ฎ—9ๅ€็š„ๅƒ็ด ๆ˜ฏไธชๅคงๅทฅ็จ‹ๆ‰€ไปฅๅฆ‚ๆžœไฟๆŒไปฃ็ ไธๅ˜ๆˆ‘ไปฌๅฐ†่ฎก็ฎ—ไธ€ไธชๅƒ็ด ็„ถๅŽๆต่งˆๅ™จๅฐ†ไปฅไธ‰ๅ€ๅคงๅฐ็ป˜ๅˆถ(3x3=9ๅƒ็ด )ใ€‚</p> + <p>ๅฏนไบŽๅคงๅž‹็š„three.jsๅบ”็”จๆฅ่ฏดไธŠ้ขๅฐฑๆ˜ฏไฝ ๆƒณ่ฆ็š„ๅฆไพงไฝ ็š„ๅธง้€Ÿ็އไผšๅพˆไฝŽใ€‚</p> + <p>ๅฐฝ็ฎกๅฆ‚ๆญคๅฆ‚ๆžœไฝ ็กฎๅฎžๆƒณ็”จ่ฎพๅค‡็š„ๅˆ†่พจ็އๆฅๆธฒๆŸ“๏ผŒthree.jsไธญๆœ‰ไธค็งๆ–นๆณ•ๆฅๅฎž็Žฐใ€‚</p> + <p>ไธ€็งๆ˜ฏไฝฟ็”จrenderer.setPixelRatioๆฅๅ‘Š่ฏ‰three.jsๅˆ†่พจ็އ็š„ๅ€ๆ•ฐใ€‚ + ่ฎฟ้—ฎๆต่งˆๅ™จไปŽCSSๅƒ็ด ๅˆฐ่ฎพๅค‡ๅƒ็ด ็š„ๅ€ๆ•ฐ็„ถๅŽไผ ็ป™three.jsใ€‚</p> + <pre class="prettyprint showlinemods notranslate notranslate" translate="no"> renderer.setPixelRatio(window.devicePixelRatio); +</pre> + <p>ไน‹ๅŽไปปไฝ•ๅฏน<code class="notranslate" translate="no">renderer.setSize</code>็š„่ฐƒ็”จ้ƒฝไผš็ฅžๅฅ‡ๅœฐไฝฟ็”จๆ‚จ่ฏทๆฑ‚็š„ๅคงๅฐไน˜ไปฅๆ‚จไผ ๅ…ฅ็š„ๅƒ็ด ๆฏ”ไพ‹. + <strong>ๅผบ็ƒˆไธๅปบ่ฎฎ่ฟ™ๆ ท</strong>ใ€‚ ็œ‹ไธ‹้ขใ€‚ + </p> + <p>ๅฆไธ€็งๆ–นๆณ•ๆ˜ฏๅœจ่ฐƒๆ•ดcanvas็š„ๅคงๅฐๆ—ถ่‡ชๅทฑๅค„็†ใ€‚</p> + <pre class="prettyprint showlinemods notranslate lang-js" translate="no"> function resizeRendererToDisplaySize(renderer) { const canvas = renderer.domElement; const pixelRatio = window.devicePixelRatio; const width = canvas.clientWidth * pixelRatio | 0; @@ -200,32 +227,37 @@ <h2 id="-hd-dpi-">ๅบ”ๅฏนHD-DPIๆ˜พ็คบๅ™จ</h2> return needResize; } </pre> -<p>็ฌฌไบŒ็ซ ๆ–นๆณ•ไปŽๅฎข่ง‚ไธŠๆฅ่ฏดๆ›ดๅฅฝใ€‚ไธบไป€ไนˆ๏ผŸๅ› ไธบๆˆ‘ๆ‹ฟๅˆฐไบ†ๆˆ‘ๆƒณ่ฆ็š„ใ€‚ -ๅœจไฝฟ็”จthree.jsๆ—ถๆœ‰ๅพˆๅคš็งๆƒ…ๅ†ตไธ‹ๆˆ‘ไปฌ้œ€่ฆ็Ÿฅ้“canvas็š„็ป˜ๅ›พ็ผ“ๅ†ฒๅŒบ็š„็กฎๅˆ‡ๅฐบๅฏธใ€‚ -ๆฏ”ๅฆ‚ๅˆถไฝœๅŽๆœŸๅค„็†ๆปค้•œๆˆ–่€…ๆˆ‘ไปฌๅœจๆ“ไฝœ็€่‰ฒๅ™จ้œ€่ฆ่ฎฟ้—ฎgl_FragCoordๅ˜้‡๏ผŒๅฆ‚ๆžœๆˆ‘ไปฌๆˆชๅฑๆˆ–่€…็ป™GPU -่ฏปๅ–ๅƒ็ด ๏ผŒ็ป˜ๅˆถๅˆฐไบŒ็ปด็š„canvas็ญ‰็ญ‰ใ€‚ -้€š่ฟ‡ๆˆ‘ไปฌ่‡ชๅทฑๅค„็†ๆˆ‘ไปฌไผšไธ€็›ด็Ÿฅ้“ไฝฟ็”จ็š„ๅฐบๅฏธๆ˜ฏไธๆ˜ฏๆˆ‘ไปฌ้œ€่ฆ็š„ใ€‚ -ๅน•ๅŽๅนถๆฒกๆœ‰ไป€ไนˆ็‰นๆฎŠ็š„้ญ”ๆณ•ๅ‘็”Ÿใ€‚</p> -<p>่ฟ™ๆ˜ฏไธ€ไธชไฝฟ็”จไธŠ้ขไปฃ็ ็š„ไพ‹ๅญใ€‚</p> -<p></p><div translate="no" class="threejs_example_container notranslate"> - <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-hd-dpi.html"></iframe></div> - <a class="threejs_center" href="/manual/examples/responsive-hd-dpi.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> -</div> - -<p></p> -<p>ๅฏ่ƒฝๅพˆ้šพ็œ‹ๅ‡บๅŒบๅˆซไฝ†ๆ˜ฏๅฆ‚ๆžœไฝ ๆœ‰ไธ€ไธชHD-DPIๆ˜พ็คบๅ™จ -ๅ’ŒไธŠ้ข็š„ไพ‹ๅญๅšๅฏนๆฏ”ไฝ ๅฐฑ่ƒฝๅ‘็Žฐ่พน่ง’ๆ›ดๆธ…ๆ™ฐใ€‚</p> -<p>่ฟ™็ฏ‡ๆ–‡็ซ ๆถต็›–ไบ†ไธ€ไธช้žๅธธๅŸบ็ก€ไฝ†ๆ˜ฏๅพˆๆœ‰ๅฟ…่ฆ็š„ไธป้ข˜ใ€‚ๆŽฅไธ‹ๆฅๆˆ‘ไปฌๅฟซ้€Ÿ -<a href="primitives.html">่ฟ‡ไธ€้three.jsๆไพ›็š„ๅŸบๆœฌ็š„ไธœ่ฅฟ </a>.</p> - + <p>็ฌฌไบŒ็งๆ–นๆณ•ไปŽๅฎข่ง‚ไธŠๆฅ่ฏดๆ›ดๅฅฝใ€‚ไธบไป€ไนˆ๏ผŸๅ› ไธบๆˆ‘ๆ‹ฟๅˆฐไบ†ๆˆ‘ๆƒณ่ฆ็š„ใ€‚ + ๅœจไฝฟ็”จthree.jsๆ—ถๆœ‰ๅพˆๅคš็งๆƒ…ๅ†ตไธ‹ๆˆ‘ไปฌ้œ€่ฆ็Ÿฅ้“canvas็š„็ป˜ๅ›พ็ผ“ๅ†ฒๅŒบ็š„็กฎๅˆ‡ๅฐบๅฏธใ€‚ + ๆฏ”ๅฆ‚ๅˆถไฝœๅŽๆœŸๅค„็†ๆปค้•œๆˆ–่€…ๆˆ‘ไปฌๅœจๆ“ไฝœ็€่‰ฒๅ™จ้œ€่ฆ่ฎฟ้—ฎgl_FragCoordๅ˜้‡๏ผŒๅฆ‚ๆžœๆˆ‘ไปฌๆˆชๅฑๆˆ–่€…็ป™GPU + ่ฏปๅ–ๅƒ็ด ๏ผŒ็ป˜ๅˆถๅˆฐไบŒ็ปด็š„canvas็ญ‰็ญ‰ใ€‚ + ้€š่ฟ‡ๆˆ‘ไปฌ่‡ชๅทฑๅค„็†ๆˆ‘ไปฌไผšไธ€็›ด็Ÿฅ้“ไฝฟ็”จ็š„ๅฐบๅฏธๆ˜ฏไธๆ˜ฏๆˆ‘ไปฌ้œ€่ฆ็š„ใ€‚ + ๅน•ๅŽๅนถๆฒกๆœ‰ไป€ไนˆ็‰นๆฎŠ็š„้ญ”ๆณ•ๅ‘็”Ÿใ€‚</p> + <p>่ฟ™ๆ˜ฏไธ€ไธชไฝฟ็”จไธŠ้ขไปฃ็ ็š„ไพ‹ๅญใ€‚</p> + <p></p> + <div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " + src="/manual/examples/resources/editor.html?url=/manual/examples/responsive-hd-dpi.html"></iframe></div> + <a class="threejs_center" href="/manual/examples/responsive-hd-dpi.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> </div> + + <p></p> + <p>ๅฏ่ƒฝๅพˆ้šพ็œ‹ๅ‡บๅŒบๅˆซไฝ†ๆ˜ฏๅฆ‚ๆžœไฝ ๆœ‰ไธ€ไธชHD-DPIๆ˜พ็คบๅ™จ + ๅ’ŒไธŠ้ข็š„ไพ‹ๅญๅšๅฏนๆฏ”ไฝ ๅฐฑ่ƒฝๅ‘็Žฐ่พน่ง’ๆ›ดๆธ…ๆ™ฐใ€‚</p> + <p>่ฟ™็ฏ‡ๆ–‡็ซ ๆถต็›–ไบ†ไธ€ไธช้žๅธธๅŸบ็ก€ไฝ†ๆ˜ฏๅพˆๆœ‰ๅฟ…่ฆ็š„ไธป้ข˜ใ€‚ๆŽฅไธ‹ๆฅๆˆ‘ไปฌๅฟซ้€Ÿ่ฟ‡ไธ€้ + <a href="primitives.html">three.jsๆไพ›็š„ๅŸบๆœฌ็š„ไธœ่ฅฟ </a>. + </p> + </div> </div> - + </div> + <script src="/manual/resources/prettify.js"></script> <script src="/manual/resources/lesson.js"></script> -</body></html> \ No newline at end of file +</body> + +</html> \ No newline at end of file
false
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/WebGL1Renderer.html
@@ -0,0 +1,52 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:WebGLRenderer] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Poichรฉ la versione r118 [page:WebGLRenderer] utilizza automaticamente un contesto di rendering WebGL 2, quando viene aggiornato un progetto estistente a + => r118, l'applicazione potrebbe rompersi per due ragioni: + + <ul> + <li>Il codice dello shader personalizzato deve essere conforme a GLSL 3.0.</li> + <li>I controlli dell'estensione WebGL 1 devono essere cambiati.</li> + </ul> + + Se non hai tempo di cambiare il tuo codice ma vuoi ancora utilizzare l'ultima versione, puoi usare [name]. + Questa versione di renderer forzerร  un contesto di rendering WebGL 1. + </p> + + <h2>Costruttore</h2> + + <h3>[name]( [param:Object parameters] )</h3> + <p> + Crea un nuovo [name]. + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:WebGLRenderer] per le proprietร  comuni.</p> + + <h3>[property:Boolean isWebGL1Renderer]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + + <h2>Metodi</h2> + <p>Vedi la classe base [page:WebGLRenderer] per i metodi comuni.</p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/WebGL3DRenderTarget.html
@@ -0,0 +1,53 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:WebGLRenderTarget] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Rappresenta un render target tridimensionale. + </p> + + <h2>Costruttore</h2> + + <h3>[name]( [param:Number width], [param:Number height], [param:Number depth] )</h3> + <p> + [page:Number width] - la lunghezza del render target, in pixel. Il valore predefinito รจ `1`.<br /> + [page:Number height] - l'altezza del render target, in pixel. Il valore predefinito รจ `1`.<br /> + [page:Number depth] - la profonditร  del render target. Il valore predefinito รจ `1`.<br /><br /> + + Crea un nuovo [name]. + </p> + + <h2>Proprietร </h2> + + <h3>Vedi [page:WebGLRenderTarget] per le proprietร  ereditate</h3> + + <h3>[property:number depth]</h3> + <p> + La profonditร  del render target. + </p> + + <h3>[property:Data3DTexture texture]</h3> + <p> + La proprietร  texture รจ sovrasctitta con un'istanza di [page:Data3DTexture]. + </p> + + <h2>Metodi</h2> + + <h3>Vedi [page:WebGLRenderTarget] per i metodi ereditati</h3> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/WebGLArrayRenderTarget.html
@@ -0,0 +1,59 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:WebGLRenderTarget] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Questo tipo di render target rappresenta un array di texture. + </p> + + <h2>Esempi</h2> + + <p> + [example:webgl2_rendertarget_texture2darray WebGL 2 / render target / array]<br /> + </p> + + <h2>Costruttore</h2> + + <h3>[name]( [param:Number width], [param:Number height], [param:Number depth] )</h3> + <p> + [page:Number width] - la lunghezza del render target, in pixel. Il valore predefinito รจ `1`.<br /> + [page:Number height] - l'altezza del render target, in pixel. Il valore predefinito รจ `1`.<br /> + [page:Number depth] - la profonditร  del render target. Il valore predefinito รจ `1`.<br /><br /> + + Crea un nuovo [name]. + </p> + + <h2>Proprietร </h2> + + <h3>Vedi [page:WebGLRenderTarget] per le proprietร  ereditate</h3> + + <h3>[property:number depth]</h3> + <p> + La profonditร  del render target. + </p> + + <h3>[property:DataArrayTexture texture]</h3> + <p> + La proprietร  texture รจ sovrasctitta con un'istanza di [page:DataArrayTexture]. + </p> + + <h2>Metodi</h2> + + <h3>Vedi [page:WebGLRenderTarget] per i metodi ereditati</h3> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/WebGLCubeRenderTarget.html
@@ -0,0 +1,79 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:WebGLRenderTarget] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Utilizzato da [page:CubeCamera] come suo [page:WebGLRenderTarget]. + </p> + + <h2>Esempi</h2> + + <p>Vedi [page:CubeCamera] per gli esempi.</p> + + + <h2>Costruttore</h2> + + + <h3>[name]([param:Number size], [param:Object options])</h3> + <p> + [page:Float size] - la dimensione, in pixel. Il valore predefinito รจ `1`.<br /> + options - (opzionale) oggetto che contiene i parametri della texture per un target texture auto generato + e i booleani depthBuffer/stencilBuffer. + + Per una spiegazione dei parametri della texture vedi [page:Texture Texture]. Le seguenti + sono opzioni valide:<br /><br /> + + [page:Constant wrapS] - Il valore predefinito รจ [page:Textures ClampToEdgeWrapping]. <br /> + [page:Constant wrapT] - Il valore predefinito รจ [page:Textures ClampToEdgeWrapping]. <br /> + [page:Constant magFilter] - Il valore predefinito รจ [page:Textures .LinearFilter]. <br /> + [page:Constant minFilter] - Il valore predefinito รจ [page:Textures LinearFilter]. <br /> + [page:Boolean generateMipmaps] - Il valore predefinito รจ `false`.<br /> + [page:Constant format] - Il valore predefinito รจ [page:Textures RGBAFormat]. <br /> + [page:Constant type] - Il valore predefinito รจ [page:Textures UnsignedByteType]. <br /> + [page:Number anisotropy] - Il valore predefinito รจ `1`. Vedi [page:Texture.anisotropy]<br /> + [page:Constant encoding] - Il valore predefinito รจ [page:Textures LinearEncoding]. <br /> + [page:Boolean depthBuffer] - Il valore predefinito รจ `true`.<br /> + [page:Boolean stencilBuffer] - Il valore predefinito รจ `false`.<br /><br /> + + Crea un nuovo [name] + </p> + + <h2>Proprietร </h2> + + <h3>Vedi [page:WebGLRenderTarget] per le proprietร  ereditate</h3> + + <h2>Metodi</h2> + + <h3>Vedi [page:WebGLRenderTarget] per i metodi ereditati</h3> + + <h3>[method:this fromEquirectangularTexture]( [param:WebGLRenderer renderer], [param:Texture texture] )</h3> + <p> + [page:WebGLRenderer renderer] โ€” il renderer.<br/> + [page:Texture texture] โ€” la texture equirettangolare. + </p> + <p> + Utilizza questo metodo se vuoi convertire un panorama equirettangolare nel formato cubemap. + </p> + + <h3>[method:undefined clear]( [param:WebGLRenderer renderer], [param:Boolean color], [param:Boolean depth], [param:Boolean stencil] )</h3> + <p> + Chiama questo metodo per cancellare il colore, la profonditร  e/o i buffer stencil del render target. + Il buffer del colore รจ impostato al colore corrente del renderer. L'impostazione predefinita degli argomenti รจ `true`. + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/WebGLMultipleRenderTargets.html
@@ -0,0 +1,67 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:WebGLRenderTarget] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Un target di rendering speciale che consente a un fragment shader di scrivere su piรน texture. + Questo approccio รจ utile per le tecniche di rendering avanzate come la post-eleborazione o il rendering differito. + + Attenzione: [name] puรฒ solo essere utilizzato in un contesto di rendering WebGL 2. + </p> + + <h2>Esempi</h2> + + <p> + [example:webgl2_multiple_rendertargets webgl2 / multiple / rendertargets ] + </p> + + <h2>Costruttore</h2> + + + <h3>[name]([param:Number width], [param:Number height], [param:Number count], [param:Object options])</h3> + + <p> + [page:Number width] - La larghezza del target di rendering. Il valore predefinito รจ `1`.<br /> + [page:Number height] - L'altezza del target di rendering. Il valore predefinito รจ `1`.<br /> + [page:Number count] - Il numero di target di rendering. Il valore predefinito รจ `1`.<br /> + + options - (oggetto opzionale che contiene i parametri della texture per una texture target auto generata + e i booleani depthBuffer/stencilBuffer. Per una spiegazione dei parametri della texture consultare [page:Texture Texture]. + Per un elenco di opzioni valide, consultare [page:WebGLRenderTarget WebGLRenderTarget].)<br /><br /> + </p> + + <h2>Proprietร </h2> + + <h3>[property:Boolean isWebGLMultipleRenderTargets]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + <h3>[property:Array texture]</h3> + <p> + La proprietร  texture viene sovrascritta in [name] e sostituita con un array. Questo array contiene i + riferimenti alla [page:WebGLRenderTarget.texture texture] dei rispettivi target di rendering. + </p> + + <p>Le proprietร  [page:WebGLRenderTarget WebGLRenderTarget] sono disponibili su questa classe.</p> + + <h2>Metodi</h2> + + <p>I metodi [page:WebGLRenderTarget WebGLRenderTarget] sono disponibili su questa classe.</p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/WebGLRenderTarget.html
@@ -0,0 +1,137 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + <h1>[name]</h1> + + <p class="desc"> + Un [link:https://webglfundamentals.org/webgl/lessons/webgl-render-to-texture.html render target] รจ un buffer + dove la scheda video disegna i pixel per una scena che viene renderizzata in background. + Viene utilizzata in diversi effetti, come applicare la post-elaborazione a un'immagine + renderizzata prima di visualizzarla sullo schermo. + </p> + + + <h2>Costruttore</h2> + + + <h3>[name]([param:Number width], [param:Number height], [param:Object options])</h3> + + <p> + [page:Float width] - La lunghezza del renderTarget. Il valore predefinito รจ `1`.<br /> + [page:Float height] - L'altezza del renderTarget. Il valore predefinito รจ `1`.<br /> + options - oggetto opzionale che contiene i parametri della texture per una texture target auto generata + e i booleani depthBuffer/stencilBuffer. + + Per una spiegazione dei parametri della texture vedi [page:Texture Texture]. Le seguenti + sono opzioni valide:<br /><br /> + + [page:Constant wrapS] - il valore predefinito รจ [page:Textures ClampToEdgeWrapping]. <br /> + [page:Constant wrapT] - il valore predefinito รจ [page:Textures ClampToEdgeWrapping]. <br /> + [page:Constant magFilter] - il valore predefinito รจ [page:Textures LinearFilter]. <br /> + [page:Constant minFilter] - il valore predefinito รจ [page:Textures LinearFilter]. <br /> + [page:Boolean generateMipmaps] - il valore predefinito รจ `false`.<br /> + [page:Constant format] - il valore predefinito รจ [page:Textures RGBAFormat]. <br /> + [page:Constant type] - il valore predefinito รจ [page:Textures UnsignedByteType]. <br /> + [page:Number anisotropy] - il valore predefinito รจ `1`. Vedi [page:Texture.anisotropy]<br /> + [page:Constant encoding] - il valore predefinito รจ [page:Textures LinearEncoding]. <br /> + [page:Boolean depthBuffer] - il valore predefinito รจ `true`. <br /> + [page:Boolean stencilBuffer] - il valore predefinito รจ `false`.<br /> + [page:Number samples] - il valore predefinito รจ 0.<br /><br /> + + Crea un nuovo [name] + </p> + + <h2>Proprietร </h2> + + <h3>[property:Boolean isWebGLRenderTarget]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + <h3>[property:number width]</h3> + <p> + La lunghezza del render target. + </p> + + <h3>[property:number height]</h3> + <p> + L'altezza del render target. + </p> + + <h3>[property:Vector4 scissor]</h3> + <p> + Un area rettangolare all'interno della viewport del render target. I frammenti che sono fuori dall'area verranno scartati. + </p> + + <h3>[property:Boolean scissorTest]</h3> + <p> + Indica se il test scissor รจ attivo o no. + </p> + + <h3>[property:Vector4 viewport]</h3> + <p> + Il viewport di questo render target. + </p> + + <h3>[property:Texture texture]</h3> + <p> + Questa istanza della texture contiene i pixel renderizzati. Utilizzalo come input per ulteriori informazioni. + </p> + + <h3>[property:Boolean depthBuffer]</h3> + <p> + Effettua il rendering al buffer di profonditร . L'impostazione predefinita รจ `true`. + </p> + + <h3>[property:Boolean stencilBuffer]</h3> + <p> + Effettua il rendering al buffer stencil. Il valore predefinito รจ `false`. + </p> + + <h3>[property:DepthTexture depthTexture]</h3> + <p> + Se impostato, la profonditร  della scena verrร  renderizzata su questa texture. Il valore predefinito รจ `null`. + </p> + + <h3>[property:Number samples]</h3> + <p> + Definisce il conteggio di campioni MSAA. Puรฒ essere utilizzato solo con WebGL 2. Il valore predefinito รจ `0`. + </p> + + <h2>Metodi</h2> + + <h3>[method:undefined setSize]( [param:Number width], [param:Number height] )</h3> + <p> + Imposta la dimensione del render target. + </p> + + <h3>[method:WebGLRenderTarget clone]()</h3> + <p> + Crea una copia di questo render target. + </p> + + <h3>[method:this copy]( [param:WebGLRenderTarget source] )</h3> + <p> + Adotta le impostazioni del render target dato. + </p> + + <h3>[method:undefined dispose]()</h3> + <p> + Libera le risorse relative alla GPU allocate a questa istanza. Chiama questo metodo ogni volta che questa istanza non viene piรน utilizzata nella tua app. + </p> + + <p>I metodi [page:EventDispatcher EventDispatcher] sono disponibili in questa classe.</p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/WebGLRenderer.html
@@ -0,0 +1,520 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + <h1>[name]</h1> + + <p class="desc"> + Il WebGL rendering mostra le tue scene meravigliosamente realizzate utilizzando + [link:https://en.wikipedia.org/wiki/WebGL WebGL]. + </p> + + <h2>Costruttore</h2> + + <h3>[name]( [param:Object parameters] )</h3> + <p> + [page:Object parameters] - (opzionale) oggetto con proprietร  che definiscono il comportamento del renderer. + Il costruttore inoltre non accetta alcun parametro. In tutti i casi, assumerร  impostazioni predefinite + quando i parametri mancheranno. I seguenti sono parametri validi:<br /><br /> + + [page:DOMElement canvas] - Un [link:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas canvas] + dove il renderer disegna il suo output. + Questo corrisponde alla proprietร  [page:WebGLRenderer.domElement domElement] di seguito. + Se non viene passato, un nuovo elemento canvas sarร  creato.<br /> + + + [page:WebGLRenderingContext context] - Questo puรฒ essere utilizzato per collegare il renderer ad un + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext RenderingContext] esistente. + Il valore predefinito รจ `null`.<br /> + + [page:String precision] - Precisione dello shader. Puรฒ essere `"highp"`, `"mediump"` o `"lowp"`. + Il valore predefinito รจ `"highp"` se supportato dal dispositivo.<br /> + + [page:Boolean alpha] - controlla il valore predefinito di alfa. Quando impostato a `true`, il valore รจ `0`. Altrimenti รจ `1`. Il valore predefinito รจ `false`.<br /> + + [page:Boolean premultipliedAlpha] - Indica se il renderer presumerร  che i colori abbiano + [link:https://en.wikipedia.org/wiki/Glossary_of_computer_graphics#Premultiplied_alpha premoltiplicato alfa]. + Il valore predefinito รจ `true`.<br /> + + [page:Boolean antialias] - Indica se eseguire l'antialiasing. Il valore predefinito รจ `false`.<br /> + + [page:Boolean stencil] - Indica se il buffer di disegno ha un + [link:https://en.wikipedia.org/wiki/Stencil_buffer buffer stencil] di almeno 8 bit. + Il valore predefinito รจ `true`.<br /> + + [page:Boolean preserveDrawingBuffer] - Indica se conservare i buffer finchรฉ non verranno cancellati + o sovrascritti manualmente. Il valore predefinito รจ `false`.<br /> + + [page:String powerPreference] - Fornisce un suggerimento allo user agent indicando quale configurazione della + GPU รจ adatta per questo contesto WebGL. Puรฒ essere `"high-performance"`, `"low-power"` o `"default"`. Il valore predefinito รจ `"default"`. + Vedi [link:https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.2 WebGL spec] per i dettagli.<br /> + + [page:Boolean failIfMajorPerformanceCaveat] - Indica se la creazione del renderer avrร  esito negativo in caso di rilevamento + di prestazioni ridotte. Il valore predefinito รจ `false`. + Vedi [link:https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.2 WebGL spec] per i dettagli.<br /> + + [page:Boolean depth] - Indica se il buffer di disegno ha un + [link:https://en.wikipedia.org/wiki/Z-buffering buffer di depth] di almeno 16 bit. + Il valore predefinito รจ `true`.<br /> + + [page:Boolean logarithmicDepthBuffer] - Indica se usare un buffer di depth logaritmico. Potrebbe essere necessario utilizzare + questa opzione se si ha a che fare con enormi differenze di scala in una singola scena. Si noti che questa impostazione + utilizza gl_FragDepth, se disponibile, che disabilita l'ottimizzione [link:https://www.khronos.org/opengl/wiki/Early_Fragment_Test Early Fragment Test] + e puรฒ causare una riduzione delle prestazioni. + Il valore predefinito รจ `false`. Vedi l'esempio [example:webgl_camera_logarithmicdepthbuffer camera / logarithmicdepthbuffer]. + </p> + + <h2>Proprietร </h2> + + <h3>[property:Boolean autoClear]</h3> + <p>Definisce se il renderer deve cancellare automaticamente il suo output prima di eseguire il rendering di un frame.</p> + + + <h3>[property:Boolean autoClearColor]</h3> + <p> + Se [page:.autoClear autoClear] รจ `true`, definisce se il renderer deve cancellare il buffer del colore. + Il valore predefinito รจ `true`. + </p> + + + <h3>[property:Boolean autoClearDepth]</h3> + <p> + Se [page:.autoClear autoClear] รจ `true`, definisce se il renderer deve cancellare il buffer di depth. + Il valore predefinito รจ `true`. + </p> + + + <h3>[property:Boolean autoClearStencil]</h3> + <p> + Se [page:.autoClear autoClear] รจ `true`, definisce se il renderer deve cancellare il buffer dello stencil. + Il valore predefinito รจ `true`. + </p> + + <h3>[property:Object debug]</h3> + <p> + - [page:Boolean checkShaderErrors]: + Se รจ `true`, definisce se i programmi material shader devono essere controllati per errori + durante la compilazione e il processo di collegamento. + Puรฒ essere utile disabilitare questo controllo in produzione per aumentare le prestazioni. + รˆ fortemente raccomandato mantenere questi controlli attivi durante lo sviluppo. + Se lo shader non si compila e non si collega - non funzionerร  e il materiale associato non verrร  visualizzato. + Il valore predefinito รจ `true`. + </p> + + <h3>[property:Object capabilities]</h3> + <p> + Un oggetto che contiene i dettagli sulle capacitร  del [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext RenderingContext] corrente.<br /> + + - [page:Boolean floatFragmentTextures]: indica se il contesto supporta l'estensione [link:https://developer.mozilla.org/en-US/docs/Web/API/OES_texture_float OES_texture_float].<br /> + - [page:Boolean floatVertexTextures]: `true` se [page:Boolean floatFragmentTextures] e [page:Boolean vertexTextures] sono entrambi true.<br /> + - [page:Method getMaxAnisotropy](): Restituisce l'anisotropia massima disponibile.<br /> + - [page:Method getMaxPrecision](): Restituisce la precisione massima disponibile per gli shader vertex e fragment. <br /> + - [page:Boolean isWebGL2]: `true` se il contesto in uso รจ un oggetto WebGL2RenderingContext.<br /> + - [page:Boolean logarithmicDepthBuffer]: `true` se il [page:parameter logarithmicDepthBuffer] era impostato a true nel costruttore e + il contesto supporta l'estensione [link:https://developer.mozilla.org/en-US/docs/Web/API/EXT_frag_depth EXT_frag_depth].<br /> + - [page:Integer maxAttributes]: Il valore di `gl.MAX_VERTEX_ATTRIBS`.<br /> + - [page:Integer maxCubemapSize]: Il valore di `gl.MAX_CUBE_MAP_TEXTURE_SIZE`. + Altezza massima * larghezza delle texture della mappa del cubo che uno shader puรฒ utilizzare.<br /> + - [page:Integer maxFragmentUniforms]: Il valore di `gl.MAX_FRAGMENT_UNIFORM_VECTORS`. + Il numero di uniforms che possono essere utilizzate da un fragment shader.<br /> + - [page:Integer maxSamples]: Il valore di `gl.MAX_SAMPLES`. + Il numero massimo di campioni nel contesto dell'anti-aliasing multicampione (MSAA).<br /> + - [page:Integer maxTextureSize]: Il valore di `gl.MAX_TEXTURE_SIZE`. + Altezza massima * larghezza di una texture che uno shader utilizza.<br /> + - [page:Integer maxTextures]: Il valore di `gl.MAX_TEXTURE_IMAGE_UNITS`. + Il numero massimo di texture che possono essere utilizzate da uno shader.<br /> + - [page:Integer maxVaryings]: Il valore di `gl.MAX_VARYING_VECTORS`. + Il numero di vettori varying che possono essere utilizzati dagli shader.<br /> + - [page:Integer maxVertexTextures]: Il valore di `gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS`. + Il numero di texture che possono essere utilizzate in un vertex shader.<br /> + - [page:Integer maxVertexUniforms]: Il valore di `gl.MAX_VERTEX_UNIFORM_VECTORS`. + Il numero massimo di uniforms che possono essere utilizzate in un vertex shader.<br /> + - [page:String precision]: La precisione dello shader attualmente utilizzata dal renderer.<br /> + - [page:Boolean vertexTextures]: `true` se [property:Integer maxVertexTextures] รจ maggiore di 0 (ad es. รจ possibile utilizzare vertex texture).<br /> + </p> + + <h3>[property:Array clippingPlanes]</h3> + <p> + L'utente definisce piani di taglio specificati come oggetti THREE.Plane nello spazio world. + Questi piani si applicano a livello globale. I punti nello spazio il cui prodotto scalare con il + piano รจ negativo vengono tagliati. + Il valore predefinito รจ []. + </p> + + <h3>[property:DOMElement domElement]</h3> + <p> + Un [link:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas canvas] dove il renderer disegna il suo output.<br /> + Questo viene automaticamente creato dal renderer nel costruttore (se non รจ giร  stato fornito); + devi solo aggiungerlo alla tua pagina in questo modo:<br /> + <code> + document.body.appendChild( renderer.domElement ); + </code> + </p> + + <h3>[property:Object extensions]</h3> + <p> + - [page:Object get]( [param:String extensionName] ): + Utilizzato per verificare se le varie estensioni sono supportate e restituisce un oggetto con i dettagli dell'estensione se disponibile. + Questo metodo puรฒ controllare per le seguenti estensioni:<br /> + + <ul> + <li>`WEBGL_depth_texture`</li> + <li>`EXT_texture_filter_anisotropic`</li> + <li>`WEBGL_compressed_texture_s3tc`</li> + <li>`WEBGL_compressed_texture_pvrtc`</li> + <li>`WEBGL_compressed_texture_etc1`</li> + </ul> + </p> + + <h3>[property:number outputEncoding]</h3> + <p>Definisce la codifica di output del renderer. Il valore predefinito รจ [page:Textures THREE.LinearEncoding].</p> + <p>Se il target render รจ stato impostato utilizzando [page:WebGLRenderer.setRenderTarget .setRenderTarget], + verrร  invece utilizzato renderTarget.texture.encoding.</p> + <p>Vedi la pagina [page:Textures texture constants] per i dettagli su altri formati.</p> + + <h3>[property:Object info]</h3> + <p> + Un oggetto con una serie di informazioni statistiche sulla memoria della scheda grafica e sul processo di rendering. + Utile per il debug o solo per curiositร . L'oggetto contiene i seguenti campi:</p> + <p> + <ul> + <li>memory: + <ul> + <li>geometries</li> + <li>textures</li> + </ul> + </li> + <li>render: + <ul> + <li>calls</li> + <li>triangles</li> + <li>points</li> + <li>lines</li> + <li>frame</li> + </ul> + </li> + <li>programs + </li> + </ul> + </p> + <p> + Per impostazione predefinita questi dati vengono reimpostati ad ogni chiamata di rendering ma quando si + hanno piรน passaggi di rendering per frame (ad esempio quando si utilizza la post elaborazione) puรฒ essere + preferibile ripristinare con un modello personalizzato. + Inanzitutto, imposta `autoReset` a `false`. + <code> + renderer.info.autoReset = false; + </code> + Chiama `reset()` ogni volta che hai terminato di renderizzare ogni singolo frame. + <code> + renderer.info.reset(); + </code> + </p> + + <h3>[property:Boolean localClippingEnabled]</h3> + <p>Definisce se il render rispetta i piani di taglio a livello di oggetto. Il valore predefinito รจ `false`.</p> + + <h3>[property:Boolean physicallyCorrectLights]</h3> + <p> + Indica se utilizzare la modalitร  di illuminazione fisicamente corretta. Il valore predefinito รจ `false`. + Vedi l'esempio [example:webgl_lights_physical lights / physical]. + </p> + + <h3>[property:Object properties]</h3> + <p> + Utilizzato internamente dal renderer per mantenere traccia delle proprietร  dei vari oggetti secondari. + </p> + + <h3>[property:WebGLRenderLists renderLists]</h3> + <p> + Utilizzato internamente per gestire l'ordine del rendering degli oggetti della scena. + </p> + + <h3>[property:WebGLShadowMap shadowMap]</h3> + <p> + Questo contiene il riferimento alla mappa delle ombre, se utilizzato.<br /> + - [page:Boolean enabled]: + Se impostato, utilizza le mappe delle ombre nella scena. Il valore predefinito รจ `false`.<br /> + - [page:Boolean autoUpdate]: + Abilita aggiornamenti automatici delle ombre nella scena. Il valore predefinito รจ `true`.<br /> + Se non hai bisogno di luci/ombre, puoi impostarlo su `false` quando viene creata un'istanza del renderer.<br /> + - [page:Boolean needsUpdate]: + Quando impostato a `true`, le mappe delle ombre nella scena verranno aggiornate nella prossima chiamata a `render`. Il valore predefinito รจ `false`.<br /> + Se hai disabilitato gli aggiornamenti automatici alle mappe della ombre (`shadowMap.autoUpdate = false`), + avrai bisogno di impostare questo a `true` e poi fare una chiamata a `render` per aggiornare le ombre nella tua scena.<br /> + - [page:Integer type]: + Definisce il tipo di mappa delle ombre (non filtrato, filtro di chiusura percentuale, filtro di chiusura percentuale con filtro + bilineare nello shader). + Le opzioni sono: + <ul> + <li>THREE.BasicShadowMap</li> + <li>THREE.PCFShadowMap (default)</li> + <li>THREE.PCFSoftShadowMap</li> + <li>THREE.VSMShadowMap</li> + </ul> + Vedi [page:Renderer Renderer constants] per i dettagli.<br /> + </p> + + <h3>[property:Boolean sortObjects]</h3> + <p> + Definisce se il renderer deve ordinare gli oggetti. Il valore predefinito รจ `true`.<br /><br /> + + Nota: L'ordinamento viene utilizzato per tentare di eseguire correttamente il rendering di oggetti + con un certo grado di trasparenza. Per definizione, l'ordinamento degli oggetti potrebbe non funzionare + in tutti i casi. A seconda delle esigenze dell'applicazione, potrebbe essere necessario disattivare + l'ordinamento e utilizzare altri metodi per gestire il rendering della trasparenza, ad es. + determinare manualmente l'ordine di rendering di ciascun oggetto. + </p> + + <h3>[property:Object state]</h3> + <p> + Contiene funzioni per settare varie proprietร  dello stato [page:WebGLRenderer.context]. + </p> + + <h3>[property:Constant toneMapping]</h3> + <p> + Il valore predefinito รจ [page:Renderer NoToneMapping]. Vedi [page:Renderer Renderer constants] per altre scelte. + </p> + + <h3>[property:Number toneMappingExposure]</h3> + <p> + Livello della mappatura dei toni. Il valore predefinito รจ `1`. + </p> + + <h3>[property:WebXRManager xr]</h3> + <p> + Fornisce accesso all'[page:WebXRManager interfaccia] relativa al WebXR del renderer. + </p> + + <h2>Metodi</h2> + + <h3>[method:undefined clear]( [param:Boolean color], [param:Boolean depth], [param:Boolean stencil] )</h3> + <p> + Dice al renderer di cancellare il suo colore, il(i) buffer di disegno depth e stancil. + Questo metodo inizializza il buffer del colore al valore di color corrente.<br /> + Il valore predefinito degli argomenti รจ `true`. + </p> + + <h3>[method:undefined clearColor]( )</h3> + <p>Cancella il buffer di colore. Equivalente a chiamare [page:WebGLRenderer.clear .clear]( true, false, false ).</p> + + <h3>[method:undefined clearDepth]( )</h3> + <p>Cancella il buffer di profonditร . Equivalente a chiamare [page:WebGLRenderer.clear .clear]( false, true, false ).</p> + + <h3>[method:undefined clearStencil]( )</h3> + <p>Cancella il buffer di stencil. Equivalente a chiamare [page:WebGLRenderer.clear .clear]( false, false, true ).</p> + + <h3>[method:undefined compile]( [param:Object3D scene], [param:Camera camera] )</h3> + <p>Compila tutti i materiali nella scena con la telecamera. Questo รจ utile per precompilare le ombre prima del primo rendering.</p> + + <h3>[method:undefined copyFramebufferToTexture]( [param:Vector2 position], [param:FramebufferTexture texture], [param:Number level] )</h3> + <p> + Copia i pixel dal WebGLFramebuffer corrente in una texture 2D. Abilita l'accesso a + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/copyTexImage2D WebGLRenderingContext.copyTexImage2D]. + </p> + + <h3>[method:undefined copyTextureToTexture]( [param:Vector2 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level] )</h3> + <p> + Copia tutti i pixel della texture in una texture esistente partendo dalla posizione data. Abilita l'accesso a + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texSubImage2D WebGLRenderingContext.texSubImage2D]. + </p> + + <h3>[method:undefined copyTextureToTexture3D]( [param:Box3 sourceBox], [param:Vector3 position], [param:Texture srcTexture], [param:Texture dstTexture], [param:Number level] )</h3> + <p> + Copia i pixel della texture nei limiti '[page:Box3 sourceBox]' nella texture di destinazione partendo dalla posizione data. Abilita l'accesso a + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/texSubImage3D WebGL2RenderingContext.texSubImage3D]. + </p> + + <h3>[method:undefined dispose]( )</h3> + <p> + Libera le risorse relative alla GPU allocata a questa istanza. Chiama questo metodo ogni volta che questa istanza non viene piรน utilizzata nella + tua applicazione. + </p> + + <h3>[method:undefined forceContextLoss]()</h3> + <p> + Simula la perdita del contesto WebGL. Questo richiede il supporto per le + estensioni [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context WEBGL_lose_context]. + </p> + + <h3>[method:undefined forceContextRestore]( )</h3> + <p> + Simula il ripristino del contesto WebGL. Questo richiede il supporto per le + estensioni [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context WEBGL_lose_context]. + </p> + + <h3>[method:Float getClearAlpha]()</h3> + <p>Restituisce un [page:Float float] con l'alfa corrente. Intervallo tra 0 e 1.</p> + + <h3>[method:Color getClearColor]( [param:Color target] )</h3> + <p>Restituisce un'istanza [page:Color THREE.Color] con l'alfa corrente.</p> + + <h3>[method:WebGL2RenderingContext getContext]()</h3> + <p>Restituisce il contesto WebGL corrente.</p> + + <h3>[method:WebGLContextAttributes getContextAttributes]()</h3> + <p>Restituisce un oggetto che descrive gli attributi impostati sul contesto WebGL quando รจ stato creato.</p> + + <h3>[method:Integer getActiveCubeFace]()</h3> + <p>Restituisce la faccia del cubo attiva corrente.</p> + + <h3>[method:Integer getActiveMipmapLevel]()</h3> + <p>Restituisce il livello mipmap attivo corrente.</p> + + <h3>[method:RenderTarget getRenderTarget]()</h3> + <p>Restituisce il [page:RenderTarget RenderTarget] correnti se ci sono; altrimenti restituisce `null`.</p> + + <h3>[method:Vector4 getCurrentViewport]( [param:Vector4 target] )</h3> + <p> + [page:Vector4 target] โ€” il risultato verrร  copiato in questo Vector4.<br /><br /> + + Restituisce il viewport corrente. + </p> + + <h3>[method:Vector2 getDrawingBufferSize]( [param:Vector2 target] )</h3> + <p> + [page:Vector2 target] โ€” il risultato verrร  copiato in questo Vector2.<br /><br /> + + Restituisce la lunghezza e l'altezza del buffer di disegno del renderer, in pixel. + </p> + + <h3>[method:number getPixelRatio]()</h3> + <p>Restituisce il pixel ratio del dispotivo corrente utilizzato.</p> + + <h3>[method:Vector4 getScissor]( [param:Vector4 target] )</h3> + <p> + [page:Vector4 target] โ€” il risultato verrร  copiato in questo Vector4.<br /><br /> + + Restituisce la regione scissor. + </p> + + <h3>[method:Boolean getScissorTest]()</h3> + <p>Restituisce `true` se scissor test รจ abilitato; altrimenti restituisce `false`.</p> + + <h3>[method:Vector2 getSize]( [param:Vector2 target] )</h3> + <p> + [page:Vector2 target] โ€” il risultato verrร  copiato in questo Vector2.<br /><br /> + + Restituisce la lunghezza e l'altezza del canvas di output del renderer, in pixel. + </p> + + <h3>[method:Vector4 getViewport]( [param:Vector4 target] )</h3> + <p> + [page:Vector4 target] โ€” il risultato verrร  copiato in questo Vector4.<br /><br /> + + Restituisce il viewport. + </p> + + <h3>[method:undefined initTexture]( [param:Texture texture] )</h3> + <p> + Inizializza la texture data. Utilizzato per precaricare una texture piuttosto che aspettare fino al primo rendering + (il quale puรฒ causare notevoli ritardi dovuti alla decodifica e al sovraccarico di caricamento della GPU). + </p> + + <h3>[method:undefined resetGLState]( )</h3> + <p>Reimposta lo stato GL al valore predefinito. Chiamato internamente se il contesto WebGL viene perso.</p> + + <h3>[method:undefined readRenderTargetPixels]( [param:WebGLRenderTarget renderTarget], [param:Float x], [param:Float y], [param:Float width], [param:Float height], [param:TypedArray buffer], [param:Integer activeCubeFaceIndex] )</h3> + <p>buffer - Uint8Array รจ l'unico tipo di destinazione supportato in tutti i casi, altri tipi dipendono dal renderTarget e dalla piattaforma. Vedi [link:https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.12 WebGL spec] per i dettagli.</p> + <p>Legge le informazioni dei pixel dal renderTarget nel buffer che gli hai passato. Questo รจ un wrapper attorno a [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/readPixels WebGLRenderingContext.readPixels]().</p> + <p>Vedi l'esempio [example:webgl_interactive_cubes_gpu interactive / cubes / gpu].</p> + <p>Per leggere un [page:WebGLCubeRenderTarget WebGLCubeRenderTarget] utilizzare il parametro opzionale activeCubeFaceIndex per determinare quale faccia deve essere letta.</p> + + + <h3>[method:undefined render]( [param:Object3D scene], [param:Camera camera] )</h3> + <p> + Renderizza una [page:Scene scena] o un altro tipo di [page:Object3D oggetto] utilizzando una [page:Camera telecamera].<br /> + + Il rendering viene seguito su un set [page:WebGLRenderTarget renderTarget] specificato chiamando + [page:WebGLRenderer.setRenderTarget .setRenderTarget] o sul canvas come al solito.<br /> + + Per impostazione predefinita i buffer sono cancellati prima del rendering ma puoi prevenirlo imposstando la proprietร  [page:WebGLRenderer.autoClear autoClear] a false. + Se vuoi prevenire solo certi buffer dall'essere cancellati puoi impostare le proprietร  [page:WebGLRenderer.autoClearColor autoClearColor], [page:WebGLRenderer.autoClearStencil autoClearStencil] o + [page:WebGLRenderer.autoClearDepth autoClearDepth] a false. Per cancellare forzatamente uno o piรน buffer chiama [page:WebGLRenderer.clear .clear]. + </p> + + <h3>[method:undefined resetState]()</h3> + <p>Puรฒ essere utilizzato per reimpostare lo stato interno WebGL. Questo metodo รจ principalmente rilevante per applicazioni che condividono un singolo contesto WebGL tra multiple librerie WebGL.</p> + + <h3>[method:undefined setAnimationLoop]( [param:Function callback] )</h3> + <p>[page:Function callback] โ€” La funzione cancellerร  ogni frame disponibile. Se viene passato `null`, si interromperร  qualsiasi animazione giร  in corso.</p> + <p>Una funzione incorporata che puรฒ essere utilizzata al posto di [link:https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame requestAnimationFrame]. + Questa funzione deve essere utilizza per oggetti WebXR.</p> + + <h3>[method:undefined setClearAlpha]( [param:Float alpha] )</h3> + <p>Imposta l'alfa. L'input valido รจ un float tra `0.0` e `1.0`.</p> + + <h3>[method:undefined setClearColor]( [param:Color color], [param:Float alpha] )</h3> + <p>Imposta il colore e l'opacitร .</p> + + <h3>[method:undefined setPixelRatio]( [param:number value] )</h3> + <p>Imposta la pixel ratio del dispositivo. Questo viene utilizzato per il dispositivo HiDPI per evitare la sfocatura del canvas di output.</p> + + <h3>[method:undefined setRenderTarget]( [param:WebGLRenderTarget renderTarget], [param:Integer activeCubeFace], [param:Integer activeMipmapLevel] )</h3> + <p> + renderTarget -- Il [page:WebGLRenderTarget renderTarget] cha ha bisogno di essere attivato. Quando viene fornito `null`, il canvas invece viene impostato come target di rendering attivo.<br /> + activeCubeFace -- Specifica il lato attivo del cubo (PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5) di [page:WebGLCubeRenderTarget]. + Quando si passa un [page:WebGLArrayRenderTarget] o [page:WebGL3DRenderTarget] questo indica il livello z in cui eseguire il rendering (opzionale).<br /> + activeMipmapLevel -- Specifica il livello mipmap attivo (opzionale).<br /><br /> + Questo metodo imposta il renderTarget attivo. + </p> + + <h3>[method:undefined setScissor]( [param:Integer x], [param:Integer y], [param:Integer width], [param:Integer height] )<br /> + [method:undefined setScissor]( [param:Vector4 vector] )</h3> + + <p> + I parametri x, y, lunghezza, e altezza della regione di scissor.<br /> + Opzionale, un vettore component-4 che specifica i parametri della regione.<br /><br /> + + Imposta la regione di scissor da (x, y) a (x + width, y + height).<br /> + (x, y) indica l'angolo in basso a sinistra della regione di scissor. + </p> + + <h3>[method:undefined setScissorTest]( [param:Boolean boolean] )</h3> + <p> + Abilita o disabilita lo scissor test. Quando questo รจ abilitato, solo i pixel con l'area di + scissor definita saranno influenzati da ulteriori azioni del render. + </p> + + <h3>[method:undefined setOpaqueSort]( [param:Function method] )</h3> + <p> + Imposta la funzione di ordinamento opaco per la WebGLRenderLists. + Passa null per utilizzare la funzione predefinita painterSortStable. + </p> + + <h3>[method:undefined setTransparentSort]( [param:Function method] )</h3> + <p> + Imposta la funzione di ordinamento trasparente per la WebGLRenderLists. + Passa null per utilizzare la funzione predefinita reversePainterSortStable. + </p> + + <h3>[method:undefined setSize]( [param:Integer width], [param:Integer height], [param:Boolean updateStyle] )</h3> + <p> + Ridimensiona il canvas di output a (width, height) con la pixel ratio del device presa nell'account, + e inoltre imposta il viewport per adattarsi a quella dimensione, partendo da (0, 0). + Impostando [page:Boolean updateStyle] a false impedisce qualsiasi modifica di stile al canvas di output. + </p> + + <h3>[method:undefined setViewport]( [param:Integer x], [param:Integer y], [param:Integer width], [param:Integer height] )<br /> + [method:undefined setViewport]( [param:Vector4 vector] )</h3> + + <p> + I parametri x, y, lunghezza, e altezza del viewport.<br /> + Opzionale, un vettore component-4 che specifica i parametri del viewport.<br /><br /> + + Imposta il viewport per il rendering da (x, y) a (x + width, y + height).<br /> + (x, y) indica l'angolo in basso a sinistra della regione. + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/shaders/ShaderChunk.html
@@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + <h1>[name]</h1> + + <p class="desc">Blocchi shader per la libreria Shader WebGL.</p> + + + + <h2>Proprietร </h2> + + + + <h2>Metodi</h2> + + + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/shaders/ShaderLib.html
@@ -0,0 +1,29 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + <h1>[name]</h1> + + <p class="desc">Libreria Shader WebGL per three.js.</p> + + + <h2>Proprietร </h2> + + + + <h2>Metodi</h2> + + + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/shaders/UniformsLib.html
@@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + <h1>[name]</h1> + + <p class="desc">Libreria di uniformi per shared webgl condivisi.</p> + + + + <h2>Proprietร </h2> + + + + <h2>Metodi</h2> + + + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/shaders/UniformsUtils.html
@@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + <h1>[name]</h1> + + <p class="desc"> + Fornisce funzioni di utilitร  per gestire le uniformi. + </p> + + <h2>Metodi</h2> + + <h3>[method:Object clone]( [param:Object src] )</h3> + <p> + src -- Un oggetto che rappresenta le definizioni delle uniformi.<br /><br /> + + Clona le definizioni delle uniformi date eseguendo una copia profonda. Questo significa che se + il [page:Uniform.value valore] di una uniforme si riferisce ad un oggetto come un [page:Vector3] + o una [page:Texture], la uniforme clonata farร  riferimento a un nuovo oggetto di riferimento. + </p> + + <h3>[method:Object merge]( [param:Array uniforms] )</h3> + <p> + uniforms -- Un array di oggetti contente le definizioni della uniforme.<br /><br /> + + Unisce le definizioni della uniforme date nel singolo oggetto. Poichรฉ il metodo + utilizza internamente [page:.clone](), esegue una copia profonda durante + la produzione delle definizioni della uniforme unita. + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/webgl/WebGLProgram.html
@@ -0,0 +1,169 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + <h1>[name]</h1> + + <p class="desc">Costruttore per il programma GLSL inviato agli shader vertex e fragment, comprese le uniformi e gli attributi.</p> + + <h2>Uniformi e attributi incorporati</h2> + + <h3>Vertex shader (incondizionato):</h3> + <div> + <code> + // = object.matrixWorld + uniform mat4 modelMatrix; + + // = camera.matrixWorldInverse * object.matrixWorld + uniform mat4 modelViewMatrix; + + // = camera.projectionMatrix + uniform mat4 projectionMatrix; + + // = camera.matrixWorldInverse + uniform mat4 viewMatrix; + + // = trasposizione inversa di modelViewMatrix + uniform mat3 normalMatrix; + + // = posizione della telecamera nello spazio world + uniform vec3 cameraPosition; + </code> + <code> + // attributi di vertice predefiniti forniti da Geometry e BufferGeometry + attribute vec3 position; + attribute vec3 normal; + attribute vec2 uv; + </code> + <p> + Si noti che รจ possibile quindi calcolare la posizione di un vertice nel vertex shader con: + <code> + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + </code> + o in alternativa + <code> + gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 ); + </code> + </p> + </div> + + <h3>Vertex shader (condizionale):</h3> + <div> + <code> + #if defined( USE_COLOR_ALPHA ) + // attributo del colore del vertice con alfa + attribute vec4 color; + #elif defined( USE_COLOR ) + // attributo del colore del vertice + attribute vec3 color; + #endif + </code> + <code> + #ifdef USE_MORPHTARGETS + + attribute vec3 morphTarget0; + attribute vec3 morphTarget1; + attribute vec3 morphTarget2; + attribute vec3 morphTarget3; + + #ifdef USE_MORPHNORMALS + + attribute vec3 morphNormal0; + attribute vec3 morphNormal1; + attribute vec3 morphNormal2; + attribute vec3 morphNormal3; + + #else + + attribute vec3 morphTarget4; + attribute vec3 morphTarget5; + attribute vec3 morphTarget6; + attribute vec3 morphTarget7; + + #endif + #endif + </code> + <code> + #ifdef USE_SKINNING + attribute vec4 skinIndex; + attribute vec4 skinWeight; + #endif + </code> + <code> + #ifdef USE_INSTANCING + // Si noti che modelViewMatrix non รจ impostato durante il rendering di un modello istanziato, + // ma puรฒ essere calcolato da viewMatrix * modelMatrix. + // + // Utilizzo di base: + // gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0); + attribute mat4 instanceMatrix; + #endif + </code> + </div> + + <h3>Fragment shader:</h3> + <div> + <code> + uniform mat4 viewMatrix; + uniform vec3 cameraPosition; + </code> + </div> + + + <h2>Costruttore</h2> + + <h3>[name]( [param:WebGLRenderer renderer], [param:String cacheKey], [param:Object parameters] )</h3> + <p>Per i parametri vedere [page:WebGLRenderer WebGLRenderer].</p> + + <h2>Proprietร </h2> + + <h3>[property:String name]</h3> + <p>Il nome del rispettivo programma di shader.</p> + + <h3>[property:String id]</h3> + <p>L'identificativo di questa istanza.</p> + + <h3>[property:String cacheKey]</h3> + <p>Questa chiave consente la riutilizzabilitร  di un unico [name] per diversi materiali.</p> + + <h3>[property:Integer usedTimes]</h3> + <p>Quante volte questa istanza viene utilizzata per il rendering di elementi di rendering.</p> + + <h3>[property:Object program]</h3> + <p>L'attuale programma di shader.</p> + + <h3>[property:WebGLShader vertexShader]</h3> + <p>Il vertex shader.</p> + + <h3>[property:WebGLShader fragmentShader]</h3> + <p>Il fragment shader.</p> + + <h2>Metodi</h2> + + <h3>[method:Object getUniforms]()</h3> + <p> + Restituisce una mappa nome-valore di tutte le posizioni uniformi attive. + </p> + + <h3>[method:Object getAttributes]()</h3> + <p> + Restituisce una mappa nome-valore di tutte le posizioni degli attributi dei vertici attivi. + </p> + + <h3>[method:undefined destroy]()</h3> + <p> + Distrugge un'istanza di [name]. + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/api/it/renderers/webxr/WebXRManager.html
@@ -0,0 +1,151 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + + <h1>[name]</h1> + + <p class="desc"> + Questa classe rappresenta un'astrazione dell'API WebXR Device ed รจ utilizzata internamente da [page:WebGLRenderer]. + [name] inoltre fornisce un'interfaccia pubblica che permette agli utenti di abilitare e disabilitare XR ed + eseguire attivitร  relative a XR come ad esempio il recupero dei controller. + </p> + + <h2>Proprietร </h2> + + <h3>[property:Boolean cameraAutoUpdate]</h3> + <p> + Indica se la telecamera XR del manager deve essere aggiornata automaticamente o no. Il valore predefinito รจ `true`. + </p> + + <h3>[property:Boolean enabled]</h3> + <p> + Questo flag notifica al renderer di essere pronto per il rendering XR. L'impostazione predefinita รจ `false`. + Impostalo a `true` se stai utilizzando XR nella tua applicazione. + </p> + + <h3>[property:Boolean isPresenting]</h3> + <p> + Indica se la presentazione XR รจ attiva o meno. Il valore predefinito รจ `false`. Questo flag รจ di sola + lettura e impostato automaticamente da [name]. + </p> + + <h2>Metodi</h2> + + <h3>[method:ArrayCamera getCamera]()</h3> + <p> + Restituisce un'istanza di [page:ArrayCamera] che rappresenta la telecamera XR sessione XR attiva. + Per ogni vista contiene un oggetto telecamera separato nella sua proprietร  [page:ArrayCamera.cameras telecamere]. + </p> + <p> + Il `fov` della telecamera non viene utilizzato attualmente e non riflette il fov della telecamera XR. Se hai bisogno del fov a + livello di app, devi calcolare manualmente dalle matrici di proiezione della telecamera XR. + </p> + + <h3>[method:Group getController]( [param:Integer index] )</h3> + <p> + [page:Integer index] โ€” L'indice del controller. <br /><br /> + + Restituisce un [page:Group gruppo] che rappresenta il cosidetto spazio *target ray* del controller XR. + Utilizza questo spazio per visualizzare gli oggetti 3D che supportano l'utente nel puntare attivitร  come + l'intersezione dell'interfaccia utente. + </p> + + <h3>[method:Group getControllerGrip]( [param:Integer index] )</h3> + <p> + [page:Integer index] โ€” L'indice del controller. <br /><br /> + + Restituisce un [page:Group gruppo] che rappresenta il cosidetto spazio `grip` del controller XR. + Utilizza questo spazio se l'utente terrร  altri oggetti 3D come una spada laser. + </p> + + <p> + Nota: Se vuoi mostrare qualcosa nella mano dell'utente e offrire un raggio di puntamento allo stesso tempo, ti consigliamo di allegare + l'oggetto tenuto in mano al gruppo restituito da [page:.getControllerGrip]() e il raggio al gruppo restituito da [page:.getController](). + L'idea รจ quella di avere due gruppi diversi in due coordinate delle spazio diverse per lo stesso controller WebXR. + </p> + + <h3>[method:Float getFoveation]()</h3> + <p> + Restituisce la quantitร  di foveazione utilizzata dal compositore XR per il livello di proiezione. + </p> + + <h3>[method:Group getHand]( [param:Integer index] )</h3> + <p> + [page:Integer index] โ€” L'indice del controller. <br /><br /> + + Restituisce un [page:Group gruppo] che rappresenta il cosidetto spazio `hand` o `joint` per il controller XR. + Utilizza questo spazio per visualizzare le mani dell'utente quando vengono utilizzati i controller non fisici. + </p> + + <h3>[method:String getReferenceSpace]()</h3> + <p> + Restituisce lo spazio di riferimento. + </p> + + <h3>[method:XRSession getSession]()</h3> + <p> + Restituisce l'oggetto `XRSession` il quale permette una maggiore gestione delle sessioni WebXR attive a livello di applicazione. + </p> + + <h3>[method:undefined setFoveation]( [param:Float foveation] )</h3> + <p> + [page:Float foveation] โ€” Il foveazione da impostare.<br /><br /> + + Specifica la quantitร  di foveazione utilizzata dal compositore XR per il livello. Deve essere un valore tra `0` e `1`. + </p> + + <h3>[method:undefined setFramebufferScaleFactor]( [param:Float framebufferScaleFactor] )</h3> + <p> + [page:Float framebufferScaleFactor] โ€” Il fattore di scala del framebuffer da impostare.<br /><br /> + + Specifica il fattore di ridimensionamento da utilizzare per determinare la dimensione del framebuffer durante il rendering + su un dispositivo XR. Il valore รจ relativo alla risoluzione del dispositivo XR predefinito. Il valore predefinito รจ `1`. + Un valore di `0.5` specificherebbe un framebuffer con il 50% della risoluzione nativa del display. + </p> + + <p> + Nota: Non รจ possibile modificare il fattore di scala del framebuffer durante la presentazione del contenuto. + </p> + + <h3>[method:undefined setReferenceSpace]( [param:XRReferenceSpace referenceSpace] )</h3> + <p> + [page:XRReferenceSpace referenceSpace] โ€” Uno spazio personalizzato di riferimento.<br /><br /> + + Puรฒ essere utilizzato per configurare uno spazio personalizzato di riferimento il quale sovrascrive + lo spazio di riferimento predefinito. + </p> + + <h3>[method:undefined setReferenceSpaceType]( [param:String referenceSpaceType] )</h3> + <p> + [page:String referenceSpaceType] โ€” Il tipo dello spazio di riferimento da impostare.<br /><br /> + + Puรฒ essere utilizzare per configurare una relazione spaziale con l'ambiente fisico dell'utente. A seconda di come l'utente + si muove nello spazio 3D, l'impostazione di uno spazio di riferimento appropriato puรฒ migliorare il tracciamento. + Il valore predefinito รจ `local-floor`. + Consultare l'[link:https://developer.mozilla.org/en-US/docs/Web/API/XRReferenceSpaceType MDN] per i possibli valori e i relativi casi d'uso. + </p> + + <h3>[method:undefined updateCamera]( [param:PerspectiveCamera camera] )</h3> + <p> + Aggiorna lo stato della telecamera XR. Utilizza questo metodo a livello di app, se imposti [page:.cameraAutoUpdate] a `false`. + Questo metodo richiede la telecamera non XR della scena come parametro. La trasformazione della telecamera passata viene automaticamente + regolata sulla posizione della telecamera XR quando si chiama questo metodo. + </p> + + <p> + Nota: Non รจ possibile modificare il tipo dello spazio di riferimento durante la presentazione del contenuto XR. + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
61807e80c5126cd664aa85bfcaf52f5f45933302.json
Add renderers italian version (#24882)
docs/list.json
@@ -1396,6 +1396,27 @@ "Skeleton": "api/it/objects/Skeleton", "SkinnedMesh": "api/it/objects/SkinnedMesh", "Sprite": "api/it/objects/Sprite" + }, + + "Renderers": { + "WebGLMultipleRenderTargets": "api/it/renderers/WebGLMultipleRenderTargets", + "WebGLRenderer": "api/it/renderers/WebGLRenderer", + "WebGL1Renderer": "api/it/renderers/WebGL1Renderer", + "WebGLRenderTarget": "api/it/renderers/WebGLRenderTarget", + "WebGL3DRenderTarget": "api/it/renderers/WebGL3DRenderTarget", + "WebGLArrayRenderTarget": "api/it/renderers/WebGLArrayRenderTarget", + "WebGLCubeRenderTarget": "api/it/renderers/WebGLCubeRenderTarget" + }, + + "Renderers / Shaders": { + "ShaderChunk": "api/it/renderers/shaders/ShaderChunk", + "ShaderLib": "api/it/renderers/shaders/ShaderLib", + "UniformsLib": "api/it/renderers/shaders/UniformsLib", + "UniformsUtils": "api/it/renderers/shaders/UniformsUtils" + }, + + "Renderers / WebXR": { + "WebXRManager": "api/it/renderers/webxr/WebXRManager" } } },
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/Bone.html
@@ -0,0 +1,58 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Un osso che รจ parte di uno [page:Skeleton Scheletro]. Lo scheletro a sua volta viene + utilizzato da [page:SkinnedMesh]. Le ossa sono quasi identiche ad un [page:Object3D] vuoto. + </p> + + <h2>Codice di Esempio</h2> + + <code> + const root = new THREE.Bone(); + const child = new THREE.Bone(); + + root.add( child ); + child.position.y = 5; + </code> + + <h2>Costruttore</h2> + + <h3>[name]( )</h3> + <p> + Crea un nuovo [name]. + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Object3D] per le proprietร  comuni.</p> + + <h3>[property:Boolean isBone]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + + <h3>[property:String type]</h3> + <p>Impostato su 'Bone', puรฒ essere utilizzato per trovare tutte le ossa in una scena.</p> + + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Object3D] per i metodi comuni.</p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/Group.html
@@ -0,0 +1,65 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Questo รจ quasi identico ad un [page:Object3D Object3D]. + Il suo scopo รจ rendere sintatticamente piรน chiaro il lavoro con gruppi di oggetti. + </p> + + <h2>Codice di Esempio</h2> + + <code> + const geometry = new THREE.BoxGeometry( 1, 1, 1 ); + const material = new THREE.MeshBasicMaterial( {color: 0x00ff00} ); + + const cubeA = new THREE.Mesh( geometry, material ); + cubeA.position.set( 100, 100, 0 ); + + const cubeB = new THREE.Mesh( geometry, material ); + cubeB.position.set( -100, -100, 0 ); + + // Crea un gruppo e aggiunge due cubi + // Questi cubi possono essere ruotati / ridimensionati etc come gruppo + const group = new THREE.Group(); + group.add( cubeA ); + group.add( cubeB ); + + scene.add( group ); + </code> + + + <h2>Costruttore</h2> + + <h3>[name]( )</h3> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Object3D] per le proprietร  comuni.</p> + + <h3>[property:Boolean isGroup]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + <h3>[property:String type]</h3> + <p>Una stringa 'Group'. Non deve essere modificata.</p> + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Object3D] per i metodi comuni.</p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/InstancedMesh.html
@@ -0,0 +1,133 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Mesh] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Una versione speciale di [page:Mesh] con il supporto per il rendering istanziato. Utilizza [name] + se devi renderizzare un grande numero di oggetti con la stessa geometria e materiale ma con + diverse trasformazioni world. L'utilizzo di [name] ti aiuterร  a ridurre il numero di + chiamate di disegno e quindi migliorare le prestazioni complessive del rendering nell'applicazione. + </p> + + <h2>Esempi</h2> + + <p> + [example:webgl_instancing_dynamic WebGL / instancing / dynamic]<br /> + [example:webgl_instancing_performance WebGL / instancing / performance]<br /> + [example:webgl_instancing_scatter WebGL / instancing / scatter]<br /> + [example:webgl_instancing_raycast WebGL / instancing / raycast] + </p> + + <h2>Costruttore</h2> + <h3>[name]( [param:BufferGeometry geometry], [param:Material material], [param:Integer count] )</h3> + <p> + [page:BufferGeometry geometry] - un'istanza di [page:BufferGeometry].<br /> + [page:Material material] - un'istanza di [page:Material]. Il valore di default รจ un nuovo [page:MeshBasicMaterial].<br /> + [page:Integer count] - il numero di istanze.<br /> + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Mesh] per le proprietร  comuni.</p> + + <h3>[property:Integer count]</h3> + <p> + Il numero di istanze. Il valore `count` passato nel costruttore rappresenta il numero + massimo di istanze di questa mesh. Puoi modificare il numero di istanze in fase di esecuzione ad un valore intero + nell'intervallo [0, count]. + </p> + <p> + Se hai bisogno di piรน istanze del valore count originale, devi creare una nuova [name]. + </p> + + <h3>[property:InstancedBufferAttribute instanceColor]</h3> + <p> + Rappresenta i colori di tutte le istanze. Il valore predefinito รจ `null`. + รˆ necessario impostare il suo flag [page:BufferAttribute.needsUpdate needsUpdate] + a true se si modificano i dati di istanza tramite [page:.setColorAt](). + </p> + + <h3>[property:InstancedBufferAttribute instanceMatrix]</h3> + <p> + Rappresenta la trasformazione locale di tutte le istanze. + รˆ necessario impostare il suo flag [page:BufferAttribute.needsUpdate needsUpdate] + a true se si modificano i dati di istanza tramite [page:.setMatrixAt](). + </p> + + <h3>[property:Boolean isInstancedMesh]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Mesh] per i metodi comuni.</p> + + <h3>[method:undefined dispose]()</h3> + <p> + Libera le risorse relative alla GPU allocate da questa istanza. + Chiama questo metodo ogni volta che questa istanza non รจ piรน utilizzata nella tua applicazione. + </p> + + <h3>[method:undefined getColorAt]( [param:Integer index], [param:Color color] )</h3> + <p> + [page:Integer index]: L'indice di un'istanza. I valori devono essere nell'intervallo [0, count]. + </p> + <p> + [page:Color color]: Il colore dell'oggetto sarร  impostato al colore dell'istanza definita. + </p> + <p> + Ottieni il colore dell'istanza definita. + </p> + + <h3>[method:undefined getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3> + <p> + [page:Integer index]: L'indice di un'istanza. I valori devono essere nell'intervallo [0, count]. + </p> + <p> + [page:Matrix4 matrix]: Questa matrice 4x4 sarร  impostata alla matrice trasformazione locale dell'istanza definita. + </p> + <p> + Ottieni la matrice trasformazione locale dell'istanza definita. + </p> + + <h3>[method:undefined setColorAt]( [param:Integer index], [param:Color color] )</h3> + <p> + [page:Integer index]: L'indice di un'istanza. I valori devono essere nell'intervallo [0, count]. + </p> + <p> + [page:Color color]: Il colore di una singola istanza. + </p> + <p> + Imposta il colore dato all'istanza definita. + Assicurati di impostare [page:.instanceColor][page:BufferAttribute.needsUpdate .needsUpdate] + a true dopo l'aggiornamento di tutti i colori. + </p> + + <h3>[method:undefined setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3> + <p> + [page:Integer index]: L'indice di un'istanza. I valori devono essere nell'intervallo [0, count]. + </p> + <p> + [page:Matrix4 matrix]: Una matrice 4x4 che rappresenta la trasformazione locale di una singola istanza. + </p> + <p> + Imposta la matrice trasformazione locale data all'istanza definita. + Assicurati di impostare [page:.instanceColor][page:BufferAttribute.needsUpdate .needsUpdate] + a true dopo l'aggiornamento di tutte le matrici. + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/LOD.html
@@ -0,0 +1,128 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Livello di Dettaglio - mostra mesh con piรน o meno geometria in base alla distanza dalla telecamera.<br /><br /> + + Ogni livello รจ associato ad un oggetto, e il rendering puรฒ essere commutato tra di loro alle distanze specificate. + In genere creeresti, per esempio, tre mesh, una per il lontano (dettaglio basse), una per la gamma media (medio dettaglio) + e una per i primi piani (alto dettaglio). + </p> + + <h2>Codice di Esempio</h2> + + <code> + const lod = new THREE.LOD(); + + // Crea sfere con 3 livelli di dettaglio e crea nuovi livelli LOD per loro + for( let i = 0; i < 3; i++ ) { + + const geometry = new THREE.IcosahedronGeometry( 10, 3 - i ) + + const mesh = new THREE.Mesh( geometry, material ); + + lod.addLevel( mesh, i * 75 ); + + } + + scene.add( lod ); + </code> + + <h2>Esempi</h2> + + <p> + [example:webgl_lod webgl / lod ] + </p> + + <h2>Costruttore</h2> + <h3>[name]( )</h3> + <p> + Crea un nuovo [name]. + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Object3D] per le proprietร  comuni.</p> + + <h3>[property:Boolean autoUpdate]</h3> + <p> + Indica se l'oggetto LOD viene aggiornato automaticamente dal renderer per frame o no. + Se impostato a false, devi chiamare da solo [page:LOD.update]() nel ciclo di rendering. + Il valore predefinito รจ true. + </p> + + <h3>[property:Boolean isLOD]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + <h3>[property:Array levels]</h3> + <p> + Un array di oggetti [page:Object level].<br /><br /> + + Ogni livello รจ un oggetto con due proprietร :<br /> + [page:Object3D object] - L'[page:Object3D] da visualizzare a questo livello.<br /> + [page:Float distance] - La distanza alla quale visualizzare questo livello di dettaglio. + </p> + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Object3D] per i metodi comuni.</p> + + <h3>[method:this addLevel]( [param:Object3D object], [param:Float distance] )</h3> + <p> + [page:Object3D object] - L'[page:Object3D] da visualizzare a questo livello.<br /> + [page:Float distance] - La distanza alla quale visualizzare questo livello di dettaglio.<br /><br /> + + Aggiunge una mesh che sarร  visualizzata ad una certa distanza e maggiore. In genere, maggiore รจ + la distanza, minore รจ il dettaglio sulla mesh. + </p> + + <h3>[method:LOD clone]()</h3> + <p> + Restituisce un clone di questo oggetto LOD e degli oggetti specifici della distanza ad esso associati. + </p> + + + <h3>[method:Integer getCurrentLevel]()</h3> + <p> + Ottiene il livello LOD attivo attualmente. Come indice dell'array dei livelli. + </p> + + <h3>[method:Object3D getObjectForDistance]( [param:Float distance] )</h3> + <p> + Ottiene un riferimento al primo [page:Object3D] (mesh) che รจ maggiore della [page:Float distance]. + </p> + + <h3>[method:undefined raycast]( [param:Raycaster raycaster], [param:Array intersects] )</h3> + <p> + Ottiene le intersezioni tra un [page:Ray] lanciato a questo LOD. + [page:Raycaster.intersectObject] chiamerร  questo metodo. + </p> + + <h3>[method:Object toJSON]( meta )</h3> + <p> + Crea una struttura JSON con i dettagli di questo oggetto LOD. + </p> + + <h3>[method:undefined update]( [param:Camera camera] )</h3> + <p> + Imposta la visibilitร  di ogni [page:Object3D oggetto] del [page:levels livello] in base + alla distanza dalla [page:Camera telecamera]. + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/Line.html
@@ -0,0 +1,110 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Una linea continua.<br /><br /> + + Questo รจ quasi lo stesso di [page:LineSegments]; l'unica differenza รจ che questo viene renderizzato utilizzando + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_STRIP] + invece di [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINES] + + </p> + + <h2>Codice di Esempio</h2> + + <code> + const material = new THREE.LineBasicMaterial({ + color: 0x0000ff + }); + + const points = []; + points.push( new THREE.Vector3( - 10, 0, 0 ) ); + points.push( new THREE.Vector3( 0, 10, 0 ) ); + points.push( new THREE.Vector3( 10, 0, 0 ) ); + + const geometry = new THREE.BufferGeometry().setFromPoints( points ); + + const line = new THREE.Line( geometry, material ); + scene.add( line ); + </code> + + + <h2>Costruttore</h2> + + <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3> + + <p> + [page:BufferGeometry geometry] โ€” vertici che rappresentano il segmento(i) di linea. Il valore predefinito รจ una nuova [page:BufferGeometry].<br /> + [page:Material material] โ€” materiale per la linea. Il valore predefinito รจ una nuova [page:LineBasicMaterial].<br /> + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Object3D] per le proprietร  comuni.</p> + + <h3>[property:BufferGeometry geometry]</h3> + <p>Vertici che rappresentano il segmento(i) di linea.</p> + + <h3>[property:Boolean isLine]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + <h3>[property:Material material]</h3> + <p>Materiale per la linea.</p> + + <h3>[property:Array morphTargetInfluences]</h3> + <p> + Un array di pesi solitamente da 0 a 1 che specifica la quantitร  di morph applicata. + Non definito per impostazione predefinita, ma reimpostato su un array vuoto da [page:.updateMorphTargets](). + </p> + + <h3>[property:Object morphTargetDictionary]</h3> + <p> + Un dizionario di morphTargets basato sulla proprietร  morphTarget.name. + Non definito per impostazione predefinita, ma ricompilato [page:.updateMorphTargets](). + </p> + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Object3D] per i metodi comuni.</p> + + <h3>[method:this computeLineDistances]()</h3> + <p> + Calcola un array di valori di distanza necessari per [page:LineDashedMaterial]. + Per ogni vertice nella geometria, il metodo calcola la lunghezza cumulativa dal punto + corrente fino all'inizio della linea. + </p> + + <h3>[method:undefined raycast]( [param:Raycaster raycaster], [param:Array intersects] )</h3> + <p> + Ottiene le intersezioni tra un [page:Ray] lanciato e questa linea. + [page:Raycaster.intersectObject] chiamerร  questo metodo. + </p> + + <h3>[method:Line clone]()</h3> + <p> + Restituisce un clone di questo oggetto Line e i suoi discendenti. + </p> + + <h3>[method:undefined updateMorphTargets]()</h3> + <p> + Aggiorna i morphTargets in modo che non abbiano alcuna influenza sull'oggetto. + Reimposta le proprietร  [page:.morphTargetInfluences] e [page:.morphTargetDictionary]. + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/LineLoop.html
@@ -0,0 +1,52 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; [page:Line] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Una linea continua che si ricollega alla partenza.<br /><br /> + + Questo รจ quasi lo stesso di [page:Line]; l'unica differenza รจ che viene + renderizzato utilizzando + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_LOOP] + invece di [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_STRIP], + il quale disegna una linea retta al vertice successivo, e ricollega l'ultimo vertice al primo. + </p> + + + <h2>Costruttore</h2> + + <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3> + + <p> + [page:BufferGeometry geometry] โ€” Elenco di vertici che rappresentano i punti del ciclo della linea.<br /> + [page:Material material] โ€” Materiale per la linea. Il valore predefinito รจ [page:LineBasicMaterial LineBasicMaterial]. + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Line] per le proprietร  comuni.</p> + + <h3>[property:Boolean isLineLoop]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Line] per i metodi comuni.</p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/LineSegments.html
@@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; [page:Line] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Una serie di linee tracciate tra coppie di vertici.<br /><br /> + + Questo รจ quasi lo stesso di [page:Line]; l'unica differenza รจ che viene + renderizzato utilizzando + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINES] + invece di [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_STRIP]. + </p> + + + <h2>Costruttore</h2> + + <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3> + + <p> + [page:BufferGeometry geometry] โ€” Coppia(e) di vertici che rappresentano ogni segmento(i) di linea.<br /> + [page:Material material] โ€” Materiale per la linea. Il valore predefinito รจ [page:LineBasicMaterial LineBasicMaterial]. + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Line] per le proprietร  comuni.</p> + + <h3>[property:Boolean isLineSegments]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Line] per i metodi comuni.</p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/Mesh.html
@@ -0,0 +1,93 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Una classe che rappresenta oggetti basati su [link:https://en.wikipedia.org/wiki/Polygon_mesh mesh poligonali] triangolari. + Serve anche come base per altre classi come [page:SkinnedMesh]. + </p> + + <h2>Codice di Esempio</h2> + + <code> + const geometry = new THREE.BoxGeometry( 1, 1, 1 ); + const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } ); + const mesh = new THREE.Mesh( geometry, material ); + scene.add( mesh ); + </code> + + <h2>Costruttore</h2> + + <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3> + <p> + [page:BufferGeometry geometry] โ€” (opzionale) un'istanza di [page:BufferGeometry]. Il valore predefinito รจ una nuova [page:BufferGeometry].<br /> + [page:Material material] โ€” (opzionale) un singolo o un array di [page:Material Material]. Il valore predefinito รจ una nuova [page:MeshBasicMaterial]. + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Object3D] per le proprietร  comuni.</p> + + <h3>[property:BufferGeometry geometry]</h3> + <p> + Un'istanza di [page:BufferGeometry] (o classi derivate), che definisce la struttura dell'oggetto. + </p> + + <h3>[property:Boolean isMesh]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + <h3>[property:Material material]</h3> + <p> + Un'istanza di materiale derivata dalla classe base [page:Material] o un array di materiali, che definisce + l'aspetto dell'oggetto. Il valore predefinito รจ [page:MeshBasicMaterial]. + </p> + + <h3>[property:Array morphTargetInfluences]</h3> + <p> + Un array di pesi solitamente da 0 a 1 che specifica la quantitร  di morph applicata. + Non definito per impostazione predefinita, ma reimpostato su un array vuoto da [page:Mesh.updateMorphTargets updateMorphTargets]. + </p> + + <h3>[property:Object morphTargetDictionary]</h3> + <p> + Un dizionario di morphTargets basato sulla proprietร  morphTarget.name. + Non definito per impostazione predefinita, ma ricompilato [page:Mesh.updateMorphTargets updateMorphTargets]. + </p> + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Object3D] per i metodi comuni.</p> + + <h3>[method:Mesh clone]()</h3> + <p>Restituisce un clone di questo oggetto [name] e i suoi discendenti.</p> + + <h3>[method:undefined raycast]( [param:Raycaster raycaster], [param:Array intersects] )</h3> + <p> + Ottiene le intersezioni tra un raggio lanciato e questa mesh. + [page:Raycaster.intersectObject] chiamerร  questo metodo, ma i risultati non saranno ordinati. + </p> + + <h3>[method:undefined updateMorphTargets]()</h3> + <p> + Aggiorna i morphTargets in modo che non abbiano influenza sull'oggetto. Reimposta le proprietร  + [page:Mesh.morphTargetInfluences morphTargetInfluences] e + [page:Mesh.morphTargetDictionary morphTargetDictionary]. + </p> + + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/Points.html
@@ -0,0 +1,88 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Una classe per visualizzare punti. + I punti sono renderizzati dal [page:WebGLRenderer] utilizzando + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.POINTS]. + </p> + + + <h2>Costruttore</h2> + + <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3> + <p> + [page:BufferGeometry geometry] โ€” (opzionale) un'istanza di [page:BufferGeometry]. Il valore predefinito รจ una nuova [page:BufferGeometry].<br /> + [page:Material material] โ€” (opzionale) un [page:Material Materiale]. Il valore predefinito รจ una nuova [page:PointsMaterial]. + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Object3D] per le proprietร  comuni.</p> + + <h3>[property:BufferGeometry geometry]</h3> + <p> + Un'istanza di [page:BufferGeometry] (o classi derivate), che definisce la struttura dell'oggetto. + </p> + + <h3>[property:Boolean isPoints]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + <h3>[property:Material material]</h3> + <p> + Un'istanza di [page:Material], che definisce + l'aspetto dell'oggetto. Il valore predefinito รจ [page:PointsMaterial]. + </p> + + <h3>[property:Array morphTargetInfluences]</h3> + <p> + Un array di pesi solitamente da 0 a 1 che specifica la quantitร  di morph applicata. + Non definito per impostazione predefinita, ma reimpostato su un array vuoto da [page:Points.updateMorphTargets updateMorphTargets]. + </p> + + <h3>[property:Object morphTargetDictionary]</h3> + <p> + Un dizionario di morphTargets basato sulla proprietร  morphTarget.name. + Non definito per impostazione predefinita, ma ricompilato [page:Points.updateMorphTargets updateMorphTargets]. + </p> + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Object3D] per i metodi comuni.</p> + + <h3>[method:undefined raycast]( [param:Raycaster raycaster], [param:Array intersects] )</h3> + <p> + Ottiene le intersezioni tra un raggio lanciato e questo Points. + [page:Raycaster.intersectObject] chiamerร  questo metodo, ma i risultati non saranno ordinati. + </p> + + <h3>[method:Points clone]()</h3> + <p> + Restituisce un clone di questo oggetto [name] e i suoi discendenti.</p> + </p> + + <h3>[method:undefined updateMorphTargets]()</h3> + <p> + Aggiorna i morphTargets in modo che non abbiano influenza sull'oggetto. Reimposta le proprietร  + [page:Points.morphTargetInfluences morphTargetInfluences] e + [page:Points.morphTargetDictionary morphTargetDictionary]. + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/Skeleton.html
@@ -0,0 +1,129 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + + <h1>[name]</h1> + + <p class="desc"> + Utilizza un array di [page:Bone ossa] per creare uno scheletro che puรฒ essere utilizzato da una + [page:SkinnedMesh]. + </p> + + <h2>Codice di Esempio</h2> + <code> + // Crea un semplice "braccio" + + const bones = []; + + const shoulder = new THREE.Bone(); + const elbow = new THREE.Bone(); + const hand = new THREE.Bone(); + + shoulder.add( elbow ); + elbow.add( hand ); + + bones.push( shoulder ); + bones.push( elbow ); + bones.push( hand ); + + shoulder.position.y = -5; + elbow.position.y = 0; + hand.position.y = 5; + + const armSkeleton = new THREE.Skeleton( bones ); + </code> + + <p> + Vedi la pagina [page:SkinnedMesh] per un esempio dell'utilizzo con [page:BufferGeometry]. + </p> + + <h2>Costruttore</h2> + + + <h3>[name]( [param:Array bones], [param:Array boneInverses] )</h3> + <p> + [page:Array bones] - L'array di [page:Bone ossa]. Il valore predefinito รจ un array vuoto.<br/> + [page:Array boneInverses] - (opzionale) Un array di [page:Matrix4 Matrix4].<br /><br /> + + Crea un nuovo [name]. + </p> + + + <h2>Proprietร </h2> + + <h3>[property:Array bones]</h3> + <p> + L'array di [page:Bone ossa]. Si noti che questa รจ una copia dell'array originale, non un riferimento, + quindi puoi modificare l'array originale senza che ci siano effetti su questo. + </p> + + <h3>[property:Array boneInverses]</h3> + <p> + Un array di [page:Matrix4 Matrix4] che rappresenta l'inverso della [page:Matrix4 matrixWorld] + delle singole ossa. + </p> + + <h3>[property:Float32Array boneMatrices]</h3> + <p> + Il buffer dell'array che contiene i dati dell'osso quando si utilizza una texture di vertice. + </p> + + <h3>[property:DataTexture boneTexture]</h3> + <p> + Il [page:DataTexture] che contiene i dati dell'osso quando si utilizza una texture di vertice. + </p> + + <h3>[property:Integer boneTextureSize]</h3> + <p> + La dimensione del [page:.boneTexture]. + </p> + + <h2>Metodi</h2> + + <h3>[method:Skeleton clone]()</h3> + <p> + Restituisce un clone di questo oggetto Skeleton. + </p> + + <h3>[method:undefined calculateInverses]()</h3> + <p>Genera l'array [page:.boneInverses boneInverses] se non viene fornito nel costruttore.</p> + + <h3>[method:this computeBoneTexture]()</h3> + <p>Calcola un'istanza di [page:DataTexture] in moda da passare i dati dell'osso in modo piรน efficiente allo shader. + La texture viene assegnata a [page:.boneTexture boneTexture].</p> + + <h3>[method:undefined pose]()</h3> + <p>Restituisce lo scheletro nella posa di base.</p> + + <h3>[method:undefined update]()</h3> + <p> + Aggiorna [page:Float32Array boneMatrices] e [page:DataTexture boneTexture] dopo che le ossa sono state modificate. + Questo viene chiamato automaticamente dal [page:WebGLRenderer] se lo scheletro viene utilizzato con una [page:SkinnedMesh]. + </p> + + <h3>[method:Bone getBoneByName]( [param:String name] )</h3> + <p> + name -- Stringa da abbinare alla proprietร  .name di Bone. <br /><br /> + + Cerca nell'array osseo dello scheletro e restituisce il primo con un nome corrispondente.<br /> + </p> + + <h3>[method:undefined dispose]()</h3> + <p> + Libera le risorse relative alla GPU allocate da questa istanza. Chiama questo metodo ogni + volta che questa istanza non viene piรน utilizzata nella tua app. + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/SkinnedMesh.html
@@ -0,0 +1,174 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; [page:Mesh] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Una mesh che ha uno [page:Skeleton scheletro] con [page:Bone ossa] che puรฒ essere + utilizzata per animare i vertici della geometria.<br /><br /> + + [name] puรฒ essere utilizzata solo con WebGL 2. Con WebGL 1 รจ necessario il supporto delle texture del vertice + e `OES_texture_float`. + </p> + + <iframe id="scene" src="scenes/bones-browser.html"></iframe> + + <script> + + // iOS iframe auto-resize workaround + + if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) { + + const scene = document.getElementById( 'scene' ); + + scene.style.width = getComputedStyle( scene ).width; + scene.style.height = getComputedStyle( scene ).height; + scene.setAttribute( 'scrolling', 'no' ); + + } + + </script> + + <h2>Codice di Esempio</h2> + + <code> + const geometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 ); + + // crea manualmente gli indici della pelle e i pesi della pelle + // (tipicamente un loader leggerebbe questi dati da un modello 3D per te) + + const position = geometry.attributes.position; + + const vertex = new THREE.Vector3(); + + const skinIndices = []; + const skinWeights = []; + + for ( let i = 0; i < position.count; i ++ ) { + + vertex.fromBufferAttribute( position, i ); + + // calcola skinIndex e skinWeight in base ad alcuni dati di configurazione + + const y = ( vertex.y + sizing.halfHeight ); + + const skinIndex = Math.floor( y / sizing.segmentHeight ); + const skinWeight = ( y % sizing.segmentHeight ) / sizing.segmentHeight; + + skinIndices.push( skinIndex, skinIndex + 1, 0, 0 ); + skinWeights.push( 1 - skinWeight, skinWeight, 0, 0 ); + + } + + geometry.setAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( skinIndices, 4 ) ); + geometry.setAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeights, 4 ) ); + + // crea skinned mesh e skeleton + + const mesh = new THREE.SkinnedMesh( geometry, material ); + const skeleton = new THREE.Skeleton( bones ); + + // vedi esempio da THREE.Skeleton + + const rootBone = skeleton.bones[ 0 ]; + mesh.add( rootBone ); + + // lega lo scheletro alla mesh + + mesh.bind( skeleton ); + + // muove le ossa e manipola il modello + + skeleton.bones[ 0 ].rotation.x = -0.1; + skeleton.bones[ 1 ].rotation.x = 0.2; + </code> + + <h2>Costruttore</h2> + <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3> + <p> + [page:BufferGeometry geometry] - un'istanza di [page:BufferGeometry].<br /> + [page:Material material] - (opzionale) un'istanza di [page:Material]. Il valore predefinito รจ un nuovo [page:MeshBasicMaterial]. + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Mesh] per le proprietร  comuni.</p> + + <h3>[property:String bindMode]</h3> + <p> + O "attached" o "detached". "attached" utilizza la proprietร  [page:SkinnedMesh.matrixWorld] + per la matrice di trasformazione delle ossa. "detached" utilizza [page:SkinnedMesh.bindMatrix]. Il valore predefinito รจ "attached". + </p> + + <h3>[property:Matrix4 bindMatrix]</h3> + <p> + La matrice di base che viene utilizzata per le trasformazioni ossee vincolate. + </p> + + <h3>[property:Matrix4 bindMatrixInverse]</h3> + <p> + La matrice di base che viene utilizzata per reimpostare le trasformazioni ossee vincolate. + </p> + + <h3>[property:Boolean isSkinnedMesh]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + <h3>[property:Skeleton skeleton]</h3> + <p> + [page:Skeleton] che rappresenta la gerarchia ossea della skinned mesh. + </p> + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Mesh] per i metodi comuni.</p> + + <h3>[method:undefined bind]( [param:Skeleton skeleton], [param:Matrix4 bindMatrix] )</h3> + <p> + [page:Skeleton skeleton] - [page:Skeleton] creato da un albero di [page:Bone Bones].<br/> + [page:Matrix4 bindMatrix] - [page:Matrix4] che rappresenta la trasformazione base dello scheletro.<br /><br /> + + Lega uno scheletro alla skinned mesh. Il bindMatrix viene salvato nella proprietร  .bindMatrix + e il .bindMatrixInverse viene calcolato. + </p> + + <h3>[method:SkinnedMesh clone]()</h3> + <p> + Questo metodo attualmente non clona correttamente un'istanza di [name]. Si prega di utilizzare [page:SkeletonUtils.clone]() nel frattempo. + </p> + + <h3>[method:undefined normalizeSkinWeights]()</h3> + <p> + Normalizza i pesi della skin. + </p> + + <h3>[method:undefined pose]()</h3> + <p> + Questo metodo imposta la skinned mesh nella posa di riposo (reimposta la posa). + </p> + + <h3>[method:Vector3 boneTransform]( [param:Integer index], [param:Vector3 target] )</h3> + <p> + Calcola la posizione del vertice in corrispondenza dell'indice specificato rispetto alle attuali trasformazioni ossee. + Il vettore target deve essere inizializzato con le coordinate del vertice prima della trasformazione: + <code> +const target = new THREE.Vector3(); +target.fromBufferAttribute( mesh.geometry.attributes.position, index ); +mesh.boneTransform( index, target ); + </code> + </p> + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/api/it/objects/Sprite.html
@@ -0,0 +1,89 @@ +<!DOCTYPE html> +<html lang="it"> + <head> + <meta charset="utf-8" /> + <base href="../../../" /> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; + + <h1>[name]</h1> + + <p class="desc"> + Una sprite รจ un piano che รจ sempre rivolto verso la telecamera, generalmente con + una texture parzialmente trasparente applicata.<br /><br /> + + Le sprite non proiettano ombre, impostare <code>castShadow = true</code> non avrร  alcun effetto. + </p> + + <h2>Codice di Esempio</h2> + + <code> + const map = new THREE.TextureLoader().load( 'sprite.png' ); + const material = new THREE.SpriteMaterial( { map: map } ); + + const sprite = new THREE.Sprite( material ); + scene.add( sprite ); + </code> + + <h2>Costruttore</h2> + + <h3>[name]( [param:Material material] )</h3> + <p> + [page:Material material] - (opzionale) un'istanza di [page:SpriteMaterial]. Il valore predefinito รจ una [page:SpriteMaterial] bianca.<br /><br /> + + Crea una nuova [name]. + </p> + + <h2>Proprietร </h2> + <p>Vedi la classe base [page:Object3D] per le proprietร  comuni.</p> + + <h3>[property:Boolean isSprite]</h3> + <p> + Flag di sola lettura per verificare se l'oggetto dato รจ di tipo [name]. + </p> + + + <h3>[property:SpriteMaterial material]</h3> + <p> + Un'istanza di [page:SpriteMaterial], che definisce l'aspetto dell'oggetto. + Il valore predefinito รจ una [page:SpriteMaterial] bianca. + </p> + + + <h3>[property:Vector2 center]</h3> + <p> + Il punto di ancoraggio della sprite, e il punto attorno al quale ruota la sprite. Un valore di (0.5, 0.5) + corrisponde al punto medio della sprite. Un valore di (0, 0) corrisponde all'angolo inferiore sinistro della sprite. + Il valore predefinito รจ (0.5, 0.5). + </p> + + <h2>Metodi</h2> + <p>Vedi la classe base [page:Object3D] per i metodi comuni.</p> + + <h3>[method:Sprite clone]()</h3> + <p> + Restituisce un clone di questo oggetto Sprite e i suoi discendenti. + </p> + + <h3>[method:this copy]( [param:Sprite sprite] )</h3> + <p> + Copia le proprietร  della sprite passata in questa. + </p> + + <h3>[method:undefined raycast]( [param:Raycaster raycaster], [param:Array intersects] )</h3> + <p> + Ottiene le intersezioni tra un raggio lanciato e questa sprite. [page:Raycaster.intersectObject]() chiamerร  questo metodo. + Il raycaster deve essere inizializzato chiamando [page:Raycaster.setFromCamera]() prima di eseguire il raycast contro le sprite. + </p> + + + <h2>Source</h2> + + <p> + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </p> + </body> +</html>
true
Other
mrdoob
three.js
2f2c19b280a596eada0adf67ff9e6d5bfcca03ac.json
Add Objects italian version (#24850)
docs/list.json
@@ -1381,6 +1381,21 @@ "DiscreteInterpolant": "api/it/math/interpolants/DiscreteInterpolant", "LinearInterpolant": "api/it/math/interpolants/LinearInterpolant", "QuaternionLinearInterpolant": "api/it/math/interpolants/QuaternionLinearInterpolant" + }, + + "Oggetti": { + "Bone": "api/it/objects/Bone", + "Group": "api/it/objects/Group", + "InstancedMesh": "api/it/objects/InstancedMesh", + "Line": "api/it/objects/Line", + "LineLoop": "api/it/objects/LineLoop", + "LineSegments": "api/it/objects/LineSegments", + "LOD": "api/it/objects/LOD", + "Mesh": "api/it/objects/Mesh", + "Points": "api/it/objects/Points", + "Skeleton": "api/it/objects/Skeleton", + "SkinnedMesh": "api/it/objects/SkinnedMesh", + "Sprite": "api/it/objects/Sprite" } } },
true
Other
mrdoob
three.js
d95e790fb089cf7ba34e1a83a2d3695c75748e58.json
improve mouse drag interaction (#24844)
examples/webgpu_equirectangular.html
@@ -72,8 +72,8 @@ controls = new OrbitControls( camera, renderer.domElement ); controls.autoRotate = true; - controls.minDistance = 2; - controls.maxDistance = 10; + controls.rotateSpeed = - 0.125; // negative, to track mouse pointer + controls.autoRotateSpeed = 1.0; window.addEventListener( 'resize', onWindowResize );
false
Other
mrdoob
three.js
305c488ad56bb21e49cbd0a8651f05b766979206.json
kill double `.normalize` (#22503)
src/extras/core/Curve.js
@@ -277,7 +277,6 @@ class Curve { const u = i / segments; tangents[ i ] = this.getTangentAt( u, new Vector3() ); - tangents[ i ].normalize(); }
false
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/js/interactive/InteractiveGroup.js
@@ -24,7 +24,7 @@ _pointer.x = event.clientX / element.clientWidth * 2 - 1; _pointer.y = - ( event.clientY / element.clientHeight ) * 2 + 1; raycaster.setFromCamera( _pointer, camera ); - const intersects = raycaster.intersectObjects( scope.children ); + const intersects = raycaster.intersectObjects( scope.children, false ); if ( intersects.length > 0 ) { @@ -63,7 +63,7 @@ tempMatrix.identity().extractRotation( controller.matrixWorld ); raycaster.ray.origin.setFromMatrixPosition( controller.matrixWorld ); raycaster.ray.direction.set( 0, 0, - 1 ).applyMatrix4( tempMatrix ); - const intersections = raycaster.intersectObjects( scope.children ); + const intersections = raycaster.intersectObjects( scope.children, false ); if ( intersections.length > 0 ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/jsm/interactive/InteractiveGroup.js
@@ -32,7 +32,7 @@ class InteractiveGroup extends Group { raycaster.setFromCamera( _pointer, camera ); - const intersects = raycaster.intersectObjects( scope.children ); + const intersects = raycaster.intersectObjects( scope.children, false ); if ( intersects.length > 0 ) { @@ -77,7 +77,7 @@ class InteractiveGroup extends Group { raycaster.ray.origin.setFromMatrixPosition( controller.matrixWorld ); raycaster.ray.direction.set( 0, 0, - 1 ).applyMatrix4( tempMatrix ); - const intersections = raycaster.intersectObjects( scope.children ); + const intersections = raycaster.intersectObjects( scope.children, false ); if ( intersections.length > 0 ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/jsm/webxr/OculusHandPointerModel.js
@@ -343,7 +343,7 @@ class OculusHandPointerModel extends THREE.Object3D { if ( this.raycaster ) { - return this.raycaster.intersectObjects( objects ); + return this.raycaster.intersectObjects( objects, false ); } @@ -353,7 +353,7 @@ class OculusHandPointerModel extends THREE.Object3D { if ( this.raycaster && ! this.attached ) { - const intersections = this.raycaster.intersectObjects( objects ); + const intersections = this.raycaster.intersectObjects( objects, false ); const direction = new THREE.Vector3( 0, 0, - 1 ); if ( intersections.length > 0 ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/misc_controls_pointerlock.html
@@ -279,7 +279,7 @@ raycaster.ray.origin.copy( controls.getObject().position ); raycaster.ray.origin.y -= 10; - const intersections = raycaster.intersectObjects( objects ); + const intersections = raycaster.intersectObjects( objects, false ); const onObject = intersections.length > 0;
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_camera_cinematic.html
@@ -188,7 +188,7 @@ raycaster.setFromCamera( mouse, camera ); - const intersects = raycaster.intersectObjects( scene.children ); + const intersects = raycaster.intersectObjects( scene.children, false ); if ( intersects.length > 0 ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_geometry_spline_editor.html
@@ -371,7 +371,7 @@ raycaster.setFromCamera( pointer, camera ); - const intersects = raycaster.intersectObjects( splineHelperObjects ); + const intersects = raycaster.intersectObjects( splineHelperObjects, false ); if ( intersects.length > 0 ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_interactive_cubes.html
@@ -135,7 +135,7 @@ raycaster.setFromCamera( pointer, camera ); - const intersects = raycaster.intersectObjects( scene.children ); + const intersects = raycaster.intersectObjects( scene.children, false ); if ( intersects.length > 0 ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_interactive_cubes_ortho.html
@@ -143,7 +143,7 @@ raycaster.setFromCamera( pointer, camera ); - const intersects = raycaster.intersectObjects( scene.children ); + const intersects = raycaster.intersectObjects( scene.children, false ); if ( intersects.length > 0 ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_interactive_raycasting_points.html
@@ -245,7 +245,7 @@ raycaster.setFromCamera( pointer, camera ); - const intersections = raycaster.intersectObjects( pointclouds ); + const intersections = raycaster.intersectObjects( pointclouds, false ); intersection = ( intersections.length ) > 0 ? intersections[ 0 ] : null; if ( toggle > 0.02 && intersection !== null ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_interactive_voxelpainter.html
@@ -117,7 +117,7 @@ raycaster.setFromCamera( pointer, camera ); - const intersects = raycaster.intersectObjects( objects ); + const intersects = raycaster.intersectObjects( objects, false ); if ( intersects.length > 0 ) { @@ -138,7 +138,7 @@ raycaster.setFromCamera( pointer, camera ); - const intersects = raycaster.intersectObjects( objects ); + const intersects = raycaster.intersectObjects( objects, false ); if ( intersects.length > 0 ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_loader_ifc.html
@@ -82,7 +82,7 @@ const raycaster = new THREE.Raycaster(); raycaster.setFromCamera( mouse, camera ); - const intersected = raycaster.intersectObjects( scene.children ); + const intersected = raycaster.intersectObjects( scene.children, false ); if ( intersected.length ) { const found = intersected[ 0 ];
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_modifier_curve.html
@@ -179,7 +179,7 @@ rayCaster.setFromCamera( mouse, camera ); action = ACTION_NONE; - const intersects = rayCaster.intersectObjects( curveHandles ); + const intersects = rayCaster.intersectObjects( curveHandles, false ); if ( intersects.length ) { const target = intersects[ 0 ].object;
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_modifier_curve_instanced.html
@@ -209,7 +209,7 @@ rayCaster.setFromCamera( mouse, camera ); action = ACTION_NONE; - const intersects = rayCaster.intersectObjects( curveHandles ); + const intersects = rayCaster.intersectObjects( curveHandles, false ); if ( intersects.length ) { const target = intersects[ 0 ].object;
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_postprocessing_ssrr.html
@@ -243,7 +243,7 @@ raycaster.setFromCamera( mouse, camera ); - const intersect = raycaster.intersectObjects( objects )[ 0 ]; + const intersect = raycaster.intersectObjects( objects, false )[ 0 ]; if ( intersect ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_postprocessing_unreal_bloom_selective.html
@@ -184,7 +184,7 @@ mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1; raycaster.setFromCamera( mouse, camera ); - const intersects = raycaster.intersectObjects( scene.children ); + const intersects = raycaster.intersectObjects( scene.children, false ); if ( intersects.length > 0 ) { const object = intersects[ 0 ].object;
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webgl_raycast_texture.html
@@ -328,7 +328,7 @@ raycaster.setFromCamera( mouse, camera ); - return raycaster.intersectObjects( objects ); + return raycaster.intersectObjects( objects, false ); }
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webxr_vr_cubes.html
@@ -205,7 +205,7 @@ raycaster.ray.origin.setFromMatrixPosition( controller.matrixWorld ); raycaster.ray.direction.set( 0, 0, - 1 ).applyMatrix4( tempMatrix ); - const intersects = raycaster.intersectObjects( room.children ); + const intersects = raycaster.intersectObjects( room.children, false ); if ( intersects.length > 0 ) {
true
Other
mrdoob
three.js
e30436d09281e940b7bcef9a957e2ee645438dc0.json
Specify the recursive flag (#22500)
examples/webxr_vr_dragging.html
@@ -217,7 +217,7 @@ raycaster.ray.origin.setFromMatrixPosition( controller.matrixWorld ); raycaster.ray.direction.set( 0, 0, - 1 ).applyMatrix4( tempMatrix ); - return raycaster.intersectObjects( group.children ); + return raycaster.intersectObjects( group.children, false ); }
true
Other
mrdoob
three.js
c191406da786ee02f601b4e04228a62feec513d3.json
remove unnecessary import
examples/jsm/renderers/webgpu/WebGPUUniformsGroup.js
@@ -1,5 +1,4 @@ import WebGPUUniformBuffer from './WebGPUUniformBuffer.js'; -import { GPUBindingType } from './constants.js'; class WebGPUUniformsGroup extends WebGPUUniformBuffer {
false
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/jsm/renderers/webgpu/WebGPUBackground.js
@@ -1,5 +1,5 @@ import { GPULoadOp } from './constants.js'; -import { Color } from '../../../../build/three.module.js'; +import { Color } from 'three'; let _clearAlpha; const _clearColor = new Color();
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/jsm/renderers/webgpu/WebGPURenderPipelines.js
@@ -7,7 +7,7 @@ import { NoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending, AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation, ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstAlphaFactor, OneMinusDstAlphaFactor, DstColorFactor, OneMinusDstColorFactor, SrcAlphaSaturateFactor -} from '../../../../build/three.module.js'; +} from 'three'; class WebGPURenderPipelines {
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/jsm/renderers/webgpu/WebGPURenderer.js
@@ -14,7 +14,7 @@ import WebGPUNodes from './nodes/WebGPUNodes.js'; import glslang from '../../libs/glslang.js'; -import { Frustum, Matrix4, Vector3, Color } from '../../../../build/three.module.js'; +import { Frustum, Matrix4, Vector3, Color } from 'three'; console.info( 'THREE.WebGPURenderer: Modified Matrix4.makePerspective() and Matrix4.makeOrtographic() to work with WebGPU, see https://github.com/mrdoob/three.js/issues/20276.' );
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/jsm/renderers/webgpu/WebGPUTextureRenderer.js
@@ -1,4 +1,4 @@ -import { WebGLRenderTarget } from '../../../../build/three.module.js'; +import { WebGLRenderTarget } from 'three'; class WebGPUTextureRenderer {
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/jsm/renderers/webgpu/WebGPUTextures.js
@@ -1,7 +1,7 @@ import { GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension } from './constants.js'; import { CubeTexture, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, RepeatWrapping, MirroredRepeatWrapping, RGBFormat, RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, sRGBEncoding -} from '../../../../build/three.module.js'; +} from 'three'; import WebGPUTextureUtils from './WebGPUTextureUtils.js'; class WebGPUTextures {
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/jsm/renderers/webgpu/WebGPUUniform.js
@@ -1,4 +1,4 @@ -import { Color, Matrix3, Matrix4, Vector2, Vector3, Vector4 } from '../../../../build/three.module.js'; +import { Color, Matrix3, Matrix4, Vector2, Vector3, Vector4 } from 'three'; class WebGPUUniform {
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/webgpu_compute.html
@@ -10,9 +10,16 @@ <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> WebGPU - Compute<br/>(Chrome Canary with flag: --enable-unsafe-webgpu) </div> + <script type="importmap"> + { + "imports": { + "three": "../build/three.module.js" + } + } + </script> <script type="module"> - import * as THREE from '../build/three.module.js'; + import * as THREE from 'three'; import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js'; import WebGPU from './jsm/renderers/webgpu/WebGPU.js';
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/webgpu_instance_uniform.html
@@ -11,9 +11,16 @@ <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - webgpu materials </div> + <script type="importmap"> + { + "imports": { + "three": "../build/three.module.js" + } + } + </script> <script type="module"> - import * as THREE from '../build/three.module.js'; + import * as THREE from 'three'; import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js'; import WebGPU from './jsm/renderers/webgpu/WebGPU.js';
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/webgpu_materials.html
@@ -11,9 +11,16 @@ <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - webgpu materials </div> + <script type="importmap"> + { + "imports": { + "three": "../build/three.module.js" + } + } + </script> <script type="module"> - import * as THREE from '../build/three.module.js'; + import * as THREE from 'three'; import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js'; import WebGPU from './jsm/renderers/webgpu/WebGPU.js';
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/webgpu_rtt.html
@@ -10,9 +10,16 @@ <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> WebGPU - RTT<br/>(Chrome Canary with flag: --enable-unsafe-webgpu) </div> + <script type="importmap"> + { + "imports": { + "three": "../build/three.module.js" + } + } + </script> <script type="module"> - import * as THREE from '../build/three.module.js'; + import * as THREE from 'three'; import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js'; import WebGPUTextureRenderer from './jsm/renderers/webgpu/WebGPUTextureRenderer.js';
true
Other
mrdoob
three.js
494b3421d4284bd83bdea1b1a56dd76753bb3178.json
Adopt importmaps in WebGPU examples
examples/webgpu_sandbox.html
@@ -10,9 +10,16 @@ <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> WebGPU - sandbox<br/>(Chrome Canary with flag: --enable-unsafe-webgpu) </div> + <script type="importmap"> + { + "imports": { + "three": "../build/three.module.js" + } + } + </script> <script type="module"> - import * as THREE from '../build/three.module.js'; + import * as THREE from 'three'; import { DDSLoader } from './jsm/loaders/DDSLoader.js';
true
Other
mrdoob
three.js
c3f83169d60fbc4f3ca25fb83d04bffc84bdf9e5.json
use default value
examples/webgpu_instance_uniform.html
@@ -35,7 +35,7 @@ this.updateType = NodeUpdateType.Object; - this.inputNode = new ColorNode( new THREE.Color() ); + this.inputNode = new ColorNode(); }
false
Other
mrdoob
three.js
015a27c4b4d9759cc0f94e4f933d57c3f1df7454.json
add missing default value
examples/jsm/renderers/nodes/inputs/ColorNode.js
@@ -1,8 +1,9 @@ import InputNode from '../core/InputNode.js'; +import { Color } from '../../../../../build/three.module.js'; class ColorNode extends InputNode { - constructor( value ) { + constructor( value = new Color() ) { super( 'color' );
true
Other
mrdoob
three.js
015a27c4b4d9759cc0f94e4f933d57c3f1df7454.json
add missing default value
examples/jsm/renderers/nodes/inputs/Vector2Node.js
@@ -1,8 +1,9 @@ import InputNode from '../core/InputNode.js'; +import { Vector2 } from '../../../../../build/three.module.js'; class Vector2Node extends InputNode { - constructor( value ) { + constructor( value = new Vector2() ) { super( 'vec2' );
true
Other
mrdoob
three.js
59e8e47d2df52b9572b14e1bd7f616b1cb0809a7.json
compile node material per object
examples/jsm/renderers/webgpu/WebGPUBindings.js
@@ -24,12 +24,11 @@ class WebGPUBindings { if ( data === undefined ) { const pipeline = this.pipelines.get( object ); - const material = object.material; - - const nodeBuilder = this.nodes.get( material ); // each material defines an array of bindings (ubos, textures, samplers etc.) + const nodeBuilder = this.nodes.get( object ); + const bindings = nodeBuilder.getBindings(); // setup (static) binding layout and (dynamic) binding group
true
Other
mrdoob
three.js
59e8e47d2df52b9572b14e1bd7f616b1cb0809a7.json
compile node material per object
examples/jsm/renderers/webgpu/WebGPURenderPipelines.js
@@ -57,7 +57,7 @@ class WebGPURenderPipelines { // get shader - const nodeBuilder = this.nodes.get( material ); + const nodeBuilder = this.nodes.get( object ); // shader modules @@ -788,22 +788,15 @@ class WebGPURenderPipelines { function onMaterialDispose( event ) { const properties = this.properties; - const nodes = this.nodes; - const shaderModules = this.shaderModules; const material = event.target; const materialProperties = properties.get( material ); - const nodeBuilder = nodes.get( material ); material.removeEventListener( 'dispose', materialProperties.disposeCallback ); properties.remove( material ); - nodes.remove( material ); - shaderModules.vertex.delete( nodeBuilder.vertexShader ); - shaderModules.fragment.delete( nodeBuilder.fragmentShader ); - - // @TODO: still needed remove bindings and pipeline + // @TODO: still needed remove nodes, bindings and pipeline }
true
Other
mrdoob
three.js
59e8e47d2df52b9572b14e1bd7f616b1cb0809a7.json
compile node material per object
examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js
@@ -13,25 +13,25 @@ class WebGPUNodes { } - get( material ) { + get( object ) { - let nodeBuilder = this.builders.get( material ); + let nodeBuilder = this.builders.get( object ); if ( nodeBuilder === undefined ) { - nodeBuilder = new WebGPUNodeBuilder( material, this.renderer ).build(); + nodeBuilder = new WebGPUNodeBuilder( object.material, this.renderer ).build(); - this.builders.set( material, nodeBuilder ); + this.builders.set( object, nodeBuilder ); } return nodeBuilder; } - remove( material ) { + remove( object ) { - this.builders.delete( material ); + this.builders.delete( object ); } @@ -45,7 +45,7 @@ class WebGPUNodes { const material = object.material; - const nodeBuilder = this.get( material ); + const nodeBuilder = this.get( object ); const nodeFrame = this.nodeFrame; nodeFrame.material = material;
true
Other
mrdoob
three.js
9d9b9fac2571c690ae81742c53769b0bc72cf06a.json
Add Chinese translation for tips article. (#23501)
manual/list.json
@@ -321,11 +321,11 @@ "ๆŒ‰้œ€ๆธฒๆŸ“": "zh/rendering-on-demand", "่ฐƒ่ฏ•JavaScript": "zh/debugging-javascript", "่ฐƒ่ฏ•็€่‰ฒๅ™จ": "zh/debugging-glsl", - "Taking a screenshot": "zh/tips#screenshot", - "Prevent the Canvas Being Cleared": "zh/tips#preservedrawingbuffer", - "Get Keyboard Input From a Canvas": "zh/tips#tabindex", - "Make the Canvas Transparent": "zh/tips#transparent-canvas", - "Use three.js as Background in HTML": "zh/tips#html-background" + "canvasๆˆชๅ›พ": "zh/tips#screenshot", + "้˜ฒๆญขcanvas่ขซๆธ…็ฉบ": "zh/tips#preservedrawingbuffer", + "ไปŽcanvas่Žทๅ–้”ฎ็›˜่พ“ๅ…ฅ": "zh/tips#tabindex", + "้€ๆ˜ŽๅŒ–canvas": "zh/tips#transparent-canvas", + "ๅœจHTMLไธญไฝฟ็”จthree.jsๅŠจ็”ป่ƒŒๆ™ฏ": "zh/tips#html-background" }, "ไผ˜ๅŒ–": { "ๅคง้‡ๅฏน่ฑก็š„ไผ˜ๅŒ–": "zh/optimize-lots-of-objects",
true
Other
mrdoob
three.js
9d9b9fac2571c690ae81742c53769b0bc72cf06a.json
Add Chinese translation for tips article. (#23501)
manual/zh/tips.html
@@ -1,6 +1,6 @@ -<!DOCTYPE html><html lang="zh"><head> +<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> - <title>Tips</title> + <title>ๅฐๆŠ€ๅทง</title> <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:site" content="@threejs"> @@ -22,7 +22,6 @@ } } </script> - <link rel="stylesheet" href="/manual/zh/lang.css"> </head> <body> <div class="container"> @@ -31,8 +30,305 @@ <h1>Tips</h1> </div> <div class="lesson"> <div class="lesson-main"> - <p>ๆŠฑๆญ‰๏ผŒ่ฟ˜ๆฒกๆœ‰ไธญๆ–‡็ฟป่ฏ‘ๅ“ฆใ€‚ <a href="https://github.com/mrdoob/three.js">ๆฌข่ฟŽๅŠ ๅ…ฅ็ฟป่ฏ‘</a>! ๐Ÿ˜„</p> -<p><a href="/manual/en/tips.html">่‹ฑๆ–‡ๅŽŸๆ–‡้“พๆŽฅ</a>.</p> + <p>ๆœฌๆ–‡ไธญๆˆ‘ไปฌๆ€ป็ป“ไบ†ไธ€ไบ›ๅœจไฝฟ็”จthree.js่ฟ‡็จ‹ไธญๅฏ่ƒฝไผš้‡ๅˆฐ็š„ไฝ†ๅˆ็œ‹่ตทๆฅไธ้œ€่ฆๅ„่‡ชๅˆ—ๅ‡บไธ€็ซ ็š„ๅฐ้—ฎ้ข˜ใ€‚</p> +<hr> +<p><a id="screenshot" data-toc="Taking a screenshot"></a></p> +<h1 id="taking-a-screenshot-of-the-canvas">canvasๆˆชๅ›พ</h1> +<p>ๅœจๆต่งˆๅ™จไธญๅญ˜ๅœจไธค็งๆœ‰ๆ•ˆ็š„ๆ–นๅผ่ฟ›่กŒๆˆชๅ›พใ€‚ +ๆ—ง็š„ +<a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL"><code class="notranslate" translate="no">canvas.toDataURL</code></a> +ไธŽๆ–ฐ็š„ๆ›ดๅฅฝ็š„ +<a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob"><code class="notranslate" translate="no">canvas.toBlob</code></a></p> +<p>ๆ‰€ไปฅไฝ ๅฏ่ƒฝ่ฎคไธบไป…้€š่ฟ‡ๆทปๅŠ ไธ‹ๅˆ—ไปฃ็ ๅณๅฏ่ฝปๆพๅฎž็Žฐๆˆชๅ›พๅŠŸ่ƒฝ</p> +<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;canvas id="c"&gt;&lt;/canvas&gt; ++&lt;button id="screenshot" type="button"&gt;Save...&lt;/button&gt; +</pre> +<pre class="prettyprint showlinemods notranslate lang-js" translate="no">const elem = document.querySelector('#screenshot'); +elem.addEventListener('click', () =&gt; { + canvas.toBlob((blob) =&gt; { + saveBlob(blob, `screencapture-${canvas.width}x${canvas.height}.png`); + }); +}); + +const saveBlob = (function() { + const a = document.createElement('a'); + document.body.appendChild(a); + a.style.display = 'none'; + return function saveData(blob, fileName) { + const url = window.URL.createObjectURL(blob); + a.href = url; + a.download = fileName; + a.click(); + }; +}()); +</pre> +<p>ไธ‹้ขๆ˜ฏๆฅ่‡ชไป‹็ป <a href="responsive.html">ๅ“ๅบ”ๅผ่ฎพ่ฎก</a> +ๅนถๆทปๅŠ ไบ†ไธŠ่ฟฐไปฃ็ ไธŽไธ€ไบ›ๆ”พ็ฝฎๆŒ‰้’ฎ็š„CSS็š„ไพ‹ๅญใ€‚</p> +<p></p><div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/tips-screenshot-bad.html"></iframe></div> + <a class="threejs_center" href="/manual/examples/tips-screenshot-bad.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> +</div> + +<p></p> +<p>ๅฝ“ๆˆ‘ๅฐ่ฏ•ๆˆชๅ›พๅพ—ๅˆฐไบ†ๅฆ‚ไธ‹ๅ›พ็‰‡</p> +<div class="threejs_center"><img src="../resources/images/screencapture-413x313.png"></div> + +<p>ๆ˜ฏ็š„๏ผŒๅฐฑๆ˜ฏไธ€ๅผ ็บฏ้ป‘็š„ๅ›พ็‰‡่€Œๅทฒใ€‚</p> +<p>ๅ–ๅ†ณไบŽไฝ ็š„ๆต่งˆๅ™จไธŽ็ณป็ปŸ็š„ไธๅŒ่ฟ™ไธชไพ‹ๅญไนŸๆœ‰ๅฏ่ƒฝไผšๆญฃๅธธ็”Ÿๆ•ˆ๏ผŒไฝ†ๆ˜ฏไธ€่ˆฌๆƒ…ๅ†ตไธ‹่ฟ™ไธชไพ‹ๅญๆ˜ฏๆ— ๆณ•ๆญฃๅธธ็”Ÿๆ•ˆ็š„ใ€‚</p> +<p>่ฟ™ไธช้—ฎ้ข˜็š„ๅ‡บ็Žฐๆ˜ฏๅ› ไธบๅŸบไบŽๆ€ง่ƒฝๅ’Œๅ…ผๅฎนๆ€ง็š„่€ƒ้‡๏ผŒ้ป˜่ฎคๆƒ…ๅ†ตไธ‹ๆต่งˆๅ™จไผšๅœจ็ป˜ๅˆถๅฎŒๆˆๅŽๆธ…้™คWebGL canvas็š„็ผ“ๅญ˜ใ€‚</p> +<p>่งฃๅ†ณๆ–นๆกˆๆ˜ฏๅœจไฝ ๆ•่Žทๆˆชๅ›พๅ‰่ฐƒ็”จไธ€ๆฌกๆธฒๆŸ“ไปฃ็ ใ€‚</p> +<p>ๅœจๆˆ‘ไปฌ็š„ไปฃ็ ้‡Œๆˆ‘ไปฌๅช่ฆ่ฟ›่กŒๅฐๅน…ๅบฆ่ฐƒๆ•ดๅณๅฏใ€‚้ฆ–ๅ…ˆ๏ผŒๅˆ†็ฆปๅ‡บๆˆ‘ไปฌ็š„ๆธฒๆŸ“ไปฃ็ </p> +<pre class="prettyprint showlinemods notranslate lang-js" translate="no">+const state = { ++ time: 0, ++}; + +-function render(time) { +- time *= 0.001; ++function render() { + if (resizeRendererToDisplaySize(renderer)) { + const canvas = renderer.domElement; + camera.aspect = canvas.clientWidth / canvas.clientHeight; + camera.updateProjectionMatrix(); + } + + cubes.forEach((cube, ndx) =&gt; { + const speed = 1 + ndx * .1; +- const rot = time * speed; ++ const rot = state.time * speed; + cube.rotation.x = rot; + cube.rotation.y = rot; + }); + + renderer.render(scene, camera); + +- requestAnimationFrame(render); +} + ++function animate(time) { ++ state.time = time * 0.001; ++ ++ render(); ++ ++ requestAnimationFrame(animate); ++} ++requestAnimationFrame(animate); +</pre> +<p>็Žฐๅœจ <code class="notranslate" translate="no">render</code> ๆ–นๆณ•ๅชไธŽๅฎž้™…็š„ๆธฒๆŸ“่ฟ‡็จ‹็›ธๅ…ณ่”ไบ†ใ€‚ๆˆ‘ไปฌๅฏไปฅๅœจๅˆšๅฅฝ่ฆๆ•่Žทcanvasๆˆชๅ›พๅ‰่ฐƒ็”จๅฎƒใ€‚</p> +<pre class="prettyprint showlinemods notranslate lang-js" translate="no">const elem = document.querySelector('#screenshot'); +elem.addEventListener('click', () =&gt; { ++ render(); + canvas.toBlob((blob) =&gt; { + saveBlob(blob, `screencapture-${canvas.width}x${canvas.height}.png`); + }); +}); +</pre> +<p>็Žฐๅœจๅบ”่ฏฅ่ƒฝๆญฃๅธธ็”Ÿๆ•ˆไบ†ใ€‚</p> +<p></p><div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/tips-screenshot-good.html"></iframe></div> + <a class="threejs_center" href="/manual/examples/tips-screenshot-good.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> +</div> + +<p></p><p>ๆœ‰ๅ…ณๅ…ถไป–่งฃๅ†ณๆ–นๆกˆ๏ผŒ่ฏทๅ‚้˜…ไธ‹ไธ€้กนใ€‚</p> +<hr> + +<p><a id="preservedrawingbuffer" data-toc="Prevent the Canvas Being Cleared"></a></p> +<h1 id="preventing-the-canvas-being-cleared">้˜ฒๆญขcanvas่ขซๆธ…็ฉบ</h1> +<p>ๅฆ‚ๆžœไฝ ๆƒณ่ฆ่ฎฉ็”จๆˆทไฝฟ็”จๅŠจ็”ปๅฏน่ฑก่ฟ›่กŒ็ป˜ๅ›พใ€‚ไฝ ้œ€่ฆๅœจๅˆ›ๅปบ <a href="/docs/#api/zh/renderers/WebGLRenderer"><code class="notranslate" translate="no">WebGLRenderer</code></a> ็š„ๆ—ถๅ€™ไผ ๅ…ฅ <code class="notranslate" translate="no">preserveDrawingBuffer: true</code>ใ€‚่ฟ™ๅฐ†้˜ปๆญขๆต่งˆๅ™จๆธ…็†canvasใ€‚็ฑปไผผ็š„๏ผŒไฝ ไนŸ้œ€่ฆๅ‘Š่ฏ‰three.jsไธ่ฆ่‡ชๅŠจๆธ…็†canvasใ€‚</p> +<pre class="prettyprint showlinemods notranslate lang-js" translate="no">const canvas = document.querySelector('#c'); +-const renderer = new THREE.WebGLRenderer({canvas}); ++const renderer = new THREE.WebGLRenderer({ ++ canvas, ++ preserveDrawingBuffer: true, ++ alpha: true, ++}); ++renderer.autoClearColor = false; +</pre> +<p></p><div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/tips-preservedrawingbuffer.html"></iframe></div> + <a class="threejs_center" href="/manual/examples/tips-preservedrawingbuffer.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> +</div> + +<p></p> +<p>้œ€่ฆๆณจๆ„็š„ๆ˜ฏๅฆ‚ๆžœไฝ ็กฎๅฎž้œ€่ฆๅˆถไฝœไธ€ไธช็”ปๅ›พ็จ‹ๅบ็š„่ฏ่ฟ™ๅนถไธ่ƒฝ่งฃๅ†ณไฝ ็š„้—ฎ้ข˜๏ผŒๅ› ไธบๆต่งˆๅ™จไป็„ถไผšๆ”นๅ˜ๅˆ†่พจ็އ็š„ๆ—ถๅ€™้šๆ—ถๆœ‰ๅฏ่ƒฝๆธ…็ฉบcanvasใ€‚ๆˆ‘ไปฌ็›ฎๅ‰็š„ๆ–นๆกˆๆ˜ฏ่ฎฉcanvas็š„ๅˆ†่พจ็އ่ทŸ้šๆ˜พ็คบๅคงๅฐ็š„ๆ”นๅ˜ใ€‚่€Œcanvas็š„ๆ˜พ็คบๅคงๅฐไนŸๅœจ้š็€็ช—ๅฃๅคงๅฐๅ˜ๅŒ–ใ€‚่ฟ™ๅŒ…ๆ‹ฌไบ†ๅณไพฟ็”จๆˆทๅœจๅฆไธ€ไธชๆ ‡็ญพ้กตไธญไธ‹่ฝฝไบ†ไธ€ไธชๆ–‡ไปถ๏ผŒๆต่งˆๅ™จๆทปๅŠ ไบ†ไธ€ไธช็Šถๆ€ๆ ็š„ๆƒ…ๅ†ตใ€‚ไนŸๅŒ…ๆ‹ฌไบ†็”จๆˆท่ฝฌๅŠจๆ‰‹ๆœบๆ—ถๆต่งˆๅ™จไปŽ็บตๅ‘ๅˆ‡ๆข่‡ณๆจชๅ‘ๅธƒๅฑ€็š„ๆƒ…ๅ†ต</p> +<p>ๅฆ‚ๆžœไฝ ๅˆ‡ๅฎž้œ€่ฆๅˆถไฝœไธ€ไธช็ป˜ๅ›พ็š„็จ‹ๅบ๏ผŒไฝ ๅฏไปฅ +<a href="rendertargets.html">ไฝฟ็”จๆธฒๆŸ“็›ฎๆ ‡็š„ๆ–นๅผๆธฒๆŸ“ๅˆฐ็บน็†ไธŠ</a>ใ€‚</p> +<hr> +<p><a id="tabindex" data-toc="Get Keyboard Input From a Canvas"></a></p> +<h1 id="getting-keyboard-input">่Žทๅ–้”ฎ็›˜่พ“ๅ…ฅ</h1> +<p>ๅœจ่ฟ™ไบ›ๆ•™็จ‹ไธญ๏ผŒๆˆ‘ไปฌ้€šๅธธไผšๅฐ†ไบ‹ไปถ็›‘ๅฌๅ™จ็ป‘ๅฎšๅˆฐcanvasไธŠ <code class="notranslate" translate="no">canvas</code>ใ€‚ +่™ฝ็„ถ่ฎธๅคšไบ‹ไปถ้ƒฝ่ƒฝ็”Ÿๆ•ˆ๏ผŒไฝ†ๆ˜ฏ้ป˜่ฎคๆƒ…ๅ†ตไธ‹้”ฎ็›˜ไบ‹ไปถไธไผšๆญฃๅธธๅ“ๅบ”ใ€‚</p> +<p>ไธบไบ†่Žทๅ–้”ฎ็›˜ไบ‹ไปถ๏ผŒๆˆ‘ไปฌๅฐ†canvas็š„ <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/tabIndex"><code class="notranslate" translate="no">tabindex</code></a> +ๅฑžๆ€ง่ฎพ็ฝฎไธบ0ๆˆ–ๆ›ด้ซ˜ใ€‚ๅฆ‚ไธ‹ใ€‚</p> +<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;canvas tabindex="0"&gt;&lt;/canvas&gt; +</pre> +<p>่ฟ™ๅฐ†ๅฏผ่‡ดไธ€ไธชๆ–ฐ็š„้—ฎ้ข˜๏ผŒไปปไฝ•่ฎพ็ฝฎไบ† <code class="notranslate" translate="no">tabindex</code> ็š„ๅ…ƒ็ด ไผšๅœจ่š็„ฆ็š„ๆ—ถๅ€™็ชๅ‡บๆ˜พ็คบใ€‚ไธบไบ†่งฃๅ†ณ่ฟ™ไธช้—ฎ้ข˜๏ผŒๆˆ‘ไปฌๅœจCSSไธญๅฐ†ๅฎƒfocus็Šถๆ€ไธ‹็š„outlineๅฑžๆ€ง่ฎพ็ฝฎไธบnone</p> +<pre class="prettyprint showlinemods notranslate lang-css" translate="no">canvas:focus { + outline:none; +} +</pre> +<p>่ฟ™้‡Œไธบไบ†ๆผ”็คบไฝฟ็”จไบ†3ไธชcanvas</p> +<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;canvas id="c1"&gt;&lt;/canvas&gt; +&lt;canvas id="c2" tabindex="0"&gt;&lt;/canvas&gt; +&lt;canvas id="c3" tabindex="1"&gt;&lt;/canvas&gt; +</pre> +<p>ๅนถไธ”ๅชไธบๆœ€ๅŽไธ€ไธชcanvas่ฎพ็ฝฎcss </p> +<pre class="prettyprint showlinemods notranslate lang-css" translate="no">#c3:focus { + outline: none; +} +</pre> +<p>่ฎฉๆˆ‘ไปฌ็”จๅŒๆ ท็š„ไบ‹ไปถ็›‘ๅฌๅ™จๅˆ†ๅˆซไธŽๅฎƒไปฌ็›ธๅ…ณ่”</p> +<pre class="prettyprint showlinemods notranslate lang-js" translate="no">document.querySelectorAll('canvas').forEach((canvas) =&gt; { + const ctx = canvas.getContext('2d'); + + function draw(str) { + ctx.clearRect(0, 0, canvas.width, canvas.height); + ctx.textAlign = 'center'; + ctx.textBaseline = 'middle'; + ctx.fillText(str, canvas.width / 2, canvas.height / 2); + } + draw(canvas.id); + + canvas.addEventListener('focus', () =&gt; { + draw('has focus press a key'); + }); + + canvas.addEventListener('blur', () =&gt; { + draw('lost focus'); + }); + + canvas.addEventListener('keydown', (e) =&gt; { + draw(`keyCode: ${e.keyCode}`); + }); +}); +</pre> +<p>่ฏทๆณจๆ„๏ผŒไฝ ๆ— ๆณ•่ฎฉ็ฌฌไธ€ไธชcanvasๆŽฅๆ”ถๅˆฐ้”ฎ็›˜่พ“ๅ…ฅใ€‚็ฌฌไบŒไธชcanvas่™ฝ็„ถ่ƒฝๆŽฅๆ”ถๅˆฐ่พ“ๅ…ฅไฝ†ๆ˜ฏ่ขซ็ชๅ‡บๆ˜พ็คบไบ†ใ€‚็ฌฌไธ‰ไธชcanvasๅŒๆ—ถ่งฃๅ†ณไบ†่ฟ™่ฟ™ไธคไธช้—ฎ้ข˜ใ€‚</p> +<p></p><div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/tips-tabindex.html"></iframe></div> + <a class="threejs_center" href="/manual/examples/tips-tabindex.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> +</div> + +<p></p> +<hr> +<p><a id="transparent-canvas" data-toc="Make the Canvas Transparent"></a></p> +<h1 id="making-the-canvas-transparent">้€ๆ˜ŽๅŒ–canvas</h1> +<p>้ป˜่ฎคๆƒ…ๅ†ตไธ‹THREE.js่ฎฉcanvasๆ˜พ็คบไธบไธ้€ๆ˜Žใ€‚ๅฆ‚ๆžœไฝ ้œ€่ฆ่ฎฉcanvasๅ˜ๅพ—้€ๆ˜Žๅฏไปฅๅœจๅˆ›ๅปบ <a href="/docs/#api/zh/renderers/WebGLRenderer"><code class="notranslate" translate="no">WebGLRenderer</code></a> ็š„ๆ—ถๅ€™ไผ ๅ…ฅ <a href="/docs/#api/zh/renderers/WebGLRenderer#alpha"><code class="notranslate" translate="no">alpha:true</code></a></p> +<pre class="prettyprint showlinemods notranslate lang-js" translate="no">const canvas = document.querySelector('#c'); +-const renderer = new THREE.WebGLRenderer({canvas}); ++const renderer = new THREE.WebGLRenderer({ ++ canvas, ++ alpha: true, ++}); +</pre> +<p>ไฝ ๅฏ่ƒฝ่ฟ˜ๆƒณๅ‘Š่ฏ‰ๅฎƒไฝ ็š„็ป“ๆžœ <strong>ไธ</strong> ไฝฟ็”จ premultiplied alpha</p> +<pre class="prettyprint showlinemods notranslate lang-js" translate="no">const canvas = document.querySelector('#c'); +const renderer = new THREE.WebGLRenderer({ + canvas, + alpha: true, ++ premultipliedAlpha: false, +}); +</pre> +<p>Three.js ไฝฟ็”จ +<a href="/docs/#api/zh/renderers/WebGLRenderer#premultipliedAlpha"><code class="notranslate" translate="no">premultipliedAlpha: true</code></a> ไฝœไธบcanvas็š„็ผบ็œๅ€ผ๏ผŒไฝ†ไฝฟ็”จ <a href="/docs/#api/zh/materials/Material#premultipliedAlpha"><code class="notranslate" translate="no">premultipliedAlpha: false</code></a> ไฝœไธบๆ่ดจ็š„็ผบ็œๅ€ผใ€‚</p> +<p>ๅฆ‚ๆžœไฝ ๆƒณ่ฆๆ›ดๅฅฝ็š„็†่งฃpremultiplied alpha็š„ไฝฟ็”จไธŽๅฆ๏ผŒ่ฟ™้‡Œๆœ‰<a href="https://developer.nvidia.com/content/alpha-blending-pre-or-not-pre">ไธ€็ฏ‡ๅ…ณไบŽ่ฟ™ไธช้—ฎ้ข˜็š„ๅฅฝๆ–‡็ซ </a>ใ€‚</p> +<p>ไธ็ฎกๆ€Žๆ ท๏ผŒ่ฎฉๆˆ‘ไปฌ็”จ้€ๆ˜Žcanvasๆฅ่ฎพ็ฝฎไธ€ไธช็ฎ€ๅ•็š„ไพ‹ๅญใ€‚</p> +<p>ๆˆ‘ไปฌๅฐ†ไธŠ่ฟฐ้…็ฝฎๅบ”็”จๅˆฐๆฅ่‡ช<a href="responsive.html">ๅ…ณไบŽๅ“ๅบ”ๅผ่ฎพ่ฎก็š„ๆ–‡็ซ </a>้‡Œ็š„ไพ‹ๅญใ€‚่ฎฉๆˆ‘ไปฌไนŸๅฐ†ๆ่ดจๅ˜ๅพ—ๆ›ด้€ๆ˜Žใ€‚</p> +<pre class="prettyprint showlinemods notranslate lang-js" translate="no">function makeInstance(geometry, color, x) { +- const material = new THREE.MeshPhongMaterial({color}); ++ const material = new THREE.MeshPhongMaterial({ ++ color, ++ opacity: 0.5, ++ }); + +... +</pre> +<p>ๅนถไธ”ๆทปๅŠ ไธ€ไบ›HTMLๅ†…ๅฎน</p> +<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;body&gt; + &lt;canvas id="c"&gt;&lt;/canvas&gt; ++ &lt;div id="content"&gt; ++ &lt;div&gt; ++ &lt;h1&gt;Cubes-R-Us!&lt;/h1&gt; ++ &lt;p&gt;We make the best cubes!&lt;/p&gt; ++ &lt;/div&gt; ++ &lt;/div&gt; +&lt;/body&gt; +</pre> +<p>่ฟ˜ๆœ‰ไธ€ไบ›ๅฐ†็”ปๅธƒๆ”พ็ฝฎๅˆฐๅ‰้ข็š„CSS</p> +<pre class="prettyprint showlinemods notranslate lang-css" translate="no">body { + margin: 0; +} +#c { + width: 100%; + height: 100%; + display: block; ++ position: fixed; ++ left: 0; ++ top: 0; ++ z-index: 2; ++ pointer-events: none; +} ++#content { ++ font-size: 7vw; ++ font-family: sans-serif; ++ text-align: center; ++ width: 100%; ++ height: 100%; ++ display: flex; ++ justify-content: center; ++ align-items: center; ++} +</pre> +<p>ๆณจๆ„ <code class="notranslate" translate="no">pointer-events: none</code> ไฝฟๅพ—canvasไธๅ“ๅบ”้ผ ๆ ‡ไธŽ่งฆๆ‘ธไบ‹ไปถ๏ผŒไปฅ่‡ณไบŽไฝ ่ƒฝๅคŸ้€‰ไธญไธ‹้ข็š„ๆ–‡ๅญ—ใ€‚</p> +<p></p><div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/tips-transparent-canvas.html"></iframe></div> + <a class="threejs_center" href="/manual/examples/tips-transparent-canvas.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> +</div> + +<p></p> +<hr> +<p><a id="html-background" data-toc="Use three.js as Background in HTML"></a></p> +<h1 id="making-your-background-a-three-js-animation">ไฝฟ็”จthree.jsๅŠจ็”ปไฝœไธบ่ƒŒๆ™ฏ</h1> +<p>ไธ€ไธชๅธธ่ง็š„้—ฎ้ข˜ๆ˜ฏๅฆ‚ไฝ•ไฝฟ็”จthree.jsๅŠจ็”ปไฝœไธบ็ฝ‘็ซ™็š„่ƒŒๆ™ฏใ€‚</p> +<p>่ฟ™ๆœ‰ไธค็งๆ˜พ่€Œๆ˜“่ง็š„ๆ–นๆณ•ใ€‚</p> +<ul> +<li>ๅฐ†canvas็š„CSS <code class="notranslate" translate="no">position</code> ๅฑžๆ€งๅฆ‚ไธ‹่ฎพ็ฝฎไธบ <code class="notranslate" translate="no">fixed</code></li> +</ul> +<pre class="prettyprint showlinemods notranslate lang-css" translate="no">#c { + position: fixed; + left: 0; + top: 0; + ... +} +</pre> +<p>ไฝ ๅฏ็ฎ€ๅ•็š„ๅœจไธŠไธ€ไธช็š„ไพ‹ๅญ้‡Œไฝฟ็”จ่ฟ™ไธช่งฃๅ†ณๆ–นๆกˆใ€‚ๅช้œ€่ฆๅฐ† <code class="notranslate" translate="no">z-index</code> ่ฎพไธบ -1 +ๅฐฑๅฏไปฅ็œ‹ๅˆฐ็ซ‹ๆ–นไฝ“ไปฌๆ˜พ็คบๅˆฐๆ–‡ๅญ—ๅŽ้ขใ€‚</p> +<p>่ฟ™ไธช่งฃๅ†ณๆ–นๆกˆๅญ˜ๅœจไธ€ไธชๅฐ็ผบ็‚น๏ผŒ้‚ฃๅฐฑๆ˜ฏไฝ ็š„Javascriptๅฟ…้กป้›†ๆˆๅœจ้กต้ขไธญใ€‚่€Œไธ”ๅฆ‚ๆžœไฝ ็š„้กต้ขๅฎž็Žฐๅพˆๅคๆ‚็š„่ฏ๏ผŒไฝ ้œ€่ฆไฟ่ฏ้กต้ข้‡Œ็š„three.jsๅฏ่ง†ๅŒ–ไปฃ็ ไธไธŽๅฎž็Žฐๅ…ถไป–ๅŠŸ่ƒฝ็š„ไปฃ็ ็›ธๅ†ฒ็ชใ€‚</p> +<ul> +<li>ไฝฟ็”จ <code class="notranslate" translate="no">iframe</code></li> +</ul> +<p>่ฟ™็ง่งฃๅ†ณๆ–นๆกˆ่ขซๅบ”็”จๅœจไบ† <a href="/">ๆœฌ็ซ™้ฆ–้กต</a>.</p> +<p>ๅœจไฝ ็š„็ฝ‘้กต็งๅช้œ€่ฆๆ’ๅ…ฅไธ€ไธชiframe๏ผŒๅƒ่ฟ™ๆ ท</p> +<pre class="prettyprint showlinemods notranslate lang-html" translate="no">&lt;iframe id="background" src="responsive.html"&gt; +&lt;div&gt; + Your content goes here. +&lt;/div&gt; +</pre> +<p>็„ถๅŽไฟฎๆ”นๆ ทๅผไฝฟๅ…ถๅกซๆปก็ช—ๅฃ๏ผŒๅนถไธ”ๅค„ไบŽ่ƒŒๆ™ฏไธญใ€‚่ฟ™ๅ‡ ไนŽๅ’Œๆˆ‘ไปฌไน‹ๅ‰็”จๅˆฐ็š„canvasๆ ทๅผไปฃ็ ไธ€ๆ ทใ€‚ๅชไธ่ฟ‡ๅ› ไธบiframeๅญ˜ๅœจ้ป˜่ฎค่พนๆก†๏ผŒๆˆ‘ไปฌ้œ€่ฆ้ขๅค–ๅฐ† <code class="notranslate" translate="no">border</code> ่ฎพไธบ <code class="notranslate" translate="no">none</code> ใ€‚</p> +<pre class="prettyprint showlinemods notranslate notranslate" translate="no">#background { + position: fixed; + width: 100%; + height: 100%; + left: 0; + top: 0; + z-index: -1; + border: none; + pointer-events: none; +} +</pre><p></p><div translate="no" class="threejs_example_container notranslate"> + <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/tips-html-background.html"></iframe></div> + <a class="threejs_center" href="/manual/examples/tips-html-background.html" target="_blank">็‚นๅ‡ปๆญคๅค„ๅœจๆ–ฐๆ ‡็ญพ้กตไธญๆ‰“ๅผ€</a> +</div> + +<p></p> </div> </div>
true
Other
mrdoob
three.js
48b05d3500acc084df50be9b4c90781ad9b8cb17.json
Remove WebGLMultisampleRenderTarget. (#23455) * Remove WebGLMultisampleRenderTarget. * THREE.Legacy.js: Add WebGLMultisampleRenderTarget. * Exampels: Clean up. * WebGLRenderer: Use multisampling when possible without reporting errors. * Update WebGLRenderer.js Co-authored-by: mrdoob <info@mrdoob.com>
docs/api/en/renderers/WebGLMultisampleRenderTarget.html
@@ -1,57 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="utf-8" /> - <base href="../../../" /> - <script src="page.js"></script> - <link type="text/css" rel="stylesheet" href="page.css" /> - </head> - <body> - [page:WebGLRenderTarget] &rarr; - - <h1>[name]</h1> - - <p class="desc"> - A special render target that can be used to utilize multi-sampled renderbuffers. - Heads up: [name] can only be used with a WebGL 2 rendering context. - </p> - - <h2>Examples</h2> - - <p> - [example:webgl2_multisampled_renderbuffers webgl2 / multisampled / renderbuffers ] - </p> - - <h2>Constructor</h2> - - - <h3>[name]([param:Number width], [param:Number height], [param:Object options])</h3> - - <p> - [page:Float width] - The width of the render target. <br /> - [page:Float height] - The height of the render target.<br /> - [page:Object options] - (optional) object that holds texture parameters for an auto-generated target - texture and depthBuffer/stencilBuffer booleans. - </p> - - <h2>Properties</h2> - - <h3>[property:number samples]</h3> - <p> - Specifies the number of samples to be used for the renderbuffer storage. However, the maximum supported - size for multisampling is platform dependent and defined via *gl.MAX_SAMPLES*. - </p> - - <p>[page:WebGLRenderTarget WebGLRenderTarget] properties are available on this class.</p> - - <h2>Methods</h2> - - <p>[page:WebGLRenderTarget WebGLRenderTarget] methods are available on this class.</p> - - <h2>Source</h2> - - <p> - [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] - </p> - </body> -</html>
true
Other
mrdoob
three.js
48b05d3500acc084df50be9b4c90781ad9b8cb17.json
Remove WebGLMultisampleRenderTarget. (#23455) * Remove WebGLMultisampleRenderTarget. * THREE.Legacy.js: Add WebGLMultisampleRenderTarget. * Exampels: Clean up. * WebGLRenderer: Use multisampling when possible without reporting errors. * Update WebGLRenderer.js Co-authored-by: mrdoob <info@mrdoob.com>
docs/api/en/renderers/WebGLRenderTarget.html
@@ -93,6 +93,10 @@ <h3>[property:DepthTexture depthTexture]</h3> If set, the scene depth will be rendered to this texture. Default is null. </p> + <h3>[property:Number samples]</h3> + <p> + Defines the count of MSAA samples. Can only be used with WebGL 2. Default is *0*. + </p> <h2>Methods</h2>
true
Other
mrdoob
three.js
48b05d3500acc084df50be9b4c90781ad9b8cb17.json
Remove WebGLMultisampleRenderTarget. (#23455) * Remove WebGLMultisampleRenderTarget. * THREE.Legacy.js: Add WebGLMultisampleRenderTarget. * Exampels: Clean up. * WebGLRenderer: Use multisampling when possible without reporting errors. * Update WebGLRenderer.js Co-authored-by: mrdoob <info@mrdoob.com>
docs/api/zh/renderers/WebGLMultisampleRenderTarget.html
@@ -1,57 +0,0 @@ -<!DOCTYPE html> -<html lang="zh"> - <head> - <meta charset="utf-8" /> - <base href="../../../" /> - <script src="page.js"></script> - <link type="text/css" rel="stylesheet" href="page.css" /> - </head> - <body> - [page:WebGLRenderTarget] &rarr; - - <h1>[name]</h1> - - <p class="desc"> - A special render target that can be used to utilize multi-sampled renderbuffers. - Heads up: [name] can only be used with a WebGL 2 rendering context. - </p> - - <h2>Examples</h2> - - <p> - [example:webgl2_multisampled_renderbuffers webgl2 / multisampled / renderbuffers ] - </p> - - <h2>Constructor</h2> - - - <h3>[name]([param:Number width], [param:Number height], [param:Object options])</h3> - - <p> - [page:Float width] - The width of the render target. <br /> - [page:Float height] - The height of the render target.<br /> - [page:Object options] - (optional) object that holds texture parameters for an auto-generated target - texture and depthBuffer/stencilBuffer booleans. - </p> - - <h2>Properties</h2> - - <h3>[property:number samples]</h3> - <p> - Specifies the number of samples to be used for the renderbuffer storage. However, the maximum supported - size for multisampling is platform dependent and defined via *gl.MAX_SAMPLES*. - </p> - - <p>[page:WebGLRenderTarget WebGLRenderTarget] properties are available on this class.</p> - - <h2>Methods</h2> - - <p>[page:WebGLRenderTarget WebGLRenderTarget] methods are available on this class.</p> - - <h2>Source</h2> - - <p> - [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] - </p> - </body> -</html>
true
Other
mrdoob
three.js
48b05d3500acc084df50be9b4c90781ad9b8cb17.json
Remove WebGLMultisampleRenderTarget. (#23455) * Remove WebGLMultisampleRenderTarget. * THREE.Legacy.js: Add WebGLMultisampleRenderTarget. * Exampels: Clean up. * WebGLRenderer: Use multisampling when possible without reporting errors. * Update WebGLRenderer.js Co-authored-by: mrdoob <info@mrdoob.com>
docs/api/zh/renderers/WebGLRenderTarget.html
@@ -89,6 +89,10 @@ <h3>[property:DepthTexture depthTexture]</h3> ๅฆ‚ๆžœ่ฎพ็ฝฎ๏ผŒ้‚ฃไนˆๅœบๆ™ฏ็š„ๆทฑๅบฆๅฐ†ไผš่ขซๆธฒๆŸ“ๅˆฐๆญค็บน็†ไธŠใ€‚้ป˜่ฎคไธบnull </p> + <h3>[property:Number samples]</h3> + <p> + Defines the count of MSAA samples. Can only be used with WebGL 2. Default is *0*. + </p> <h2>ๆ–นๆณ•</h2>
true
Other
mrdoob
three.js
48b05d3500acc084df50be9b4c90781ad9b8cb17.json
Remove WebGLMultisampleRenderTarget. (#23455) * Remove WebGLMultisampleRenderTarget. * THREE.Legacy.js: Add WebGLMultisampleRenderTarget. * Exampels: Clean up. * WebGLRenderer: Use multisampling when possible without reporting errors. * Update WebGLRenderer.js Co-authored-by: mrdoob <info@mrdoob.com>
docs/list.json
@@ -283,7 +283,6 @@ "Renderers": { "WebGLMultipleRenderTargets": "api/en/renderers/WebGLMultipleRenderTargets", - "WebGLMultisampleRenderTarget": "api/en/renderers/WebGLMultisampleRenderTarget", "WebGLRenderer": "api/en/renderers/WebGLRenderer", "WebGL1Renderer": "api/en/renderers/WebGL1Renderer", "WebGLRenderTarget": "api/en/renderers/WebGLRenderTarget", @@ -783,7 +782,6 @@ "ๆธฒๆŸ“ๅ™จ": { "WebGLMultipleRenderTargets": "api/zh/renderers/WebGLMultipleRenderTargets", - "WebGLMultisampleRenderTarget": "api/zh/renderers/WebGLMultisampleRenderTarget", "WebGLRenderer": "api/zh/renderers/WebGLRenderer", "WebGL1Renderer": "api/zh/renderers/WebGL1Renderer", "WebGLRenderTarget": "api/zh/renderers/WebGLRenderTarget",
true
Other
mrdoob
three.js
48b05d3500acc084df50be9b4c90781ad9b8cb17.json
Remove WebGLMultisampleRenderTarget. (#23455) * Remove WebGLMultisampleRenderTarget. * THREE.Legacy.js: Add WebGLMultisampleRenderTarget. * Exampels: Clean up. * WebGLRenderer: Use multisampling when possible without reporting errors. * Update WebGLRenderer.js Co-authored-by: mrdoob <info@mrdoob.com>
examples/jsm/objects/Reflector.js
@@ -8,8 +8,7 @@ import { UniformsUtils, Vector3, Vector4, - WebGLRenderTarget, - WebGLMultisampleRenderTarget + WebGLRenderTarget } from 'three'; class Reflector extends Mesh { @@ -27,7 +26,7 @@ class Reflector extends Mesh { const textureHeight = options.textureHeight || 512; const clipBias = options.clipBias || 0; const shader = options.shader || Reflector.ReflectorShader; - const multisample = options.multisample || 4; + const multisample = ( options.multisample !== undefined ) ? options.multisample : 4; // @@ -46,18 +45,7 @@ class Reflector extends Mesh { const textureMatrix = new Matrix4(); const virtualCamera = new PerspectiveCamera(); - let renderTarget; - - if ( multisample > 0 ) { - - renderTarget = new WebGLMultisampleRenderTarget( textureWidth, textureHeight ); - renderTarget.samples = multisample; - - } else { - - renderTarget = new WebGLRenderTarget( textureWidth, textureHeight ); - - } + const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight, { samples: multisample } ); const material = new ShaderMaterial( { uniforms: UniformsUtils.clone( shader.uniforms ),
true
Other
mrdoob
three.js
48b05d3500acc084df50be9b4c90781ad9b8cb17.json
Remove WebGLMultisampleRenderTarget. (#23455) * Remove WebGLMultisampleRenderTarget. * THREE.Legacy.js: Add WebGLMultisampleRenderTarget. * Exampels: Clean up. * WebGLRenderer: Use multisampling when possible without reporting errors. * Update WebGLRenderer.js Co-authored-by: mrdoob <info@mrdoob.com>
examples/jsm/objects/Refractor.js
@@ -9,8 +9,7 @@ import { UniformsUtils, Vector3, Vector4, - WebGLRenderTarget, - WebGLMultisampleRenderTarget + WebGLRenderTarget } from 'three'; class Refractor extends Mesh { @@ -28,7 +27,7 @@ class Refractor extends Mesh { const textureHeight = options.textureHeight || 512; const clipBias = options.clipBias || 0; const shader = options.shader || Refractor.RefractorShader; - const multisample = options.multisample || 4; + const multisample = ( options.multisample !== undefined ) ? options.multisample : 4; // @@ -43,18 +42,7 @@ class Refractor extends Mesh { // render target - let renderTarget; - - if ( multisample > 0 ) { - - renderTarget = new WebGLMultisampleRenderTarget( textureWidth, textureHeight ); - renderTarget.samples = multisample; - - } else { - - renderTarget = new WebGLRenderTarget( textureWidth, textureHeight ); - - } + const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight, { samples: multisample } ); // material
true