SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Unconventional webapps with
  GWT/Elemental, WebRTC &
          WebGL
                     Alberto Mancini
                   alberto@jooink.com

Blog: http://jooink.blogspot.com

Online Demo:
      http://www.jooink.com/experiments/DevFest2012
GWT 2.5 Elemental

Elemental is a new library for fast, lightweight,
and "to the metal" web programming in GWT.

Elemental includes every HTML5 feature, ... DOM access
... WebGL, WebAudio, WebSockets, WebRTC, Web
Intents, Shadow DOM, the File API, and more.
... we generate Java code directly from the WebIDL files
used by JavaScript engines. (like DART)
Unconventional


... insomma qualcosa che non ci sembrava
possibile fare con il solo browser, tipo accedere
a devices attaccati al 'client', una webcam
per esempio.



L'idea e' farsi una foto ...
WebRTC

WebRTC (Web Real-Time Communication) is an API
definition being drafted by W3C and IETF.

The goal of WebRTC is to enable applications such as
voice calling, video chat and P2P file sharing without
plugins.

Specification & Up to date info: http://www.webrtc.org

Support:   Chrome 22+, ... well work-in-progress at least for firefox.


what we need: getUserMedia (chrome !!)
WebRTC (with Elemental)
Video in a canvas
     final VideoElement videoElement =
                        Browser.getDocument().createVideoElement();
    final CanvasElement canvas =
                        Browser.getDocument().createCanvasElement();
    final CanvasRenderingContext2D ctx2d =
              (CanvasRenderingContext2D)canvas.getContext("2d");
       ...
      //repeatedly, e.g. in a Timer or RepeatingCommand
      ctx2d.drawImage(videoElement, 0, 0);

Take snapshot as easy as:
    Image img = new Image(canvas.toDataURL("png"));
