Socket
Socket
Sign inDemoInstall

@gltf-transform/core

Package Overview
Dependencies
Maintainers
1
Versions
205
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gltf-transform/core - npm Package Compare versions

Comparing version 4.0.0-alpha.1 to 4.0.0-alpha.2

./dist/index.cjs

2

dist/io/reader-context.d.ts

@@ -5,3 +5,3 @@ import type { JSONDocument } from '../json-document.js';

/**
* Model class providing glTF-Transform objects representing each definition in the glTF file, used
* Model class providing glTF Transform objects representing each definition in the glTF file, used
* by a {@link GLTFReader} and its {@link Extension} implementations. Indices of all properties will be

@@ -8,0 +8,0 @@ * consistent with the glTF file.

@@ -57,3 +57,3 @@ import { Nullable, PropertyType, TypedArray } from '../constants.js';

*
* glTF-Transform does not expose many details of sparse, normalized, or interleaved accessors
* glTF Transform does not expose many details of sparse, normalized, or interleaved accessors
* through its API. It reads files using those techniques, presents a simplified view of the data

@@ -60,0 +60,0 @@ * for editing, and attempts to write data back out with optimizations. For example, vertex

@@ -10,3 +10,3 @@ import { Nullable, PropertyType } from '../constants.js';

* glTF 2.0 has three concepts relevant to binary storage: accessors, buffer views, and buffers.
* In glTF-Transform, an {@link Accessor} is referenced by any property that requires numeric typed
* In glTF Transform, an {@link Accessor} is referenced by any property that requires numeric typed
* array data. Meshes, Primitives, and Animations all reference Accessors. Buffers define how that

@@ -23,5 +23,5 @@ * data is organized into transmitted file(s). A `.glb` file has only a single Buffer, and when

*
* Buffer Views define how Accessors are organized within a given Buffer. glTF-Transform creates an
* Buffer Views define how Accessors are organized within a given Buffer. glTF Transform creates an
* efficient Buffer View layout automatically at export: there is no Buffer View property exposed
* by the glTF-Transform API, simplifying data management.
* by the glTF Transform API, simplifying data management.
*

@@ -28,0 +28,0 @@ * Usage:

@@ -124,10 +124,2 @@ import { Nullable, PropertyType, vec3, vec4 } from '../constants.js';

/**
* Base color / albedo; sRGB hexadecimal color. See {@link Material.getBaseColorTexture getBaseColorTexture}.
*/
getBaseColorHex(): number;
/**
* Base color / albedo; sRGB hexadecimal color. See {@link Material.getBaseColorTexture getBaseColorTexture}.
*/
setBaseColorHex(hex: number): this;
/**
* Base color / albedo. The visible color of a non-metallic surface under constant ambient

@@ -157,6 +149,2 @@ * light would be a linear combination (multiplication) of its vertex colors, base color

setEmissiveFactor(emissiveFactor: vec3): this;
/** Emissive; sRGB hexadecimal color. See {@link Material.getBaseColorTexture getBaseColorTexture}. */
getEmissiveHex(): number;
/** Emissive; sRGB hexadecimal color. See {@link Material.getEmissiveTexture getEmissiveTexture}. */
setEmissiveHex(hex: number): this;
/**

@@ -163,0 +151,0 @@ * Emissive texture. Emissive color is added to any base color of the material, after any

@@ -19,8 +19,8 @@ import { PropertyType, mat4, vec3, vec4, Nullable } from '../constants.js';

*
* Each node may have one or more children, and a transform (position, rotation, and scale) that
* applies to all of its descendants. A node may also reference (or "instantiate") other resources
* at its location, including {@link Mesh}, Camera, Light, and Skin properties. A node cannot be
* Each Node may have one or more children, and a transform (position, rotation, and scale) that
* applies to all of its descendants. A Node may also reference (or "instantiate") other resources
* at its location, including {@link Mesh}, Camera, Light, and Skin properties. A Node cannot be
* part of more than one {@link Scene}.
*
* A node's local transform is represented with array-like objects, intended to be compatible with
* A Node's local transform is represented with array-like objects, intended to be compatible with
* [gl-matrix](https://github.com/toji/gl-matrix), or with the `toArray`/`fromArray` methods of

@@ -51,17 +51,17 @@ * libraries like three.js and babylon.js.

*/
/** Returns the translation (position) of this node in local space. */
/** Returns the translation (position) of this Node in local space. */
getTranslation(): vec3;
/** Returns the rotation (quaternion) of this node in local space. */
/** Returns the rotation (quaternion) of this Node in local space. */
getRotation(): vec4;
/** Returns the scale of this node in local space. */
/** Returns the scale of this Node in local space. */
getScale(): vec3;
/** Sets the translation (position) of this node in local space. */
/** Sets the translation (position) of this Node in local space. */
setTranslation(translation: vec3): this;
/** Sets the rotation (quaternion) of this node in local space. */
/** Sets the rotation (quaternion) of this Node in local space. */
setRotation(rotation: vec4): this;
/** Sets the scale of this node in local space. */
/** Sets the scale of this Node in local space. */
setScale(scale: vec3): this;
/** Returns the local matrix of this node. */
/** Returns the local matrix of this Node. */
getMatrix(): mat4;
/** Sets the local matrix of this node. Matrix will be decomposed to TRS properties. */
/** Sets the local matrix of this Node. Matrix will be decomposed to TRS properties. */
setMatrix(matrix: mat4): this;

