New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@gltf-transform/core

Package Overview
Dependencies
Maintainers
1
Versions
209
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 0.12.9 to 0.12.10

35

dist/io/writer-context.d.ts

@@ -8,2 +8,12 @@ import { Document } from '../document';

declare type PropertyDef = GLTF.IScene | GLTF.INode | GLTF.IMaterial | GLTF.ISkin | GLTF.ITexture;
declare enum BufferViewTarget {
ARRAY_BUFFER = 34962,
ELEMENT_ARRAY_BUFFER = 34963
}
declare enum BufferViewUsage {
ARRAY_BUFFER = "ARRAY_BUFFER",
ELEMENT_ARRAY_BUFFER = "ELEMENT_ARRAY_BUFFER",
INVERSE_BIND_MATRICES = "INVERSE_BIND_MATRICES",
OTHER = "OTHER"
}
/**

@@ -19,2 +29,14 @@ * Model class providing writing state to a {@link Writer} and its {@link Extension}

readonly options: Required<WriterOptions>;
/** Explicit buffer view targets defined by glTF specification. */
static readonly BufferViewTarget: typeof BufferViewTarget;
/**
* Implicit buffer view usage, not required by glTF specification, but nonetheless useful for
* proper grouping of accessors into buffer views. Additional usages are defined by extensions,
* like `EXT_mesh_gpu_instancing`.
*/
static readonly BufferViewUsage: typeof BufferViewUsage;
/** Maps usage type to buffer view target. Usages not mapped have undefined targets. */
static readonly USAGE_TO_TARGET: {
[key: string]: BufferViewTarget | undefined;
};
readonly accessorIndexMap: Map<Accessor, number>;

@@ -53,7 +75,8 @@ readonly bufferIndexMap: Map<Buffer, number>;

/**
* Returns usage for the given accessor, if any. Some accessor types must be grouped into
* buffer views with like accessors. This includes the specified buffer view "targets", but
* also implicit usage like IBMs or instanced mesh attributes.
* Returns implicit usage type of the given accessor, related to grouping accessors into
* buffer views. Usage is a superset of buffer view target, including ARRAY_BUFFER and
* ELEMENT_ARRAY_BUFFER, but also usages that do not match GPU buffer view targets such as
* IBMs. Additional usages are defined by extensions, like `EXT_mesh_gpu_instancing`.
*/
getAccessorUsage(accessor: Accessor): string | null;
getAccessorUsage(accessor: Accessor): BufferViewUsage | string;
/**

@@ -65,5 +88,5 @@ * Sets usage for the given accessor. Some accessor types must be grouped into

*/
setAccessorUsage(accessor: Accessor, usage: string): this;
addAccessorToUsageGroup(accessor: Accessor, usage: BufferViewUsage | string): this;
/** Lists accessors grouped by usage. Accessors with unspecified usage are not included. */
listAccessorsByUsage(): {
listAccessorUsageGroups(): {
[key: string]: Accessor[];

@@ -70,0 +93,0 @@ };

4

package.json
{
"name": "@gltf-transform/core",
"version": "0.12.9",
"version": "0.12.10",
"repository": "github:donmccurdy/glTF-Transform",

@@ -43,3 +43,3 @@ "homepage": "https://gltf-transform.donmccurdy.com/",

},
"gitHead": "f1746a34aaafa39ccbed30521d71f9ee1b647d6c"
"gitHead": "625a26d84538eef957d28394aa5fe58f71083cbf"
}

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

const assetDef = jsonDoc.json.asset;
const assetDef = json.asset;
const asset = doc.getRoot().getAsset();

@@ -55,2 +55,6 @@

if (json.extras !== undefined) {
doc.getRoot().setExtras({...json.extras});
}
/** Extensions (1/2). */

@@ -57,0 +61,0 @@

import { Format } from '../constants';
import { Document } from '../document';
import { JSONDocument } from '../json-document';
import { Accessor, Buffer, Camera, Material, Mesh, Node, Property, Skin, Texture, TextureInfo } from '../properties';
import { Accessor, AttributeLink, Buffer, Camera, IndexLink, Material, Mesh, Node, Property, Skin, Texture, TextureInfo } from '../properties';
import { GLTF } from '../types/gltf';

@@ -11,2 +11,13 @@ import { ImageUtils, Logger } from '../utils';

enum BufferViewTarget {
ARRAY_BUFFER = 34962,
ELEMENT_ARRAY_BUFFER = 34963,
}
enum BufferViewUsage {
ARRAY_BUFFER = 'ARRAY_BUFFER',
ELEMENT_ARRAY_BUFFER = 'ELEMENT_ARRAY_BUFFER',
INVERSE_BIND_MATRICES = 'INVERSE_BIND_MATRICES',
OTHER = 'OTHER',
}
/**

@@ -19,2 +30,16 @@ * Model class providing writing state to a {@link Writer} and its {@link Extension}

export class WriterContext {
/** Explicit buffer view targets defined by glTF specification. */
public static readonly BufferViewTarget = BufferViewTarget;
/**
* Implicit buffer view usage, not required by glTF specification, but nonetheless useful for
* proper grouping of accessors into buffer views. Additional usages are defined by extensions,
* like `EXT_mesh_gpu_instancing`.
*/
public static readonly BufferViewUsage = BufferViewUsage;
/** Maps usage type to buffer view target. Usages not mapped have undefined targets. */
public static readonly USAGE_TO_TARGET: {[key: string]: BufferViewTarget | undefined} = {
[BufferViewUsage.ARRAY_BUFFER]: BufferViewTarget.ARRAY_BUFFER,
[BufferViewUsage.ELEMENT_ARRAY_BUFFER]: BufferViewTarget.ELEMENT_ARRAY_BUFFER,
};
public readonly accessorIndexMap = new Map<Accessor, number>();

@@ -41,3 +66,3 @@ public readonly bufferIndexMap = new Map<Buffer, number>();

private readonly _accessorUsageMap = new Map<Accessor, string>();
private readonly _accessorUsageMap = new Map<Accessor, BufferViewUsage | string>();
public readonly accessorUsageGroupedByParent = new Set<string>(['ARRAY_BUFFER']);

@@ -150,8 +175,25 @@ public readonly accessorParents = new Map<Property, Set<Accessor>>();

