À¥¿¡¼­ ½ÃÀÛÇÏ´Â
3dÇÁ·Î±×·¡¹Ö




JenniferSoft / ±èÇÐÁø

¹ßÇ¥ÀÚ ¼Ò°³

  • 2007³â ~ 2011³â Java 3D °³¹ß
  • LWJGL (LightWeight Java Game Library)
  • Ardor3d (http://www.ardor3d.com/)
  • JME (http://jmonkeyengine.com/)

lwjgl + jme

lwjgl + jme

lwjgl + ardor3d

html5

¿À´ÃÀÇ ÁÖÁ¦

  • WebGL
  • Three.js (3d programming)
  • Util.js
  • WebGL·Î ÇÒ¼ö Àִ°͵é

webgl

  • À¥ ±â¹ÝÀÇ Çϵå¿þ¾î(GPU) °¡¼ÓÀ» ¹Þ´Â 3D Graphics Library
  • OpenGL ES 2.0

Áö¿ø ºê¶ó¿ìÀú

µ¥½ºÅ©Å¾
¸ð¹ÙÀÏ

IE´Â »ç¿ëÇÏÁö ¸øÇϳª¿ä?

  • IEWebGL (http://iewebgl.com)
  • IE Plugin
  • Works in all actual IE versions

¸ð¹ÙÀÏÀº ?

  • Chrome 25beta Áö¿ø ¿¹Á¤
  • ¸ð¹ÙÀÏ ±×·¡ÇÈĨ OpenGL ES 2.0¸¦ Áö¿ø
  • ÇâÈÄ ¸ðµç ¸ð¹ÙÀÏ ±â±â ºê¶ó¿ìÀú¿¡¼­ Áö¿øµÉ¼ö ÀÖÀ½

http://get.webgl.org/

Geometry

  • VBO(VertexBufferObject)+ IBO(IndexBufferObject)
  • Polygon
  • Quad

Polygon


var vertices = [
             -1.0, -1.0,  0.0,
             0.0,  1.0,  0.0,
             1.0, -1.0,  0.0
        ];
var indices = [0, 2, 1];
					

Quad


var vertices = [
             -1.0, -1.0,  0.0,
             0.0,  1.0,  0.0,
             1.0, -1.0,  0.0,
             2,0, 1,0, 0,0
        ];
var indices = [0, 2, 1, 1, 2, 3];
					

WebGL¡¯s rendering pipeline

WebGL »ùÇÃÄڵ带 Â¥º¼±î¿ä?

WebGL code(1)


function webGLStart() {
    var canvas = document.getElementById("canvas-id");
    initGL(canvas);
    initShaders()
    initBuffers();

    gl.clearColor(0.0, 0.0, 0.0, 1.0);
    gl.enable(gl.DEPTH_TEST);

    drawScene();
}
					

WebGL code(2)


function initGL(canvas) {
    try {
        gl = canvas.getContext("experimental-webgl");
        gl.viewportWidth = canvas.width;
        gl.viewportHeight = canvas.height;
    } catch (e) {
    }
    if (!gl) {
        alert("Could not initialise WebGL, sorry :-(");
    }
}
					

WebGL code(3)


function initShaders() {
	var fragmentShader = getShader(gl, "shader-fs");
	var vertexShader = getShader(gl, "shader-vs");

	shaderProgram = gl.createProgram();
	gl.attachShader(shaderProgram, vertexShader);
	gl.attachShader(shaderProgram, fragmentShader);
	gl.linkProgram(shaderProgram);

	if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
		alert("Could not initialise shaders");
	}

	gl.useProgram(shaderProgram);

	shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
	gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);

	shaderProgram.vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
	gl.enableVertexAttribArray(shaderProgram.vertexColorAttribute);

	shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
	shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
}
					

WebGL code(4)


function initBuffers() {
	triangleVertexPositionBuffer = gl.createBuffer();
	gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexPositionBuffer);
	var vertices = [
		 0.0,  1.0,  0.0,
		-1.0, -1.0,  0.0,
		 1.0, -1.0,  0.0
	];
	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
	triangleVertexPositionBuffer.itemSize = 3;
	triangleVertexPositionBuffer.numItems = 3;
	
	var indices = [0, 2, 1];
	
	triangleIndexPositionBuffer = gl.createBuffer();
	gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, triangleIndexPositionBuffer);
	gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);

	triangleVertexColorBuffer = gl.createBuffer();
	gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexColorBuffer);
	var colors = [
		1.0, 0.0, 0.0, 1.0,
		0.0, 1.0, 0.0, 1.0,
		0.0, 0.0, 1.0, 1.0
	];
	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW);
	triangleVertexColorBuffer.itemSize = 4;
	triangleVertexColorBuffer.numItems = 3;
}
					

