일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- probability
- 김양재 목사님
- 김양재 목사
- Machine Learning
- WebGL
- No SQL
- R
- 빅 데이터
- Artificial Intelligence
- node.js
- 빅데이타
- 통계
- openCV
- 데이터 과학
- 주일설교
- 확률
- 빅 데이타
- MongoDB
- c++
- 인공지능
- Big Data
- 딥러닝
- 우리들교회
- 김양재
- Statistics
- 몽고디비
- data science
- nodeJS
- Deep learning
- 빅데이터
Archives
- Today
- Total
Scientific Computing & Data Science
[WebGL] Texture Canvas 본문
이번 예제는 Texture Canvas에 관한 것입니다. Canvas는 HTML5의 Canvas 엘리먼트를 의미하며, Canvas에 texture를 맵핑하는 기법입니다.
Download Project
Click here to view with full screen mode
Operations
Mouse Left Button Click & Drag: Camera Rotating
Mouse Wheel: Camera Zoom In & Out
Mouse Right Button Click & Drag: Camera Panning
main.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | // standard global variables var container, scene, camera, renderer, controls, stats; var keyboard = new THREEx.KeyboardState(); var clock = new THREE.Clock(); // custom global variables var canvas = []; var context = []; var texture = []; var imageObj = []; var material = []; var mesh = []; init(); animate(); // FUNCTIONS function init() { // SCENE scene = new THREE.Scene(); // CAMERA var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight; var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000; camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR); scene.add(camera); camera.position.set(0,150,400); camera.lookAt(scene.position); // RENDERER if ( Detector.webgl ) renderer = new THREE.WebGLRenderer( {antialias:true} ); else renderer = new THREE.CanvasRenderer(); renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); container = document.getElementById( 'ThreeJS' ); container.appendChild( renderer.domElement ); // EVENTS THREEx.WindowResize(renderer, camera); THREEx.FullScreen.bindKey({ charCode : 'f'.charCodeAt(0) }); // CONTROLS controls = new THREE.OrbitControls( camera, renderer.domElement ); // STATS stats = new Stats(); stats.domElement.style.position = 'absolute'; stats.domElement.style.bottom = '0px'; stats.domElement.style.zIndex = 100; container.appendChild( stats.domElement ); // LIGHT // FLOOR // SKYBOX/FOG var skyBoxGeometry = new THREE.CubeGeometry( 10000, 10000, 10000 ); var skyBoxMaterial = new THREE.MeshBasicMaterial( { color: 0x000000, side: THREE.BackSide } ); var skyBox = new THREE.Mesh( skyBoxGeometry, skyBoxMaterial ); scene.add(skyBox); //////////// // CUSTOM // //////////// /////// draw text on canvas ///////// // create a canvas element var canvas1 = document.createElement('canvas'); var context1 = canvas1.getContext('2d'); context1.font = "Bold 40px Arial"; context1.fillStyle = "rgba( 123, 244, 15, 0.8)"; context1.fillText('WebGL', 0, 30); // canvas contents will be used for a texture var texture1 = new THREE.Texture(canvas1); texture1.needsUpdate = true; var material1 = new THREE.MeshBasicMaterial( {map: texture1, side:THREE.DoubleSide } ); material1.transparent = true; var mesh1 = new THREE.Mesh( new THREE.PlaneGeometry(canvas1.width, canvas1.height), material1 ); mesh1.position.set(0,50,0); scene.add( mesh1 ); // create a canvas element var canvas2 = document.createElement('canvas'); var context2 = canvas1.getContext('2d'); context2.font = "Bold 50px Arial"; context2.fillStyle = "rgba( 16, 86, 244, 0.9)"; context2.fillText('Hello World', 0, 90); // canvas contents will be used for a texture var texture2 = new THREE.Texture(canvas2); texture2.needsUpdate = true; var material2 = new THREE.MeshBasicMaterial( {map: texture2, side:THREE.DoubleSide } ); material2.transparent = true; var mesh2 = new THREE.Mesh( new THREE.PlaneGeometry(canvas2.width, canvas2.height), material2 ); mesh2.position.set(0,20,0); scene.add( mesh2 ); /////// draw image on canvas 0 ///////// // create a canvas element canvas[0] = document.createElement('canvas'); context[0] = canvas[0].getContext('2d'); // canvas contents will be used for a texture texture[0] = new THREE.Texture(canvas[0]); // load an image imageObj[0] = new Image(); imageObj[0].src = "img/0.png"; // after the image is loaded, this function executes imageObj[0].onload = function() { context[0].drawImage(imageObj[0], 0, 0); if ( texture[0] ) // checks if texture exists texture[0].needsUpdate = true; }; material[0] = new THREE.MeshBasicMaterial( {map: texture[0], side:THREE.DoubleSide} ); material[0].transparent = true; mesh[0] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[0].width, canvas[0].height), material[0] ); mesh[0].position.set(-300,50,-50); scene.add( mesh[0] ); /////// draw image on canvas 1 ///////// // create a canvas element canvas[1] = document.createElement('canvas'); context[1] = canvas[1].getContext('2d'); // canvas contents will be used for a texture texture[1] = new THREE.Texture(canvas[1]); // load an image imageObj[1] = new Image(); imageObj[1].src = "img/1.png"; // after the image is loaded, this function executes imageObj[1].onload = function() { context[1].drawImage(imageObj[1], 0, 0); if ( texture[1] ) // checks if texture exists texture[1].needsUpdate = true; }; material[1] = new THREE.MeshBasicMaterial( {map: texture[1], side:THREE.DoubleSide} ); material[1].transparent = true; mesh[1] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[1].width, canvas[1].height), material[1] ); mesh[1].position.set(-100,50,-50); scene.add( mesh[1] ); /////// draw image on canvas 2 ///////// // create a canvas element canvas[2] = document.createElement('canvas'); context[2] = canvas[2].getContext('2d'); // canvas contents will be used for a texture texture[2] = new THREE.Texture(canvas[2]); // load an image imageObj[2] = new Image(); imageObj[2].src = "img/2.png"; // after the image is loaded, this function executes imageObj[2].onload = function() { context[2].drawImage(imageObj[2], 0, 0); if ( texture[2] ) // checks if texture exists texture[2].needsUpdate = true; }; material[2] = new THREE.MeshBasicMaterial( {map: texture[2], side:THREE.DoubleSide} ); material[2].transparent = true; mesh[2] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[2].width, canvas[2].height), material[2] ); mesh[2].position.set(100,50,-50); scene.add( mesh[2] ); /////// draw image on canvas 3 ///////// // create a canvas element canvas[3] = document.createElement('canvas'); context[3] = canvas[3].getContext('2d'); // canvas contents will be used for a texture texture[3] = new THREE.Texture(canvas[3]); // load an image imageObj[3] = new Image(); imageObj[3].src = "img/3.png"; // after the image is loaded, this function executes imageObj[3].onload = function() { context[3].drawImage(imageObj[3], 0, 0); if ( texture[3] ) // checks if texture exists texture[3].needsUpdate = true; }; material[3] = new THREE.MeshBasicMaterial( {map: texture[3], side:THREE.DoubleSide} ); material[3].transparent = true; mesh[3] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[3].width, canvas[3].height), material[3] ); mesh[3].position.set(300,50,-50); scene.add( mesh[3] ); /////// draw image on canvas 4 ///////// // create a canvas element canvas[4] = document.createElement('canvas'); context[4] = canvas[4].getContext('2d'); // canvas contents will be used for a texture texture[4] = new THREE.Texture(canvas[4]); // load an image imageObj[4] = new Image(); imageObj[4].src = "img/4.png"; // after the image is loaded, this function executes imageObj[4].onload = function() { context[4].drawImage(imageObj[4], 0, 0); if ( texture[4] ) // checks if texture exists texture[4].needsUpdate = true; }; material[4] = new THREE.MeshBasicMaterial( {map: texture[4], side:THREE.DoubleSide} ); material[4].transparent = true; mesh[4] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[4].width, canvas[4].height), material[4] ); mesh[4].position.set(500,50,-50); scene.add( mesh[4] ); /////// draw image on canvas 5 ///////// // create a canvas element canvas[5] = document.createElement('canvas'); context[5] = canvas[5].getContext('2d'); // canvas contents will be used for a texture texture[5] = new THREE.Texture(canvas[5]); // load an image imageObj[5] = new Image(); imageObj[5].src = "img/5.png"; // after the image is loaded, this function executes imageObj[5].onload = function() { context[5].drawImage(imageObj[5], 0, 0); if ( texture[5] ) // checks if texture exists texture[5].needsUpdate = true; }; material[5] = new THREE.MeshBasicMaterial( {map: texture[5], side:THREE.DoubleSide} ); material[5].transparent = true; mesh[5] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[5].width, canvas[5].height), material[5] ); mesh[5].position.set(-300,250,-50); scene.add( mesh[5] ); /////// draw image on canvas 6 ///////// // create a canvas element canvas[6] = document.createElement('canvas'); context[6] = canvas[6].getContext('2d'); // canvas contents will be used for a texture texture[6] = new THREE.Texture(canvas[6]); // load an image imageObj[6] = new Image(); imageObj[6].src = "img/6.png"; // after the image is loaded, this function executes imageObj[6].onload = function() { context[6].drawImage(imageObj[6], 0, 0); if ( texture[6] ) // checks if texture exists texture[6].needsUpdate = true; }; material[6] = new THREE.MeshBasicMaterial( {map: texture[6], side:THREE.DoubleSide} ); material[6].transparent = true; mesh[6] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[6].width, canvas[6].height), material[6] ); mesh[6].position.set(-100,250,-60); scene.add( mesh[6] ); /////// draw image on canvas 7 ///////// // create a canvas element canvas[7] = document.createElement('canvas'); context[7] = canvas[7].getContext('2d'); // canvas contents will be used for a texture texture[7] = new THREE.Texture(canvas[7]); // load an image imageObj[7] = new Image(); imageObj[7].src = "img/7.png"; // after the image is loaded, this function executes imageObj[7].onload = function() { context[7].drawImage(imageObj[7], 0, 0); if ( texture[7] ) // checks if texture exists texture[7].needsUpdate = true; }; material[7] = new THREE.MeshBasicMaterial( {map: texture[7], side:THREE.DoubleSide} ); material[7].transparent = true; mesh[7] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[7].width, canvas[7].height), material[7] ); mesh[7].position.set(300,250,-60); scene.add( mesh[7] ); /////// draw image on canvas 8 ///////// // create a canvas element canvas[8] = document.createElement('canvas'); context[8] = canvas[8].getContext('2d'); // canvas contents will be used for a texture texture[8] = new THREE.Texture(canvas[8]); // load an image imageObj[8] = new Image(); imageObj[8].src = "img/8.png"; // after the image is loaded, this function executes imageObj[8].onload = function() { context[8].drawImage(imageObj[8], 0, 0); if ( texture[8] ) // checks if texture exists texture[8].needsUpdate = true; }; material[8] = new THREE.MeshBasicMaterial( {map: texture[8], side:THREE.DoubleSide} ); material[8].transparent = true; mesh[8] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[8].width, canvas[8].height), material[8] ); mesh[8].position.set(100,250,-60); scene.add( mesh[8] ); /////// draw image on canvas 9 ///////// // create a canvas element canvas[9] = document.createElement('canvas'); context[9] = canvas[9].getContext('2d'); // canvas contents will be used for a texture texture[9] = new THREE.Texture(canvas[9]); // load an image imageObj[9] = new Image(); imageObj[9].src = "img/9.png"; // after the image is loaded, this function executes imageObj[9].onload = function() { context[9].drawImage(imageObj[9], 0, 0); if ( texture[9] ) // checks if texture exists texture[9].needsUpdate = true; }; material[9] = new THREE.MeshBasicMaterial( {map: texture[9], side:THREE.DoubleSide} ); material[9].transparent = true; mesh[9] = new THREE.Mesh( new THREE.PlaneGeometry(canvas[9].width, canvas[9].height), material[9] ); mesh[9].position.set(500,250,-60); scene.add( mesh[9] ); } function animate() { requestAnimationFrame( animate ); render(); update(); } function update() { controls.update(); stats.update(); } function render() { renderer.render( scene, camera ); } | cs |
'Programming > WebGL(ThreeJS)' 카테고리의 다른 글
[WebGL] Geometry Collada Loader (0) | 2015.08.07 |
---|---|
[WebGL] GUI Basic (0) | 2015.08.07 |
[WebGL] Video Texture (0) | 2015.08.06 |
[WebGL] Render Texture (0) | 2015.08.06 |
[WebGL] Multiple Cameras (0) | 2015.08.06 |
Comments