@@ -71,9 +71,9 @@ /**********************************************************************************************

*/
/** Returns the translation (position) of this node in world space. */
/** Returns the translation (position) of this Node in world space. */
getWorldTranslation(): vec3;
/** Returns the rotation (quaternion) of this node in world space. */
/** Returns the rotation (quaternion) of this Node in world space. */
getWorldRotation(): vec4;
/** Returns the scale of this node in world space. */
/** Returns the scale of this Node in world space. */
getWorldScale(): vec3;
/** Returns the world matrix of this node. */
/** Returns the world matrix of this Node. */
getWorldMatrix(): mat4;

@@ -83,10 +83,22 @@ /**********************************************************************************************

*/
/** Adds another node as a child of this one. Nodes cannot have multiple parents. */
/**
* Adds the given Node as a child of this Node.
*
* Requirements:
*
* 1. Nodes MAY be root children of multiple {@link Scene Scenes}
* 2. Nodes MUST NOT be children of >1 Node
* 3. Nodes MUST NOT be children of both Nodes and {@link Scene Scenes}
*
* The `addChild` method enforces these restrictions automatically, and will
* remove the new child from previous parents where needed. This behavior
* may change in future major releases of the library.
*
* @privateRemarks Requires non-graph state.
*/
addChild(child: Node): this;
/** Removes a node from this node's child node list. */
/** Removes a Node from this Node's child Node list. */
removeChild(child: Node): this;
/** Lists all child nodes of this node. */
/** Lists all child Nodes of this Node. */
listChildren(): Node[];
/** @deprecated Use {@link Node.getParentNode} and {@link listNodeScenes} instead. */
getParent(): SceneNode | null;
/**

@@ -104,19 +116,19 @@ * Returns the Node's unique parent Node within the scene graph. If the

*/
/** Returns the {@link Mesh}, if any, instantiated at this node. */
/** Returns the {@link Mesh}, if any, instantiated at this Node. */
getMesh(): Mesh | null;
/**
* Sets a {@link Mesh} to be instantiated at this node. A single mesh may be instatiated by
* multiple nodes; reuse of this sort is strongly encouraged.
* Sets a {@link Mesh} to be instantiated at this Node. A single mesh may be instatiated by
* multiple Nodes; reuse of this sort is strongly encouraged.
*/
setMesh(mesh: Mesh | null): this;
/** Returns the {@link Camera}, if any, instantiated at this node. */
/** Returns the {@link Camera}, if any, instantiated at this Node. */
getCamera(): Camera | null;
/** Sets a {@link Camera} to be instantiated at this node. */
/** Sets a {@link Camera} to be instantiated at this Node. */
setCamera(camera: Camera | null): this;
/** Returns the {@link Skin}, if any, instantiated at this node. */
/** Returns the {@link Skin}, if any, instantiated at this Node. */
getSkin(): Skin | null;
/** Sets a {@link Skin} to be instantiated at this node. */
/** Sets a {@link Skin} to be instantiated at this Node. */
setSkin(skin: Skin | null): this;
/**
* Initial weights of each {@link PrimitiveTarget} for the mesh instance at this node.
* Initial weights of each {@link PrimitiveTarget} for the mesh instance at this Node.
* Most engines only support 4-8 active morph targets at a time.

@@ -126,3 +138,3 @@ */

/**
* Initial weights of each {@link PrimitiveTarget} for the mesh instance at this node.
* Initial weights of each {@link PrimitiveTarget} for the mesh instance at this Node.
* Most engines only support 4-8 active morph targets at a time.

@@ -137,8 +149,2 @@ */

}
interface SceneNode {
propertyType: PropertyType;
_parent?: SceneNode | null;
addChild(node: Node): this;
removeChild(node: Node): this;
}
export {};

