Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit of first glTF tutorial #1

Merged
merged 55 commits into from
Nov 26, 2017
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
cf36a27
Initial commit of first glTF tutorial
javagl Oct 20, 2016
57ad950
Included first comments for first pull request
javagl Oct 31, 2016
9c09afe
Updated link anchor
javagl Oct 31, 2016
14ef12f
Fixed link anchor
javagl Oct 31, 2016
9c67b42
Refactored introduction
javagl Nov 1, 2016
2030187
Fixed matrix image
javagl Nov 2, 2016
e108349
Next refactoring and cleanup of the generic glTF tutorial
javagl Nov 2, 2016
e73b738
Next step of tutorial refactoring
javagl Nov 4, 2016
6e73912
Fixed navigation elements
javagl Nov 4, 2016
be84f85
Next refactoring step of tutorial
javagl Nov 4, 2016
9325982
Fixed buffer length in images
javagl Nov 4, 2016
13414b4
Next refactoring steps of glTF tutorial
javagl Nov 7, 2016
4de3dcc
Fixed navigation links.
javagl Nov 7, 2016
a9921ea
Refactoring of tutorial, mainly related to materials
javagl Nov 14, 2016
692af8e
Continued with materials section
javagl Nov 15, 2016
96db262
Continued with "Advanced Material". Started cameras.
javagl Nov 17, 2016
000d921
Added cameras. Started simple texture example.
javagl Nov 27, 2016
3a1112b
Updates for materials
javagl Dec 9, 2016
e2eaf9c
Updated links
javagl Dec 9, 2016
e35949f
Minor restructuring before adding skins
javagl Dec 10, 2016
2f61612
Updated links and image captions
javagl Dec 11, 2016
b190766
Updated skin images
javagl Dec 11, 2016
e73f143
Added skinning sections
javagl Dec 14, 2016
dfb0979
Finished skinning. Minor cleanups.
javagl Dec 19, 2016
4b275d0
Copy of @slchow edits, attempt to fix git branch/pull request.
emackey Jan 6, 2017
2e56f56
Merge pull request #1 from emackey/slchow-edits
javagl Jan 6, 2017
add4488
Minor fixes based on copyedit comments
javagl Jan 12, 2017
baea61e
Updated content pipeline image
javagl Jan 12, 2017
cfeef19
Minor fix based on copyedit comment.
javagl Jan 12, 2017
b5a0f84
Aligned tutorial with updated sample models.
javagl Jan 12, 2017
b1dadea
First pass of update for 2.0
javagl Apr 9, 2017
96b4459
Updated sections 8 and 9 for 2.0
javagl Apr 9, 2017
47e9669
Update gltfTutorial_005_BuffersBufferViewsAccessors.md
PeakFish Jul 9, 2017
d357a07
Merge pull request #2 from PeakFish/patch-1
javagl Jul 9, 2017
cc8b428
Update gltfTutorial_007_Animations.md
PeakFish Jul 12, 2017
fced2e1
Merge pull request #3 from PeakFish/patch-1
javagl Jul 13, 2017
a5cc729
Added a minor fix to the 4th tutorial
ambient-seclusion Sep 7, 2017
35f0dcd
Merge pull request #4 from LT-Kerrigan/master
javagl Sep 7, 2017
68d627b
Minor fix of broken anchor to 8th tutorial
ambient-seclusion Sep 7, 2017
8c19bcc
Merge pull request #5 from LT-Kerrigan/master
javagl Sep 7, 2017
5dffe82
Updated links to point to 2.0 specification
javagl Oct 12, 2017
42f113c
Updated section about interleaved data
javagl Oct 14, 2017
92b78b0
Updates of Materials and Cameras for 2.0
javagl Oct 16, 2017
34b2af2
Updated first part of skinning for 2.0
javagl Oct 17, 2017
ddf5cd8
Update gltfTutorial_020_Skins.md
alexchicn Oct 31, 2017
73cb6fc
Merge pull request #6 from alexchicn/patch-1
javagl Oct 31, 2017
7762dbc
Added section about sparse accessors
javagl Nov 4, 2017
d40b5ee
Added note about infinite projection matrices
javagl Nov 4, 2017
f72209c
Updated skins sections for 2.0
javagl Nov 4, 2017
6b9b245
Minor fix in animation sample
javagl Nov 5, 2017
9f55617
Added initial draft of morph targets section
javagl Nov 7, 2017
848d8ab
Finalized Morph and Skin. Added Advanced Material.
javagl Nov 12, 2017
8b520ae
Fixes for images and image links
javagl Nov 12, 2017
82349ca
Copyedit
slchow Nov 23, 2017
4afe369
Merge pull request #7 from slchow/master
javagl Nov 26, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions gltfTutorial/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# glTF Tutorial

