SlideShare una empresa de Scribd logo
1 de 26
WebGL + THREE.js
3D grafika na mreži
Marko Gaćeša
StartIt 2014
Ko sam ja?
• Zaposlen u PSTech-u 4 godine
marko.gacesa@pstech.rs
• Senior web developer
Java, JavaScript, Linux
• InsideMaps start up
3D Virtual Tour
3D Room Editor
Fotografije
Šta je WebGL?
• JavaScript API
• Baziran na OpenGL ES 2.0
• HTML5 <canvas>
• Podrška u browser-ima:
Mozilla Firefox 4
Google Chrome 9
Safari 5.1
Internet Explorer 11
Opera 12
Prednosti WebGL-a
• Nezavistan od platforme
• Ne traži plug-in
• Deo HTML5
• Standardizovan (Khronos Group)
• Visoke performanse (hardversko iscrtavanje)
Inicijalizacija WebGL-а
<canvas id="webgl-canvas"></canvas>
<script type="application/javascript">
var canvas = document.getElementById("webgl-canvas");
var gl;
try {
gl = canvas.getContext("webgl") ||
canvas.getContext("experimental-webgl");
} catch (e) {
gl = null;
}
if (gl === null) {
alert("WebGL is not supported!");
return;
}
gl.clearColor(0.4, 0.5, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
</script>
Problemi sa WebGL-om
• WebGL API je vrlo bazičan i na niskom nivou
• Zahteva poznavanje 3D matematike
– matrice transformacije i projekcije
– množenje matrica i vektora
• Zahteva pisanje šejdera
THREE.js
• JavaScript biblioteka
http://threejs.org/
• Open source
https://github.com/mrdoob/three.js/
• Jedna datoteka
<script type="application/javascript" src="three.min.js"></script>
– three.js (834 kB)
– three.min.js (420 kB)
– gzipped three.min.js (101 kB)
Zašto THREE.js
• Omogućava rad sa grafikom na višem nivou
• Objektno orijentisan
• Bogat pomoćnim alatkama i dodacima
• Sakriva složenu matematiku
• Aktivno se razvija – nova verzija izlazi svakih
mesec dana (poslednja verzija je r67)
• Popularan
Osnovni elementi THREE.js-a (1)
• Renderer
THREE.WebGLRenderer, THREE.CanvasRenderer
• Scena
THREE.Scene
• Kamere
THREE.PerspectiveCamera, THREE.OrthographicCamera
• Geometrije
THREE.PlaneGeometry, THREE.BoxGeometry,
THREE.SphereGeometry, THREE.CylinderGeometry, ...
• Materijali
THREE.MeshBasicMaterial, THREE.MeshLambertMaterial,
THREE.MeshPhongMaterial, THREE.ShaderMaterial, ...
Osnovni elementi THREE.js-a (2)
• Modeli / 3D Objekti
THREE.Mesh, THREE.Line, THREE.Sprite, THREE.ParticleSystem
• Svetla
THREE.AmbientLight, THREE.DirectionalLight, THREE.SpotLight,
THREE.PointLight
• Teksture
THREE.Texture
• Matematika
THREE.Math, THREE.Vector2, THREE.Vector3, THREE.Matrix3,
THREE.Matrix4, THREE.Ray, THREE.Box3, THREE.Sphere,
THREE.Plane, ...
Dijagram klasa (1)
Object3D
Camera Scene Light Mesh Line
PerspectiveCamera AmbientLight DirectionalLight
Dijagram klasa (2)
Geometry
SphereGeometry BoxGeometry
Material
MeshBasicMaterial MeshLambertMaterial
PlaneGeometry…
…
THREE.js – Hello World
<canvas id="webgl-canvas"></canvas>
<script type="application/javascript">
var canvas = document.getElementById("webgl-canvas");
var renderer = new THREE.WebGLRenderer({
canvas: canvas,
antialias: true
});
renderer.setClearColor(new THREE.Color(0x000000), 1);
renderer.setSize(document.body.offsetWidth, document.body.offsetHeight);
var camera =
new THREE.PerspectiveCamera(45, canvas.width / canvas.height, 1, 200);
camera.position.set(70, 80, 90);
camera.lookAt(new THREE.Vector3(0, 0, 0));
var scene = new THREE.Scene();
var cube = new THREE.Mesh(
new THREE.BoxGeometry(50, 50, 50),
new THREE.MeshNormalMaterial());
scene.add(cube);
renderer.render(scene, camera);
</script>
Materijali
MeshLambertMaterial MeshPhongMaterial MeshBasicMaterial
MeshNormalMaterial MeshDepthMaterial
Teksture
• Učitavanje
var texture =
new THREE.ImageUtils.loadTexture("texture.jpeg");
• Dodavanje
material.map = texture;
MeshBasicMaterial MeshLambertMaterial
Animacija
• Za svaku promenu u sceni potrebno je ponovo
iscrtati celu scenu
• requestAnimationFrame()
function render() {
renderer.render(scene, camera);
requestAnimationFrame(render);
}
render();
Animacija – Primer
var geometry = new THREE.BoxGeometry(50, 50, 50);
var material = new THREE.MeshLambertMaterial({
map: new THREE.ImageUtils.loadTexture("pstech-logo.png")
});
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
var lightAmb = new THREE.AmbientLight(0x404040);
scene.add(lightAmb);
var lightDir = new THREE.DirectionalLight(0xFFFFFF, 0.5);
lightDir.position.set(0, 200, 100);
scene.add(lightDir);
function render() {
renderer.render(scene, camera);
cube.rotation.x += 0.01;
cube.rotation.y += 0.02;
requestAnimationFrame(render);
}
render();
Senke
• Jednostavno u THREE.js
• Renderer
renderer.shadowMapEnabled = true
• Svetla
light.castShadow = true
• Objekti
obj.castShadow = true
obj.receiveShadow = true
Senke – Primer (1)
Senke – Primer (2)
var positions = [
new THREE.Vector3(-70, 80, 30),
new THREE.Vector3(0, 60, 0),
new THREE.Vector3(60, 100, -30),
new THREE.Vector3(0, 110, 65),
new THREE.Vector3(0, 120, -50)];
var cubes = [];
for (var i = 0; i < positions.length; i++) {
var cube = new THREE.Mesh(geomCube, matCube);
cube.position = positions[i];
cube.castShadow = true;
cube.receiveShadow = true;
cube.rotation.x = Math.random() * Math.PI;
cube.rotation.y = Math.random() * Math.PI;
cubes.push(cube);
scene.add(cube);
});
Senke – Primer (3)
var geomPlane = new THREE.PlaneGeometry(400, 400);
var matPlane = new THREE.MeshLambertMaterial();
matPlane.color = new THREE.Color(0x004488);
var plane = new THREE.Mesh(geomPlane, matPlane);
plane.lookAt(new THREE.Vector3(0, 100, 0));
plane.receiveShadow = true;
scene.add(plane);
var lightDir = new THREE.DirectionalLight(0xFFFFFF, 0.5);
lightDir.position.set(-100, 200, 100);
lightDir.shadowMapWidth = 2048;
lightDir.shadowMapHeight = 2048;
lightDir.castShadow = true;
scene.add(lightDir);
Ostale mogućnosti biblioteke THREE.js
• Učitavanje 3D modela (Maya, SketchUp, Blender)
• Projector/Raycaster za detekciju lokacije
miša u 3D sceni
• Teksture za bump, normal i specular mape
• THREE.ShaderMaterial
• Fog za efekat magle u 3D sceni
• …
Primene
• Igre
• 3D Modelovanje
• Vizualizacije
• Komponente
Linkovi
• THREE.js - dokumentacija, primeri
http://threejs.org/
• THREE.js – izvorni kod
http://github.com/mrdoob/three.js/
• Primeri
http://stemkoski.github.io/Three.js/
@PSTechSerbia PSTech PSTechSerbia
posao@pstech.rs praksa@pstech.rs