@@ -41,3 +41,3 @@ import { Nullable, PropertyType } from '../constants.js';

* indirectly) by the root. Metadata about the asset's license, generator, and glTF specification
* version are stored in the asset, accessible with {@link .getAsset}().
* version are stored in the asset, accessible with {@link Root.getAsset}.
*

@@ -85,5 +85,5 @@ * Properties are added to the root with factory methods on its {@link Document}, and removed by

*/
/** Lists all {@link Extension} properties enabled for this root. */
/** Lists all {@link Extension Extensions} enabled for this root. */
listExtensionsUsed(): Extension[];
/** Lists all {@link Extension} properties enabled and required for this root. */
/** Lists all {@link Extension Extensions} enabled and required for this root. */
listExtensionsRequired(): Extension[];

@@ -90,0 +90,0 @@ /**********************************************************************************************

@@ -26,3 +26,17 @@ import { Nullable, PropertyType } from '../constants.js';

copy(other: this, resolve?: <T extends import("./property.js").Property<import("./property.js").IProperty>>(t: T) => T): this;
/** Adds a {@link Node} to the Scene. */
/**
* Adds a {@link Node} to the Scene.
*
* Requirements:
*
* 1. Nodes MAY be root children of multiple {@link Scene Scenes}
* 2. Nodes MUST NOT be children of >1 Node
* 3. Nodes MUST NOT be children of both Nodes and {@link Scene Scenes}
*
* The `addChild` method enforces these restrictions automatically, and will
* remove the new child from previous parents where needed. This behavior
* may change in future major releases of the library.
*
* @privateRemarks Requires non-graph state.
*/
addChild(node: Node): this;

@@ -29,0 +43,0 @@ /** Removes a {@link Node} from the Scene. */

@@ -11,3 +11,3 @@ import { Nullable, PropertyType, vec2 } from '../constants.js';

*
* Textures in glTF-Transform are a combination of glTF's `texture` and `image` properties, and
* Textures in glTF Transform are a combination of glTF's `texture` and `image` properties, and
* should be unique within a document, such that no other texture contains the same

@@ -14,0 +14,0 @@ * {@link Texture.getImage getImage()} data. Where duplicates may already exist, the `dedup({textures: true})`