This tutorial gives an introduction to [glTF](https://www.khronos.org/gltf), the GL transmission format. It summarizes the most important features and application cases of glTF, and describes the structure of the files that are related to glTF. It explains how glTF assets may be read, processed, and used to display 3D graphics efficiently.

Some basic knowledge about [JSON](http://json.org/), the JavaScript Object Notation, is assumed. Additionally, a basic understanding of common graphics APIs, like OpenGL or WebGL, is required. The code examples will be given in [WebGL](https://www.khronos.org/webgl/).

- [Introduction](gltfTutorial_001_Introduction.md)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can each .md file link to the previous, next, and contents?

- [Basic glTF Structure](gltfTutorial_002_BasicGltfStructure.md)
- [Example: A Minimal glTF File](gltfTutorial_003_MinimalGltfFile.md)
- [Scenes and Nodes](gltfTutorial_004_ScenesNodes.md)
- [Buffers, BufferViews, and Accessors](gltfTutorial_005_BuffersBufferViewsAccessors.md)
- [Example: A Simple Animation](gltfTutorial_006_SimpleAnimation.md)
- [Animations](gltfTutorial_007_Animations.md)
- [Example: Simple Meshes](gltfTutorial_008_Meshes.md)
- [Meshes](gltfTutorial_009_Meshes.md)
- [Materials](gltfTutorial_010_Materials.md)
- [Example: A Simple Material](gltfTutorial_011_SimpleMaterial.md)
- [Programs and Shaders](gltfTutorial_012_ProgramsShaders.md)
- [Materials and Techniques](gltfTutorial_013_MaterialsTechniques.md)
- [Example: An Advanced Material](gltfTutorial_014_AdvancedMaterial.md)
- (TBD: "Simple opacity": Explaining the `technique.states.functions` with the SimpleOpacity example)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a reminder that there's a TBD here.

- [Example: A Simple Texture](gltfTutorial_015_SimpleTexture.md)
- [Textures, Images, and Samplers](gltfTutorial_016_TexturesImagesSamplers.md)
- [Example: Simple Cameras](gltfTutorial_017_SimpleCameras.md)
- [Cameras](gltfTutorial_019_Cameras.md)
- [Example: Simple Skin](gltfTutorial_019_SimpleSkin.md)
- [Skins](gltfTutorial_020_Skins.md)
- Extensions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder that Extensions and Summary aren't in yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This as well as the TBD will likely not be part of the initial version. The extensions will be explained separately, and the Summary (locally) mainly contains code snippets for rendering with WebGL, which would go into a separate tutorial.

- Summary: Rendering a glTF asset with WebGL



**Acknowledgements:**

- Patrick Cozzi, Cesium, [@pjcozzi](https://twitter.com/pjcozzi)
- Alexey Knyazev, [lexaknyazev](https://github.com/lexaknyazev)
54 changes: 54 additions & 0 deletions gltfTutorial/gltfTutorial_001_Introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[Table of Contents](README.md) | Next: [Basic glTF Structure](gltfTutorial_002_BasicGltfStructure.md)





# Introduction to glTF using WebGL

An increasing number of applications and services are based on 3D content. Online shops offer product configurators with a 3D preview. Museums digitize their artifacts with 3D scans and allow visitors to explore their collections in virtual galleries. City planners use 3D city models for planning and information visualization. Educators create interactive, animated 3D models of the human body. Many of these applications run directly in the web browser, which is possible because all modern browsers support efficient rendering with WebGL.

<p align="center">
<img src="images/applications.png" /><br>
<a name="applications-png"></a>Image 1a: Screenshots of various websites and applications showing 3D models.
</p>

Demand for 3D content in various applications is constantly increasing. In many cases, the 3D content has to be transferred over the web, and it has to be rendered efficiently on the client side. But until now, there has been a gap between the 3D content creation and efficient rendering of that 3D content in the runtime applications.


## 3D content pipelines

3D content that is rendered in client applications comes from different sources and is stored in different file formats. The [list of 3D graphics file formats on Wikipedia](https://en.wikipedia.org/wiki/List_of_file_formats#3D_graphics) shows an overwhelming number, with more than 70 different file formats for 3D data, serving different purposes and application cases.

For example, raw 3D data may be obtained with a 3D scanner. These scanners usually provide the geometry data of a single object, which is stored in [OBJ](https://en.wikipedia.org/wiki/Wavefront_.obj_file), [PLY](https://en.wikipedia.org/wiki/PLY_(file_format)), or [STL](https://en.wikipedia.org/wiki/STL_(file_format)) files. These file formats do not contain information about the scene structure or how the objects should be rendered.

More sophisticated 3D scenes can be created with authoring tools. These tools allow one to edit the structure of the scene, the light setup, cameras, animations, and, of course, the 3D geometry of the objects that appear in the scene. Applications store this information in their own, custom file formats. For example, [Blender](https://www.blender.org/) stores the scenes in `.blend` files, [LightWave3D](https://www.lightwave3d.com/) uses the `.lws` file format, [3ds Max](http://www.autodesk.com/3dsmax) uses the `.max` file format, and [Maya](http://www.autodesk.com/maya) uses `.ma` files.

In order to render such 3D content, the runtime application must be able to read different input file formats. The scene structure has to be parsed, and the 3D geometry data has to be converted into the format required by the graphics API. The 3D data has to be transferred to the graphics card memory, and then the rendering process can be described with sequences of graphics API calls. Thus, each runtime application has to create importers, loaders, or converters for all file formats that it will support, as shown in Image 1b.

<p align="center">
<img src="images/contentPipeline.png" /><br>
<a name="contentPipeline-png"></a>Image 1b: The 3D content pipeline today.
</p>


## glTF: A transmission format for 3D scenes

The goal of glTF is to define a standard for representing 3D content, in a form that is suitable for use in runtime applications. The existing file formats are not appropriate for this use case: some of do not contain any scene information, but only geometry data; others have been designed for exchanging data between authoring applications, and their main goal is to retain as much information about the 3D scene as possible, resulting in files that are usually large, complex, and hard to parse. Additionally, the geometry data may have to be preprocessed so that it can be rendered with the client application.

None of the existing file formats were designed for the use case of efficiently transferring 3D scenes over the web and rendering them as efficiently as possible. But glTF is not "yet another file format." It is the definition of a *transmission* format for 3D scenes:

- The scene structure is described with JSON, which is very compact and can easily be parsed.
- The 3D data of the objects are stored in a form that can be directly used by the common graphics APIs, so there is no overhead for decoding or pre-processing the 3D data.

Different content creation tools may now provide 3D content in the glTF format. And an increasing number of client applications are able to consume and render glTF. Some of these applications are shown in [Image 1b](#applications-png). So glTF may help to bridge the gap between content creation and rendering, as shown in Image 1c.

<p align="center">
<img src="images/contentPipelineWithGltf.png" /><br>
<a name="contentPipelineWithGltf-png"></a>Image 1c: The 3D content pipeline with glTF.
</p>

An increasing number of content creation tools will be able to provide glTF directly. Alternatively, other file formats can be used to create glTF assets, using one of the open-source conversion utilities listed in the [Khronos glTF repository](https://github.com/KhronosGroup/glTF#converters). For example, nearly all authoring applications can export their scenes in the [COLLADA](https://www.khronos.org/collada/) format. So the [COLLADA2GLTF](https://github.com/KhronosGroup/glTF/tree/master/COLLADA2GLTF) tool can be used to convert scenes and models from these authoring applications to glTF. `OBJ` files may be converted to glTF using [obj2gltf](https://github.com/AnalyticalGraphicsInc/obj2gltf). For other file formats, custom converters can be used to create glTF assets, thus making the 3D content available for a broad range of runtime applications.


[Table of Contents](README.md) | Next: [Basic glTF Structure](gltfTutorial_002_BasicGltfStructure.md)
127 changes: 127 additions & 0 deletions gltfTutorial/gltfTutorial_002_BasicGltfStructure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
Previous: [Introduction](gltfTutorial_001_Introduction.md) | [Table of Contents](README.md) | Next: [A Minimal glTF File](gltfTutorial_003_MinimalGltfFile.md)


# The Basic Structure of glTF

The core of glTF is a JSON file. This file describes the whole contents of the 3D scene. It consists of a description of the scene structure itself, which is given by a hierarchy of nodes that define a scene graph. The 3D objects that appear in the scene are defined using meshes that are attached to the nodes. Materials define the appearance of the objects. Animations describe how the 3D objects are transformed (e.g., rotated to translated) over time, and skins define how the geometry of the objects is deformed based on a skeleton pose. Cameras describe the view configuration for the renderer.

## The JSON structure

The scene objects are stored in dictionaries in the JSON file. They can be accessed using an ID, which is the key of the dictionary:

```javascript
"meshes": {
"FirstExampleMeshId": { ... },
"SecondExampleMeshId": { ... },
"ThirdExampleMeshId": { ... }
}
```


These IDs are also used to define the *relationships* between the objects. The example above defines multiple meshes, and a node may refer to one of these meshes, using the mesh ID, to indicate that the mesh should be attached to this node:

```javascript
"nodes:" {
"FirstExampleNodeId": {
"meshes": [
"FirstExampleMeshId"
]
},
...
}
```

The following image (adapted from the [glTF concepts section](https://github.com/KhronosGroup/glTF/tree/master/specification#concepts)) gives an overview of the top-level elements of a glTF:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"elements of a glTF": is there a word missing here? Maybe "elements of a glTF asset"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm ... it could be "glTF asset", but the asset is more than just the JSON. So I think I'll change this to something like "top-level elements of the JSON part of a glTF asset"


<p align="center">
<img src="images/gltfJsonStructure.png" /><br>
<a name="gltfJsonStructure-png"></a>Image 2a: The glTF JSON structure
</p>


These elements are summarized here quickly, to give an overview, with links to the respective sections of the glTF specification. More detailed explanations of the relationships between these elements will be given in the following sections.

- The [`scene`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-scene) is the entry point for the description of the scene that is stored in the glTF. It refers to the `node`s that define the scene graph.
- The [`node`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-node) is one node in the scene graph hierarchy. It can contain a transformation (e.g., rotation or translation), and it may refer to further (child) nodes. Additionally, it may refer to `mesh` or `camera` instances that are "attached" to the node, or to a `skin` that describes a mesh deformation.
- The [`camera`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-camera) defines the view configuration for rendering the scene.
- A [`mesh`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-mesh) describes a geometric object that appears in the scene. It refers to `accessor` objects that are used for accessing the actual geometry data, and to `material`s that define the appearance of the object when it is rendered.
- The [`skin`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-skin) defines parameters that are required for vertex skinning, which allows the deformation of a mesh based on the pose of a virtual character. The values of these parameters are obtained from an `accessor`.
- An [`animation`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-animation) describes how transformations of certain nodes (e.g., rotation or translation) change over time.
- The [`accessor`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-accessor) is used as an abstract source of arbitrary data. It is used by the `mesh`, `skin`, and `animation`, and provides the geometry data, the skinning parameters and the time-dependent animation values. It refers to a [`bufferView`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-bufferView), which is a part of a [`buffer`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-buffer) that contains the actual raw binary data.
- The [`material`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-material) contains the parameters that define the appearance of an object. It can refer to a `texture` that will be applied to the object, and it refers to the `technique` for rendering an object with the given material. The [`technique`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-technique) refers to a [`program`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-program) that contains the GLSL vertex and fragment [`shader`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-shader)s that are used for rendering the object.
- The [`texture`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-texture) is defined by a [`sampler`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-sampler) and an [`image`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-image). The `sampler` defines how the texture `image` should be placed on the object.




## References to external data

The binary data, like geometry and textures of the 3D objects, are usually not contained in the JSON file. Instead, they are stored in dedicated files, and the JSON part only contains links to these files. This allows the binary data to be stored in a form that is very compact and can efficiently be transferred over the web. Additionally, the data can be stored in a format that can be used directly in the renderer, without having to parse, decode, or preprocess the data.

<p align="center">
<img src="images/gltfStructure.png" /><br>
<a name="gltfStructure-png"></a>Image 2b: The glTF structure
</p>

As shown in the image above, there are three types of objects that may contain such links to external resources, namely `buffers`, `images`, and `shaders`. These objects will later be explained in more detail.



## Reading and managing external data

Reading and processing a glTF asset starts with parsing the JSON structure. After the structure has been parsed, the `buffers`, `images`, and `shaders` are available as dictionaries. The keys of these dictionaries are IDs, and the values are the [`buffer`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-buffer), [`image`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-image), and [`shader`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-shader) objects, respectively.

Each of these objects contains links, in the form of URIs. For further processing, the data that is referred to by these URIs has to be read into memory. Usually it will be stored in a dictionary (or map) data structure, so that it may be looked up using the ID of the object that it belongs to.


## Binary data in `buffers`

A [`buffer`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-buffer) contains a URI that points to a file containing the raw, binary buffer data:

```javascript
"buffer01": {
"byteLength": 12352,
"type": "arraybuffer",
"uri": "buffer01.bin"
}
```

This binary data is just a raw block of memory that is read from the URI of the `buffer`, with no inherent meaning or structure. The [Buffers, BufferViews, and Accessors](gltfTutorial_005_BuffersBufferViewsAccessors.md) section will show how this raw data is extended with information about data types and the data layout. With this information, one part of the data may, for example, be interpreted as animation data, and another part may be interpreted as geometry data. Storing the data in a binary form allows it to be transferred over the web much more efficiently than in the JSON format, and the binary data can be passed directly to the renderer without having to decode or pre-process it.



## Image data in `images`

An [`image`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-image) refers to an external image file that can be used as the texture of a rendered object:

```javascript
"image01": {
"uri": "image01.png"
}
```

The reference is given as a URI that usually points to a PNG or JPG file. These formats significantly reduce the size of the files, so that they may efficiently be transferred over the web.




## GLSL shader data in `shaders`

A GLSL vertex or fragment [`shader`](https://github.com/KhronosGroup/glTF/tree/master/specification#reference-shader) that should be used for rendering the 3D objects contains a URI that points to a file containing the shader source code:

```javascript
"fragmentShader01": {
"type": 35632,
"uri": "fragmentShader01.glsl"
}
```

The shader source code is stored as plain text so that it can be directly compiled with WebGL, OpenGL, or any other graphics API that is capable of interpreting GLSL shaders.


## Binary data in data URIs

Usually, the URIs that are contained in the `buffer`, `image`, and `shader` objects will point to a file that contains the actual data. As an alternative, the data may be *embedded* into the JSON, in binary format, by using a [data URI](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs).


Previous: [Introduction](gltfTutorial_001_Introduction.md) | [Table of Contents](README.md) | Next: [A Minimal glTF File](gltfTutorial_003_MinimalGltfFile.md)
Loading