140716 : 同業前端聚會分享 - webgl 與 three.js

74
WebGL And Three.js EIA - 2014 / 07 / 16 These slides are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License .

Upload: angelliya00

Post on 06-May-2015

404 views

Category:

Technology


5 download

DESCRIPTION

Webgl 與 Three.js 介紹、個人學習經驗

TRANSCRIPT

Page 1: 140716 : 同業前端聚會分享 - webgl 與 three.js

WebGL And Three.jsEIA - 2014 / 07 / 16

These slides are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Page 2: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://about.me/eia

Page 3: 140716 : 同業前端聚會分享 - webgl 與 three.js

About

Page 4: 140716 : 同業前端聚會分享 - webgl 與 three.js

WIKIWebGL是一項利用JavaScript API呈現3D電腦圖形的技術,有別於過往需加裝瀏覽器外掛程式,透過WebGL的技術,只需要編寫網頁代碼即可實現3D圖像的展示。WebGL的規格尚在發展中,由非營利的Khronos Group管理。

WebGL基於OpenGL ES 2.0,提供了3D影像的程式介面。它使用HTML5 Canvas並允許利用文件物件模型介面。可利用部分Javascript實作自動記憶體管理。

http://zh.wikipedia.org/wiki/WebGLhttp://en.wikipedia.org/wiki/WebGL

Page 5: 140716 : 同業前端聚會分享 - webgl 與 three.js

WebGL APIWebGL™ is an immediate mode 3D rendering API designed for the web. It is derived from OpenGL® ES 2.0, and provides similar

rendering functionality, but in an HTML context. WebGL is designed as a rendering context for the HTML Canvas element. The

HTML Canvas provides a destination for programmatic rendering in web pages, and allows for performing that rendering using

different rendering APIs. The only such interface described as part of the Canvas specification is the 2D canvas rendering context,

CanvasRenderingContext2D. This document describes another such interface, WebGLRenderingContext, which presents the

WebGL API.

The immediate mode nature of the API is a divergence from most web APIs. Given the many use cases of 3D graphics, WebGL

chooses the approach of providing flexible primitives that can be applied to any use case. Libraries can provide an API on top of

WebGL that is more tailored to specific areas, thus adding a convenience layer to WebGL that can accelerate and simplify

development. However, because of its OpenGL ES 2.0 heritage, it should be straightforward for developers familiar with modern

desktop OpenGL or OpenGL ES 2.0 development to transition to WebGL development.

http://www.khronos.org/registry/webgl/specs/latest/1.0/

Page 6: 140716 : 同業前端聚會分享 - webgl 與 three.js

Browser Support

Page 7: 140716 : 同業前端聚會分享 - webgl 與 three.js

caniuse - 14 / 06 / 06

http://caniuse.com/#feat=webgl

Parent feature: Canvas (basic support)

Page 8: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://webglsamples.googlecode.com/hg/aquarium/aquarium.html

IE11

fps: 13Chrome

fps: 59

Page 9: 140716 : 同業前端聚會分享 - webgl 與 three.js

IE8 IE11 http://onemillionreasons.audi.de/

Chrome

Page 10: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://activetheory.net/

Chrome IE11 IE8

Page 11: 140716 : 同業前端聚會分享 - webgl 與 three.js

WebGL in Safari

Page 12: 140716 : 同業前端聚會分享 - webgl 與 three.js

Apple WWDC 2014

http://learningwebgl.com/blog/?p=6368

Page 13: 140716 : 同業前端聚會分享 - webgl 與 three.js

Mobile : THREE.CanvasRenderer();

Sony Z1 (2013)HTC Desire HD (2010)

iPhone 4 (2010)

Page 14: 140716 : 同業前端聚會分享 - webgl 與 three.js

Frameworks

Page 16: 140716 : 同業前端聚會分享 - webgl 與 three.js

Debug

Page 17: 140716 : 同業前端聚會分享 - webgl 與 three.js

Debug

WebGL Inspector

http://www.khronos.org/webgl/wiki/Debugginghttp://benvanik.github.io/WebGL-Inspector/

Page 18: 140716 : 同業前端聚會分享 - webgl 與 three.js
Page 19: 140716 : 同業前端聚會分享 - webgl 與 three.js
Page 20: 140716 : 同業前端聚會分享 - webgl 與 three.js
Page 21: 140716 : 同業前端聚會分享 - webgl 與 three.js

The popup is extensive and first shows a mesh of the element drawn that can be zoomed inand out with the mouse wheel and rotated while holding down a mouse button.

BeginningWebGL for HTML5

Page 22: 140716 : 同業前端聚會分享 - webgl 與 three.js

Three.JS

Page 23: 140716 : 同業前端聚會分享 - webgl 與 three.js

three.js - JavaScript 3D library

http://threejs.org/

Page 24: 140716 : 同業前端聚會分享 - webgl 與 three.js

20 Impressive Examples for Learning WebGL with Three.js

http://tutorialzine.com/2013/09/20-impressive-examples-for-learning-webgl-with-three-js/

Page 25: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://threejs.org/examples/

Page 26: 140716 : 同業前端聚會分享 - webgl 與 three.js

Coding

Page 27: 140716 : 同業前端聚會分享 - webgl 與 three.js

scene = new THREE.Scene();scene.fog = new THREE.FogExp2( 0xDDDDDD, 0.00001);

