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

fix(tile-converter): skip failing content #2576

Merged
merged 3 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ export default class Tiles3DConverter {
if (sourceChild.contentUrl) {
const content = await loadI3SContent(this.sourceTileset, sourceChild, this.loaderOptions);

if (!content) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment?

await this._addChildren(sourceChild, parentNode, level + 1);
return;
}

this.vertexCounter += content?.vertexCount || 0;

let featureAttributes: FeatureAttribute | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {Matrix4, Vector3} from '@math.gl/core';
import {Ellipsoid} from '@math.gl/geospatial';
import {convertTextureAtlas} from './texture-atlas';
import {generateSyntheticIndices} from '../../lib/utils/geometry-utils';
import {I3STileContent} from '@loaders.gl/i3s';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import type?


const Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
const scratchVector = new Vector3();

export type I3SAttributesData = {
tileContent: any;
tileContent: I3STileContent;
box: number[];
textureFormat: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {TypedArray} from '@loaders.gl/loader-utils';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import type?


/**
* Apply uvRegions to texture coordinates.
* Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md
* Shader formula vec2 uv = fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;
* @param texCoords
* @param uvRegions
*/
export function convertTextureAtlas(texCoords: Float32Array, uvRegions: Uint16Array): Float32Array {
const convertedTexCoords = new Float32Array(texCoords.length);
export function convertTextureAtlas(texCoords: TypedArray, uvRegions: TypedArray): Float32Array {
const convertedTexCoords = new texCoords[Symbol.species](texCoords.length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I have never needed to use Symbol.species. Do we need this or can we get away with a simpler constructor. This feature seems to be for overriding default constructor when subclassing built in types? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species.

Also do we still need the original texCoords after conversion? If not consider converting "in place" and avoid an allocation?

Finally an unrelated comment: In the algorithm below there are lots of little arrays being created for each iteration. I would recommend creating a few scratch arrays before the loop and reusing those, to reduce memory pressure and improve performance.

const normalisedRegions = normalizeRegions(uvRegions);

for (let index = 0; index < texCoords.length; index += 2) {
Expand Down Expand Up @@ -43,7 +45,9 @@ function fract(uv: [number, number]): [number, number] {
* Normalize uvRegions by dividing by the maximum Uint16 value
* @param regions
*/
function normalizeRegions(regions: Uint16Array): number[] {
function normalizeRegions(regions: TypedArray): number[] {
// The code is for Uint16Array because it is the spec requirement
// https://github.com/Esri/i3s-spec/blob/master/docs/1.8/geometryUVRegion.cmn.md
const MAX_UINT_16_VALUE = 65535;
const normalizedRegions: number[] = [];

Expand Down