Webgl: up and Running

Total Page:16

File Type:pdf, Size:1020Kb

Webgl: up and Running WebGL: Up and Running Tony Parisi O'REILLY' Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo Table of Contents Foreword vii Preface ix 1. An Introduction to WebGL 1 WebGL—A Technical Definition 2 3D Graphics—A Primer 4 3D Coordinate Systems 4 Meshes, Polygons, and Vertices 4 Materials, Textures, and Lights 5 Transforms and Matrices 6 Cameras, Perspective, Viewports, and Projections 7 Shaders 7 The WebGL API 9 The Anatomy of a WebGL Application 10 The Canvas and Drawing Context 10 The Viewport 11 Buffers, ArrayBuffer, and Typed Arrays 11 Matrices 12 TheShader 13 Drawing Primitives 14 Chapter Summary 15 2. Your First WebGL Program 17 Three.js—A JavaScript 3D Engine 17 Setting Up Three.j s 19 A Simple Three.js Page 20 A Real Example 22 Shading the Scene 26 Adding a Texture Map 27 Rotating the Object 28 iii The Run Loop and requestAnimationFrame() 28 Bringing the Page to Life 29 Chapter Summary 30 3. Graphics 31 Sim.js—A Simple Simulation Framework for WebGL 32 Creating Meshes 33 Using Materials, Textures, and Lights 38 Types of Lights 38 Creating Serious Realism with Multiple Textures 41 Textures and Transparency 46 Building a Transform Hierarchy 46 Creating Custom Geometry 50 Rendering Points and Lines 54 Point Rendering with Particle Systems 54 Line Rendering 56 Writing a Shader 57 WebGL Shader Basics 57 Shaders in Three.js 59 Chapter Summary 64 4. Animation 67 Animation Basics 67 Frame-Based Animation 67 Time-Based Animation 68 Interpolation and Tweening 69 Keyframes 70 Articulated Animation 70 Skinned Animation 71 Morphs 71 Creating Tweens Using the Tween.js Library 72 Creating a Basic Tween 73 Tweens with Easing 76 Animating an Articulated Model with Keyframes 79 Loading the Model 79 Animating the Model 81 Animating Materials and Lights 84 Animating Textures 86 Animating Skinned Meshes and Morphs 89 Chapter Summary 89 5. Interaction 91 iv Table of Contents Hit Detection, Picking, and Projection 91 Hit Detection in Three.js 92 Implementing Rollovers and Clicks 95 Implementing Dragging 98 Using Tweens with Dragging 102 Using Hit Point and Normal Information 102 Camera-Based Interaction 103 Implementing a Model Viewer with Camera Interaction 104 Navigating Within a Scene 106 Chapter Summary 108 6. Integrating 2D and 3D 109 Combining Dynamic HTML and WebGL 110 Creating Pop Ups with DIV Elements 110 Using 2D Screen Positions to Annotate 3D Objects 114 Adding a Background Image to the 3D Scene 116 Overlaying 3D Visuals on 2D Pages 116 Creating Dynamic Textures with a Canvas 2D 119 Using Video As a Texture 127 Rendering Dynamically Generated 3D Text 132 WebGL for Ultimate Mashups 134 Chapter Summary 136 7. WebGL in Production 137 Choosing a Runtime Framework 138 Loading 3D Content 139 COLLADA: The Digital Asset Exchange Format 140 The Three.js JSON Model Format 145 The Three.js Binary Model Format 148 3D Model Compression 150 The Three.js JSON Scene Format 150 Creating 3D Content 151 Exporting Art from Blender 152 Converting OBJ Files to Three.js JSON Format 154 Converting OBJ Files to Three.js Binary Format 154 Converting from Other Tools and Formats 154 Browser Realities 155 Detecting WebGL Support in Your Browser 156 Turning WebGL On in Safari 157 Handling Context Lost Events 159 WebGL and Security 162 Table of Contents v Chapter Summary 164 8. Your First WebGL Game 165 Building the Pieces 167 Camera, Character, and Control 167 Art Direction 174 The Model Previewer 177 Creating a Particle System 179 Adding Sound 182 Putting It All Together 184 Chapter Summary 196 Afterword cxcvii A. WebGL Resources 199 Index 203 vi Table of Contents .
Recommended publications
  • DHTML Effects in HTML Generated from DITA
    DHTML Effects in HTML Generated from DITA XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/ 2 | OpenTopic | TOC Contents DHTML Effects in HTML Generated from DITA............................................................3 XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/ OpenTopic | DHTML Effects in HTML Generated from DITA | 3 DHTML Effects in HTML Generated from DITA This topic describes an approach to creating expanding text and other DHTML effects in HTML-based output generated from DITA content. It is common for Help systems to use layering techniques to limit the amount of information presented to the reader. The reader chooses to view the information by clicking on a link. Most layering techniques, including expanding text, dropdown text and popup text, are implemented using Dynamic HTML. Overview The DITA Open Toolkit HTML transformations do not provide for layering effects. However, some changes to the XSL-T files, and the use of outputclassmetadata in the DITA topic content, along with some judicious use of JavaScript and CSS, can deliver these layering effects. Authoring Example In the following example illustrating the technique, a note element is to output as dropdown text, where the note label is used to toggle the display of the note text. The note element is simply marked up with an outputclass distinct attribute value (in this case, hw_expansion). < note outputclass="hw_expansion" type="note">Text of the note</note> Without any modification, the DITA OT will transform the note element to a paragraph element with a CSS class of the outputclass value.
    [Show full text]
  • Introduction to Scalable Vector Graphics
    Introduction to Scalable Vector Graphics Presented by developerWorks, your source for great tutorials ibm.com/developerWorks Table of Contents If you're viewing this document online, you can click any of the topics below to link directly to that section. 1. Introduction.............................................................. 2 2. What is SVG?........................................................... 4 3. Basic shapes............................................................ 10 4. Definitions and groups................................................. 16 5. Painting .................................................................. 21 6. Coordinates and transformations.................................... 32 7. Paths ..................................................................... 38 8. Text ....................................................................... 46 9. Animation and interactivity............................................ 51 10. Summary............................................................... 55 Introduction to Scalable Vector Graphics Page 1 of 56 ibm.com/developerWorks Presented by developerWorks, your source for great tutorials Section 1. Introduction Should I take this tutorial? This tutorial assists developers who want to understand the concepts behind Scalable Vector Graphics (SVG) in order to build them, either as static documents, or as dynamically generated content. XML experience is not required, but a familiarity with at least one tagging language (such as HTML) will be useful. For basic XML
    [Show full text]
  • COMP 2145 Web Programming
    South Central College COMP 2145 Web Programming Common Course Outline Course Information Description This course covers the popular server-side language PHP and Drupal, a popular CMS (Content Management System). It includes important language concepts such as data types, control statements, debugging techniques, the use of SQL (Standard Query Language). PHP will give the student experience with LAMP (Linux, Apache, MySQL, and PHP) . Prerequisites: COMP1140 - Web Development with a C or higher, or a working knowledge of HTML, CSS, and FTP. COMP1130 - Programming Fundamentals with a C or higher, or a working knowledge of at least one programming language. It is strongly recommended that you have a minimum typing speed of at least 35 wpm as well as a working knowledge of Microsoft Access (COMP1125). Instructional Associate Degree Level Total Credits 4.00 Total Hours 64.00 Types of Instruction Instruction Type Credits/Hours Online/lecture Pre/Corequisites C or better in COMP1140 C or better in COMP1130 or equivalent programming experience Course Competencies 1 Install and use PHP on a local server. Learning Objectives Describe Open Source software and why it is effective for improved software development. Draw a picture describing the relationship between client/server objects used by PHP and mySQL. Common Course Outline September, 2016 Install PHP and mySQL and an Apache web server. Write a simple test program using PHP on the local server (http://localhost/ ) Establish a working environment for PHP web page development. Use variables, constants, and environment variables in a PHP program. 2 Utilize HTML forms and PHP to get information from the user.
    [Show full text]
  • AJAX and Jquery L Raw AJAX Handling in JS Is Very Tedious L Jquery Provides Flexible and Strong Support to Handle AJAX Interactions Through a Set of Jquery Functions
    AJAX Asynchronous Design in Web Apps IT 4403 Advanced Web and Mobile Applications Jack G. Zheng Fall 2019 Topics l AJAX concepts and technical elements l AJAX implications and impacts l jQuery AJAX l Basic and shorthand methods l Error handling 2 AJAX l AJAX (Asynchronous JavaScript and XML) is a group of interrelated web development techniques used on the client-side to create interactive web applications. l Despite the name, the use of XML is not actually required, nor do the requests need to be asynchronous. 3 First Impression l https://www.google.com Use Chrome’s developer tools to view network communications while typing the search terms. A set of requests have been made to get JSON data from the server as I type in the search term box. Observe the “q” parameter in all URLs. 4 AJAX Model Difference With Ajax, web applications can communicate with servers in the background without a complete page loading after every request/response cycle. http://www.adaptivepath.com /ideas/ajax-new-approach- web-applications/ 5 Traditional Model The client does not generate views/presentations (HTML/CSS). Synchronous communications feature sequential request/response cycles, one after another The server prepares the whole page. http://www.websiteoptimization.com/secrets/ajax/8-1-ajax-pattern.html 6 Ajax Model l With Ajax, web applications can communicate with servers in the background without a complete page loading after every request/response cycle. The client generates views/presentations and update content (partial page) by manipulating DOM. Asynchronous communications feature independent request/response cycles The server prepares partial pages (partial HTML) or just data (XML or JSON).
    [Show full text]
  • EMERGING TECHNOLOGIES Dymamic Web Page Creation
    Language Learning & Technology January 1998, Volume 1, Number 2 http://llt.msu.edu/vol1num2/emerging/ pp. 9-15 (page numbers in PDF differ and should not be used for reference) EMERGING TECHNOLOGIES Dymamic Web Page Creation Robert Godwin-Jones Virginia Comonwealth University Contents: • Plug-ins and Applets • JavaScript • Dynamic HTML and Style Sheets • Instructional Uses • Resource List While remaining a powerful repository of information, the Web is being transformed into a medium for creating truly interactive learning environments, leading toward a convergence of Internet connectivity with the functionality of traditional multimedia authoring tools like HyperCard, Toolbook, and Authorware. Certainly it is not fully interactive yet, but that is undeniably the trend as manifested in the latest (version 4) Web browsers. "Dynamic HTML," incorporated into the new browsers, joins plug-ins, Web forms, Java applets, and JavaScript as options for Web interactivity. Plug-ins and Applets While Web pages are beginning to behave more like interactive applications, traditional authoring tools are themselves becoming Internet-savvy, primarily through the use of "plug-in" versions of players which integrate with Web browsers. The most commonly used plug-in today is Macromedia's "Shockwave," used to Web-enable such applications as Director, Authorware, and Flash. "Shocked" Web pages can be very interactive and provide a visually appealing means of interacting with users (as in some sample ESL exercises from Jim Duber). Plug-ins are easy to use -- they just need to be downloaded and installed. Some come bundled with Netscape and Microsoft's browsers, which simplifies considerably the installation process (and gives developers the confidence that most users will actually have the plug-in installed).
    [Show full text]
  • Chapter 10 Document Object Model and Dynamic HTML
    Chapter 10 Document Object Model and Dynamic HTML The term Dynamic HTML, often abbreviated as DHTML, refers to the technique of making Web pages dynamic by client-side scripting to manipulate the document content and presen- tation. Web pages can be made more lively, dynamic, or interactive by DHTML techniques. With DHTML you can prescribe actions triggered by browser events to make the page more lively and responsive. Such actions may alter the content and appearance of any parts of the page. The changes are fast and e±cient because they are made by the browser without having to network with any servers. Typically the client-side scripting is written in Javascript which is being standardized. Chapter 9 already introduced Javascript and basic techniques for making Web pages dynamic. Contrary to what the name may suggest, DHTML is not a markup language or a software tool. It is a technique to make dynamic Web pages via client-side programming. In the past, DHTML relies on browser/vendor speci¯c features to work. Making such pages work for all browsers requires much e®ort, testing, and unnecessarily long programs. Standardization e®orts at W3C and elsewhere are making it possible to write standard- based DHTML that work for all compliant browsers. Standard-based DHTML involves three aspects: 447 448 CHAPTER 10. DOCUMENT OBJECT MODEL AND DYNAMIC HTML Figure 10.1: DOM Compliant Browser Browser Javascript DOM API XHTML Document 1. Javascript|for cross-browser scripting (Chapter 9) 2. Cascading Style Sheets (CSS)|for style and presentation control (Chapter 6) 3. Document Object Model (DOM)|for a uniform programming interface to access and manipulate the Web page as a document When these three aspects are combined, you get the ability to program changes in Web pages in reaction to user or browser generated events, and therefore to make HTML pages more dynamic.
    [Show full text]
  • Introduction to HTML/CSS/SVG/D3
    D3 Tutorial Introduction of Basic Components: HTML, CSS, SVG, and JavaScript D3.js Setup Edit by Jiayi Xu and Han-Wei SHen, THe OHio State University HTML - Hyper Text Markup Language • HTML is the standard markup language for creating Web pages • HTML describes the structure of Web pages using markup • HTML elements • HTML elements are the building blocks of HTML pages • represented by tags • Tags • HTML tags label pieces of content such as • <head> tag for “heading” • <p> for “paragraph” • <table> for “table” and so on • Browsers do not display the HTML tags, but use them to render the content of the page HTML - Plain Text • If we display the information only by plain text HTML Basics HTML is designed for marking up text by adding tags such as <p> to create HTML elements. Example image: HTML - Codes and the Result HTML - DOM • When a web page is loaded, the browser creates a Document Object Model of the page • The HTML DOM model is constructed as a tree of Objects HTML - DOM Document Root element: <html> Element: Element: <head> <body> Element: Element: Element: Element: <p> Element: <p> <title> <h1> <img> "to create Text: "HTML Text: "HTML Element "is designed Element: "by adding Element Element: Attribute: Attribute: HTML Tutorial" Basics" <strong> for" <em> tags such as" <code> <strong> "src" "style" elements. " "marking up “Example "HTML" "<p>" text" image” HTML - DOM • With the object model, JavaScript can create dynamic HTML by manipulating the objects: • JavaScript can change all the HTML elements in the page • Change all the
    [Show full text]
  • Dynamic HTML Friday, October 29, 2010 8:04:48 AM
    Introduction to Dynamic HTML Friday, October 29, 2010 8:04:48 AM ©2010 Microsoft Corporation. All rights reserved. Introduction to Dynamic HTML Dynamic HTML (DHTML) is a set of innovative features originally introduced in Microsoft Internet Explorer 4.0. By enabling authors to dynamically change the rendering and content of a Web page as the user interacts with it, DHTML enables authors to create visually compelling Web sites without the overhead of server-side programs or complicated sets of controls to achieve special effects. With DHTML, you can easily add effects to your pages that previously were difficult to achieve. For example, you can: Hide content until a given time elapses or the user interacts with the page. Animate text and images in your document, independently moving each element from any starting point to any ending point, following a predetermined path or one chosen by the user. Embed a ticker that automatically refreshes its content with the latest news, stock quotes, or other data. Use a form [ http://msdn.microsoft.com/en-us/library/ms535249(VS.85).aspx ] to capture user input, and then instantly process and respond to that data. DHTML achieves these effects by modifying the in-memory representation of the current document and automatically reformatting it to show changes. It does not reload the document, load a new document, or require a distant server to generate new content. Instead, it uses the user's computer to calculate and carry out changes. This means a user does not wait for text and data to complete time-consuming roundtrips to and from a server before seeing the results.
    [Show full text]
  • Formal Resume
    JOHN GARRETT 984-255-4525 [email protected] Experienced web, desktop, and iOS developer 1220 Barnes Street, Atlanta GA https://garrepi.dev EDUCATION Georgia Institute of Technology Atlanta, GA B.S. in Computer Science with a minor in Mathematics, GPA 3.31 Aug 2019 - Fall 2022 - Thread selection in Devices and Systems & Architecture The University of North Carolina at Charlotte Charlotte, NC Freshman year studying Computer Science with a minor in Mathematics, GPA 4.0 Jul 2018 –May 2019 EXPERIENCE Barrel Proof Apps Atlanta, GA Independent Contractor, Cross Platform Developer Aug 2020 – President - Built and maintained infrastructure to meet the demands of clients - Contributed to the ReactNative inspection utility app used by QI2 - Utilized Node.Js, MongoDB, and React to structure the web client and interoperability between QI2 inspectors - Effectively handled an entirely remote work environment by reliably communicating and exceeding deadlines SameTunes - sametunes.com Atlanta, GA Fullstack Developer, Interim CTO May 2020 - Nov 2020 - Migrated an existing codebase to a type-safe MVVM architecture - Increased speed, stability, and code uniformity while decreasing duplication, database calls, and page load times - Built and implemented a caching engine that has stored over 15 million items to reduce Spotify’s rate limiting - Designed a majority of the APIs, frontend pages, and backend logic used throughout the entire platform today Kabbage Atlanta, GA Mobile iOS Engineer Intern Jun 2019 – Dec 2019 - Studied and implemented a GraphQL
    [Show full text]
  • Building Dynamic Forms with XML, XSLT
    International Journal of Computing and Optimization Vol. 2, 2015, no. 1, 23 - 34 HIKARI Ltd, www.m-hikari.com http://dx.doi.org/10.12988/ijco.2015.517 Building Dynamic Forms with XML, XSLT Dhori Terpo University “E. Çabej”, Faculty of Natural Sciences, Department of Mathematics & Informatics, Gjirokastra, Albania Endrit Xhina University of Tirana, Faculty of Natural Sciences, Department of Informatics, Tirana, Albania Copyright © 2015 Dhori Terpo and Endrit Xhina. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited. Abstract Data entry forms are a key component of all process automation applications. This paper will present an approach for building dynamic data entry forms using data that have been stored in a relational database. By following a series of steps, we transform these data into a dynamic HTML form using the web technologies XML and XSLT. This approach reduces the amount of software development time and maintenance required to generate and process such forms and can have very high payoff in many enterprise process automation applications. Keywords: Data Entry Form, HTML, XML, XSLT 1 The need for dynamic forms Data entry forms are a key component of all process automation applications. In current applications, most of the content of a data entry form is created during the phase of its development. When the requirements of an application are changed, this leads to redesign or recompile the form’s file. Furthermore, because different processes have different data inputs, the design of a preliminary data entry form for generalization, is impossible.
    [Show full text]
  • Asynchronous Javascript and XML
    Asynchronous JavaScript and XML Literature study on Ajax as part of the project ‘AJAX for Content Management’. By: Teunis van Wijngaarden ( [email protected] ) Abstract [Voor dit document een aparte abstract schrijven?] 1 Contents Asynchronous JavaScript and XML ........................................................................................1 Abstract ..............................................................................................................................1 1 Contents .......................................................................................................................1 2 Introduction .................................................................................................................2 3 Ajax history .................................................................................................................2 3.1 Introduction of Javascript ......................................................................................2 3.2 Introduction of frames ...........................................................................................2 3.3 Ansynchronous requests with ‘old’ techniques ......................................................2 3.4 An easier way to perform Asynchronous requests .................................................3 3.5 The new approach: Ajax .......................................................................................3 3.6 Ajax’s context: Web 2.0 ........................................................................................4
    [Show full text]
  • HTML5 Audio 1 HTML5 Audio
    HTML5 Audio 1 HTML5 Audio HTML • HTML and HTML5; HTML editor • Dynamic HTML • XHTML • XHTML Basic (Mobile) • XHTML Mobile Profile and C-HTML • HTML element • Span and div • HTML attribute • Character encodings; Unicode • Language code • Document Object Model • Browser Object Model • Style sheets and CSS • Font family and Web colors • HTML scripting and JavaScript • W3C, WHATWG, and validator • Quirks mode • HTML Frames • HTML5 Canvas, WebGL, and WebCL • HTML5 Audio and HTML5 video • Web storage • Web browser (layout) engine • Comparison of • document markup languages • web browsers • layout engine support for • HTML; Non-standard HTML • XHTML (1.1) • HTML5; HTML5 canvas, • HTML5 media (Audio, Video) • v • t [1] • e HTML5 Audio is a subject of the HTML5 specification, investigating audio input, playback, synthesis, as well as speech to text in the browser. HTML5 Audio 2 <audio> element The <audio> element represents a sound, or an audio stream.[2] It is commonly used to play back a single audio file within a web page, showing a GUI widget with play/pause/volume controls. Supported browsers • PC • Google Chrome • Internet Explorer 9 • Mozilla Firefox 3.5 • Opera 10.5 • Safari 3.1[3] • Mobile • Android Browser 2.3 • Blackberry Browser • Google Chrome for Android • Internet Explorer Mobile 9 • Mobile Safari 4 • Mozilla Firefox for Android • Opera Mobile 11 • Tizen Supported audio codecs This table documents the current support for audio codecs by the <audio> element. Browser Operating Formats supported by different web browsers system Ogg
    [Show full text]