@gltf-transform/functions
Advanced tools
Comparing version 4.0.0-alpha.12 to 4.0.0-alpha.13
@@ -53,3 +53,3 @@ import { Scene, Node, Mesh, Primitive } from '@gltf-transform/core'; | ||
* | ||
* @hidden Not yet implemented. | ||
* @hidden TODO(feat): Not yet implemented. | ||
*/ | ||
@@ -63,3 +63,3 @@ DISTINCT = "distinct", | ||
* | ||
* @hidden Not yet implemented. | ||
* @hidden TODO(feat): Not yet implemented. | ||
*/ | ||
@@ -66,0 +66,0 @@ DISTINCT_POSITION = "distinct-position", |
export * from './center.js'; | ||
export * from './clear-node-parent.js'; | ||
export * from './clear-node-transform.js'; | ||
export * from './convert-primitive-mode.js'; | ||
export * from './dedup.js'; | ||
@@ -8,2 +9,3 @@ export { dequantize, dequantizePrimitive, DequantizeOptions } from './dequantize.js'; | ||
export * from './flatten.js'; | ||
export * from './get-bounds.js'; | ||
export * from './get-vertex-count.js'; | ||
@@ -10,0 +12,0 @@ export * from './get-texture-color-space.js'; |
@@ -1,2 +0,2 @@ | ||
import { Document, Primitive, Transform } from '@gltf-transform/core'; | ||
import { Primitive, Transform } from '@gltf-transform/core'; | ||
/** Options for the {@link simplify} function. */ | ||
@@ -60,2 +60,3 @@ export interface SimplifyOptions { | ||
export declare function simplify(_options: SimplifyOptions): Transform; | ||
export declare function simplifyPrimitive(document: Document, prim: Primitive, _options: SimplifyOptions): Primitive; | ||
/** @hidden */ | ||
export declare function simplifyPrimitive(prim: Primitive, _options: SimplifyOptions): Primitive; |
import type { NdArray } from 'ndarray'; | ||
import { Accessor, Document, Primitive, Property, Texture, Transform, TransformContext, TypedArray, vec2 } from '@gltf-transform/core'; | ||
import { Accessor, Document, GLTF, Primitive, Property, Texture, Transform, TransformContext, TypedArray, vec2 } from '@gltf-transform/core'; | ||
/** | ||
@@ -73,2 +73,8 @@ * Prepares a function used in an {@link Document#transform} pipeline. Use of this wrapper is | ||
export declare function ceilPowerOfTwo(value: number): number; | ||
/** | ||
* Mapping from any glTF primitive mode to its equivalent basic mode, as returned by | ||
* {@link convertPrimitiveMode}. | ||
* @hidden | ||
*/ | ||
export declare const BASIC_MODE_MAPPING: Record<GLTF.MeshPrimitiveMode, GLTF.MeshPrimitiveMode>; | ||
export {}; |
{ | ||
"name": "@gltf-transform/functions", | ||
"version": "4.0.0-alpha.12", | ||
"version": "4.0.0-alpha.13", | ||
"repository": "github:donmccurdy/glTF-Transform", | ||
@@ -38,4 +38,4 @@ "homepage": "https://gltf-transform.dev/functions.html", | ||
"dependencies": { | ||
"@gltf-transform/core": "^4.0.0-alpha.12", | ||
"@gltf-transform/extensions": "^4.0.0-alpha.12", | ||
"@gltf-transform/core": "^4.0.0-alpha.13", | ||
"@gltf-transform/extensions": "^4.0.0-alpha.13", | ||
"ktx-parse": "^0.7.0", | ||
@@ -56,3 +56,3 @@ "ndarray": "^1.0.19", | ||
}, | ||
"gitHead": "28df1abd4360a833b6cb170955d6cddae66ca7f7" | ||
"gitHead": "e1040fa15cba3d6c753047e0a974ed3b4176e4d5" | ||
} |
@@ -59,3 +59,3 @@ import { Scene, Node, Mesh, Primitive, Accessor } from '@gltf-transform/core'; | ||
* | ||
* @hidden Not yet implemented. | ||
* @hidden TODO(feat): Not yet implemented. | ||
*/ | ||
@@ -70,3 +70,3 @@ DISTINCT = 'distinct', | ||
* | ||
* @hidden Not yet implemented. | ||
* @hidden TODO(feat): Not yet implemented. | ||
*/ | ||
@@ -73,0 +73,0 @@ DISTINCT_POSITION = 'distinct-position', |
export * from './center.js'; | ||
export * from './clear-node-parent.js'; | ||
export * from './clear-node-transform.js'; | ||
export * from './convert-primitive-mode.js'; | ||
export * from './dedup.js'; | ||
@@ -8,2 +9,3 @@ export { dequantize, dequantizePrimitive, DequantizeOptions } from './dequantize.js'; | ||
export * from './flatten.js'; | ||
export * from './get-bounds.js'; | ||
export * from './get-vertex-count.js'; | ||
@@ -10,0 +12,0 @@ export * from './get-texture-color-space.js'; |
import { Document, Primitive, ComponentTypeToTypedArray } from '@gltf-transform/core'; | ||
import { createIndices, createPrimGroupKey, remapAttribute, remapIndices, shallowCloneAccessor } from './utils.js'; | ||
import { convertPrimitiveToLines, convertPrimitiveToTriangles } from './convert-primitive-mode.js'; | ||
@@ -14,2 +15,4 @@ interface JoinPrimitiveOptions { | ||
const { LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP, TRIANGLE_FAN } = Primitive.Mode; | ||
/** | ||
@@ -50,2 +53,16 @@ * Given a list of compatible Mesh {@link Primitive Primitives}, returns new Primitive | ||
// (2) Convert all prims to POINTS, LINES, or TRIANGLES. | ||
for (const prim of prims) { | ||
switch (prim.getMode()) { | ||
case LINE_STRIP: | ||
case LINE_LOOP: | ||
convertPrimitiveToLines(prim); | ||
break; | ||
case TRIANGLE_STRIP: | ||
case TRIANGLE_FAN: | ||
convertPrimitiveToTriangles(prim); | ||
break; | ||
} | ||
} | ||
const primRemaps = [] as Uint32Array[]; // remap[srcIndex] → dstIndex, by prim | ||
@@ -57,3 +74,3 @@ const primVertexCounts = new Uint32Array(prims.length); // vertex count, by prim | ||
// (2) Build remap lists. | ||
// (3) Build remap lists. | ||
for (let primIndex = 0; primIndex < prims.length; primIndex++) { | ||
@@ -80,3 +97,3 @@ const srcPrim = prims[primIndex]; | ||
// (3) Allocate joined attributes. | ||
// (4) Allocate joined attributes. | ||
const dstPrim = document.createPrimitive().setMode(templatePrim.getMode()).setMaterial(templatePrim.getMaterial()); | ||
@@ -92,3 +109,3 @@ for (const semantic of templatePrim.listSemantics()) { | ||
// (4) Allocate joined indices. | ||
// (5) Allocate joined indices. | ||
const srcIndices = templatePrim.getIndices(); | ||
@@ -100,3 +117,3 @@ const dstIndices = srcIndices | ||
// (5) Remap attributes into joined Primitive. | ||
// (6) Remap attributes into joined Primitive. | ||
let dstIndicesOffset = 0; | ||
@@ -103,0 +120,0 @@ for (let primIndex = 0; primIndex < primRemaps.length; primIndex++) { |
@@ -16,5 +16,8 @@ import { Document, Primitive, PropertyType, Transform } from '@gltf-transform/core'; | ||
import { unweldPrimitive } from './unweld.js'; | ||
import { convertPrimitiveToTriangles } from './convert-primitive-mode.js'; | ||
const NAME = 'simplify'; | ||
const { POINTS, LINES, LINE_STRIP, LINE_LOOP, TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN } = Primitive.Mode; | ||
/** Options for the {@link simplify} function. */ | ||
@@ -99,13 +102,16 @@ export interface SimplifyOptions { | ||
let numUnsupported = 0; | ||
// Simplify mesh primitives. | ||
for (const mesh of document.getRoot().listMeshes()) { | ||
for (const prim of mesh.listPrimitives()) { | ||
if (prim.getMode() === Primitive.Mode.TRIANGLES) { | ||
simplifyPrimitive(document, prim, options); | ||
const mode = prim.getMode(); | ||
if (mode === TRIANGLES || mode === TRIANGLE_STRIP || mode === TRIANGLE_FAN) { | ||
simplifyPrimitive(prim, options); | ||
if (prim.getIndices()!.getCount() === 0) prim.dispose(); | ||
} else if (prim.getMode() === Primitive.Mode.POINTS && !!simplifier.simplifyPoints) { | ||
simplifyPrimitive(document, prim, options); | ||
} else if (prim.getMode() === POINTS && !!simplifier.simplifyPoints) { | ||
simplifyPrimitive(prim, options); | ||
if (prim.getAttribute('POSITION')!.getCount() === 0) prim.dispose(); | ||
} else { | ||
logger.warn(`${NAME}: Skipping primitive of mesh "${mesh.getName()}": Unsupported draw mode.`); | ||
numUnsupported++; | ||
} | ||
@@ -117,2 +123,6 @@ } | ||
if (numUnsupported > 0) { | ||
logger.warn(`${NAME}: Skipping simplification of ${numUnsupported} primitives: Unsupported draw mode.`); | ||
} | ||
// Where simplification removes meshes, we may need to prune leaf nodes. | ||
@@ -135,11 +145,24 @@ if (options.cleanup) { | ||
export function simplifyPrimitive(document: Document, prim: Primitive, _options: SimplifyOptions): Primitive { | ||
/** @hidden */ | ||
export function simplifyPrimitive(prim: Primitive, _options: SimplifyOptions): Primitive { | ||
const options = { ...SIMPLIFY_DEFAULTS, ..._options } as Required<SimplifyOptions>; | ||
const simplifier = options.simplifier as typeof MeshoptSimplifier; | ||
const graph = prim.getGraph(); | ||
const document = Document.fromGraph(graph)!; | ||
const logger = document.getLogger(); | ||
if (prim.getMode() === Primitive.Mode.POINTS) { | ||
return _simplifyPoints(document, prim, options); | ||
switch (prim.getMode()) { | ||
case POINTS: | ||
return _simplifyPoints(document, prim, options); | ||
case LINES: | ||
case LINE_STRIP: | ||
case LINE_LOOP: | ||
logger.warn(`${NAME}: Skipping primitive simplification: Unsupported draw mode.`); | ||
return prim; | ||
case TRIANGLE_STRIP: | ||
case TRIANGLE_FAN: | ||
convertPrimitiveToTriangles(prim); | ||
break; | ||
} | ||
const logger = document.getLogger(); | ||
const position = prim.getAttribute('POSITION')!; | ||
@@ -146,0 +169,0 @@ const srcIndices = prim.getIndices()!; |
@@ -6,2 +6,3 @@ import type { NdArray } from 'ndarray'; | ||
Document, | ||
GLTF, | ||
Primitive, | ||
@@ -18,2 +19,4 @@ Property, | ||
const { POINTS, LINES, LINE_STRIP, LINE_LOOP, TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN } = Primitive.Mode; | ||
/** | ||
@@ -318,3 +321,3 @@ * Prepares a function used in an {@link Document#transform} pipeline. Use of this wrapper is | ||
const materialIndex = document.getRoot().listMaterials().indexOf(material!); | ||
const mode = prim.getMode(); | ||
const mode = BASIC_MODE_MAPPING[prim.getMode()]; | ||
const indices = !!prim.getIndices(); | ||
@@ -415,1 +418,16 @@ | ||
} | ||
/** | ||
* Mapping from any glTF primitive mode to its equivalent basic mode, as returned by | ||
* {@link convertPrimitiveMode}. | ||
* @hidden | ||
*/ | ||
export const BASIC_MODE_MAPPING = { | ||
[POINTS]: POINTS, | ||
[LINES]: LINES, | ||
[LINE_STRIP]: LINES, | ||
[LINE_LOOP]: LINES, | ||
[TRIANGLES]: TRIANGLES, | ||
[TRIANGLE_STRIP]: TRIANGLES, | ||
[TRIANGLE_FAN]: TRIANGLES, | ||
} as Record<GLTF.MeshPrimitiveMode, GLTF.MeshPrimitiveMode>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2328470
99
27747