Skip to content

Commit

Permalink
Merge branch 'master' into ib/batch-types
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen authored Sep 19, 2023
2 parents 5cf75f1 + fef5d92 commit 5fe2bae
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 135 deletions.
2 changes: 1 addition & 1 deletion modules/gltf/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type {
GLTF_EXT_feature_metadata_FeatureIdTextureAccessor
} from './lib/types/gltf-json-schema';

export type {GLTF_EXT_structural_metadata} from './lib/types/gltf-ext-structural-metadata-schema';
export type {GLTF_EXT_structural_metadata_GLTF} from './lib/types/gltf-ext-structural-metadata-schema';

export type {
GLTF_EXT_mesh_features,
Expand Down
2 changes: 2 additions & 0 deletions modules/gltf/src/lib/extensions/EXT_mesh_features.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// GLTF EXTENSION: EXT_mesh_features
// https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features
/* eslint-disable camelcase */
import type {GLTF, GLTFMeshPrimitive} from '../types/gltf-json-schema';
import {GLTFLoaderOptions} from '../../gltf-loader';
Expand Down
12 changes: 7 additions & 5 deletions modules/gltf/src/lib/extensions/EXT_structural_metadata.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// GLTF EXTENSION: EXT_structural_metadata
// https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata
/* eslint-disable camelcase */
import type {BigTypedArray, TypedArray} from '@loaders.gl/schema';
import type {GLTF, GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';
Expand All @@ -7,7 +9,7 @@ import type {
GLTF_EXT_structural_metadata_Enum,
GLTF_EXT_structural_metadata_EnumValue,
GLTF_EXT_structural_metadata_PropertyTable,
GLTF_EXT_structural_metadata,
GLTF_EXT_structural_metadata_GLTF,
GLTF_EXT_structural_metadata_PropertyTexture,
GLTF_EXT_structural_metadata_PropertyTable_Property,
GLTF_EXT_structural_metadata_Primitive
Expand Down Expand Up @@ -100,7 +102,7 @@ export function getPropertyTablePopulated(
scenegraph: GLTFScenegraph,
propertyTableIndex: number
): GLTF_EXT_structural_metadata_PropertyTable {
const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension(
const extension: GLTF_EXT_structural_metadata_GLTF | null = scenegraph.getExtension(
EXT_STRUCTURAL_METADATA_NAME
);
const propertyTable = extension?.propertyTables?.[propertyTableIndex];
Expand All @@ -119,7 +121,7 @@ export function getPropertyTablePopulated(
* @param options - loader options.
*/
function decodeExtStructuralMetadata(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void {
const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension(
const extension: GLTF_EXT_structural_metadata_GLTF | null = scenegraph.getExtension(
EXT_STRUCTURAL_METADATA_NAME
);
if (!extension?.schema) {
Expand Down Expand Up @@ -180,7 +182,7 @@ function processPrimitivePropertyTextures(
scenegraph: GLTFScenegraph,
propertyTextures: GLTF_EXT_structural_metadata_PropertyTexture[],
primitive: GLTFMeshPrimitive,
extension: GLTF_EXT_structural_metadata
extension: GLTF_EXT_structural_metadata_GLTF
): void {
if (!propertyTextures) {
return;
Expand Down Expand Up @@ -210,7 +212,7 @@ function processPrimitivePropertyTexture(
scenegraph: GLTFScenegraph,
propertyTexture: GLTF_EXT_structural_metadata_PropertyTexture,
primitive: GLTFMeshPrimitive,
extension: GLTF_EXT_structural_metadata
extension: GLTF_EXT_structural_metadata_GLTF
): void {
if (!propertyTexture.properties) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {GLTFTextureInfoMetadata} from './gltf-json-schema';
/**
* @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/glTF.EXT_structural_metadata.schema.json
*/
export type GLTF_EXT_structural_metadata = {
export type GLTF_EXT_structural_metadata_GLTF = {
/** An object defining classes and enums. */
schema?: GLTF_EXT_structural_metadata_Schema;
/** A uri to an external schema file. */
Expand Down
3 changes: 3 additions & 0 deletions modules/parquet/src/lib/geo/decode-geo-column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ function parseGeometry(geometry: string, columnMetadata: GeoColumnMetadata): Geo
wkb: {shape: 'geometry'}
}) as unknown as Geometry;
return geojson; // binaryGeometry ? binaryToGeometry(binaryGeometry) : null;
// const binaryGeometry = WKBLoader.parseSync?.(geometry);
// ts-ignore
// return binaryGeometry ? binaryToGeometry(binaryGeometry) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import type {NumericArray} from '@loaders.gl/loader-utils';
import type {
GLTF_EXT_feature_metadata_FeatureIdTexture,
GLTF_EXT_feature_metadata_GLTF,
GLTF_EXT_feature_metadata_Primitive,
GLTF_EXT_structural_metadata
GLTF_EXT_feature_metadata_Primitive
} from '@loaders.gl/gltf';

import type {GLTF_EXT_mesh_features} from '@loaders.gl/gltf';

import {TypedArray} from '@math.gl/core';
import {TextureImageProperties} from '../types';
import {emod} from '@loaders.gl/math';
import {EXT_STRUCTURAL_METADATA, EXT_MESH_FEATURES, EXT_FEATURE_METADATA} from '@loaders.gl/gltf';
import {EXT_MESH_FEATURES, EXT_FEATURE_METADATA} from '@loaders.gl/gltf';
import {Tiles3DTileContent} from '@loaders.gl/3d-tiles';

/**
Expand Down Expand Up @@ -75,12 +74,6 @@ export function handleBatchIdsExtensions(
);
case EXT_MESH_FEATURES:
return handleExtMeshFeaturesExtension(attributes, extensionData as GLTF_EXT_mesh_features);
case EXT_STRUCTURAL_METADATA:
return handleExtStructuralMetadataExtension(
attributes,
extensionData as GLTF_EXT_structural_metadata
);

default:
return [];
}
Expand All @@ -89,23 +82,6 @@ export function handleBatchIdsExtensions(
return [];
}

function handleExtStructuralMetadataExtension(
attributes: {
[key: string]: GLTFAccessorPostprocessed;
},
extStructuralMetadata: GLTF_EXT_structural_metadata
): NumericArray {
// Take only first extension object to get batchIds attribute name.
const dataAttributeNames = extStructuralMetadata?.dataAttributeNames;
if (dataAttributeNames?.length) {
// Let's use the first element of the array
// TODO: What to do with others if any?
const batchIdsAttribute = attributes[dataAttributeNames[0]];
return batchIdsAttribute.value;
}
return [];
}

/**
* Getting batchIds from EXT_mesh_features extensions.
* @param attributes - gltf accessors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {FeatureTableJson, Tiles3DTileContent} from '@loaders.gl/3d-tiles';
import type {
GLTF_EXT_mesh_features,
GLTF_EXT_structural_metadata,
GLTF_EXT_structural_metadata_GLTF,
GLTFAccessorPostprocessed,
GLTFMaterialPostprocessed,
GLTFNodePostprocessed,
Expand Down Expand Up @@ -1625,16 +1625,9 @@ export function getPropertyTable(
const {extensionName, extension} = getPropertyTableExtension(tileContent);

switch (extensionName) {
case EXT_MESH_FEATURES: {
propertyTable = getPropertyTableFromExtMeshFeatures(
extension as GLTF_EXT_mesh_features,
metadataClass
);
return propertyTable;
}
case EXT_STRUCTURAL_METADATA: {
propertyTable = getPropertyTableFromExtStructuralMetadata(
extension as GLTF_EXT_structural_metadata,
extension as GLTF_EXT_structural_metadata_GLTF,
metadataClass
);
return propertyTable;
Expand All @@ -1660,7 +1653,7 @@ function getPropertyTableExtension(tileContent: Tiles3DTileContent): {
extension:
| string
| GLTF_EXT_feature_metadata_GLTF
| GLTF_EXT_structural_metadata
| GLTF_EXT_structural_metadata_GLTF
| GLTF_EXT_mesh_features
| null;
} {
Expand Down Expand Up @@ -1759,7 +1752,7 @@ function getPropertyTableFromExtFeatureMetadata(
* @returns {FeatureTableJson | null} Property table or null if the extension can't be handled properly.
*/
function getPropertyTableFromExtStructuralMetadata(
extension: GLTF_EXT_structural_metadata,
extension: GLTF_EXT_structural_metadata_GLTF,
metadataClass?: string
): FeatureTableJson | null {
if (extension?.propertyTables) {
Expand Down Expand Up @@ -1803,33 +1796,3 @@ function getPropertyTableFromExtStructuralMetadata(
);
return null;
}

/**
* Handle EXT_mesh_features to get property table
* @param extension - global level of EXT_MESH_FEATURES extension
* @param metadataClass - user selected feature metadata class name
* @returns {FeatureTableJson | null} Property table or null if the extension can't be handled properly.
*/
function getPropertyTableFromExtMeshFeatures(
extension: GLTF_EXT_mesh_features,
metadataClass?: string
): FeatureTableJson | null {
if (extension?.featureIds) {
const firstFeatureId = extension?.featureIds[0];
const propertyTableWithData = {};

// When firstFeatureId.propertyTable is defined, the property data will be taken from EXT_structural_metadata extension
if (!firstFeatureId.propertyTable) {
console.warn(
'Should be implemented as we have the tileset with Ext_mesh_features not linked with EXT_structural_metadata extension'
);
}

return propertyTableWithData;
}

console.warn(
"The I3S converter couldn't handle EXT_mesh_features extension: There is no featureIds in the extension."
);
return null;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import {Tiles3DTileContent} from '@loaders.gl/3d-tiles';
import {GLTFPrimitiveModeString, PreprocessData} from '../types';
import {GLTF, GLTFLoader, GLTF_EXT_feature_metadata_GLTF} from '@loaders.gl/gltf';
import {
EXT_STRUCTURAL_METADATA,
GLTF,
GLTFLoader,
GLTF_EXT_feature_metadata_GLTF,
GLTF_EXT_structural_metadata_GLTF
} from '@loaders.gl/gltf';
import {parse} from '@loaders.gl/core';
import {EXT_FEATURE_METADATA} from '@loaders.gl/gltf';

Expand Down Expand Up @@ -81,11 +87,23 @@ const getMeshTypesFromGLTF = (gltfJson: GLTF): Set<GLTFPrimitiveModeString> => {
const getMetadataClassesFromGLTF = (gltfJson: GLTF): Set<string> => {
const result: Set<string> = new Set();

const classes = (gltfJson.extensions?.[EXT_FEATURE_METADATA] as GLTF_EXT_feature_metadata_GLTF)
?.schema?.classes;
// Try to parse from EXT_feature_metadata
const extFeatureMetadataClasses = (
gltfJson.extensions?.[EXT_FEATURE_METADATA] as GLTF_EXT_feature_metadata_GLTF
)?.schema?.classes;

if (classes) {
for (const classKey of Object.keys(classes)) {
if (extFeatureMetadataClasses) {
for (const classKey of Object.keys(extFeatureMetadataClasses)) {
result.add(classKey);
}
}

// Try to parse from EXT_structural_metadata
const extStructuralMetadataClasses = (
gltfJson.extensions?.[EXT_STRUCTURAL_METADATA] as GLTF_EXT_structural_metadata_GLTF
)?.schema?.classes;
if (extStructuralMetadataClasses) {
for (const classKey of Object.keys(extStructuralMetadataClasses)) {
result.add(classKey);
}
}
Expand Down
22 changes: 12 additions & 10 deletions modules/wkt/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// loaders.gl, MIT license

export {WKTCRSLoader} from './wkt-crs-loader';
export {WKTCRSWriter} from './wkt-crs-writer';

export {WKTLoader, WKTWorkerLoader} from './wkt-loader';
export {WKTWriter} from './wkt-writer';

export {WKBLoader, WKBWorkerLoader} from './wkb-loader';
export {WKBWriter} from './wkb-writer';

export {TWKBLoader} from './twkb-loader';
export {TWKBWriter} from './twkb-writer';

export {HexWKBLoader} from './hex-wkb-loader';

export {WKTLoader, WKTWorkerLoader} from './wkt-loader';
export {WKTWriter} from './wkt-writer';

export {WKTCRSLoader} from './wkt-crs-loader';
export {WKTCRSWriter} from './wkt-crs-writer';
export {TWKBLoader} from './twkb-loader';
export {TWKBWriter} from './twkb-writer';

// EXPERIMENTAL APIs
export type {WKBHeader} from './lib/parse-wkb-header';
export {isWKT} from './lib/parse-wkt';

export {isWKB, parseWKBHeader} from './lib/parse-wkb-header';
export type {WKBHeader} from './lib/parse-wkb-header';

export {isWKT} from './lib/parse-wkt';
export {isTWKB} from './lib/parse-twkb';

export {encodeHex, decodeHex} from './lib/utils/hex-transcoder';
28 changes: 9 additions & 19 deletions modules/wkt/src/lib/parse-twkb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// loaders.gl, MIT license
// Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz

import type {BinaryGeometry, Geometry, GeometryCollection} from '@loaders.gl/schema';
import type {Geometry, GeometryCollection} from '@loaders.gl/schema';
import type {Point, LineString, Polygon} from '@loaders.gl/schema';
import type {MultiPoint, MultiLineString, MultiPolygon} from '@loaders.gl/schema';
import {BinaryReader} from './utils/binary-reader';
Expand All @@ -26,14 +26,6 @@ export function isTWKB(arrayBuffer: ArrayBuffer): boolean {
return true;
}

/**
* Parse a TWKB encoded array buffer
* @param arrayBuffer
*/
export function parseTWKB(arrayBuffer: ArrayBuffer): BinaryGeometry {
throw new Error('not implemented');
}

/** State passed around between parsing functions, extracted from the header */
type ParseTWKBState = {
hasBoundingBox: boolean;
Expand Down Expand Up @@ -158,7 +150,7 @@ function parsePoint(reader: BinaryReader, context: ParseTWKBState): Point {
return {type: 'Point', coordinates: []};
}

return {type: 'Point', coordinates: parsePointCoordinates(reader, context)};
return {type: 'Point', coordinates: readFirstPoint(reader, context)};
}

function parseLineString(reader: BinaryReader, context: ParseTWKBState): LineString {
Expand All @@ -185,14 +177,12 @@ function parsePolygon(reader: BinaryReader, context: ParseTWKBState): Polygon {

const ringCount = reader.readVarInt();

const polygons: number[][][] = [];

const previousPoint = makePreviousPoint(context);

const exteriorRingCount = reader.readVarInt();
const exteriorRingLength = reader.readVarInt();
const exteriorRing: number[][] = [];

for (let i = 0; i < exteriorRingCount; i++) {
for (let i = 0; i < exteriorRingLength; i++) {
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
}

Expand All @@ -208,7 +198,7 @@ function parsePolygon(reader: BinaryReader, context: ParseTWKBState): Polygon {
polygon.push(interiorRing);
}

return {type: 'Polygon', coordinates: polygons};
return {type: 'Polygon', coordinates: polygon};
}

function parseMultiPoint(reader: BinaryReader, context: ParseTWKBState): MultiPoint {
Expand Down Expand Up @@ -269,14 +259,14 @@ function parseMultiPolygon(reader: BinaryReader, context: ParseTWKBState): Multi
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
}

const polygon: number[][][] = [exteriorRing];
const polygon: number[][][] = exteriorRing ? [exteriorRing] : [];

for (let j = 1; j < ringCount; j++) {
const interiorRing: number[][] = [];

const interiorRingCount = reader.readVarInt();
const interiorRingLength = reader.readVarInt();

for (let k = 0; k < interiorRingCount; k++) {
for (let k = 0; k < interiorRingLength; k++) {
interiorRing.push(parseNextPoint(reader, context, previousPoint));
}

Expand Down Expand Up @@ -330,7 +320,7 @@ function makePreviousPoint(context: ParseTWKBState): number[] {
return makePointCoordinates(0, 0, context.hasZ ? 0 : undefined, context.hasM ? 0 : undefined);
}

function parsePointCoordinates(reader: BinaryReader, context: ParseTWKBState): number[] {
function readFirstPoint(reader: BinaryReader, context: ParseTWKBState): number[] {
const x = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
const y = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
const z = context.hasZ ? zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor : undefined;
Expand Down
2 changes: 1 addition & 1 deletion modules/wkt/src/lib/utils/binary-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class BinaryReader {
let nextByte;
do {
// TODO - this needs to be accessed via data view?
nextByte = this.arrayBuffer[this.byteOffset + bytesRead];
nextByte = this.dataView.getUint8(this.byteOffset + bytesRead);
result += (nextByte & 0x7f) << (7 * bytesRead);
bytesRead++;
} while (nextByte >= 0x80);
Expand Down
Loading

0 comments on commit 5fe2bae

Please sign in to comment.