WebGL code(5)


   function drawScene() {
	gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
	gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

	mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0, pMatrix);

	mat4.identity(mvMatrix);

	mat4.translate(mvMatrix, [0, 0.0, -7.0]);
	gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexPositionBuffer);
	gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, triangleVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);

	gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexColorBuffer);
	gl.vertexAttribPointer(shaderProgram.vertexColorAttribute, triangleVertexColorBuffer.itemSize, gl.FLOAT, false, 0, 0);

	setMatrixUniforms();
		
	gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, triangleIndexPositionBuffer);
	gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT,0);
	
}
					

WebGL Engine.js

  • Three.js
  • SpiderGL
  • SceneJS

Three.js

  • Abstraction layer over WebGL
  • 3D scenegraph library
  • http://github.com/mrdoob/three.js
  • 2010 04 24 ~ 2013 02 15 - r56
  • + : Active Community, updated frequently
  • - : Documentation
  • http://mrdoob.com/

Three.js sample


var camera, scene, renderer;
var mesh;

init();
animate();

function init() {

	renderer = new THREE.WebGLRenderer();
	renderer.setSize( window.innerWidth, window.innerHeight );
	document.body.appendChild( renderer.domElement );

	//

	camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
	camera.position.z = 400;

	scene = new THREE.Scene();

	var geometry = new THREE.CubeGeometry( 200, 200, 200 );
	var material = new THREE.MeshNormalMaterial();

	mesh = new THREE.Mesh( geometry, material );
	scene.add( mesh );

	window.addEventListener( 'resize', onWindowResize, false );
}

function onWindowResize() {

	camera.aspect = window.innerWidth / window.innerHeight;
	camera.updateProjectionMatrix();

	renderer.setSize( window.innerWidth, window.innerHeight );

}

function animate() {

	requestAnimationFrame( animate );

	mesh.rotation.x += 0.005;
	mesh.rotation.y += 0.01;

	renderer.render( scene, camera );

}
					

Three.js sample

ÁÂÇ¥°è

  • DiretX (¿Þ¼Õ ÁÂÇ¥°è)
  • OpenGL (¿À¸¥¼Õ ÁÂÇ¥°è)

Camera

  • Perspective Camera (Åõ½ÃÅõ¿µ)
  • Orthographic Camera (Á÷±³Åõ¿µ)

Material

¹°Ã¼ÀÇ Ç¥¸é ÀçÁúÀ» °áÁ¤ÇÏ´Â ¼Ó¼º°ª

  • MeshBasicMaterial
  • MeshFaceMaterial
  • MeshLambertMaterial
  • MeshNormalMaterial
  • MeshPhongMaterial

Material

Mesh

  • ±×¹°¸Á ÇüÅ·Π¸¸µé¾îÁø ±¸Á¶¹° ¶Ç´Â ±× ÇüÅÂ
  • Mesh = Geometry + Material

Light

Çö½Ç¼¼°è¿Í °°ÀÌ ¹°Ã¼¸¦ ½Äº°Çϴµ¥ ºûÀÌ ÇÊ¿äÇÏ´Ù.

  • Point Light
  • Direction Light
  • Spot Light

Point Light

Direction Light

Spot Light

Point Light Example

Texture

´Ù°¢Çü Ç¥¸éÀ» È¿°úÀûÀ¸·Î À̹ÌÁö·Î ·»´õ¸µ ÇÏ´Â ±â¹ý

Scene

  • ÇϳªÀÇ È­¸éÀ» ±¸¼ºÇÏ´Â ÁýÇÕü
  • °¢°¢ÀÇ SceneÀ¸·Î ¿ªÇÒÀ» ºÐ¸®ÇÒ¼ö ÀÖ´Ù
  • ÀúÀåÀÌ °¡´ÉÇÏ´Ù

Export

  • Blender - http://www.blender.org/
  • .dae .json
  • http://www.turbosquid.com/

Import

  • ColladaLoader .dae
  • JSONLoader .js
  • SceneLoader .js

tQuery.js

  • three.js + jQuery.js
  • three.js À» wrapping ÇÏ¿© »ç¿ëÇϱ⠴õ ½±´Ù
  • ported to three.js R53

tQuery.js


var world = tQuery.createWorld().boilerplate().start();
var object = tQuery.createTorus().addTo(world);
				

Physics Engine.js

  • Physijs (for three.js base Ammo.js)
  • cannon.js
  • bullet.js

Physijs

WebGL Inspector

  • http://benvanik.github.com/WebGL-Inspector
  • Capture individual frames
  • View assets and programs
  • Example

WebGL·Î ÇÒ¼ö Àִ°͵é

Google Map (WebGL)

maps.google.com

Google Body

www.zygotebody.com

Game

hexgl.bkcore.com

WebGL Earth

www.webglearth.com

WebGL+3D printer

www.myrobotnation.com

Visitor Monitor

www.chromeweblab.com/lab-tag-explorer

Arms and Ammunition

http://workshop.chromeexperiments.com/projects/armsglobe/

Âü°í »çÀÌÆ®

°¨»çÇÕ´Ï´Ù.


kaidu1982@gmail.com / ±èÇÐÁø