Skip to content
Merged
Changes from 1 commit
Commits
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
93 changes: 75 additions & 18 deletions specification/2.0/Specification.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -525,53 +525,110 @@ This is typically achieved with algorithms like Grisu2 used by common JSON libra
[[uris]]
== URIs

glTF assets use <<uri,URIs>> or <<iri,IRIs>> to reference buffers and image resources. Assets **MAY** contain at least these two URI types:
[[uris-overview]]
=== Overview

glTF assets use <<iri,IRI-references>> to refer to external resources or embed resources directly. Only two kinds of IRI-references are in scope of this specification: `data:` URLs and relative paths without parameters.
Comment thread
lexaknyazev marked this conversation as resolved.

[NOTE]
.Implementation Note
====
This allows the application to decide the best approach for delivery: if different assets share many of the same resources, separate files may be preferred to reduce the total amount of data requested. With separate files, applications may progressively load data and do not need to load data for parts of a asset that are not visible. If an application cares more about single-file deployment, embedding data may be preferred even though it increases the overall size due to base64 encoding and does not support progressive or on-demand loading. Alternatively, an asset could use the GLB container to store JSON and binary data in one file without base64 encoding. See <<glb-file-format-specification,GLB File Format Specification>> for details.
====

Client implementations **MAY** optionally support additional reference types, such as `https://` or `file://` schemes, authorities, absolute paths, and query or fragment parameters. Assets containing such references would be less portable and are out of scope of this specification.

The following steps are **RECOMMENDED** for all IRI-reference strings when loading glTF assets. These adjustments would make no difference for valid IRI-references but they could fix strings that slightly deviate from the standard syntax.

- Removing all leading and trailing space characters (`U+0020`).
- Removing all leading and trailing characters with code points from `U+0000` to `U+001F` inclusive.
- Removing all tab (`U+0009`), line feed (`U+000A`), and carriage return (`U+000D`) characters.
Comment thread
lexaknyazev marked this conversation as resolved.

[[uris-data]]
=== Data URLs
Comment thread
lexaknyazev marked this conversation as resolved.

A resource **MAY** be embedded directly in glTF JSON by being represented as a URL with the `data:` scheme (<<data-uri,RFC 2397>>). The URL's `mediatype` field **MUST** match its content.

- **Data URIs** that embed binary resources in the glTF JSON as defined by the <<data-uri,RFC 2397>>. The Data URI's `mediatype` field **MUST** match the encoded content.
+
[NOTE]
.Implementation Note
====
Base64 encoding used in Data URI increases the payload's byte length by 33%.
An omitted `mediatype` field defaults to `text/plain;charset=US-ASCII`, which is generally not used for external resources used in glTF.
====

- **Relative paths** -- `path-noscheme` or `ipath-noscheme` as defined by <<uri,RFC 3986>>, Section 4.2 or <<iri,RFC 3987>>, Section 2.2 -- without scheme, authority, or parameters. Reserved characters (as defined by <<uri,RFC 3986>>, Section 2.2. and <<iri,RFC 3987>>, Section 2.2.) **MUST** be percent-encoded.
Binary resources encoded in data URLs **SHOULD** use the base64 encoding. Base64 encoding increases the byte length by 33% compared to the original binary resource size, so data URLs **SHOULD NOT** be used for binary resources larger than what would be reasonable to be embedded in JSON.

Paths with non-ASCII characters **MAY** be written as-is, with JSON string escaping, or with percent-encoding; all these options are valid. For example, the following three paths point to the same resource:
[NOTE]
.Example
====
In the following example, a very small glTF buffer is directly embedded in glTF JSON. Although the URL string is notably larger than the actual buffer size, this layout reduces the total number of files required to represent the asset while keeping the glTF JSON easy to edit manually.

[source,json]
----
{
"images": [
{
"uri": "grande_sphère.png"
},
{
"uri": "grande_sph\u00E8re.png"
},
"buffers": [
{
"uri": "grande_sph%C3%A8re.png"
"byteLength": 8,
"uri": "data:application/gltf-buffer;base64,AAECAwQFBgc="
}
]
}
----
====

Client implementations **MAY** optionally support additional URI components. For example `http://` or `file://` schemes, authorities, hostnames, absolute paths, and query or fragment parameters. Assets containing these additional URI components would be less portable.
[[uris-paths]]
=== Relative Paths

Relative paths represent external resource locations relative to the location of the glTF asset.

Relative paths **SHOULD** adhere to the `ipath-noscheme` syntax as defined in <<iri,RFC 3987>>, Section 2.2.

[NOTE]
.Implementation Note
====
This allows the application to decide the best approach for delivery: if different assets share many of the same geometries, animations, or textures, separate files may be preferred to reduce the total amount of data requested. With separate files, applications may progressively load data and do not need to load data for parts of a model that are not visible. If an application cares more about single-file deployment, embedding data may be preferred even though it increases the overall size due to base64 encoding and does not support progressive or on-demand loading. Alternatively, an asset could use the GLB container to store JSON and binary data in one file without base64 encoding. See <<glb-file-format-specification,GLB File Format Specification>> for details.
For maximum compatibility, implementations writing glTF assets can choose to percent-encode non-ASCII characters and thus adhere to the `path-noscheme` syntax as defined by <<uri,RFC 3986>>, Section 3.3.
====

[NOTE]
.Example
====
The following two snippets refer to the same external resource. The first example uses an IRI-reference (RFC 3987), while the second example uses a URI-reference (RFC 3986).

[source,json]
----
{
"images": [
{
"uri": "grande_sphère.png"
}
]
}
----

[source,json]
----
{
"images": [
{
"uri": "grande_sph%C3%A8re.png"
}
]
}
----
====

URIs **SHOULD** undergo syntax-based normalization as defined by <<uri,RFC 3986>>, Section 6.2.2, <<iri,RFC 3987>>, Section 5.3.2, and applicable schema rules (e.g., <<http,RFC 7230>>, Section 2.7.3 for HTTP) on export and/or import.
Relative paths **SHOULD** undergo syntax-based normalization as defined by <<iri,RFC 3987>>, Section 5.3.2.

[NOTE]
.Implementation Note
====
While the specification does not explicitly disallow non-normalized URIs, their use may be unsupported or lead to unwanted side-effects -- such as security warnings or cache misses -- on some platforms.
While the specification does not explicitly disallow non-normalized paths, their use may be unsupported or lead to unwanted side-effects -- such as security warnings or cache misses -- on some platforms.
====

The following steps are **RECOMMENDED** after the aforementioned invalid character removals before normalization and percent-decoding when loading glTF assets. These adjustments would make no difference for references that strictly adhere to the `ipath-noscheme` or `path-noscheme` syntaxes but could fix strings that slightly deviate from them.

- Replacing all reverse solidus (`U+005C`) characters with solidus (`U+002F`) characters.
- Percent-encoding all characters from the following list: characters with code points from `U+0000` to `U+001F` inclusive, space (`U+0020`), quotation mark (`U+0022`), less-than sign (`U+003C`), greater-than sign (`U+003E`), left square bracket (`U+005B`), right square bracket (`U+005D`), circumflex accent (`U+005E`), grave accent (`U+0060`), left curly bracket (`U+007B`), vertical bar (`U+007C`), right curly bracket (`U+007D`), and <delete> (`U+007F`).


[[concepts]]
= Concepts
Expand Down
Loading