Skip to content

Commit

Permalink
v4: Remove deprecated APIs (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Dec 20, 2023
1 parent bf9b464 commit fbbc5ca
Show file tree
Hide file tree
Showing 28 changed files with 76 additions and 447 deletions.
3 changes: 1 addition & 2 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
QUANTIZE_DEFAULTS,
ResampleOptions,
SequenceOptions,
TEXTURE_RESIZE_DEFAULTS,
TextureResizeFilter,
UnweldOptions,
WeldOptions,
Expand Down Expand Up @@ -1157,7 +1156,7 @@ preserving original aspect ratio. Texture dimensions are never increased.
})
.option('--filter', 'Resampling filter', {
validator: [TextureResizeFilter.LANCZOS3, TextureResizeFilter.LANCZOS2],
default: TEXTURE_RESIZE_DEFAULTS.filter,
default: TextureResizeFilter.LANCZOS3,
})
.option('--width <pixels>', 'Maximum width (px) of output textures.', {
validator: Validator.NUMBER,
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export {
MathUtils,
Verbosity,
getBounds,
bounds,
uuid,
} from './utils/index.js';
export {
Expand Down
35 changes: 0 additions & 35 deletions packages/core/src/properties/material.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Nullable, PropertyType, TextureChannel, vec3, vec4 } from '../constants.js';
import type { GLTF } from '../types/gltf.js';
import { ColorUtils } from '../utils/index.js';
import { ExtensibleProperty, IExtensibleProperty } from './extensible-property.js';
import type { Texture } from './texture.js';
import { TextureInfo } from './texture-info.js';
Expand Down Expand Up @@ -206,23 +205,6 @@ export class Material extends ExtensibleProperty<IMaterial> {
return this.set('baseColorFactor', baseColorFactor);
}

/**
* Base color / albedo; sRGB hexadecimal color. See {@link Material.getBaseColorTexture getBaseColorTexture}.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public getBaseColorHex(): number {
return ColorUtils.factorToHex(this.get('baseColorFactor'));
}

/**
* Base color / albedo; sRGB hexadecimal color. See {@link Material.getBaseColorTexture getBaseColorTexture}.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public setBaseColorHex(hex: number): this {
const factor = this.get('baseColorFactor').slice() as vec4;
return this.set('baseColorFactor', ColorUtils.hexToFactor(hex, factor));
}

/**
* Base color / albedo. The visible color of a non-metallic surface under constant ambient
* light would be a linear combination (multiplication) of its vertex colors, base color
Expand Down Expand Up @@ -264,23 +246,6 @@ export class Material extends ExtensibleProperty<IMaterial> {
return this.set('emissiveFactor', emissiveFactor);
}

/**
* Emissive; sRGB hexadecimal color. See {@link Material.getBaseColorTexture getBaseColorTexture}.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public getEmissiveHex(): number {
return ColorUtils.factorToHex(this.get('emissiveFactor'));
}

/**
* Emissive; sRGB hexadecimal color. See {@link Material.getEmissiveTexture getEmissiveTexture}.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public setEmissiveHex(hex: number): this {
const factor = this.get('emissiveFactor').slice() as vec3;
return this.set('emissiveFactor', ColorUtils.hexToFactor(hex, factor));
}

/**
* Emissive texture. Emissive color is added to any base color of the material, after any
* lighting/shadowing are applied. An emissive color does not inherently "glow", or affect
Expand Down
16 changes: 1 addition & 15 deletions packages/core/src/properties/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class Node extends ExtensibleProperty<INode> {
this.get('translation'),
this.get('rotation'),
this.get('scale'),
[] as unknown as mat4
[] as unknown as mat4,
);
}

Expand Down Expand Up @@ -233,13 +233,6 @@ export class Node extends ExtensibleProperty<INode> {
return this.listRefs('children');
}

/** @deprecated Use {@link Node.getParentNode} and {@link listNodeScenes} instead. */
public getParent(): SceneNode | null {
if (this._parentNode) return this._parentNode;
const scene = this.listParents().find((parent) => parent.propertyType === PropertyType.SCENE);
return (scene as unknown as SceneNode) || null;
}

/**
* Returns the Node's unique parent Node within the scene graph. If the
* Node has no parents, or is a direct child of the {@link Scene}
Expand Down Expand Up @@ -316,10 +309,3 @@ export class Node extends ExtensibleProperty<INode> {
return this;
}
}

interface SceneNode {
propertyType: PropertyType;
_parent?: SceneNode | null;
addChild(node: Node): this;
removeChild(node: Node): this;
}
6 changes: 0 additions & 6 deletions packages/core/src/utils/get-bounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ export function getBounds(node: Node | Scene): bbox {
return resultBounds;
}

/**
* @deprecated Renamed to {@link getBounds}.
* @hidden
*/
export const bounds = getBounds;

/** Computes mesh bounds in local space. */
function getMeshBounds(mesh: Mesh, worldMatrix: mat4): bbox {
const meshBounds = createBounds();
Expand Down
10 changes: 0 additions & 10 deletions packages/core/src/utils/math-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ export class MathUtils {
}
}

/** @deprecated Renamed to {@link MathUtils.decodeNormalizedInt}. */
public static denormalize(i: number, componentType: GLTF.AccessorComponentType): number {
return MathUtils.decodeNormalizedInt(i, componentType);
}

// TODO(v4): Compare performance if we replace the switch with individual functions.
// TODO(v4): Consider clamping to [0, 1] or [-1, 1] here.
public static encodeNormalizedInt(f: number, componentType: GLTF.AccessorComponentType): number {
Expand All @@ -63,11 +58,6 @@ export class MathUtils {
}
}

/** @deprecated Renamed to {@link MathUtils.encodeNormalizedInt}. */
public static normalize(f: number, componentType: GLTF.AccessorComponentType): number {
return MathUtils.encodeNormalizedInt(f, componentType);
}

/**
* Decompose a mat4 to TRS properties.
*
Expand Down
9 changes: 0 additions & 9 deletions packages/core/test/properties/material.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ test('factors', (t) => {
t.is(mat.getRoughnessFactor(), 0.9, 'roughnessFactor');
});

test('hex', (t) => {
const document = new Document();

const mat = document.createMaterial('mat').setAlpha(0.9).setBaseColorHex(0x00ff00);

t.is(mat.getAlpha(), 0.9, 'alpha');
t.is(mat.getBaseColorHex(), 65024, 'baseColorHex');
});

test('textures', (t) => {
const document = new Document();

Expand Down
19 changes: 0 additions & 19 deletions packages/extensions/src/khr-lights-punctual/light.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ExtensionProperty, IProperty, Nullable, PropertyType, vec3 } from '@gltf-transform/core';
import { ColorUtils } from '@gltf-transform/core';
import { KHR_LIGHTS_PUNCTUAL } from '../constants.js';

interface ILight extends IProperty {
Expand Down Expand Up @@ -67,24 +66,6 @@ export class Light extends ExtensionProperty<ILight> {
return this.set('color', color);
}

/**
* Light color; sRGB hexadecimal color.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public getColorHex(): number {
return ColorUtils.factorToHex(this.getColor());
}

/**
* Light color; sRGB hexadecimal color.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public setColorHex(hex: number): this {
const color = this.getColor().slice() as vec3;
ColorUtils.hexToFactor(hex, color);
return this.setColor(color);
}

/**********************************************************************************************
* INTENSITY.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
ColorUtils,
ExtensionProperty,
IProperty,
Nullable,
Expand Down Expand Up @@ -65,23 +64,6 @@ export class PBRSpecularGlossiness extends ExtensionProperty<IPBRSpecularGlossin
return this.set('diffuseFactor', factor);
}

/**
* Diffuse; sRGB hexadecimal color.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public getDiffuseHex(): number {
return ColorUtils.factorToHex(this.getDiffuseFactor());
}

/**
* Diffuse; sRGB hexadecimal color.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public setDiffuseHex(hex: number): this {
const factor = this.getDiffuseFactor().slice() as vec4;
return this.setDiffuseFactor(ColorUtils.hexToFactor(hex, factor));
}

/**
* Diffuse texture; sRGB. Alternative to baseColorTexture, used within the
* spec/gloss PBR workflow.
Expand Down
18 changes: 0 additions & 18 deletions packages/extensions/src/khr-materials-sheen/sheen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
ColorUtils,
ExtensionProperty,
IProperty,
Nullable,
Expand Down Expand Up @@ -57,28 +56,11 @@ export class Sheen extends ExtensionProperty<ISheen> {
return this.get('sheenColorFactor');
}

/**
* Sheen; hex color in sRGB colorspace.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public getSheenColorHex(): number {
return ColorUtils.factorToHex(this.getSheenColorFactor());
}

/** Sheen; linear multiplier. */
public setSheenColorFactor(factor: vec3): this {
return this.set('sheenColorFactor', factor);
}

/**
* Sheen; hex color in sRGB colorspace.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public setSheenColorHex(hex: number): this {
const factor = this.getSheenColorFactor().slice() as vec3;
return this.set('sheenColorFactor', ColorUtils.hexToFactor(hex, factor));
}

/**
* Sheen color texture, in sRGB colorspace.
*/
Expand Down
18 changes: 0 additions & 18 deletions packages/extensions/src/khr-materials-specular/specular.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
ColorUtils,
ExtensionProperty,
IProperty,
Nullable,
Expand Down Expand Up @@ -72,23 +71,6 @@ export class Specular extends ExtensionProperty<ISpecular> {
return this.set('specularColorFactor', factor);
}

/**
* Specular color; sRGB hexadecimal color. See {@link Specular.getSpecularTexture getSpecularTexture}
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public getSpecularColorHex(): number {
return ColorUtils.factorToHex(this.getSpecularColorFactor());
}

/**
* Specular color; sRGB hexadecimal color. See {@link Specular.getSpecularTexture getSpecularTexture}
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public setSpecularColorHex(hex: number): this {
const factor = this.getSpecularColorFactor().slice() as vec3;
return this.set('specularColorFactor', ColorUtils.hexToFactor(hex, factor));
}

/**
* Specular texture; linear multiplier. Configures the strength of the specular reflection in
* the dielectric BRDF. A value of zero disables the specular reflection, resulting in a pure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface VolumeDef {
* .setThicknessFactor(1.0)
* .setThicknessTexture(texture)
* .setAttenuationDistance(1.0)
* .setAttenuationColorHex(0xFFEEEE);
* .setAttenuationColorFactor([1, 0.5, 0.5]);
*
* // Attach the property to a Material.
* material.setExtension('KHR_materials_volume', volume);
Expand Down
20 changes: 0 additions & 20 deletions packages/extensions/src/khr-materials-volume/volume.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
ColorUtils,
ExtensionProperty,
IProperty,
Nullable,
Expand Down Expand Up @@ -127,23 +126,4 @@ export class Volume extends ExtensionProperty<IVolume> {
public setAttenuationColor(color: vec3): this {
return this.set('attenuationColor', color);
}

/**
* Color (sRGB) that white light turns into due to absorption when reaching the attenuation
* distance.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public getAttenuationColorHex(): number {
return ColorUtils.factorToHex(this.getAttenuationColor());
}

/**
* Color (sRGB) that white light turns into due to absorption when reaching the attenuation
* distance.
* @deprecated Will be removed in v4. Use {@link ColorUtils.hexToFactor} / {@link ColorUtils.factorToHex} instead.
*/
public setAttenuationColorHex(hex: number): this {
const factor = this.getAttenuationColor().slice() as vec3;
return this.set('attenuationColor', ColorUtils.hexToFactor(hex, factor));
}
}
7 changes: 0 additions & 7 deletions packages/extensions/test/lights-punctual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ test('copy', (t) => {
t.is(light2.getOuterConeAngle(), 0.75, 'copy outerConeAngle');
});

test('hex', (t) => {
const document = new Document();
const lightsExtension = document.createExtension(KHRLightsPunctual);
const light = lightsExtension.createLight().setColorHex(0x111111);
t.is(light.getColorHex(), 0x111111, 'colorHex');
});

test('i/o', async (t) => {
const document = new Document();
const lightsExtension = document.createExtension(KHRLightsPunctual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ test('basic', async (t) => {
specularGlossinessTexture: { index: 0 },
},
},
'writes specGloss extension'
'writes specGloss extension',
);
t.deepEqual(
jsonDoc.json.extensionsUsed,
[KHRMaterialsPBRSpecularGlossiness.EXTENSION_NAME],
'writes extensionsUsed'
'writes extensionsUsed',
);

specGlossExtension.dispose();
Expand Down Expand Up @@ -78,10 +78,3 @@ test('copy', (t) => {
t.is(specGloss2.getGlossinessFactor(), 0.5, 'copy glossinessFactor');
t.is(specGloss2.getSpecularGlossinessTexture().getName(), 'specGloss', 'copy specularGlossinessTexture');
});

test('hex', (t) => {
const doc = new Document();
const specGlossExtension = doc.createExtension(KHRMaterialsPBRSpecularGlossiness);
const specGloss = specGlossExtension.createPBRSpecularGlossiness().setDiffuseHex(0x0000ff);
t.is(specGloss.getDiffuseHex(), 254, 'diffuseHex');
});
9 changes: 1 addition & 8 deletions packages/extensions/test/materials-sheen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('basic', async (t) => {
sheenColorTexture: { index: 0 },
},
},
'writes sheen extension'
'writes sheen extension',
);
t.deepEqual(jsonDoc.json.extensionsUsed, [KHRMaterialsSheen.EXTENSION_NAME], 'writes extensionsUsed');

Expand Down Expand Up @@ -64,10 +64,3 @@ test('copy', (t) => {
t.deepEqual(sheen2.getSheenColorFactor(), [0.9, 0.5, 0.8], 'copy sheenColorFactor');
t.is(sheen2.getSheenColorTexture().getName(), 'sheen', 'copy sheenColorTexture');
});

test('hex', (t) => {
const doc = new Document();
const sheenExtension = doc.createExtension(KHRMaterialsSheen);
const sheen = sheenExtension.createSheen().setSheenColorHex(0x252525);
t.is(sheen.getSheenColorHex(), 0x252525, 'sheenColorHex');
});
Loading

0 comments on commit fbbc5ca

Please sign in to comment.