-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Arrow loaders for Pointcloud / Mesh formats (#3158)
- Loading branch information
Showing
29 changed files
with
344 additions
and
95 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import type {Format} from '@loaders.gl/loader-utils'; | ||
|
||
/** Comma-Separated Values */ | ||
export const CSVFormat = { | ||
id: 'csv', | ||
module: 'csv', | ||
name: 'CSV', | ||
extensions: ['csv', 'tsv', 'dsv'], | ||
mimeTypes: ['text/csv', 'text/tab-separated-values', 'text/dsv'], | ||
category: 'table' | ||
} as const satisfies Format; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import type {ArrowTable} from '@loaders.gl/schema'; | ||
import type {LoaderWithParser} from '@loaders.gl/loader-utils'; | ||
import type {DracoLoaderOptions} from './draco-loader'; | ||
import {DracoLoader} from './draco-loader'; | ||
import {convertMeshToTable} from '@loaders.gl/schema-utils'; | ||
|
||
/** | ||
* Loader for Draco3D compressed geometries | ||
*/ | ||
export const DracoArrowLoader = { | ||
...DracoLoader, | ||
dataType: null as unknown as ArrowTable, | ||
worker: false, | ||
parse | ||
} as const satisfies LoaderWithParser<ArrowTable, never, DracoLoaderOptions>; | ||
|
||
async function parse(arrayBuffer: ArrayBuffer, options?: DracoLoaderOptions): Promise<ArrowTable> { | ||
const mesh = await DracoLoader.parse(arrayBuffer, options); | ||
const arrowTable = convertMeshToTable(mesh, 'arrow-table'); | ||
return arrowTable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* eslint-disable max-len */ | ||
import test from 'tape-promise/tape'; | ||
import {validateLoader} from 'test/common/conformance'; | ||
|
||
import {DracoArrowLoader} from '@loaders.gl/draco'; | ||
import {setLoaderOptions, load} from '@loaders.gl/core'; | ||
import draco3d from 'draco3d'; | ||
|
||
const BUNNY_DRC_URL = '@loaders.gl/draco/test/data/bunny.drc'; | ||
const CESIUM_TILE_URL = '@loaders.gl/draco/test/data/cesium-tile.drc'; | ||
|
||
setLoaderOptions({ | ||
_workerType: 'test' | ||
}); | ||
|
||
test('DracoArrowLoader#loader conformance', (t) => { | ||
validateLoader(t, DracoArrowLoader, 'DracoArrowLoader'); | ||
t.end(); | ||
}); | ||
|
||
test('DracoArrowLoader#parse(mainthread)', async (t) => { | ||
const table = await load(BUNNY_DRC_URL, DracoArrowLoader, {worker: false}); | ||
// validateMeshCategoryData(t, data); | ||
const {data} = table; | ||
t.equal(data.numRows, 104502 / 3, 'number of rows is correct'); | ||
const positions = data.getChild('POSITION')!; | ||
t.ok(positions, 'POSITION attribute was found'); | ||
t.ok(data.schema, 'Has arrow-like schema'); | ||
t.end(); | ||
}); | ||
|
||
test('DracoArrowLoader#draco3d npm package', async (t) => { | ||
const table = await load(BUNNY_DRC_URL, DracoArrowLoader, { | ||
worker: false, | ||
modules: { | ||
draco3d | ||
} | ||
}); | ||
const {data} = table; | ||
// validateMeshCategoryData(t, data); | ||
t.ok(data.getChild('POSITION'), 'POSITION attribute was found'); | ||
t.end(); | ||
}); | ||
|
||
test('DracoArrowLoader#parse custom attributes(mainthread)', async (t) => { | ||
let table = await load(CESIUM_TILE_URL, DracoArrowLoader, { | ||
worker: false | ||
}); | ||
const {data} = table; | ||
t.equal( | ||
data.getChild('CUSTOM_ATTRIBUTE_2')?.data[0].length, | ||
173210, | ||
'Custom (Intensity) attribute was found' | ||
); | ||
t.equal( | ||
data.getChild('CUSTOM_ATTRIBUTE_3')?.data[0].length, | ||
173210, | ||
'Custom (Classification) attribute was found' | ||
); | ||
|
||
table = await load(CESIUM_TILE_URL, DracoArrowLoader, { | ||
worker: false, | ||
draco: { | ||
extraAttributes: { | ||
Intensity: 2, | ||
Classification: 3 | ||
} | ||
} | ||
}); | ||
t.equal( | ||
table.data.getChild('Intensity')?.data[0].length, | ||
173210, | ||
'Intensity attribute was found' | ||
); | ||
t.equal( | ||
table.data.getChild('Classification')?.data[0].length, | ||
173210, | ||
'Classification attribute was found' | ||
); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import type {Format} from '@loaders.gl/loader-utils'; | ||
|
||
/** flatgeobuf format */ | ||
export const FlatGeobufFormat = { | ||
id: 'flatgeobuf', | ||
name: 'FlatGeobuf', | ||
module: 'flatgeobuf', | ||
extensions: ['fgb'], | ||
mimeTypes: ['application/octet-stream'], | ||
category: 'geometry' | ||
} as const satisfies Format; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import type {Format} from '@loaders.gl/loader-utils'; | ||
|
||
export const GeoPackageFormat = { | ||
id: 'geopackage', | ||
name: 'GeoPackage', | ||
module: 'geopackage', | ||
extensions: ['gpkg'], | ||
mimeTypes: ['application/geopackage+sqlite3'], | ||
category: 'geometry' | ||
} as const satisfies Format; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import type {LoaderWithParser} from '@loaders.gl/loader-utils'; | ||
import type {ArrowTable} from '@loaders.gl/schema'; | ||
|
||
import {OBJLoaderOptions, OBJWorkerLoader} from './obj-loader'; | ||
import {convertMeshToTable} from '@loaders.gl/schema-utils'; | ||
import {parseOBJ} from './lib/parse-obj'; | ||
|
||
/** | ||
* Worker loader for OBJ - Point Cloud Data | ||
*/ | ||
export const OBJArrowLoader = { | ||
...OBJWorkerLoader, | ||
dataType: null as unknown as ArrowTable, | ||
batchType: null as never, | ||
worker: false, | ||
parse: async (arrayBuffer: ArrayBuffer) => { | ||
const text = new TextDecoder().decode(arrayBuffer); | ||
const mesh = parseOBJ(text); | ||
const arrowTable = convertMeshToTable(mesh, 'arrow-table'); | ||
return arrowTable; | ||
} | ||
} as const satisfies LoaderWithParser<ArrowTable, never, OBJLoaderOptions>; |
Oops, something went wrong.