WebRTC (with Elemental)
binding <video/> to userMedia (search for facelogin on googlecode)
public void
 bindVideoToUserMedia(final VideoElement video, final EventListener l) {
      final Mappable map = (Mappable) JsMappable.createObject();
      map.setAt("video", true);
      Browser.getWindow().getNavigator().webkitGetUserMedia(map,
                 new NavigatorUserMediaSuccessCallback() {
                             public boolean onNavigatorUserMediaSuccessCallback
                                                     (LocalMediaStream stream) {
                                         setVideoSrc(video, stream);
                                         video.play(); ...
      }, new NavigatorUserMediaErrorCallback() {...});
  }

private static native void setVideoSrc( VideoElement v, LocalMediaStream s) /*-{
      v.src = window.webkitURL.createObjectURL(s);
}-*/;
WebGL
WebGL (Web Graphics Library) is a JavaScript API for
rendering interactive 3D graphics and 2D graphics within
any compatible web browser without the use of plug-ins.

Specification: http://www.khronos.org/webgl/

Support: http://caniuse.com/webgl



Chrome 22+, FireFox 15+, Safari 6+, Opera 12+ (partial)
WebGL (with Elemental)
Video in a canvas (3d rendering context)
  ...
  WebGLRenderingContext ctx3d =
        (WebGLRenderingContext)canvas.getContext("experimental-webgl");

Drawing is a bit harder:
  create a texture, create a background rectangle,
  use the video as a texture
  ctx3d.texImage2D(WebGLRenderingContext.TEXTURE_2D, 0,
        WebGLRenderingContext.RGBA, WebGLRenderingContext.RGBA,
          WebGLRenderingContext.UNSIGNED_BYTE, videoElement);
WebGL (with Elemental)
  shaders

Vertex Shader                                          Fragment Shader

precision mediump float;                               precision mediump float;
attribute vec2 a_position;                             uniform sampler2D u_image;
attribute vec2 a_texCoord;                             varying vec2 v_texCoord;
uniform vec2 u_resolution;
varying vec2 v_texCoord;                               void main() {
void main() {                                            gl_FragColor =
  vec2 zeroToOne = a_position / u_resolution;                texture2D(u_image, v_texCoord);
  vec2 zeroToTwo = zeroToOne * 2.0;                    }
  vec2 clipSpace = zeroToTwo - 1.0;
  gl_Position = vec4(clipSpace * vec2(1, -1), 1, 1);
  v_texCoord = a_texCoord;
}




             from html5rocks.com's WebGL Fundamentals ... probably :o
WebGL (with Elemental)
  shaders

Fragment Shader                                        Fragment Shader
...
// Sepia tone                                          precision mediump float;
// Convert to greyscale using NTSC weightings          uniform sampler2D u_image;
   float grey = dot(texture2D(u_image,                 uniform sampler2D SECOND_u_image;
       v_texCoord).rgb, vec3(0.299, 0.587, 0.114));    uniform float alpha;
   gl_FragColor =                                      varying vec2 v_texCoord;
       vec4(grey * vec3(1.2, 1.0, 0.8), 1.0);           void main(void) {
...                                                      vec4 prev = texture2D(SECOND_u_image,
// Negative                                                      vec2(v_texCoord.s,1.0-v_texCoord.t));
 vec4 texColour =                                        vec4 cur = texture2D(u_image, v_texCoord);
      texture2D(u_image, v_texCoord);                    gl_FragColor = alpha*prev + (1.0-alpha)*cur;
 gl_FragColor = vec4(1.0 - texColour.rgb, 1.0);        }




from http://r3dux.org/2011/06/glsl-image-processing/
WebGL (with Elemental)
  3D


WebGL e' una libreria 2D !!

Trasformazioni prospettiche (proiezioni), frustum, modelview
vanno implementate.

VertexShader: applichera' le trasformazioni (matrici) che noi gli
forniremo, vertice per vertice

FragmentShader: usera', pixel-per-pixel, le informazioni
calcolate vertice-per-vertice (ed interpolate dal 'sistema')
per assegnare il colore
WebGL (with Elemental)
    3D


double a = (right + left) / (right - left);
double b = (top + bottom) / (top - bottom);
double c = (farPlane + nearPlane) / (farPlane - nearPlane);
double d = (2 * farPlane * nearPlane) / (farPlane - nearPlane);
double x = (2 * nearPlane) / (right - left);
double y = (2 * nearPlane) / (top - bottom);
double[] perspectiveMatrix = new double[]{
     x, 0, a, 0,
     0, y, b, 0,
     0, 0, c, d,
     0, 0, -1, 0
 };


....
ctx3d.uniformMatrix4fv(pMatrixUniform, false, Utilities.createArrayOfFloat32(perspectiveMatrix));
...
private native static Float32Array createFloat32Array(JsArrayOfNumber a) /*-{
       return new Float32Array(a);
}-*/;
WebGL (with Elemental)
  3D/Wavefront-OBJ


Loading Wavefront-obj files ...

parser in java facile da trovare in rete


ClientBundle DataResource perfetto per il loading
asincrono dei modelli


Javascript per calcolare le normali se non sono nel
modello
Unconventional

Tutto quello che abbiamo visto fino ad ora si poteva fare,
probabilmente con lo stesso sforzo, direttamente in javascript.



  Ma usare GWT ci da o no una marcia in piu' ?



Nota:
non stiamo dicendo che quello che segue non si potesse fare in
javascript, ndr: Turing completeness, se ce ne fosse bisogno !
GWT



Compiler: Java -> Javascript


Javascript as a target language
NyARToolkit

ARToolKit is a computer tracking library for creation of strong augmented
reality applications that overlay virtual imagery on the real world.
NyARToolKit is an ARToolkit class library released for virtual machines,
particularly those that host Java, C# and Android.

Up to date info
http://nyatla.jp/nyartoolkit/wp/?page_id=198


Support:
Java ... "Write once, run anywhere" (WORA), or sometimes write once, run
everywhere (WORE) ... in my browser ?!?!?!
NyARToolkit con GWT
http://jooink.blogpsot.com
super-source tag
per InputStream & altre parti della JRE non disponibili in GWT

byte[] raster;
UInt8ClampedArray image = ImageData.getData();
private static native byte[] toArrayOfBytes(Uint8ClampedArray a) /*-{
   return a;
}-*/;



Documented in JAPANESE !!!
How It Works



   cam    WebRTC      <video/>
                                 canvas    ImageData




                                                   Elemental/jsni
               WebGL + model
  video




                        GWT(NyARToolkit)      byte[]
          mv matrix
Demo http://www.jooink.com/experiments/DevFest2012

Contenu connexe

Tendances

Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011
Johan Thelin
 
Back from BUILD - WebGL
Back from BUILD -  WebGLBack from BUILD -  WebGL
Back from BUILD - WebGL
davrous
 
WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms
philn2
 
Introduction to QtWebKit
Introduction to QtWebKitIntroduction to QtWebKit
Introduction to QtWebKit
Ariya Hidayat
 

Tendances (20)

OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
Building the QML Run-time
Building the QML Run-timeBuilding the QML Run-time
Building the QML Run-time
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011
 
NIR on the Mesa i965 backend (FOSDEM 2016)
NIR on the Mesa i965 backend (FOSDEM 2016)NIR on the Mesa i965 backend (FOSDEM 2016)
NIR on the Mesa i965 backend (FOSDEM 2016)
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key concepts
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
Back from BUILD - WebGL
Back from BUILD -  WebGLBack from BUILD -  WebGL
Back from BUILD - WebGL
 
Multimedia in WebKitGtk+, past/present/future
Multimedia in WebKitGtk+, past/present/futureMultimedia in WebKitGtk+, past/present/future
Multimedia in WebKitGtk+, past/present/future
 
WebKit and GStreamer
WebKit and GStreamerWebKit and GStreamer
WebKit and GStreamer
 
Petri Niemi Qt Web Kit
Petri Niemi Qt Web KitPetri Niemi Qt Web Kit
Petri Niemi Qt Web Kit
 
Qt for beginners part 5 ask the experts
Qt for beginners part 5   ask the expertsQt for beginners part 5   ask the experts
Qt for beginners part 5 ask the experts
 
WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms
 
WPE WebKit for Android
WPE WebKit for AndroidWPE WebKit for Android
WPE WebKit for Android
 
Introduction to QtWebKit
Introduction to QtWebKitIntroduction to QtWebKit
Introduction to QtWebKit
 
Qt Multiplatform development
Qt Multiplatform developmentQt Multiplatform development
Qt Multiplatform development
 
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
 
JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...
JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...
JS Fest 2019: Comparing Node.js processes and threads for clustering HTTP, TC...
 
Ultrasound Image Viewer - Qt + SGX
Ultrasound Image Viewer - Qt + SGXUltrasound Image Viewer - Qt + SGX
Ultrasound Image Viewer - Qt + SGX
 
Async await in C++
Async await in C++Async await in C++
Async await in C++
 
GStreamer support in WebKit. what’s new?
GStreamer support in WebKit. what’s new?GStreamer support in WebKit. what’s new?
GStreamer support in WebKit. what’s new?
 

Similaire à Unconventional webapps with gwt:elemental & html5

Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
Chihoon Byun
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
tamillarasan
 
Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010
Chris Ramsdale
 

Similaire à Unconventional webapps with gwt:elemental & html5 (20)

Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
 
COLLADA & WebGL
COLLADA & WebGLCOLLADA & WebGL
COLLADA & WebGL
 
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter LuhBuilding Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
 
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
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
 
How to Create Custom Shaders in Flutter?
How to Create Custom Shaders in Flutter?How to Create Custom Shaders in Flutter?
How to Create Custom Shaders in Flutter?
 
Developing Web Graphics with WebGL
Developing Web Graphics with WebGLDeveloping Web Graphics with WebGL
Developing Web Graphics with WebGL
 
The next frontier: WebGL and WebVR
The next frontier: WebGL and WebVRThe next frontier: WebGL and WebVR
The next frontier: WebGL and WebVR
 
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?
 
GL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfGL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdf
 
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
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
Game development with_lib_gdx
Game development with_lib_gdxGame development with_lib_gdx
Game development with_lib_gdx
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
OpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering TechniquesOpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering Techniques
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
 
iOS Visual F/X Using GLSL
iOS Visual F/X Using GLSLiOS Visual F/X Using GLSL
iOS Visual F/X Using GLSL
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
 
Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010
 

Plus de firenze-gtug

Maven from dummies
Maven from dummiesMaven from dummies
Maven from dummies
firenze-gtug
 

Plus de firenze-gtug (20)

Html5 apps - GWT oriented
Html5 apps - GWT orientedHtml5 apps - GWT oriented
Html5 apps - GWT oriented
 
Android ndk - ottimizzazione su dispositivi Intel
Android ndk - ottimizzazione su dispositivi IntelAndroid ndk - ottimizzazione su dispositivi Intel
Android ndk - ottimizzazione su dispositivi Intel
 
Gwt kickoff - Alberto Mancini & Francesca Tosi
Gwt kickoff - Alberto Mancini & Francesca TosiGwt kickoff - Alberto Mancini & Francesca Tosi
Gwt kickoff - Alberto Mancini & Francesca Tosi
 
Youtube broadcast live - Massimiliano D'Ambrosio
Youtube broadcast live - Massimiliano D'AmbrosioYoutube broadcast live - Massimiliano D'Ambrosio
Youtube broadcast live - Massimiliano D'Ambrosio
 
Intro BeagleBone Black - Massimiliano D'Ambrosio
Intro BeagleBone Black - Massimiliano D'AmbrosioIntro BeagleBone Black - Massimiliano D'Ambrosio
Intro BeagleBone Black - Massimiliano D'Ambrosio
 
Arduino - Massimiliano D'Ambrosio
Arduino - Massimiliano D'AmbrosioArduino - Massimiliano D'Ambrosio
Arduino - Massimiliano D'Ambrosio
 
Introduzione a GAE - Alessandro Aglietti e Lorenzo Bugiani
Introduzione a GAE - Alessandro Aglietti e Lorenzo BugianiIntroduzione a GAE - Alessandro Aglietti e Lorenzo Bugiani
Introduzione a GAE - Alessandro Aglietti e Lorenzo Bugiani
 
RFID: What & Why - Stefano Coluccini
RFID: What & Why - Stefano ColucciniRFID: What & Why - Stefano Coluccini
RFID: What & Why - Stefano Coluccini
 
GWT - AppDays - (25 aprile 2014, pordenone)
GWT - AppDays - (25 aprile 2014, pordenone)GWT - AppDays - (25 aprile 2014, pordenone)
GWT - AppDays - (25 aprile 2014, pordenone)
 
Presentazione Google App Engine
Presentazione Google App EnginePresentazione Google App Engine
Presentazione Google App Engine
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloud
 
Clean android code
Clean android codeClean android code
Clean android code
 
#Html2Native
#Html2Native#Html2Native
#Html2Native
 
Intel ndk - a few Benchmarks
Intel ndk - a few BenchmarksIntel ndk - a few Benchmarks
Intel ndk - a few Benchmarks
 
EE Incremental Store
EE Incremental StoreEE Incremental Store
EE Incremental Store
 
Programming objects with android
Programming objects with androidProgramming objects with android
Programming objects with android
 
Apertura "Mobile & Embedded" - 13 febbraio 2014
Apertura "Mobile & Embedded" - 13 febbraio 2014Apertura "Mobile & Embedded" - 13 febbraio 2014
Apertura "Mobile & Embedded" - 13 febbraio 2014
 
Maven from dummies
Maven from dummiesMaven from dummies
Maven from dummies
 
Apps fuel oct2012
Apps fuel oct2012Apps fuel oct2012
Apps fuel oct2012
 
Dev fest android application case study
Dev fest android application   case studyDev fest android application   case study
Dev fest android application case study
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Unconventional webapps with gwt:elemental & html5

  • 1. Unconventional webapps with GWT/Elemental, WebRTC & WebGL Alberto Mancini alberto@jooink.com Blog: http://jooink.blogspot.com Online Demo: http://www.jooink.com/experiments/DevFest2012
  • 2. GWT 2.5 Elemental Elemental is a new library for fast, lightweight, and "to the metal" web programming in GWT. Elemental includes every HTML5 feature, ... DOM access ... WebGL, WebAudio, WebSockets, WebRTC, Web Intents, Shadow DOM, the File API, and more. ... we generate Java code directly from the WebIDL files used by JavaScript engines. (like DART)
  • 3. Unconventional ... insomma qualcosa che non ci sembrava possibile fare con il solo browser, tipo accedere a devices attaccati al 'client', una webcam per esempio. L'idea e' farsi una foto ...
  • 4. WebRTC WebRTC (Web Real-Time Communication) is an API definition being drafted by W3C and IETF. The goal of WebRTC is to enable applications such as voice calling, video chat and P2P file sharing without plugins. Specification & Up to date info: http://www.webrtc.org Support: Chrome 22+, ... well work-in-progress at least for firefox. what we need: getUserMedia (chrome !!)
  • 5. WebRTC (with Elemental) Video in a canvas final VideoElement videoElement = Browser.getDocument().createVideoElement(); final CanvasElement canvas = Browser.getDocument().createCanvasElement(); final CanvasRenderingContext2D ctx2d = (CanvasRenderingContext2D)canvas.getContext("2d"); ... //repeatedly, e.g. in a Timer or RepeatingCommand ctx2d.drawImage(videoElement, 0, 0); Take snapshot as easy as: Image img = new Image(canvas.toDataURL("png"));
  • 6. WebRTC (with Elemental) binding <video/> to userMedia (search for facelogin on googlecode) public void bindVideoToUserMedia(final VideoElement video, final EventListener l) { final Mappable map = (Mappable) JsMappable.createObject(); map.setAt("video", true); Browser.getWindow().getNavigator().webkitGetUserMedia(map, new NavigatorUserMediaSuccessCallback() { public boolean onNavigatorUserMediaSuccessCallback (LocalMediaStream stream) { setVideoSrc(video, stream); video.play(); ... }, new NavigatorUserMediaErrorCallback() {...}); } private static native void setVideoSrc( VideoElement v, LocalMediaStream s) /*-{ v.src = window.webkitURL.createObjectURL(s); }-*/;
  • 7. WebGL WebGL (Web Graphics Library) is a JavaScript API for rendering interactive 3D graphics and 2D graphics within any compatible web browser without the use of plug-ins. Specification: http://www.khronos.org/webgl/ Support: http://caniuse.com/webgl Chrome 22+, FireFox 15+, Safari 6+, Opera 12+ (partial)
  • 8. WebGL (with Elemental) Video in a canvas (3d rendering context) ... WebGLRenderingContext ctx3d = (WebGLRenderingContext)canvas.getContext("experimental-webgl"); Drawing is a bit harder: create a texture, create a background rectangle, use the video as a texture ctx3d.texImage2D(WebGLRenderingContext.TEXTURE_2D, 0, WebGLRenderingContext.RGBA, WebGLRenderingContext.RGBA, WebGLRenderingContext.UNSIGNED_BYTE, videoElement);
  • 9. WebGL (with Elemental) shaders Vertex Shader Fragment Shader precision mediump float; precision mediump float; attribute vec2 a_position; uniform sampler2D u_image; attribute vec2 a_texCoord; varying vec2 v_texCoord; uniform vec2 u_resolution; varying vec2 v_texCoord; void main() { void main() { gl_FragColor = vec2 zeroToOne = a_position / u_resolution; texture2D(u_image, v_texCoord); vec2 zeroToTwo = zeroToOne * 2.0; } vec2 clipSpace = zeroToTwo - 1.0; gl_Position = vec4(clipSpace * vec2(1, -1), 1, 1); v_texCoord = a_texCoord; } from html5rocks.com's WebGL Fundamentals ... probably :o
  • 10. WebGL (with Elemental) shaders Fragment Shader Fragment Shader ... // Sepia tone precision mediump float; // Convert to greyscale using NTSC weightings uniform sampler2D u_image; float grey = dot(texture2D(u_image, uniform sampler2D SECOND_u_image; v_texCoord).rgb, vec3(0.299, 0.587, 0.114)); uniform float alpha; gl_FragColor = varying vec2 v_texCoord; vec4(grey * vec3(1.2, 1.0, 0.8), 1.0); void main(void) { ... vec4 prev = texture2D(SECOND_u_image, // Negative vec2(v_texCoord.s,1.0-v_texCoord.t)); vec4 texColour = vec4 cur = texture2D(u_image, v_texCoord); texture2D(u_image, v_texCoord); gl_FragColor = alpha*prev + (1.0-alpha)*cur; gl_FragColor = vec4(1.0 - texColour.rgb, 1.0); } from http://r3dux.org/2011/06/glsl-image-processing/
  • 11. WebGL (with Elemental) 3D WebGL e' una libreria 2D !! Trasformazioni prospettiche (proiezioni), frustum, modelview vanno implementate. VertexShader: applichera' le trasformazioni (matrici) che noi gli forniremo, vertice per vertice FragmentShader: usera', pixel-per-pixel, le informazioni calcolate vertice-per-vertice (ed interpolate dal 'sistema') per assegnare il colore
  • 12. WebGL (with Elemental) 3D double a = (right + left) / (right - left); double b = (top + bottom) / (top - bottom); double c = (farPlane + nearPlane) / (farPlane - nearPlane); double d = (2 * farPlane * nearPlane) / (farPlane - nearPlane); double x = (2 * nearPlane) / (right - left); double y = (2 * nearPlane) / (top - bottom); double[] perspectiveMatrix = new double[]{ x, 0, a, 0, 0, y, b, 0, 0, 0, c, d, 0, 0, -1, 0 }; .... ctx3d.uniformMatrix4fv(pMatrixUniform, false, Utilities.createArrayOfFloat32(perspectiveMatrix)); ... private native static Float32Array createFloat32Array(JsArrayOfNumber a) /*-{ return new Float32Array(a); }-*/;
  • 13. WebGL (with Elemental) 3D/Wavefront-OBJ Loading Wavefront-obj files ... parser in java facile da trovare in rete ClientBundle DataResource perfetto per il loading asincrono dei modelli Javascript per calcolare le normali se non sono nel modello
  • 14. Unconventional Tutto quello che abbiamo visto fino ad ora si poteva fare, probabilmente con lo stesso sforzo, direttamente in javascript. Ma usare GWT ci da o no una marcia in piu' ? Nota: non stiamo dicendo che quello che segue non si potesse fare in javascript, ndr: Turing completeness, se ce ne fosse bisogno !
  • 15. GWT Compiler: Java -> Javascript Javascript as a target language
  • 16. NyARToolkit ARToolKit is a computer tracking library for creation of strong augmented reality applications that overlay virtual imagery on the real world. NyARToolKit is an ARToolkit class library released for virtual machines, particularly those that host Java, C# and Android. Up to date info http://nyatla.jp/nyartoolkit/wp/?page_id=198 Support: Java ... "Write once, run anywhere" (WORA), or sometimes write once, run everywhere (WORE) ... in my browser ?!?!?!
  • 17. NyARToolkit con GWT http://jooink.blogpsot.com super-source tag per InputStream & altre parti della JRE non disponibili in GWT byte[] raster; UInt8ClampedArray image = ImageData.getData(); private static native byte[] toArrayOfBytes(Uint8ClampedArray a) /*-{ return a; }-*/; Documented in JAPANESE !!!
  • 18. How It Works cam WebRTC <video/> canvas ImageData Elemental/jsni WebGL + model video GWT(NyARToolkit) byte[] mv matrix