renderer = new THREE.WebGLRenderer({antialias:true});renderer.setClearColor(scene.fog.color,1);renderer.setSize( window.innerWidth, window.innerHeight );

Page 28: 140716 : 同業前端聚會分享 - webgl 與 three.js

var mapUrl = "../images/molumen_small_funny_angry_monster.jpg";var map = THREE.ImageUtils.loadTexture(mapUrl);// Now, create a Phong material to show shading; pass in the mapvar material = new THREE.MeshPhongMaterial({ map: map });// Create the cube geometryvar geometry = new THREE.CubeGeometry(1, 1, 1);// And put the geometry and material together into a meshcube = new THREE.Mesh(geometry, material);// Turn it toward the scene, or we won't see the cube shape!cube.rotation.x = Math.PI / 5;cube.rotation.y = Math.PI / 5;// Add the cube to our scenescene.add( cube );

Page 29: 140716 : 同業前端聚會分享 - webgl 與 three.js

Away3d 4.x ?

Page 30: 140716 : 同業前端聚會分享 - webgl 與 three.js

1. Renderer > webgl vs canvas (performance)

> CSS3DRenderer, SoftwareRenderer

2. Geometry3. Material4. Camera5. 3d Model6. Interactive7. Particles

My ThreeJS Learning Experience

Page 31: 140716 : 同業前端聚會分享 - webgl 與 three.js

RendererWebGL / CANVAS

Page 33: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://threejs.org/examples/#css3d_molecules

CSS3DRenderer

Page 34: 140716 : 同業前端聚會分享 - webgl 與 three.js

renderer = new THREE.WebGLRenderer( { antialias: true } );renderer = new THREE.CanvasRenderer();

** THREE.Particle(material); // CanvasRenderer** THREE.ParticleSystem(geom, material); // WebGLRenderer

Page 35: 140716 : 同業前端聚會分享 - webgl 與 three.js

Geometry

Page 40: 140716 : 同業前端聚會分享 - webgl 與 three.js

VertexNormals();

Page 42: 140716 : 同業前端聚會分享 - webgl 與 three.js
Page 43: 140716 : 同業前端聚會分享 - webgl 與 three.js
Page 45: 140716 : 同業前端聚會分享 - webgl 與 three.js

Materials

Page 47: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://threejs.org/examples/#canvas_materials_depth

THREE.MeshDepthMaterial

Page 49: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://threejs.org/examples/#webgl_materials_lightmap

ShaderMaterial

Page 50: 140716 : 同業前端聚會分享 - webgl 與 three.js

Camera

Page 52: 140716 : 同業前端聚會分享 - webgl 與 three.js

3d Model

Page 53: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://v.hxsd.com/

Page 54: 140716 : 同業前端聚會分享 - webgl 與 three.js
Page 55: 140716 : 同業前端聚會分享 - webgl 與 three.js
Page 57: 140716 : 同業前端聚會分享 - webgl 與 three.js

No keyframes in 3D model

Page 58: 140716 : 同業前端聚會分享 - webgl 與 three.js

.dae .js

Page 60: 140716 : 同業前端聚會分享 - webgl 與 three.js
Page 61: 140716 : 同業前端聚會分享 - webgl 與 three.js

Particles

Page 62: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://threejs.org/examples/#canvas_particles_sprites

Sprites

Page 63: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://threejs.org/examples/#webgl_particles_shapes

Sparks

Page 64: 140716 : 同業前端聚會分享 - webgl 與 three.js

http://threejs.org/examples/#webgl_particles_shapes

- addInitializer();- addAction();

Page 65: 140716 : 同業前端聚會分享 - webgl 與 three.js

Spark.jshttps://github.com/zz85/sparks.js

Page 66: 140716 : 同業前端聚會分享 - webgl 與 three.js

Spark.js

MIT license

Page 67: 140716 : 同業前端聚會分享 - webgl 與 three.js

Spark.js

Page 68: 140716 : 同業前端聚會分享 - webgl 與 three.js

Interaction

Page 69: 140716 : 同業前端聚會分享 - webgl 與 three.js

InteractionWebGL is only a drawing system and, as such, has no built-in support for hit detection. You need to build that yourself. Thankfully, Three.js gives us the support we need so that we can tell when the mouse is over an object.

WebGL: Up and Running

Page 70: 140716 : 同業前端聚會分享 - webgl 與 three.js

Books

Page 72: 140716 : 同業前端聚會分享 - webgl 與 three.js

Referencehttp://learningwebgl.com/blog/

Samplehttp://threejs.org/examples/https://code.google.com/p/webglsamples/http://tutorialzine.com/2013/09/20-impressive-examples-for-learning-webgl-with-three-js/

This is a list of all the WebGL related activities happening on the web. If you know of anything missing or out of date on this list, we invite you to add it or update it.http://www.khronos.org/webgl/wiki/User_Contributions

Page 73: 140716 : 同業前端聚會分享 - webgl 與 three.js

ReferencePhong reflection modelhttp://en.wikipedia.org/wiki/Phong_reflection_model

Lambertian reflectancehttp://en.wikipedia.org/wiki/Lambertian_reflectance

Mandelbrot sethttp://en.wikipedia.org/wiki/Mandelbrot_set

Julia sethttp://en.wikipedia.org/wiki/Julia_set

Page 74: 140716 : 同業前端聚會分享 - webgl 與 three.js

Thanks!