SlideShare a Scribd company logo
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

More Related Content

What's hot

Introduction to three.js & Leap Motion
Introduction to three.js & Leap MotionIntroduction to three.js & Leap Motion
Introduction to three.js & Leap Motion
Lee Trout
 
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
Future Insights
 
[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...
iMasters
 
nunuStudio Geometrix 2017
nunuStudio Geometrix 2017nunuStudio Geometrix 2017
nunuStudio Geometrix 2017
José Ferrão
 
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Ontico
 
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
 
3D everywhere
3D everywhere3D everywhere
3D everywhere
Vasilika Klimova
 
WebGL 3D player
WebGL 3D playerWebGL 3D player
WebGL 3D player
Vasilika Klimova
 
Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例
Yuichi Higuchi
 
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
YEONG-CHEON YOU
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
Gary Yeh
 
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
pdeschen
 
OpenGL L05-Texturing
OpenGL L05-TexturingOpenGL L05-Texturing
OpenGL L05-Texturing
Mohammad Shaker
 
Efek daun
Efek daunEfek daun
Efek daun
Yadi Adi
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
Ofir's Fridman
 
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
Tomomi Imura
 
3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with Python
Martin Christen
 
Developing Web Graphics with WebGL
Developing Web Graphics with WebGLDeveloping Web Graphics with WebGL
Developing Web Graphics with WebGL
Tony Parisi
 
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
Takao Wada
 

What's hot (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 to WebGL and three.js - Web 3D Graphics

лукьянченко л.а. пос 10а
лукьянченко л.а. пос 10алукьянченко л.а. пос 10а
лукьянченко л.а. пос 10а
l10bov
 
Begin three.js.key
Begin three.js.keyBegin three.js.key
Begin three.js.keyYi-Fan Liao
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
Ankara JUG
 
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
iMasters
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGLChihoon Byun
 
WebGL - 3D programming
WebGL - 3D programmingWebGL - 3D programming
WebGL - 3D programming
Minh Ng
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScriptersgerbille
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
GCS2013
 
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?
Patrick Chanezon
 
XNA L07–Skybox and Terrain
XNA L07–Skybox and TerrainXNA L07–Skybox and Terrain
XNA L07–Skybox and TerrainMohammad Shaker
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
gerbille
 
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.v1Bitla Software
 
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
Denis Radin
 
Augmented reality in web rtc browser
Augmented reality in web rtc browserAugmented reality in web rtc browser
Augmented reality in web rtc browser
ALTANAI BISHT
 
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
Thomas Fuchs
 
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
Vincenzo Barone
 
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
Raphael Amorim
 
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 to 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....
 

Recently uploaded

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 

Recently uploaded (20)

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 

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/