Más contenido relacionado

La actualidad más candente

3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
JavaScript Meetup HCMC
 

La actualidad más candente (20)

Introduction to three.js & Leap Motion
Introduction to three.js & Leap MotionIntroduction to three.js & Leap Motion
Introduction to three.js & Leap Motion
 
Creating Applications with WebGL and Three.js
Creating Applications with WebGL and Three.jsCreating Applications with WebGL and Three.js
Creating Applications with WebGL and Three.js
 
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
 
nunuStudio Geometrix 2017
nunuStudio Geometrix 2017nunuStudio Geometrix 2017
nunuStudio Geometrix 2017
 
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
 
3D everywhere
3D everywhere3D everywhere
3D everywhere
 
WebGL 3D player
WebGL 3D playerWebGL 3D player
WebGL 3D player
 
Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例
 
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
How to Hack a Road Trip with a Webcam, a GSP and Some Fun with Node
How to Hack a Road Trip  with a Webcam, a GSP and Some Fun with NodeHow to Hack a Road Trip  with a Webcam, a GSP and Some Fun with Node
How to Hack a Road Trip with a Webcam, a GSP and Some Fun with Node
 
OpenGL L05-Texturing
OpenGL L05-TexturingOpenGL L05-Texturing
OpenGL L05-Texturing
 
