Skip to content

Commit

Permalink
[core] Progress toward noImplicitAny.
Browse files Browse the repository at this point in the history
  • Loading branch information
Don McCurdy committed Apr 2, 2021
1 parent 121dcac commit 1672dfe
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 51 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"docs:deploy": "yarn run docs && vercel --prod"
},
"devDependencies": {
"@types/command-exists": "^1.2.0",
"@types/gl-matrix": "^3.2.0",
"@types/markdown-table": "^2.0.0",
"@types/ndarray": "^1.0.8",
"@types/node": "^14.14.37",
"@types/node-gzip": "^1.1.0",
"@types/tape": "^4.13.0",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
Expand Down
4 changes: 0 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
"@gltf-transform/core": "^0.9.7",
"@gltf-transform/extensions": "^0.9.7",
"@gltf-transform/lib": "^0.9.7",
"@types/command-exists": "^1.2.0",
"@types/markdown-table": "^2.0.0",
"@types/node": "^14.14.37",
"@types/node-gzip": "^1.1.0",
"cli-table3": "^0.6.0",
"command-exists": "^1.2.9",
"csv-stringify": "^5.6.2",
Expand Down
54 changes: 29 additions & 25 deletions packages/cli/src/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,39 @@ export async function inspect (

// Detailed report.
const report = inspectDoc(doc);
await reportSection('scenes', report.scenes);
await reportSection('meshes', report.meshes);
await reportSection('materials', report.materials);
await reportSection('textures', report.textures);
await reportSection('animations', report.animations);
await reportSection('scenes', format, logger, report.scenes);
await reportSection('meshes', format, logger, report.meshes);
await reportSection('materials', format, logger, report.materials);
await reportSection('textures', format, logger, report.textures);
await reportSection('animations', format, logger, report.animations);
}

async function reportSection(type: string, section: InspectPropertyReport<AnyPropertyReport>) {
const properties = section.properties;
async function reportSection(
type: string,
format: InspectFormat,
logger: Logger,
section: InspectPropertyReport<AnyPropertyReport>) {
const properties = section.properties;

console.log(formatHeader(type));
if (!properties.length) {
console.log(`No ${type} found.\n`);
return;
}
console.log(formatHeader(type));
if (!properties.length) {
console.log(`No ${type} found.\n`);
return;
}

const formattedRecords = properties
.map((property: AnyPropertyReport, index: number) => {
return formatPropertyReport(property, index, format);
});
const header = Object.keys(formattedRecords[0]);
const rows = formattedRecords.map((p: Record<string, string>) => Object.values(p));
const footnotes = format !== InspectFormat.CSV ? getFootnotes(type, rows, header) : [];
console.log(await formatTable(format, header, rows));
if (footnotes.length) console.log('\n' + footnotes.join('\n'));
if (section.warnings) {
section.warnings.forEach((warning) => logger.warn(formatParagraph(warning)));
}
console.log('\n');
const formattedRecords = properties
.map((property: AnyPropertyReport, index: number) => {
return formatPropertyReport(property, index, format);
});
const header = Object.keys(formattedRecords[0]);
const rows = formattedRecords.map((p: Record<string, string>) => Object.values(p));
const footnotes = format !== InspectFormat.CSV ? getFootnotes(type, rows, header) : [];
console.log(await formatTable(format, header, rows));
if (footnotes.length) console.log('\n' + footnotes.join('\n'));
if (section.warnings) {
section.warnings.forEach((warning) => logger.warn(formatParagraph(warning)));
}
console.log('\n');
}

async function formatTable(
Expand Down
23 changes: 14 additions & 9 deletions packages/core/src/utils/color-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ export class ColorUtils {
*/
static hexToFactor<T = vec3 | vec4>(hex: number, target: T): T {
hex = Math.floor( hex );
target[0] = ( hex >> 16 & 255 ) / 255;
target[1] = ( hex >> 8 & 255 ) / 255;
target[2] = ( hex & 255 ) / 255;
const _target = target as unknown as vec3;
_target[0] = ( hex >> 16 & 255 ) / 255;
_target[1] = ( hex >> 8 & 255 ) / 255;
_target[2] = ( hex & 255 ) / 255;
return this.convertSRGBToLinear<T>(target, target);
}

Expand All @@ -47,10 +48,12 @@ export class ColorUtils {
* @typeParam T vec3 or vec4 linear components.
*/
static convertSRGBToLinear<T = vec3 | vec4>(source: T, target: T): T {
const _source = source as unknown as vec3;
const _target = target as unknown as vec3;
for (let i = 0 ; i < 3; i++) {
target[i] = ( source[i] < 0.04045 )
? source[i] * 0.0773993808
: Math.pow( source[i] * 0.9478672986 + 0.0521327014, 2.4 );
_target[i] = ( _source[i] < 0.04045 )
? _source[i] * 0.0773993808
: Math.pow( _source[i] * 0.9478672986 + 0.0521327014, 2.4 );
}
return target;
}
Expand All @@ -60,10 +63,12 @@ export class ColorUtils {
* @typeParam T vec3 or vec4 linear components.
*/
static convertLinearToSRGB<T = vec3 | vec4>(source: T, target: T): T {
const _source = source as unknown as vec3;
const _target = target as unknown as vec3;
for (let i = 0; i < 3; i++) {
target[i] = ( source[i] < 0.0031308 )
? source[i] * 12.92
: 1.055 * ( Math.pow( source[i], 0.41666 ) ) - 0.055;
_target[i] = ( _source[i] < 0.0031308 )
? _source[i] * 12.92
: 1.055 * ( Math.pow( _source[i], 0.41666 ) ) - 0.055;
}
return target;
}
Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/utils/math-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { determinant, getRotation } from 'gl-matrix/mat4';
import { length } from 'gl-matrix/vec3';
import { ReadonlyMat4, mat4 as glMat4, vec3 as glVec3 } from 'gl-matrix';
import { mat4, vec3, vec4 } from '../constants';
import { GLTF } from '../types/gltf';

Expand Down Expand Up @@ -73,12 +72,12 @@ export class MathUtils {
dstTranslation: vec3,
dstRotation: vec4,
dstScale: vec3): void {
let sx = length([srcMat[0], srcMat[1], srcMat[2]]);
const sy = length([srcMat[4], srcMat[5], srcMat[6]]);
const sz = length([srcMat[8], srcMat[9], srcMat[10]]);
let sx = glVec3.length([srcMat[0], srcMat[1], srcMat[2]]);
const sy = glVec3.length([srcMat[4], srcMat[5], srcMat[6]]);
const sz = glVec3.length([srcMat[8], srcMat[9], srcMat[10]]);

// if determine is negative, we need to invert one scale
const det = determinant(srcMat);
const det = glMat4.determinant(srcMat);
if (det < 0) sx = - sx;

dstTranslation[0] = srcMat[12];
Expand All @@ -104,7 +103,7 @@ export class MathUtils {
_m1[9] *= invSZ;
_m1[10] *= invSZ;

getRotation(dstRotation, _m1);
glMat4.getRotation(dstRotation, _m1 as unknown as ReadonlyMat4);

dstScale[0] = sx;
dstScale[1] = sy;
Expand Down
1 change: 0 additions & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"dependencies": {
"@gltf-transform/core": "^0.9.7",
"@gltf-transform/extensions": "^0.9.7",
"@types/ndarray": "^1.0.8",
"geo-ambient-occlusion": "^3.0.2",
"get-pixels": "^3.3.2",
"gl-matrix": "^3.3.0",
Expand Down
17 changes: 12 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,13 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==

"@types/gl-matrix@^3.2.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@types/gl-matrix/-/gl-matrix-3.2.0.tgz#a62e0f26be4ab6fa55284a29eec631c8641438a1"
integrity sha512-CY4JAtSOGQX7rVgqVuOk7ZfaLv8VeadDMPj3smMOy8Hp/YiHONa3Mr0mEUgbo0eEwV7+Owpf6BwspcA7hv4NXg==
dependencies:
gl-matrix "*"

"@types/glob@^7.1.1":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"
Expand Down Expand Up @@ -4706,16 +4713,16 @@ gl-mat4@^1.1.4:
resolved "https://registry.yarnpkg.com/gl-mat4/-/gl-mat4-1.2.0.tgz#49d8a7636b70aa00819216635f4a3fd3f4669b26"
integrity sha512-sT5C0pwB1/e9G9AvAoLsoaJtbMGjfd/jfxo8jMCKqYYEnjZuFvqV5rehqar0538EmssjdDeiEWnKyBSTw7quoA==

gl-matrix@*, gl-matrix@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/gl-matrix/-/gl-matrix-3.3.0.tgz#232eef60b1c8b30a28cbbe75b2caf6c48fd6358b"
integrity sha512-COb7LDz+SXaHtl/h4LeaFcNdJdAQSDeVqjiIihSXNrkWObZLhDI4hIkZC11Aeqp7bcE72clzB0BnDXr2SmslRA==

gl-matrix@^2.4.0:
version "2.8.1"
resolved "https://registry.yarnpkg.com/gl-matrix/-/gl-matrix-2.8.1.tgz#1c7873448eac61d2cd25803a074e837bd42581a3"
integrity sha512-0YCjVpE3pS5XWlN3J4X7AiAx65+nqAI54LndtVFnQZB6G/FVLkZH8y8V6R3cIoOQR4pUdfwQGd1iwyoXHJ4Qfw==

gl-matrix@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/gl-matrix/-/gl-matrix-3.3.0.tgz#232eef60b1c8b30a28cbbe75b2caf6c48fd6358b"
integrity sha512-COb7LDz+SXaHtl/h4LeaFcNdJdAQSDeVqjiIihSXNrkWObZLhDI4hIkZC11Aeqp7bcE72clzB0BnDXr2SmslRA==

gl-vec3@^1.0.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/gl-vec3/-/gl-vec3-1.1.3.tgz#a47c62f918774a06cbed1b65bcd0288ecbb03826"
Expand Down

0 comments on commit 1672dfe

Please sign in to comment.