/**
* Module for glTF 2.0 Interface
*/
export declare module GLTF {
export declare namespace GLTF {
/** Data type of the values composing each element in the accessor. */

@@ -6,0 +6,0 @@ type AccessorComponentType = 5120 | 5121 | 5122 | 5123 | 5125 | 5126;

@@ -13,6 +13,1 @@ import { bbox } from '../constants.js';

export declare function getBounds(node: Node | Scene): bbox;
/**
* @deprecated Renamed to {@link getBounds}.
* @hidden
*/
export declare const bounds: typeof getBounds;

@@ -7,8 +7,4 @@ import type { mat4, vec3, vec4 } from '../constants.js';

static eq(a: number[], b: number[], tolerance?: number): boolean;
static decodeNormalizedInt(c: number, componentType: GLTF.AccessorComponentType): number;
/** @deprecated Renamed to {@link MathUtils.decodeNormalizedInt}. */
static denormalize(c: number, componentType: GLTF.AccessorComponentType): number;
static decodeNormalizedInt(i: number, componentType: GLTF.AccessorComponentType): number;
static encodeNormalizedInt(f: number, componentType: GLTF.AccessorComponentType): number;
/** @deprecated Renamed to {@link MathUtils.encodeNormalizedInt}. */
static normalize(f: number, componentType: GLTF.AccessorComponentType): number;
/**

@@ -15,0 +11,0 @@ * Decompose a mat4 to TRS properties.

{
"name": "@gltf-transform/core",
"version": "4.0.0-alpha.1",
"version": "4.0.0-alpha.2",
"repository": "github:donmccurdy/glTF-Transform",
"homepage": "https://gltf-transform.donmccurdy.com/",
"homepage": "https://gltf-transform.dev/",
"description": "glTF 2.0 SDK for JavaScript and TypeScript, on Web and Node.js.",
"author": "Don McCurdy <dm@donmccurdy.com>",
"license": "MIT",
"funding": "https://github.com/sponsors/donmccurdy",
"type": "module",
"sideEffects": false,
"exports": {
"types": "./dist/core.d.ts",
"require": "./dist/core.cjs",
"default": "./dist/core.modern.js"
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.modern.js"
},
"types": "./dist/core.d.ts",
"main": "./dist/core.cjs",
"module": "./dist/core.modern.js",
"source": "./src/core.ts",
"types": "./dist/index.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.modern.js",
"source": "./src/index.ts",
"browserslist": [

@@ -26,5 +27,4 @@ "defaults",

"scripts": {
"dist": "microbundle --format modern,cjs --define PACKAGE_VERSION=$npm_package_version",
"watch": "microbundle watch --format modern,cjs --define PACKAGE_VERSION=$npm_package_version",
"watch:debug": "microbundle watch --format modern,cjs --define PACKAGE_VERSION=$npm_package_version --no-compress"
"dist": "microbundle --format modern,cjs --no-compress --define PACKAGE_VERSION=$npm_package_version",
"watch": "microbundle watch --format modern,cjs --no-compress --define PACKAGE_VERSION=$npm_package_version"
},

@@ -50,3 +50,3 @@ "keywords": [

"dependencies": {
"property-graph": "^1.2.0"
"property-graph": "^1.3.1"
},

@@ -56,3 +56,3 @@ "mangle": {

},
"gitHead": "fb71aa67ca90f719b2d8d2d8fc759c49d5f9aa45"
"gitHead": "f2b911d41dd35f81a3e85debdfd17f5fb45df429"
}

@@ -7,13 +7,35 @@ # @gltf-transform/core

Part of the glTF-Transform project.
Part of the glTF Transform project.
- GitHub: https://github.com/donmccurdy/glTF-Transform
- Documentation: https://gltf-transform.donmccurdy.com/
- Documentation: https://gltf-transform.dev/
## Credits
See [*Credits*](https://gltf-transform.donmccurdy.com/credits).
See [*Credits*](https://gltf-transform.dev/credits).
<h2>Commercial Use</h2>
<p>
<b>Using glTF Transform for a personal project?</b> That's great! Sponsorship is neither expected nor required. Feel
free to share screenshots if you've made something you're excited about — I enjoy seeing those!
</p>
<p>
<b>Using glTF Transform in for-profit work?</b> That's wonderful! Your support is important to keep glTF Transform
maintained, independent, and open source under MIT License. Please consider a
<a href="https://gltf-transform.dev/pro" target="_blank">subscription</a>
or
<a href="https://github.com/sponsors/donmccurdy" target="_blank">GitHub sponsorship</a>.
</p>
<p>
<i>
Learn more in the
<a href="https://gltf-transform.dev/pro" target="_blank"> glTF Transform Pro </a> FAQs</i
>.
</p>
## License
Copyright 2023, MIT License.

@@ -63,3 +63,5 @@ import { PlatformIO } from './platform-io.js';

protected resolve(base: string, path: string): string {
return this._path.resolve(base, path);
// https://github.com/KhronosGroup/glTF/issues/1449
// https://stackoverflow.com/a/27278490/1314762
return this._path.resolve(base, decodeURIComponent(path));
}

@@ -66,0 +68,0 @@

@@ -116,3 +116,5 @@ import { Format } from '../constants.js';

}
return this._path.resolve(base, path);
// https://github.com/KhronosGroup/glTF/issues/1449
// https://stackoverflow.com/a/27278490/1314762
return this._path.resolve(base, decodeURIComponent(path));
}

@@ -161,4 +163,6 @@

}
// TODO(v4): Consider storing decoded URIs in memory, and avoid decoding here. However,
// we'll need to think through implications for absolute URLs.
const resource = Buffer.from(resources[resourceURI]);
const resourcePath = path.join(dir, resourceURI);
const resourcePath = path.join(dir, decodeURIComponent(resourceURI));
await fs.mkdir(path.dirname(resourcePath), { recursive: true });

@@ -165,0 +169,0 @@ await fs.writeFile(resourcePath, resource);

@@ -191,5 +191,8 @@ import { Format, GLB_BUFFER, VertexLayout } from '../constants.js';

// TODO(v4): Perhaps the resources dictionary could have been keyed by decoded URIs
// like "my image.png" instead of "my%20image.png". But for now, we use the URIs
// verbatim as found in resource definition. Consider revisiting in v4.
jsonDoc.resources[uri] = await this.readURI(this.resolve(base, uri), 'view');
this.lastReadBytes += jsonDoc.resources[uri].byteLength;
}
},
);

@@ -196,0 +199,0 @@ await Promise.all(pendingResources);

@@ -18,3 +18,3 @@ import type { JSONDocument } from '../json-document.js';

/**
* Model class providing glTF-Transform objects representing each definition in the glTF file, used
* Model class providing glTF Transform objects representing each definition in the glTF file, used
* by a {@link GLTFReader} and its {@link Extension} implementations. Indices of all properties will be

@@ -21,0 +21,0 @@ * consistent with the glTF file.

@@ -124,3 +124,3 @@ import { GLB_BUFFER, PropertyType, TypedArray, mat4, vec3, vec4, ComponentTypeToTypedArray } from '../constants.js';

// glTF-Transform's "Texture" properties correspond 1:1 with glTF "Image" properties, and
// glTF Transform's "Texture" properties correspond 1:1 with glTF "Image" properties, and
// with image files. The glTF file may contain more one texture per image, where images

@@ -138,3 +138,3 @@ // are reused with different sampler properties.

// glTF Image corresponds 1:1 with glTF-Transform Texture. See `writer.ts`.
// glTF Image corresponds 1:1 with glTF Transform Texture. See `writer.ts`.
if (imageDef.extras) texture.setExtras(imageDef.extras);

@@ -141,0 +141,0 @@

@@ -378,3 +378,3 @@ import {

// glTF-Transform's "Texture" properties correspond 1:1 with glTF "Image" properties, and
// glTF Transform's "Texture" properties correspond 1:1 with glTF "Image" properties, and
// with image files. The glTF file may contain more one texture per image, where images

@@ -381,0 +381,0 @@ // are reused with different sampler properties.

@@ -61,3 +61,3 @@ import { Nullable, PropertyType, TypedArray } from '../constants.js';

*
* glTF-Transform does not expose many details of sparse, normalized, or interleaved accessors
* glTF Transform does not expose many details of sparse, normalized, or interleaved accessors
* through its API. It reads files using those techniques, presents a simplified view of the data

@@ -111,3 +111,3 @@ * for editing, and attempts to write data back out with optimizations. For example, vertex

* 2-byte signed integer, stored as
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array Uint16Array}.
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array Int16Array}.
*/

@@ -365,3 +365,3 @@ SHORT: 5122,

if (normalized) {
this._out = (c: number): number => MathUtils.decodeNormalizedInt(c, this.get('componentType'));
this._out = (i: number): number => MathUtils.decodeNormalizedInt(i, this.get('componentType'));
this._in = (f: number): number => MathUtils.encodeNormalizedInt(f, this.get('componentType'));

@@ -368,0 +368,0 @@ } else {

@@ -12,3 +12,3 @@ import { Nullable, PropertyType } from '../constants.js';

* glTF 2.0 has three concepts relevant to binary storage: accessors, buffer views, and buffers.
* In glTF-Transform, an {@link Accessor} is referenced by any property that requires numeric typed
* In glTF Transform, an {@link Accessor} is referenced by any property that requires numeric typed
* array data. Meshes, Primitives, and Animations all reference Accessors. Buffers define how that

@@ -25,5 +25,5 @@ * data is organized into transmitted file(s). A `.glb` file has only a single Buffer, and when

*
* Buffer Views define how Accessors are organized within a given Buffer. glTF-Transform creates an
* Buffer Views define how Accessors are organized within a given Buffer. glTF Transform creates an
* efficient Buffer View layout automatically at export: there is no Buffer View property exposed
* by the glTF-Transform API, simplifying data management.
* by the glTF Transform API, simplifying data management.
*

@@ -30,0 +30,0 @@ * Usage:

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';

@@ -210,17 +209,2 @@ import type { Texture } from './texture.js';

/**
* Base color / albedo; sRGB hexadecimal color. See {@link Material.getBaseColorTexture getBaseColorTexture}.
*/
public getBaseColorHex(): number {
return ColorUtils.factorToHex(this.get('baseColorFactor'));
}
/**
* Base color / albedo; sRGB hexadecimal color. See {@link Material.getBaseColorTexture getBaseColorTexture}.
*/
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

@@ -266,13 +250,2 @@ * light would be a linear combination (multiplication) of its vertex colors, base color

/** Emissive; sRGB hexadecimal color. See {@link Material.getBaseColorTexture getBaseColorTexture}. */
public getEmissiveHex(): number {
return ColorUtils.factorToHex(this.get('emissiveFactor'));
}
/** Emissive; sRGB hexadecimal color. See {@link Material.getEmissiveTexture getEmissiveTexture}. */
public setEmissiveHex(hex: number): this {
const factor = this.get('emissiveFactor').slice() as vec3;
return this.set('emissiveFactor', ColorUtils.hexToFactor(hex, factor));
}
/**

@@ -279,0 +252,0 @@ * Emissive texture. Emissive color is added to any base color of the material, after any

@@ -10,2 +10,3 @@ import { multiply } from 'gl-matrix/mat4';

import type { Skin } from './skin.js';
import type { Scene } from './scene.js';

@@ -26,8 +27,8 @@ interface INode extends IExtensibleProperty {

*
* Each node may have one or more children, and a transform (position, rotation, and scale) that
* applies to all of its descendants. A node may also reference (or "instantiate") other resources
* at its location, including {@link Mesh}, Camera, Light, and Skin properties. A node cannot be
* Each Node may have one or more children, and a transform (position, rotation, and scale) that
* applies to all of its descendants. A Node may also reference (or "instantiate") other resources
* at its location, including {@link Mesh}, Camera, Light, and Skin properties. A Node cannot be
* part of more than one {@link Scene}.
*
* A node's local transform is represented with array-like objects, intended to be compatible with
* A Node's local transform is represented with array-like objects, intended to be compatible with
* [gl-matrix](https://github.com/toji/gl-matrix), or with the `toArray`/`fromArray` methods of

@@ -53,4 +54,14 @@ * libraries like three.js and babylon.js.

/** @internal Internal reference to node's parent, omitted from {@link Graph}. */
/**
* Internal reference to <=1 parent Nodes, omitted from {@link Graph}.
* @internal
* @privateRemarks Requires non-graph state.
*/
public _parentNode: Node | null = null;
/**
* Internal reference to N parent scenes, omitted from {@link Graph}.
* @internal
* @privateRemarks Requires non-graph state.
*/
public _parentScenes = new Set<Scene>();

@@ -75,4 +86,4 @@ protected init(): void {

public copy(other: this, resolve = COPY_IDENTITY): this {
// Node cannot be copied, only cloned. Copying is shallow, but nodes cannot have more than
// one parent. Rather than leaving one of the two nodes without children, throw an error here.
// Node cannot be copied, only cloned. Copying is shallow, but Nodes cannot have more than
// one parent. Rather than leaving one of the two Nodes without children, throw an error here.
if (resolve === COPY_IDENTITY) throw new Error('Node cannot be copied.');

@@ -86,3 +97,3 @@ return super.copy(other, resolve);

/** Returns the translation (position) of this node in local space. */
/** Returns the translation (position) of this Node in local space. */
public getTranslation(): vec3 {

@@ -92,3 +103,3 @@ return this.get('translation');

/** Returns the rotation (quaternion) of this node in local space. */
/** Returns the rotation (quaternion) of this Node in local space. */
public getRotation(): vec4 {

@@ -98,3 +109,3 @@ return this.get('rotation');

/** Returns the scale of this node in local space. */
/** Returns the scale of this Node in local space. */
public getScale(): vec3 {

@@ -104,3 +115,3 @@ return this.get('scale');

/** Sets the translation (position) of this node in local space. */
/** Sets the translation (position) of this Node in local space. */
public setTranslation(translation: vec3): this {

@@ -110,3 +121,3 @@ return this.set('translation', translation);

/** Sets the rotation (quaternion) of this node in local space. */
/** Sets the rotation (quaternion) of this Node in local space. */
public setRotation(rotation: vec4): this {

@@ -116,3 +127,3 @@ return this.set('rotation', rotation);

/** Sets the scale of this node in local space. */
/** Sets the scale of this Node in local space. */
public setScale(scale: vec3): this {

@@ -122,3 +133,3 @@ return this.set('scale', scale);

/** Returns the local matrix of this node. */
/** Returns the local matrix of this Node. */
public getMatrix(): mat4 {

@@ -129,7 +140,7 @@ return MathUtils.compose(

this.get('scale'),
[] as unknown as mat4
[] as unknown as mat4,
);
}
/** Sets the local matrix of this node. Matrix will be decomposed to TRS properties. */
/** Sets the local matrix of this Node. Matrix will be decomposed to TRS properties. */
public setMatrix(matrix: mat4): this {

@@ -147,3 +158,3 @@ const translation = this.get('translation').slice() as vec3;

/** Returns the translation (position) of this node in world space. */
/** Returns the translation (position) of this Node in world space. */
public getWorldTranslation(): vec3 {

@@ -155,3 +166,3 @@ const t = [0, 0, 0] as vec3;

/** Returns the rotation (quaternion) of this node in world space. */
/** Returns the rotation (quaternion) of this Node in world space. */
public getWorldRotation(): vec4 {

@@ -163,3 +174,3 @@ const r = [0, 0, 0, 1] as vec4;

/** Returns the scale of this node in world space. */
/** Returns the scale of this Node in world space. */
public getWorldScale(): vec3 {

@@ -171,3 +182,3 @@ const s = [1, 1, 1] as vec3;

/** Returns the world matrix of this node. */
/** Returns the world matrix of this Node. */
public getWorldMatrix(): mat4 {

@@ -195,6 +206,25 @@ // Build ancestor chain.

/** Adds another node as a child of this one. Nodes cannot have multiple parents. */
/**
* Adds the given Node as a child of this Node.
*
* Requirements:
*
* 1. Nodes MAY be root children of multiple {@link Scene Scenes}
* 2. Nodes MUST NOT be children of >1 Node
* 3. Nodes MUST NOT be children of both Nodes and {@link Scene Scenes}
*
* The `addChild` method enforces these restrictions automatically, and will
* remove the new child from previous parents where needed. This behavior
* may change in future major releases of the library.
*
* @privateRemarks Requires non-graph state.
*/
public addChild(child: Node): this {
// Remove existing parent.
// Remove existing parents.
if (child._parentNode) child._parentNode.removeChild(child);
if (child._parentScenes.size) {
for (const scene of child._parentScenes) {
scene.removeChild(child);
}
}

@@ -205,3 +235,3 @@ // Edge in graph.

// Set new parent.
// TODO(cleanup): Avoid using $attributes here?
// TODO(cleanup): Avoid reaching into $attributes.
child._parentNode = this;

@@ -214,3 +244,3 @@ const childrenRefs = this[$attributes]['children'];

/** Removes a node from this node's child node list. */
/** Removes a Node from this Node's child Node list. */
public removeChild(child: Node): this {

@@ -220,3 +250,3 @@ return this.removeRef('children', child);

/** Lists all child nodes of this node. */
/** Lists all child Nodes of this Node. */
public listChildren(): Node[] {

@@ -226,9 +256,2 @@ 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;
}
/**

@@ -250,3 +273,3 @@ * Returns the Node's unique parent Node within the scene graph. If the

/** Returns the {@link Mesh}, if any, instantiated at this node. */
/** Returns the {@link Mesh}, if any, instantiated at this Node. */
public getMesh(): Mesh | null {

@@ -257,4 +280,4 @@ return this.getRef('mesh');

/**
* Sets a {@link Mesh} to be instantiated at this node. A single mesh may be instatiated by
* multiple nodes; reuse of this sort is strongly encouraged.
* Sets a {@link Mesh} to be instantiated at this Node. A single mesh may be instatiated by
* multiple Nodes; reuse of this sort is strongly encouraged.
*/

@@ -265,3 +288,3 @@ public setMesh(mesh: Mesh | null): this {

/** Returns the {@link Camera}, if any, instantiated at this node. */
/** Returns the {@link Camera}, if any, instantiated at this Node. */
public getCamera(): Camera | null {

@@ -271,3 +294,3 @@ return this.getRef('camera');

/** Sets a {@link Camera} to be instantiated at this node. */
/** Sets a {@link Camera} to be instantiated at this Node. */
public setCamera(camera: Camera | null): this {

@@ -277,3 +300,3 @@ return this.setRef('camera', camera);

/** Returns the {@link Skin}, if any, instantiated at this node. */
/** Returns the {@link Skin}, if any, instantiated at this Node. */
public getSkin(): Skin | null {

@@ -283,3 +306,3 @@ return this.getRef('skin');

/** Sets a {@link Skin} to be instantiated at this node. */
/** Sets a {@link Skin} to be instantiated at this Node. */
public setSkin(skin: Skin | null): this {

@@ -290,3 +313,3 @@ return this.setRef('skin', skin);

/**
* Initial weights of each {@link PrimitiveTarget} for the mesh instance at this node.
* Initial weights of each {@link PrimitiveTarget} for the mesh instance at this Node.
* Most engines only support 4-8 active morph targets at a time.

@@ -299,3 +322,3 @@ */

/**
* Initial weights of each {@link PrimitiveTarget} for the mesh instance at this node.
* Initial weights of each {@link PrimitiveTarget} for the mesh instance at this Node.
* Most engines only support 4-8 active morph targets at a time.

@@ -318,8 +341,1 @@ */

}
interface SceneNode {
propertyType: PropertyType;
_parent?: SceneNode | null;
addChild(node: Node): this;
removeChild(node: Node): this;
}

@@ -47,3 +47,3 @@ import { Nullable, PropertyType, VERSION } from '../constants.js';

* indirectly) by the root. Metadata about the asset's license, generator, and glTF specification
* version are stored in the asset, accessible with {@link .getAsset}().
* version are stored in the asset, accessible with {@link Root.getAsset}.
*

@@ -175,3 +175,3 @@ * Properties are added to the root with factory methods on its {@link Document}, and removed by

/** Lists all {@link Extension} properties enabled for this root. */
/** Lists all {@link Extension Extensions} enabled for this root. */
public listExtensionsUsed(): Extension[] {

@@ -181,3 +181,3 @@ return Array.from(this._extensions);

/** Lists all {@link Extension} properties enabled and required for this root. */
/** Lists all {@link Extension Extensions} enabled and required for this root. */
public listExtensionsRequired(): Extension[] {

@@ -184,0 +184,0 @@ return this.listExtensionsUsed().filter((extension) => extension.isRequired());

@@ -0,1 +1,2 @@

import { $attributes } from 'property-graph';
import { Nullable, PropertyType } from '../constants.js';

@@ -42,5 +43,31 @@ import { ExtensibleProperty, IExtensibleProperty } from './extensible-property.js';

/** Adds a {@link Node} to the Scene. */
/**
* Adds a {@link Node} to the Scene.
*
* Requirements:
*
* 1. Nodes MAY be root children of multiple {@link Scene Scenes}
* 2. Nodes MUST NOT be children of >1 Node
* 3. Nodes MUST NOT be children of both Nodes and {@link Scene Scenes}
*
* The `addChild` method enforces these restrictions automatically, and will
* remove the new child from previous parents where needed. This behavior
* may change in future major releases of the library.
*
* @privateRemarks Requires non-graph state.
*/
public addChild(node: Node): this {
return this.addRef('children', node);
// Remove existing parent.
if (node._parentNode) node._parentNode.removeChild(node);
// Edge in graph.
this.addRef('children', node);
// Set new parent.
// TODO(cleanup): Avoid reaching into $attributes.
node._parentScenes.add(this);
const childrenRefs = this[$attributes]['children'];
const ref = childrenRefs[childrenRefs.length - 1];
ref.addEventListener('dispose', () => node._parentScenes.delete(this));
return this;
}

@@ -47,0 +74,0 @@

@@ -14,3 +14,3 @@ import { Nullable, PropertyType, vec2 } from '../constants.js';

*
* Textures in glTF-Transform are a combination of glTF's `texture` and `image` properties, and
* Textures in glTF Transform are a combination of glTF's `texture` and `image` properties, and
* should be unique within a document, such that no other texture contains the same

@@ -17,0 +17,0 @@ * {@link Texture.getImage getImage()} data. Where duplicates may already exist, the `dedup({textures: true})`

@@ -33,8 +33,2 @@ import { transformMat4 } from 'gl-matrix/vec3';

/**
* @deprecated Renamed to {@link getBounds}.
* @hidden
*/
export const bounds = getBounds;
/** Computes mesh bounds in local space. */

@@ -41,0 +35,0 @@ function getMeshBounds(mesh: Mesh, worldMatrix: mat4): bbox {

@@ -22,15 +22,16 @@ import { determinant, getRotation } from 'gl-matrix/mat4';

public static decodeNormalizedInt(c: number, componentType: GLTF.AccessorComponentType): number {
// TODO(v4): Compare performance if we replace the switch with individual functions.
public static decodeNormalizedInt(i: number, componentType: GLTF.AccessorComponentType): number {
// Hardcode enums from accessor.ts to avoid a circular dependency.
switch (componentType) {
case 5126:
return c;
case 5123:
return c / 65535.0;
case 5121:
return c / 255.0;
case 5122:
return Math.max(c / 32767.0, -1.0);
case 5120:
return Math.max(c / 127.0, -1.0);
case 5126: // FLOAT
return i;
case 5123: // UNSIGNED_SHORT
return i / 65535.0;
case 5121: // UNSIGNED_BYTE
return i / 255.0;
case 5122: // SHORT
return Math.max(i / 32767.0, -1.0);
case 5120: // BYTE
return Math.max(i / 127.0, -1.0);
default:

@@ -41,19 +42,16 @@ throw new Error('Invalid component type.');

/** @deprecated Renamed to {@link MathUtils.decodeNormalizedInt}. */
public static denormalize(c: number, componentType: GLTF.AccessorComponentType): number {
return MathUtils.decodeNormalizedInt(c, 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 {
// Hardcode enums from accessor.ts to avoid a circular dependency.
switch (componentType) {
case 5126:
case 5126: // FLOAT
return f;
case 5123:
case 5123: // UNSIGNED_SHORT
return Math.round(f * 65535.0);
case 5121:
case 5121: // UNSIGNED_BYTE
return Math.round(f * 255.0);
case 5122:
case 5122: // SHORT
return Math.round(f * 32767.0);
case 5120:
case 5120: // BYTE
return Math.round(f * 127.0);

@@ -65,7 +63,2 @@ default:

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

@@ -72,0 +65,0 @@ * Decompose a mat4 to TRS properties.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc