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

Quantized mesh loader #729

Merged
merged 28 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
19 changes: 19 additions & 0 deletions modules/quantized-mesh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @loaders.gl/quantized-mesh

[loaders.gl](https://loaders.gl/docs) is a collection of framework independent 3D and geospatial parsers and encoders.

This module reconstructs mesh surfaces from the [quantized mesh](https://github.com/CesiumGS/quantized-mesh) format.

For documentation please visit the [website](https://loaders.gl).

`@loaders.gl/terrain` uses [`quantized-mesh-decoder`](https://github.com/heremaps/quantized-mesh-decoder) to decode quantized mesh.

MIT License
kylebarron marked this conversation as resolved.
Show resolved Hide resolved

Copyright (C) 2018-2019 HERE Europe B.V.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 changes: 22 additions & 0 deletions modules/quantized-mesh/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Overview

The `@loaders.gl/quantized-mesh` module reconstructs mesh surfaces from the [quantized mesh](https://github.com/CesiumGS/quantized-mesh) format.

## Installation

```bash
npm install @loaders.gl/quantized-mesh
npm install @loaders.gl/core
```

## Attribution

`@loaders.gl/terrain` uses [`quantized-mesh-decoder`](https://github.com/heremaps/quantized-mesh-decoder) to decode quantized mesh.

Copyright (C) 2018-2019 HERE Europe B.V.
kylebarron marked this conversation as resolved.
Show resolved Hide resolved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73 changes: 73 additions & 0 deletions modules/quantized-mesh/docs/api-reference/quantized-mesh-loader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# TerrainLoader
kylebarron marked this conversation as resolved.
Show resolved Hide resolved

The `TerrainLoader` reconstructs mesh surfaces from height map images, e.g. [Mapzen Terrain Tiles](https://github.com/tilezen/joerd/blob/master/docs/formats.md), which encodes elevation into R,G,B values.

| Loader | Characteristic |
| --------------------- | --------------------------------------------- |
| File Extension | `.png`, `.pngraw` |
kylebarron marked this conversation as resolved.
Show resolved Hide resolved
| File Type | Binary |
| File Format | Encoded height map |
| Data Format | [Mesh](/docs/specifications/category-mesh.md) |
| Decoder Type | Asynchronous |
| Worker Thread Support | Yes |
| Streaming Support | No |

## Usage

```js
import {ImageLoader} from '@loaders.gl/images';
import {TerrainLoader} from '@loaders.gl/terrain';
import {load, registerLoaders} from '@loaders.gl/core';

registerLoaders(ImageLoader);

const data = await load(url, TerrainLoader, options);
```

## Options

| Option | Type | Default | Description |
| -------------------------- | ------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `terrain.meshMaxError` | number | `10` | Mesh error in meters. The output mesh is in higher resolution (more vertices) if the error is smaller. |
| `terrain.bounds` | array<number> | `null` | Bounds of the image to fit x,y coordinates into. In `[minX, minY, maxX, maxY]`. If not supplied, x and y are in pixels relative to the image. |
| `terrain.elevationDecoder` | object | See below | See below |

### elevationDecoder

Parameters used to convert a pixel to elevation in meters.
An object containing the following fields:

- `rScale`: Multiplier of the red channel.
- `gScale`: Multiplier of the green channel.
- `bScale`: Multiplier of the blue channel.
- `offset`: Translation of the sum.

Each color channel (r, g, and b) is a number between `[0, 255]`.

For example, the Mapbox terrain service's elevation is [encoded as follows](https://docs.mapbox.com/help/troubleshooting/access-elevation-data/#decode-data):

```
height = -10000 + ((R * 256 * 256 + G * 256 + B) * 0.1)
```

The corresponding `elevationDecoder` is:

```
{
"rScale": 6553.6,
"gScale": 25.6,
"bScale": 0.1,
"offset": -10000
}
```

The default value of `elevationDecoder` decodes a grayscale image:

```
{
"rScale": 1,
"gScale": 0,
"gScale": 0,
"offset": 0
}
```
39 changes: 39 additions & 0 deletions modules/quantized-mesh/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@loaders.gl/quantized-mesh",
"version": "2.1.0-beta.2",
"description": "Framework-independent loader for quantized mesh",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/visgl/loaders.gl"
},
"keywords": [
"webgl",
"loader",
"3d",
"mesh",
"point cloud",
"OBJ"
],
"main": "dist/es5/index.js",
"module": "dist/esm/index.js",
"esnext": "dist/es6/index.js",
"sideEffects": false,
"files": [
"src",
"dist",
"README.md"
],
"scripts": {
"pre-build": "npm run build-worker && npm run build-bundle && npm run build-bundle -- --env.dev",
"build-bundle": "webpack --display=minimal --config ../../scripts/bundle.config.js",
"build-worker": "webpack --entry ./src/quantized-mesh-loader.worker.js --output ./dist/quantized-mesh-loader.worker.js --config ../../scripts/worker-webpack-config.js"
},
"dependencies": {
"@babel/runtime": "^7.3.1",
"@loaders.gl/loader-utils": "^2.1.1"
}
}
8 changes: 8 additions & 0 deletions modules/quantized-mesh/src/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* global window, global */
const moduleExports = require('./index');

const _global = typeof window === 'undefined' ? global : window;
// @ts-ignore
_global.loaders = _global.loaders || {};
// @ts-ignore
module.exports = Object.assign(_global.loaders, moduleExports);
1 change: 1 addition & 0 deletions modules/quantized-mesh/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {QuantizedMeshLoader, QuantizedMeshWorkerLoader} from './quantized-mesh-loader';
Loading