/**
* Returns usage for the given accessor, if any. Some accessor types must be grouped into
* buffer views with like accessors. This includes the specified buffer view "targets", but
* also implicit usage like IBMs or instanced mesh attributes.
* Returns implicit usage type of the given accessor, related to grouping accessors into
* buffer views. Usage is a superset of buffer view target, including ARRAY_BUFFER and
* ELEMENT_ARRAY_BUFFER, but also usages that do not match GPU buffer view targets such as
* IBMs. Additional usages are defined by extensions, like `EXT_mesh_gpu_instancing`.
*/
getAccessorUsage(accessor: Accessor): string | null {
return this._accessorUsageMap.get(accessor) || null;
public getAccessorUsage(accessor: Accessor): BufferViewUsage | string {
const cachedUsage = this._accessorUsageMap.get(accessor);
if (cachedUsage) return cachedUsage;
for (const link of this._doc.getGraph().listParentLinks(accessor)) {
if (link.getName() === 'inverseBindMatrices') {
return WriterContext.BufferViewUsage.INVERSE_BIND_MATRICES;
}
if (link instanceof AttributeLink) {
return WriterContext.BufferViewUsage.ARRAY_BUFFER;
}
if (link instanceof IndexLink) {
return WriterContext.BufferViewUsage.ELEMENT_ARRAY_BUFFER;
}
}
// Group accessors with no specified usage into a miscellaneous buffer view.
return WriterContext.BufferViewUsage.OTHER;
}

@@ -165,3 +207,3 @@

*/
setAccessorUsage(accessor: Accessor, usage: string): this {
public addAccessorToUsageGroup(accessor: Accessor, usage: BufferViewUsage | string): this {
const prevUsage = this._accessorUsageMap.get(accessor);

@@ -176,3 +218,3 @@ if (prevUsage && prevUsage !== usage) {

/** Lists accessors grouped by usage. Accessors with unspecified usage are not included. */
listAccessorsByUsage(): {[key: string]: Accessor[]} {
public listAccessorUsageGroups(): {[key: string]: Accessor[]} {
const result = {} as {[key: string]: Accessor[]};

@@ -179,0 +221,0 @@ for (const [accessor, usage] of Array.from(this._accessorUsageMap.entries())) {

@@ -5,3 +5,3 @@ import { Format, GLB_BUFFER, PropertyType, VERSION, VertexLayout } from '../constants';

import { JSONDocument } from '../json-document';
import { Accessor, AnimationSampler, AttributeLink, Camera, IndexLink, Material, Property } from '../properties';
import { Accessor, AnimationSampler, Camera, Material, Property } from '../properties';
import { GLTF } from '../types/gltf';

@@ -11,14 +11,4 @@ import { BufferUtils, Logger, MathUtils } from '../utils';

const BufferViewTarget = {
ARRAY_BUFFER: 34962,
ELEMENT_ARRAY_BUFFER: 34963
};
const { BufferViewUsage } = WriterContext;
const BufferViewUsage = {
ARRAY_BUFFER: 'ARRAY_BUFFER',
ELEMENT_ARRAY_BUFFER: 'ELEMENT_ARRAY_BUFFER',
INVERSE_BIND_MATRICES: 'INVERSE_BIND_MATRICES',
OTHER: 'OTHER',
};
export interface WriterOptions {

@@ -37,4 +27,6 @@ format: Format;

const root = doc.getRoot();
const asset = {...root.getAsset(), generator: `glTF-Transform ${VERSION}`};
const json = {asset} as GLTF.IGLTF;
const json = {
asset: {...root.getAsset(), generator: `glTF-Transform ${VERSION}`},
extras: {...root.getExtras()},
} as GLTF.IGLTF;
const jsonDoc = {json, resources: {}} as JSONDocument;

@@ -187,3 +179,3 @@

byteStride: byteStride,
target: BufferViewTarget.ARRAY_BUFFER,
target: WriterContext.BufferViewTarget.ARRAY_BUFFER,
};

@@ -259,23 +251,8 @@ json.bufferViews!.push(bufferViewDef);

const accessorRefs = accessorLinks.get(accessor) || [];
for (const link of accessorRefs) {
if (context.getAccessorUsage(accessor)) break;
const usage = context.getAccessorUsage(accessor);
context.addAccessorToUsageGroup(accessor, usage);
if (link instanceof AttributeLink) {
context.setAccessorUsage(accessor, BufferViewUsage.ARRAY_BUFFER);
} else if (link instanceof IndexLink) {
context.setAccessorUsage(accessor, BufferViewUsage.ELEMENT_ARRAY_BUFFER);
} else if (link.getName() === 'inverseBindMatrices') {
context.setAccessorUsage(accessor, BufferViewUsage.INVERSE_BIND_MATRICES);
}
}
// Group accessors with no specified usage into a miscellaneous buffer view.
if (!context.getAccessorUsage(accessor)) {
context.setAccessorUsage(accessor, BufferViewUsage.OTHER);
}
// For accessor usage that requires grouping by parent (vertex and instance
// attributes) organize buffer views accordingly.
const usage = context.getAccessorUsage(accessor);
if (usage && groupByParent.has(usage)) {
if (groupByParent.has(usage)) {
const parent = accessorRefs[0].getParent();

@@ -310,3 +287,3 @@ const parentAccessors = accessorParents.get(parent) || new Set<Accessor>();

const usageGroups = context.listAccessorsByUsage();
const usageGroups = context.listAccessorUsageGroups();

@@ -356,3 +333,3 @@ for (const usage in usageGroups) {

const target = usage === BufferViewUsage.ELEMENT_ARRAY_BUFFER
? BufferViewTarget.ELEMENT_ARRAY_BUFFER
? WriterContext.BufferViewTarget.ELEMENT_ARRAY_BUFFER
: undefined;

@@ -367,4 +344,5 @@ const result = concatAccessors(

// We only support embedded images in GLB, so we know there is only one buffer.
if (context.imageBufferViews.length) {
// We only support embedded images in GLB, where the embedded buffer must be the first.
// Additional buffers are currently left empty (see EXT_meshopt_compression fallback).
if (context.imageBufferViews.length && index === 0) {
for (let i = 0; i < context.imageBufferViews.length; i++) {

@@ -737,2 +715,4 @@ json.bufferViews![json.images![i].bufferView!].byteOffset = bufferByteLength;

unused.push(key);
} else if (value && typeof value === 'object' && Object.keys(value).length === 0) {
unused.push(key);
}

@@ -739,0 +719,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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