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

GLTF Draco Integration Improvements #113

Merged
merged 4 commits into from Mar 7, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+325 −488
Diff settings

Always

Just for now

Next

glTF Draco decode improvements

  • Loading branch information...
ibgreen committed Mar 6, 2019
commit c2e6a5ee55f1840ea9ba71ffa4b1f2a93f231517
@@ -58,7 +58,7 @@ Stores the supplied `data` in the given top-level field given by `key`.

The data object will be encoded as JSON before being stored. By default, any typed arrays in the data object will be removed fromn the data payload and packed in the binary chunk.

* `packOptions.nopack` - Don't pack any typed arrays
* `packOptions.packTypedArrays` - Packs typed arrays into the binary chunk
* `packOptions.flattenArrays` - Flatten "nested" standard JavaScript arrays into typed arrays (and then pack them into the binary chunk).


@@ -66,23 +66,23 @@ A version of `encode` that returns the final arrayBuffer together with the gener

Stores the supplied `data` in the given top-level field given by `key`.

* `options.nopack` - Don't pack any typed arrays
* `options.packTypedArrays` - Packs typed arrays into the binary chunk
* `options.flattenArrays` - Pack (and flatten nested) standard JavaScript arrays into the binary chunk.


### setExtraData(key : String, data : any [, options: Object])

Populates (merges into) the top-level glTF `extras` field, which the glTF specification reserves for application specific data.

* `options.nopack` - Don't pack any typed arrays
* `options.packTypedArrays` - Packs typed arrays into the binary chunk
* `options.flattenArrays` - Pack (and flatten nested) standard JavaScript arrays into the binary chunk.


### addExtension(extensionName : String, extension : any [, options: Object])

Adds a top-level glTF extension object, and marks it as used.

* `options.nopack` - Don't pack any typed arrays
* `options.packTypedArrays` - Packs typed arrays into the binary chunk
* `options.flattenArrays` - Pack (and flatten nested) standard JavaScript arrays into the binary chunk.


@@ -92,7 +92,7 @@ Adds a top-level glTF extension object, and marks it as used and required.

Note: If possible, use `addExtension` instead of `addRequiredExtension`. It is recommended to avoid using required extensions if possible, as they can reduce the ability to use glTF tools on the resulting file.

* `options.nopack` - Don't pack any typed arrays
* `options.packTypedArrays` - Packs typed arrays into the binary chunk
* `options.flattenArrays` - Pack (and flatten nested) standard JavaScript arrays into the binary chunk.


@@ -1,30 +1,25 @@
# glTF Extensions

The glTF classes in `@loaders.gl/gltf` provide support selected glTF extensions.
Arbitrary glTF extensions can be present in glTF files, and will remain present in the parsed JSON as you would expect. Such extensions can supported by applications by inspecting the `extensions` fields inside glTF objects, and it is up to each application to handle or ignore them.

## Official Extensions

### KHR_draco_mesh_compression
Many glTF extensions affect e.g. rendering which is outside of the scope of loaders.gl, however in a few cases it is possible to provide support for extensions directly during loading. This article describes glTF extensions that are fully or partially processed by the `@loaders.gl/gltf` classes.

> Support for this extension is in progress but not yet fully implemented.

[KHR_draco_mesh_compression](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression) will be supported soon.
## Official Extensions

### KHR_draco_mesh_compression

## Custom Extensions
Description: [KHR_draco_mesh_compression](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression).

> A second round of review should be done to ensure that the official extension cannot cover these use cases.
This extension is partially implemented. Meshes can be compressed as they are added to the `GLTFBuilder` and decompressed by the `GLTFParser`.

### UBER_draco_mesh_compression

Similar to `KHR_draco_mesh_compression`, but does not contain any accessors and does not support any fallback or non-compressed accessors/attributes. The primitive's accessors field will be populated after decompression.

## Custom Extensions

### UBER_draco_point_cloud_compression

Similar to `KHR_draco_mesh_compression`, but does not contain any accessors and does not support any fallback or non-compressed accessors/attributes. The primitive's accessors field will be populated after decompression.

Description: Similar to `KHR_draco_mesh_compression`, but does not contain any accessors and does not support any fallback or non-compressed accessors/attributes. The primitive's accessors field will be populated after decompression.

## Remarks
Point clouds can be compressed as they are added to the `GLTFBuilder` and decompressed by the `GLTFParser`.

Additional extensions can be supported by the application by inspecting the `extensions` fields inside glTF objects. This document only documents the extensions that are fully or partially supported by `@loaders.gl/gltf` classes.
@@ -1,15 +1,15 @@
# GLTFLoader (@loaders.gl/gltf)

Parses a glTF file into a hirearchical scenegraph description that can be used to instantiate an actual Scenegraph in most WebGL libraries.
Parses a glTF file into a hirearchical scenegraph description that can be used to instantiate an actual Scenegraph in most WebGL libraries. Can load both binary `.glb` files and JSON `.gltf` files.

| Loader | Characteristic |
| --- | --- |
| File Extension | `.glb`,`.gltf` |
| File Type | Binary |
| File Extensions | `.glb`,`.gltf` |
| File Types | Binary/JSON/Linked Assets |
| File Format | [glTF](https://github.com/KhronosGroup/glTF/tree/master/specification/2.0) |
| Parser Category | glTF Scenegraph |
| Format Category | glTF Scenegraph |
| Parser Type | Asynchronous (Synchronous w/ limited functionality) |
| Worker Thread Support | Not yet |
| Worker Thread Support | No |
| Streaming Support | No |


@@ -21,33 +21,40 @@ import {GLTFLoader} from '@loaders.gl/gltf';
const gltf = await loadFile(url, GLTFLoader);
```

To decompress Draco compressed meshes:
```
import {loadFile} from '@loaders.gl/core';
import {GLTFLoader} from '@loaders.gl/gltf';
import {DracoDecoder} from '@loaders.gl/draco';
const gltf = loadFile(url, GLTFLoader, {DracoDecoder, decompress: true});
```

## Options

* `DracoEncoder` - supply this to enable decoding of Draco compressed meshes. `import {DracoEncoder} from '@loaders.gl/draco'`


## Structure of Loaded Data

Returns a JSON object with "embedded" binary data in the form of typed javascript arrays.


## Attributions
## Options

The `GLTFLoader` was written specifically for loaders.gl.
| Option | Default | Description |
| --- | --- | --- |
| `fetchLinkedResources` | `true` | Fetch any linked .BIN files, decode base64 encoded URIS. Only supported in asynchronous parsing. |
| `fetch` | `fetchFile` | Function used to fetch linked resources |
| `decompress` | `true` | Decompress Draco compressed meshes (if DracoDecoder available) |
| `DracoDecoder` | `null` | Supply to enable decoding of Draco compressed meshes. |
| `postProcess` | `false` | Perform additional post processing to simplify use in WebGL libraries |
| `createImages` | `false` | Create image objects from loaded image data |


## Additional Information
## Structure of Loaded Data

Can load both binary `.glb` files and JSON `.gltf` files.
Returns a JSON object with "embedded" binary data in the form of typed javascript arrays.

When parsed asynchronously (not using `loadSync` or `parseSync`):
* linked binary resources will be loaded and resolved (if url is available).
* base64 encoded binary data inside the JSON payload will be decoded

To support decoding of Draco compressed meshes:
```
import {loadFile} from '@loaders.gl/core';
import {GLTFLoader} from '@loaders.gl/gltf';
import {DracoDecoder} from '@loaders.gl/draco';
const gltf = loadFile(url, GLTFLoader, {DracoDecoder});
```

## Attributions

The `GLTFLoader` was developed for loaders.gl.
@@ -1,16 +1,36 @@
# GLTFWriter

The `GLTFWriter` is the descriptor object for the GLB encoder.
> `GLTFWriter` is still a work-in-progress. In the mean time, it is strongly recommended to directly use the `GLTFBuilder` class.
The `GLTFWriter` is a writer for glTF scenegraphs.

| Writer | Characteristic |
| --- | --- |
| File Extensions | `.glb`,`.gltf` |
| File Types | Binary/JSON/Linked Assets |
| File Format | [glTF](https://github.com/KhronosGroup/glTF/tree/master/specification/2.0) |
| Format Category | glTF Scenegraph |
| Writer Type | Asynchronous (Synchronous w/ limited functionality) |
| Worker Thread Support | No |
| Streaming Support | No |


## Usage

```
import {GLTFWriter} from `@loaders.gl/gltf';
new GLTFWriter();
import {saveFile} from `@loaders.gl/core';
const gltf = ...;
saveFile(gltf, GLTFWriter);
```

## Options

* `packTypedArrays` - Packs typed arrays
* `DracoEncoder` - To enable DRACO encoding, the application needs to import and supply the `DracoEncoder` class.
* `DracoDecoder` - To enable DRACO encoding, the application needs to import and supply the `DracoDecoder` class.


## Remarks
## Attributions

* To build a binary GLB file that can be saved with the `GLTFWriter`, use the `GLTFBuilder` class.
The `GLTFWriter` was developed for loaders.gl.
@@ -8,8 +8,9 @@ This module is currently in unofficial "soft pre-release" stage. You are welcome
## v0.8

* `fetchFile` - New function supports fetch API under browser and Node.js
* `glTFLoader` - improvements, supports async loading of linked resources and base64 encoded buffer.
* `glTFParser` - API changes: `parse()` is now async and supports linked resource loading, and a separate `parseSync()` method is provided for applications that depend on the old sync behavior and do not need the new features.
* `GLTFLoader` - improvements, supports async loading of linked resources and base64 encoded buffer.
* `GLTFParser` - API changes: `parse()` is now async and supports linked resource loading, and a separate `parseSync()` method is provided for applications that depend on the old sync behavior and do not need the new features.
* `GLBBuilder`,`GLTFBuilder` - `nopack` option renamed to `packTypedArrays`. It must now explicitly be set to `true` to enable packing.


## v0.7
@@ -1,6 +1,6 @@
{
"lerna": "2.9.1",
"version": "0.7.2",
"version": "0.8.0",

This comment has been minimized.

Copy link
@georgios-uber

georgios-uber Mar 7, 2019

Collaborator

This will be done automatically when you publish

This comment has been minimized.

Copy link
@ibgreen

ibgreen Mar 7, 2019

Author Contributor

I guess our publish script would need to pass a parameter I am not quite familiar with how that works.

"commands": {
"publish": {},
"bootstrap": {}
@@ -44,7 +44,7 @@ function dumpFile(filename) {

const arrayBuffer = toArrayBuffer(binary);

const data = new GLBParser().parse(arrayBuffer, {ignoreMagic: true}).getJSON();
const data = new GLBParser().parseSync(arrayBuffer, {ignoreMagic: true}).getJSON();

if (options.dumpGLTF) {
dumpGLTFScenes(data);
@@ -68,7 +68,7 @@ export default class GLBBuilder {
// Add an extra application-defined key to the top-level data structure
// By default packs JSON by extracting binary data and replacing it with JSON pointers
addApplicationData(key, data, packOptions = {}) {
const jsonData = packOptions.nopack ? data : packBinaryJson(data, this, packOptions);
const jsonData = packOptions.packTypedArrays ? packBinaryJson(data, this, packOptions) : data;
this.json[key] = jsonData;
return this;
}
@@ -7,7 +7,7 @@ import {
ATTRIBUTE_TYPE_TO_COMPONENTS,
ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE,
ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY
} from '../utils/gltf-type-utils';
} from './gltf-types';

const MAGIC_glTF = 0x676c5446; // glTF in Big-Endian ASCII

@@ -0,0 +1,31 @@
// TODO - Remove: glTF constants should not be know to the GLB layer
This conversation was marked as resolved by ibgreen

This comment has been minimized.

Copy link
@georgios-uber

georgios-uber Mar 7, 2019

Collaborator

I think we should move this to luma.gl

Please remove if not referenced here.

This comment has been minimized.

Copy link
@ibgreen

ibgreen Mar 7, 2019

Author Contributor

I think we should move this to luma.gl. Please remove if not referenced here.

Problem is they are referenced here. I have a bullet in the GLTF Tracker to refactor this.


// glTF ACCESSOR CONSTANTS

export const ATTRIBUTE_TYPE_TO_COMPONENTS = {
SCALAR: 1,
VEC2: 2,
VEC3: 3,
VEC4: 4,
MAT2: 4,
MAT3: 9,
MAT4: 16
};

export const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
5120: 1,
5121: 1,
5122: 2,
5123: 2,
5125: 4,
5126: 4
};

export const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
5120: Int8Array,
5121: Uint8Array,
5122: Int16Array,
5123: Uint16Array,
5125: Uint32Array,
5126: Float32Array
};
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.