Efek daun
Efek daunEfek daun
Efek daun
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
 
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
 
3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with Python
 
Developing Web Graphics with WebGL
Developing Web Graphics with WebGLDeveloping Web Graphics with WebGL
Developing Web Graphics with WebGL
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
HTML 5_Canvas
HTML 5_CanvasHTML 5_Canvas
HTML 5_Canvas
 

Similar a WebGL and three.js - Web 3D Graphics

Begin three.js.key
Begin three.js.keyBegin three.js.key
Begin three.js.key
Yi-Fan Liao
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
Chihoon Byun
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
gerbille
 
XNA L07–Skybox and Terrain
XNA L07–Skybox and TerrainXNA L07–Skybox and Terrain
XNA L07–Skybox and Terrain
Mohammad Shaker
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
Bitla Software
 
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
Patrick Lauke
 

Similar a WebGL and three.js - Web 3D Graphics (20)

лукьянченко л.а. пос 10а
лукьянченко л.а. пос 10алукьянченко л.а. пос 10а
лукьянченко л.а. пос 10а
 
Begin three.js.key
Begin three.js.keyBegin three.js.key
Begin three.js.key
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
 
JS Experience 2017 - Animações simples com o three.js
JS Experience 2017 - Animações simples com o three.jsJS Experience 2017 - Animações simples com o three.js
JS Experience 2017 - Animações simples com o three.js
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
 
WebGL - 3D programming
WebGL - 3D programmingWebGL - 3D programming
WebGL - 3D programming
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
XNA L07–Skybox and Terrain
XNA L07–Skybox and TerrainXNA L07–Skybox and Terrain
XNA L07–Skybox and Terrain
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
 
Migrating your Web app to Virtual Reality
Migrating your Web app to Virtual RealityMigrating your Web app to Virtual Reality
Migrating your Web app to Virtual Reality
 
Augmented reality in web rtc browser
Augmented reality in web rtc browserAugmented reality in web rtc browser
Augmented reality in web rtc browser
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not Flash
 
Jeroen Vloothuis Bend Kss To Your Will
Jeroen Vloothuis   Bend Kss To Your WillJeroen Vloothuis   Bend Kss To Your Will
Jeroen Vloothuis Bend Kss To Your Will
 
The Power of WebGL - Hackeando sua GPU com JavaScript
The Power of WebGL - Hackeando sua GPU com JavaScriptThe Power of WebGL - Hackeando sua GPU com JavaScript
The Power of WebGL - Hackeando sua GPU com JavaScript
 
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Último (20)

Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

WebGL and three.js - Web 3D Graphics

  • 1. WebGL + THREE.js 3D grafika na mreži Marko Gaćeša StartIt 2014
  • 2. Ko sam ja? • Zaposlen u PSTech-u 4 godine marko.gacesa@pstech.rs • Senior web developer Java, JavaScript, Linux • InsideMaps start up
  • 3. 3D Virtual Tour 3D Room Editor Fotografije
  • 4. Šta je WebGL? • JavaScript API • Baziran na OpenGL ES 2.0 • HTML5 <canvas> • Podrška u browser-ima: Mozilla Firefox 4 Google Chrome 9 Safari 5.1 Internet Explorer 11 Opera 12
  • 5. Prednosti WebGL-a • Nezavistan od platforme • Ne traži plug-in • Deo HTML5 • Standardizovan (Khronos Group) • Visoke performanse (hardversko iscrtavanje)
  • 6. Inicijalizacija WebGL-а <canvas id="webgl-canvas"></canvas> <script type="application/javascript"> var canvas = document.getElementById("webgl-canvas"); var gl; try { gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); } catch (e) { gl = null; } if (gl === null) { alert("WebGL is not supported!"); return; } gl.clearColor(0.4, 0.5, 0.0, 1.0); gl.clear(gl.COLOR_BUFFER_BIT); </script>
  • 7. Problemi sa WebGL-om • WebGL API je vrlo bazičan i na niskom nivou • Zahteva poznavanje 3D matematike – matrice transformacije i projekcije – množenje matrica i vektora • Zahteva pisanje šejdera
  • 8. THREE.js • JavaScript biblioteka http://threejs.org/ • Open source https://github.com/mrdoob/three.js/ • Jedna datoteka <script type="application/javascript" src="three.min.js"></script> – three.js (834 kB) – three.min.js (420 kB) – gzipped three.min.js (101 kB)
  • 9. Zašto THREE.js • Omogućava rad sa grafikom na višem nivou • Objektno orijentisan • Bogat pomoćnim alatkama i dodacima • Sakriva složenu matematiku • Aktivno se razvija – nova verzija izlazi svakih mesec dana (poslednja verzija je r67) • Popularan
  • 10. Osnovni elementi THREE.js-a (1) • Renderer THREE.WebGLRenderer, THREE.CanvasRenderer • Scena THREE.Scene • Kamere THREE.PerspectiveCamera, THREE.OrthographicCamera • Geometrije THREE.PlaneGeometry, THREE.BoxGeometry, THREE.SphereGeometry, THREE.CylinderGeometry, ... • Materijali THREE.MeshBasicMaterial, THREE.MeshLambertMaterial, THREE.MeshPhongMaterial, THREE.ShaderMaterial, ...
  • 11. Osnovni elementi THREE.js-a (2) • Modeli / 3D Objekti THREE.Mesh, THREE.Line, THREE.Sprite, THREE.ParticleSystem • Svetla THREE.AmbientLight, THREE.DirectionalLight, THREE.SpotLight, THREE.PointLight • Teksture THREE.Texture • Matematika THREE.Math, THREE.Vector2, THREE.Vector3, THREE.Matrix3, THREE.Matrix4, THREE.Ray, THREE.Box3, THREE.Sphere, THREE.Plane, ...
  • 12. Dijagram klasa (1) Object3D Camera Scene Light Mesh Line PerspectiveCamera AmbientLight DirectionalLight
  • 13. Dijagram klasa (2) Geometry SphereGeometry BoxGeometry Material MeshBasicMaterial MeshLambertMaterial PlaneGeometry… …
  • 14. THREE.js – Hello World <canvas id="webgl-canvas"></canvas> <script type="application/javascript"> var canvas = document.getElementById("webgl-canvas"); var renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true }); renderer.setClearColor(new THREE.Color(0x000000), 1); renderer.setSize(document.body.offsetWidth, document.body.offsetHeight); var camera = new THREE.PerspectiveCamera(45, canvas.width / canvas.height, 1, 200); camera.position.set(70, 80, 90); camera.lookAt(new THREE.Vector3(0, 0, 0)); var scene = new THREE.Scene(); var cube = new THREE.Mesh( new THREE.BoxGeometry(50, 50, 50), new THREE.MeshNormalMaterial()); scene.add(cube); renderer.render(scene, camera); </script>
  • 16. Teksture • Učitavanje var texture = new THREE.ImageUtils.loadTexture("texture.jpeg"); • Dodavanje material.map = texture; MeshBasicMaterial MeshLambertMaterial
  • 17. Animacija • Za svaku promenu u sceni potrebno je ponovo iscrtati celu scenu • requestAnimationFrame() function render() { renderer.render(scene, camera); requestAnimationFrame(render); } render();
  • 18. Animacija – Primer var geometry = new THREE.BoxGeometry(50, 50, 50); var material = new THREE.MeshLambertMaterial({ map: new THREE.ImageUtils.loadTexture("pstech-logo.png") }); var cube = new THREE.Mesh(geometry, material); scene.add(cube); var lightAmb = new THREE.AmbientLight(0x404040); scene.add(lightAmb); var lightDir = new THREE.DirectionalLight(0xFFFFFF, 0.5); lightDir.position.set(0, 200, 100); scene.add(lightDir); function render() { renderer.render(scene, camera); cube.rotation.x += 0.01; cube.rotation.y += 0.02; requestAnimationFrame(render); } render();
  • 19. Senke • Jednostavno u THREE.js • Renderer renderer.shadowMapEnabled = true • Svetla light.castShadow = true • Objekti obj.castShadow = true obj.receiveShadow = true
  • 21. Senke – Primer (2) var positions = [ new THREE.Vector3(-70, 80, 30), new THREE.Vector3(0, 60, 0), new THREE.Vector3(60, 100, -30), new THREE.Vector3(0, 110, 65), new THREE.Vector3(0, 120, -50)]; var cubes = []; for (var i = 0; i < positions.length; i++) { var cube = new THREE.Mesh(geomCube, matCube); cube.position = positions[i]; cube.castShadow = true; cube.receiveShadow = true; cube.rotation.x = Math.random() * Math.PI; cube.rotation.y = Math.random() * Math.PI; cubes.push(cube); scene.add(cube); });
  • 22. Senke – Primer (3) var geomPlane = new THREE.PlaneGeometry(400, 400); var matPlane = new THREE.MeshLambertMaterial(); matPlane.color = new THREE.Color(0x004488); var plane = new THREE.Mesh(geomPlane, matPlane); plane.lookAt(new THREE.Vector3(0, 100, 0)); plane.receiveShadow = true; scene.add(plane); var lightDir = new THREE.DirectionalLight(0xFFFFFF, 0.5); lightDir.position.set(-100, 200, 100); lightDir.shadowMapWidth = 2048; lightDir.shadowMapHeight = 2048; lightDir.castShadow = true; scene.add(lightDir);
  • 23. Ostale mogućnosti biblioteke THREE.js • Učitavanje 3D modela (Maya, SketchUp, Blender) • Projector/Raycaster za detekciju lokacije miša u 3D sceni • Teksture za bump, normal i specular mape • THREE.ShaderMaterial • Fog za efekat magle u 3D sceni • …
  • 24. Primene • Igre • 3D Modelovanje • Vizualizacije • Komponente
  • 25. Linkovi • THREE.js - dokumentacija, primeri http://threejs.org/ • THREE.js – izvorni kod http://github.com/mrdoob/three.js/ • Primeri http://stemkoski.github.io/Three.js/