@needle-tools/gltf-build-pipeline 2.16.0-next.eb5a640 → 3.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +13 -1
- package/dist/cli/index.js +4154 -258
- package/package.json +9 -14
- package/tools/pmrem/pkg/pmrem_wasm.d.ts +25 -0
- package/tools/pmrem/pkg/pmrem_wasm.js +110 -0
- package/tools/pmrem/pkg/pmrem_wasm_bg.wasm +0 -0
- package/dist/cache/cache.d.ts +0 -59
- package/dist/cache/cache.js +0 -350
- package/dist/cache/index.d.ts +0 -2
- package/dist/cache/index.js +0 -2
- package/dist/cache/job-cache.d.ts +0 -28
- package/dist/cache/job-cache.js +0 -86
- package/dist/cli/index.d.ts +0 -2
- package/dist/config/index.d.ts +0 -64
- package/dist/config/index.js +0 -161
- package/dist/constants.d.ts +0 -7
- package/dist/constants.js +0 -7
- package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.d.ts +0 -24
- package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.js +0 -54
- package/dist/extensions/NEEDLE_compression_texture/index.d.ts +0 -1
- package/dist/extensions/NEEDLE_compression_texture/index.js +0 -1
- package/dist/extensions/NEEDLE_lightmaps/index.d.ts +0 -39
- package/dist/extensions/NEEDLE_lightmaps/index.js +0 -257
- package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.d.ts +0 -27
- package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.js +0 -88
- package/dist/extensions/NEEDLE_mesh_compression/index.d.ts +0 -1
- package/dist/extensions/NEEDLE_mesh_compression/index.js +0 -1
- package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.d.ts +0 -27
- package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.js +0 -1078
- package/dist/extensions/NEEDLE_opaque/index.d.ts +0 -2
- package/dist/extensions/NEEDLE_opaque/index.js +0 -30
- package/dist/extensions/NEEDLE_pmrem/index.d.ts +0 -21
- package/dist/extensions/NEEDLE_pmrem/index.js +0 -95
- package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.d.ts +0 -48
- package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.js +0 -69
- package/dist/extensions/NEEDLE_progressive/index.d.ts +0 -1
- package/dist/extensions/NEEDLE_progressive/index.js +0 -1
- package/dist/extensions/NEEDLE_progressive_mesh_settings/index.d.ts +0 -23
- package/dist/extensions/NEEDLE_progressive_mesh_settings/index.js +0 -41
- package/dist/extensions/NEEDLE_progressive_texture_settings/index.d.ts +0 -25
- package/dist/extensions/NEEDLE_progressive_texture_settings/index.js +0 -38
- package/dist/extensions/index.d.ts +0 -15
- package/dist/extensions/index.js +0 -34
- package/dist/extensions/utils.d.ts +0 -9
- package/dist/extensions/utils.js +0 -79
- package/dist/functions/weld.3.d.ts +0 -76
- package/dist/functions/weld.3.js +0 -414
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -8
- package/dist/scripts/index.d.ts +0 -2
- package/dist/scripts/index.js +0 -2
- package/dist/scripts/pack-gltf.d.ts +0 -19
- package/dist/scripts/pack-gltf.js +0 -187
- package/dist/scripts/stats.d.ts +0 -5
- package/dist/scripts/stats.js +0 -20
- package/dist/transforms/index.d.ts +0 -12
- package/dist/transforms/index.js +0 -12
- package/dist/transforms/needle_animation_transform.d.ts +0 -2
- package/dist/transforms/needle_animation_transform.js +0 -5
- package/dist/transforms/needle_asset.d.ts +0 -3
- package/dist/transforms/needle_asset.js +0 -50
- package/dist/transforms/needle_audio.d.ts +0 -12
- package/dist/transforms/needle_audio.js +0 -104
- package/dist/transforms/needle_audio_ffmpeg.d.ts +0 -14
- package/dist/transforms/needle_audio_ffmpeg.js +0 -51
- package/dist/transforms/needle_audio_registry.d.ts +0 -38
- package/dist/transforms/needle_audio_registry.js +0 -47
- package/dist/transforms/needle_common.d.ts +0 -17
- package/dist/transforms/needle_common.js +0 -1
- package/dist/transforms/needle_mesh_transform.d.ts +0 -15
- package/dist/transforms/needle_mesh_transform.js +0 -223
- package/dist/transforms/needle_pmrem.d.ts +0 -21
- package/dist/transforms/needle_pmrem.js +0 -238
- package/dist/transforms/needle_progressive.d.ts +0 -53
- package/dist/transforms/needle_progressive.js +0 -1117
- package/dist/transforms/needle_texture_transform.d.ts +0 -15
- package/dist/transforms/needle_texture_transform.js +0 -271
- package/dist/transforms/needle_toktx.d.ts +0 -26
- package/dist/transforms/needle_toktx.js +0 -250
- package/dist/transforms/needle_webp.d.ts +0 -15
- package/dist/transforms/needle_webp.js +0 -53
- package/dist/transforms/toktx.d.ts +0 -52
- package/dist/transforms/toktx.js +0 -208
- package/dist/transforms/toktx_types.d.ts +0 -78
- package/dist/transforms/toktx_types.js +0 -62
- package/dist/transforms/util.d.ts +0 -21
- package/dist/transforms/util.js +0 -90
- package/dist/utils/analytics.d.ts +0 -24
- package/dist/utils/analytics.js +0 -128
- package/dist/utils/compression_utils.d.ts +0 -2
- package/dist/utils/compression_utils.js +0 -6
- package/dist/utils/fileutils.d.ts +0 -22
- package/dist/utils/fileutils.js +0 -195
- package/dist/utils/guid.d.ts +0 -1
- package/dist/utils/guid.js +0 -5
- package/dist/utils/index.d.ts +0 -9
- package/dist/utils/index.js +0 -9
- package/dist/utils/mesh.d.ts +0 -13
- package/dist/utils/mesh.js +0 -124
- package/dist/utils/nodeio.d.ts +0 -11
- package/dist/utils/nodeio.js +0 -116
- package/dist/utils/stats.d.ts +0 -70
- package/dist/utils/stats.js +0 -273
- package/dist/utils/test-assert.d.ts +0 -8
- package/dist/utils/test-assert.js +0 -18
- package/dist/utils/texture.d.ts +0 -5
- package/dist/utils/texture.js +0 -14
- package/dist/utils/validate.d.ts +0 -9
- package/dist/utils/validate.js +0 -24
- package/dist/utils/version.d.ts +0 -1
- package/dist/utils/version.gen.d.ts +0 -1
- package/dist/utils/version.gen.js +0 -1
- package/dist/utils/version.js +0 -4
- package/scripts/clear-caches.mjs +0 -4
- package/scripts/defaults.mjs +0 -12
- package/scripts/fileutils.mjs +0 -6
- package/scripts/index.mjs +0 -41
- package/scripts/limit-caches.mjs +0 -4
- package/scripts/make-progressive.mjs +0 -16
- package/scripts/pack-gltf.mjs +0 -107
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { Extension, ExtensionProperty, PropertyType, TextureChannel } from '@gltf-transform/core';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { join, dirname } from 'path';
|
|
4
|
-
import { isLightmap } from '../../utils/texture.js';
|
|
5
|
-
import { getExtensionInputFile } from '../index.js';
|
|
6
|
-
import { findSource, getTexture } from '../utils.js';
|
|
7
|
-
import { testAssert } from '../../utils/test-assert.js';
|
|
8
|
-
const EXTENSION_NAME = 'NEEDLE_lightmaps';
|
|
9
|
-
/**
|
|
10
|
-
* Opaque-like ExtensionProperty that holds NEEDLE_lightmaps data on the Root.
|
|
11
|
-
* This keeps gltf-transform from garbage-collecting referenced textures.
|
|
12
|
-
*/
|
|
13
|
-
class LightmapProperty extends ExtensionProperty {
|
|
14
|
-
static EXTENSION_NAME = EXTENSION_NAME;
|
|
15
|
-
propertyType = 'LightmapProperty';
|
|
16
|
-
parentTypes = [PropertyType.ROOT];
|
|
17
|
-
init() {
|
|
18
|
-
this.extensionName = EXTENSION_NAME;
|
|
19
|
-
}
|
|
20
|
-
getDefaults() {
|
|
21
|
-
return Object.assign(super.getDefaults(), {});
|
|
22
|
-
}
|
|
23
|
-
/** Public wrapper around protected setRef to register references */
|
|
24
|
-
setReference(name, value, attributes) {
|
|
25
|
-
this.setRef(name, value, attributes);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* NEEDLE_lightmaps gltf-transform extension.
|
|
30
|
-
*
|
|
31
|
-
* Handles both embedded (`/textures/N` pointer) and external (`sunrise.exr` pointer) lightmaps.
|
|
32
|
-
*
|
|
33
|
-
* - **preread(TEXTURE)**: Injects external EXR files into the JSON document so the core reader
|
|
34
|
-
* creates proper Texture objects from them.
|
|
35
|
-
* - **read()**: Resolves `/textures/N` pointers to Texture objects. Sets references so that
|
|
36
|
-
* gltf-transform doesn't prune/dedup referenced textures.
|
|
37
|
-
* - **write()**: Updates pointer strings:
|
|
38
|
-
* - Embedded textures: resolves to the new `/textures/N` index in the output.
|
|
39
|
-
* - External textures: uses the Texture's current URI (e.g. updated by PMREM to `.pmrem.ktx2`).
|
|
40
|
-
*/
|
|
41
|
-
export class NEEDLE_lightmaps_ext extends Extension {
|
|
42
|
-
static EXTENSION_NAME = EXTENSION_NAME;
|
|
43
|
-
extensionName = EXTENSION_NAME;
|
|
44
|
-
prereadTypes = [PropertyType.TEXTURE];
|
|
45
|
-
prewriteTypes = [PropertyType.MATERIAL];
|
|
46
|
-
/** The raw extension JSON from the input (mutated in-place during write) */
|
|
47
|
-
extensionData = null;
|
|
48
|
-
/** Entries with resolved Texture references */
|
|
49
|
-
resolved = [];
|
|
50
|
-
/** Image indices injected during preread (for external EXR files) */
|
|
51
|
-
injectedImageIndices = new Map();
|
|
52
|
-
/** The ExtensionProperty that holds references to prevent dedup/prune */
|
|
53
|
-
lightmapProp = null;
|
|
54
|
-
// ── preread ──────────────────────────────────────────────────
|
|
55
|
-
preread(context, _propertyType) {
|
|
56
|
-
const json = context.jsonDoc.json;
|
|
57
|
-
const ext = json.extensions?.[EXTENSION_NAME];
|
|
58
|
-
if (!ext?.textures)
|
|
59
|
-
return this;
|
|
60
|
-
const inputFile = getExtensionInputFile();
|
|
61
|
-
const inputDir = inputFile ? dirname(inputFile) : '';
|
|
62
|
-
for (const entry of ext.textures) {
|
|
63
|
-
// Skip embedded pointers — handled in read()
|
|
64
|
-
if (entry.pointer.startsWith('/') || entry.pointer.startsWith('textures/'))
|
|
65
|
-
continue;
|
|
66
|
-
// External file path (e.g. "sunrise.exr")
|
|
67
|
-
if (!entry.pointer.match(/\.exr$/i))
|
|
68
|
-
continue;
|
|
69
|
-
const exrPath = inputDir ? join(inputDir, entry.pointer) : '';
|
|
70
|
-
if (!exrPath || !existsSync(exrPath)) {
|
|
71
|
-
this.document.getLogger().error(`NEEDLE_lightmaps: External EXR not found: ${exrPath || entry.pointer}`);
|
|
72
|
-
testAssert(false, `NEEDLE_lightmaps: External EXR not found: ${exrPath || entry.pointer}`);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
// Read EXR bytes and inject into JSON so the core reader creates a Texture
|
|
76
|
-
const exrBytes = readFileSync(exrPath);
|
|
77
|
-
json.images = json.images || [];
|
|
78
|
-
json.textures = json.textures || [];
|
|
79
|
-
const imageIndex = json.images.length;
|
|
80
|
-
json.images.push({
|
|
81
|
-
uri: entry.pointer,
|
|
82
|
-
mimeType: 'image/exr',
|
|
83
|
-
name: entry.pointer,
|
|
84
|
-
});
|
|
85
|
-
json.textures.push({
|
|
86
|
-
source: imageIndex,
|
|
87
|
-
name: entry.pointer,
|
|
88
|
-
});
|
|
89
|
-
context.jsonDoc.resources[entry.pointer] = new Uint8Array(exrBytes);
|
|
90
|
-
this.injectedImageIndices.set(entry.pointer, imageIndex);
|
|
91
|
-
this.document.getLogger().info(`NEEDLE_lightmaps: Registered external EXR "${entry.pointer}" as image[${imageIndex}]`);
|
|
92
|
-
}
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
// ── read ─────────────────────────────────────────────────────
|
|
96
|
-
read(context) {
|
|
97
|
-
const json = context.jsonDoc.json;
|
|
98
|
-
const ext = json.extensions?.[EXTENSION_NAME];
|
|
99
|
-
if (!ext?.textures)
|
|
100
|
-
return this;
|
|
101
|
-
// Store the raw extension data — we'll mutate the pointers during write
|
|
102
|
-
this.extensionData = ext;
|
|
103
|
-
// Create the property and attach to root
|
|
104
|
-
const root = this.document.getRoot();
|
|
105
|
-
this.lightmapProp = new LightmapProperty(this.document.getGraph());
|
|
106
|
-
root.setExtension(EXTENSION_NAME, this.lightmapProp);
|
|
107
|
-
const textureDefs = json.textures || [];
|
|
108
|
-
const logger = this.document.getLogger();
|
|
109
|
-
for (const entry of ext.textures) {
|
|
110
|
-
let texture = null;
|
|
111
|
-
let inputTextureDef;
|
|
112
|
-
if (entry.pointer.startsWith('/textures/') || entry.pointer.startsWith('textures/')) {
|
|
113
|
-
// Embedded pointer — resolve Found lightmapto Texture via the JSON texture definition
|
|
114
|
-
const prefix = entry.pointer.startsWith('/') ? '/textures/' : 'textures/';
|
|
115
|
-
const texIndex = parseInt(entry.pointer.substring(prefix.length));
|
|
116
|
-
const texDef = textureDefs[texIndex];
|
|
117
|
-
if (texDef) {
|
|
118
|
-
inputTextureDef = texDef;
|
|
119
|
-
texture = getTexture(context, texDef) ?? null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else if (entry.pointer.match(/\.exr$/i)) {
|
|
123
|
-
// External pointer — find the Texture created from our injected image
|
|
124
|
-
const imageIndex = this.injectedImageIndices.get(entry.pointer);
|
|
125
|
-
if (imageIndex !== undefined) {
|
|
126
|
-
texture = context.textures[imageIndex] ?? null;
|
|
127
|
-
inputTextureDef = textureDefs.find(t => findSource(t) === imageIndex);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else if (!entry.pointer.startsWith('/')) {
|
|
131
|
-
// Already-processed external pointer (e.g. "sunrise.pmrem.ktx2")
|
|
132
|
-
// Find the texture by matching the URI in the existing images
|
|
133
|
-
const images = json.images ?? [];
|
|
134
|
-
for (let i = 0; i < images.length; i++) {
|
|
135
|
-
if (images[i].uri === entry.pointer) {
|
|
136
|
-
texture = context.textures[i] ?? null;
|
|
137
|
-
inputTextureDef = textureDefs.find(t => findSource(t) === i);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (texture) {
|
|
143
|
-
this.resolved.push({ entry, texture, inputTextureDef });
|
|
144
|
-
// Set a reference so gltf-transform won't prune/dedup this texture
|
|
145
|
-
const refName = `lightmapTexture_${entry.pointer}`;
|
|
146
|
-
const channels = TextureChannel.R | TextureChannel.G | TextureChannel.B | TextureChannel.A;
|
|
147
|
-
this.lightmapProp.setReference(refName, texture, { channels });
|
|
148
|
-
// Also keep a reference to the buffer
|
|
149
|
-
const buffer = this.document.getRoot().listBuffers()[0];
|
|
150
|
-
if (buffer) {
|
|
151
|
-
this.lightmapProp.setReference('buffer', buffer);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
this.document.getLogger().error(`NEEDLE_lightmaps: Could not resolve texture for pointer "${entry.pointer}"`);
|
|
156
|
-
testAssert(false, `NEEDLE_lightmaps: Could not resolve texture for pointer "${entry.pointer}"`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
// Lightmap workaround: prevent compression on lightmap textures (non-EXR)
|
|
160
|
-
const textures = this.document.getRoot().listTextures();
|
|
161
|
-
for (const tex of textures) {
|
|
162
|
-
if (isLightmap(tex) && tex.getMimeType() !== 'image/exr') {
|
|
163
|
-
const refName = `lightmapTexture_${tex.getName()}`;
|
|
164
|
-
const channels = TextureChannel.R | TextureChannel.G | TextureChannel.B | TextureChannel.A;
|
|
165
|
-
this.lightmapProp.setReference(refName, tex, { channels });
|
|
166
|
-
this.document.getLogger().debug(`[NEEDLE_lightmaps] Found lightmap texture "${tex.getName()}" (${tex.getMimeType()})`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
// ── prewrite ─────────────────────────────────────────────────
|
|
172
|
-
prewrite(context, _propertyType) {
|
|
173
|
-
// Resolve pointers early so json.textures is populated for textures
|
|
174
|
-
// not used by any material (same pattern as opaque system)
|
|
175
|
-
this.resolvePointers(context);
|
|
176
|
-
return this;
|
|
177
|
-
}
|
|
178
|
-
// ── write ────────────────────────────────────────────────────
|
|
179
|
-
write(context) {
|
|
180
|
-
if (!this.extensionData)
|
|
181
|
-
return this;
|
|
182
|
-
// Resolve any remaining pointers
|
|
183
|
-
this.resolvePointers(context);
|
|
184
|
-
// Write the extension data to the output JSON
|
|
185
|
-
context.jsonDoc.json.extensions = context.jsonDoc.json.extensions || {};
|
|
186
|
-
context.jsonDoc.json.extensions[EXTENSION_NAME] = this.extensionData;
|
|
187
|
-
return this;
|
|
188
|
-
}
|
|
189
|
-
// ── private ──────────────────────────────────────────────────
|
|
190
|
-
pointersResolved = false;
|
|
191
|
-
resolvePointers(context) {
|
|
192
|
-
if (this.pointersResolved)
|
|
193
|
-
return;
|
|
194
|
-
this.pointersResolved = true;
|
|
195
|
-
for (const { entry, texture, inputTextureDef } of this.resolved) {
|
|
196
|
-
if (entry.pointer.startsWith('/textures/') || entry.pointer.startsWith('textures/')) {
|
|
197
|
-
// Embedded: find the new texture index in the output JSON
|
|
198
|
-
const newIndex = this.findOrCreateTextureIndex(context, texture, inputTextureDef);
|
|
199
|
-
if (newIndex !== undefined) {
|
|
200
|
-
entry.pointer = `/textures/${newIndex}`;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
// External: use the texture's current URI (may have been updated by PMREM)
|
|
205
|
-
const uri = texture.getURI();
|
|
206
|
-
if (uri) {
|
|
207
|
-
entry.pointer = uri;
|
|
208
|
-
// Ensure the image definition in the output JSON has the URI set.
|
|
209
|
-
// When PMREM clears image data (setImage(null)) for external textures,
|
|
210
|
-
// gltf-transform's core writer won't set a uri or bufferView on the image.
|
|
211
|
-
const imageIndex = context.imageIndexMap.get(texture);
|
|
212
|
-
if (imageIndex !== undefined) {
|
|
213
|
-
const images = context.jsonDoc.json.images;
|
|
214
|
-
if (images && images[imageIndex]) {
|
|
215
|
-
images[imageIndex].uri = uri;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Find (or create) a texture def in the output JSON that references the given Texture.
|
|
224
|
-
* This replicates the logic from the opaque system's TextureIndexResolver.
|
|
225
|
-
*/
|
|
226
|
-
findOrCreateTextureIndex(context, texture, inputTextureDef) {
|
|
227
|
-
const imageIndex = context.imageIndexMap.get(texture);
|
|
228
|
-
if (imageIndex === undefined)
|
|
229
|
-
return undefined;
|
|
230
|
-
const textures = context.jsonDoc.json.textures = context.jsonDoc.json.textures || [];
|
|
231
|
-
// Try to find an existing texture def pointing to the same image
|
|
232
|
-
for (let i = 0; i < textures.length; i++) {
|
|
233
|
-
if (findSource(textures[i]) === imageIndex) {
|
|
234
|
-
return i;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
// Not found — create a new texture definition
|
|
238
|
-
let extensions = inputTextureDef?.extensions ? { ...inputTextureDef.extensions } : undefined;
|
|
239
|
-
if (extensions) {
|
|
240
|
-
// Remove consumed extensions
|
|
241
|
-
delete extensions['NEEDLE_progressive_texture_settings'];
|
|
242
|
-
// Remove EXT_texture_exr if texture was converted
|
|
243
|
-
if (extensions['EXT_texture_exr'] && texture.getMimeType() !== 'image/exr') {
|
|
244
|
-
delete extensions['EXT_texture_exr'];
|
|
245
|
-
}
|
|
246
|
-
if (Object.keys(extensions).length === 0)
|
|
247
|
-
extensions = undefined;
|
|
248
|
-
}
|
|
249
|
-
const hasExtSource = extensions && Object.values(extensions).some((v) => v?.source !== undefined);
|
|
250
|
-
const texDef = {
|
|
251
|
-
source: hasExtSource ? undefined : imageIndex,
|
|
252
|
-
extensions,
|
|
253
|
-
};
|
|
254
|
-
textures.push(texDef);
|
|
255
|
-
return textures.length - 1;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Extension, ExtensionProperty, PropertyType, ReaderContext, WriterContext } from "@gltf-transform/core";
|
|
2
|
-
export declare class NEEDLE_mesh_compression_model_root {
|
|
3
|
-
compression: "none" | "draco" | "meshopt";
|
|
4
|
-
constructor(compression: "none" | "draco" | "meshopt");
|
|
5
|
-
}
|
|
6
|
-
export declare class NEEDLE_mesh_compression_model {
|
|
7
|
-
useSimplifier: boolean;
|
|
8
|
-
error: number;
|
|
9
|
-
ratio: number;
|
|
10
|
-
lockBorder: boolean;
|
|
11
|
-
}
|
|
12
|
-
export declare class NEEDLE_mesh_compression extends Extension {
|
|
13
|
-
static EXTENSION_NAME: string;
|
|
14
|
-
extensionName: string;
|
|
15
|
-
create(model: NEEDLE_mesh_compression_model | NEEDLE_mesh_compression_model_root): NEEDLE_mesh_compression_property;
|
|
16
|
-
read(context: ReaderContext): this;
|
|
17
|
-
write(ctx: WriterContext): this;
|
|
18
|
-
}
|
|
19
|
-
export declare class NEEDLE_mesh_compression_property extends ExtensionProperty {
|
|
20
|
-
static EXTENSION_NAME: string;
|
|
21
|
-
readonly extensionName: string;
|
|
22
|
-
parentTypes: PropertyType[];
|
|
23
|
-
propertyType: string;
|
|
24
|
-
init(): void;
|
|
25
|
-
model: NEEDLE_mesh_compression_model | NEEDLE_mesh_compression_model_root;
|
|
26
|
-
copy(other: this, resolve?: (property: ExtensionProperty) => ExtensionProperty): this;
|
|
27
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Extension, ExtensionProperty, PropertyType } from "@gltf-transform/core";
|
|
2
|
-
const EXTENSION_NAME = "NEEDLE_mesh_compression";
|
|
3
|
-
// TODO: this extension can now be on the root and on primitives containing different contents
|
|
4
|
-
export class NEEDLE_mesh_compression_model_root {
|
|
5
|
-
compression;
|
|
6
|
-
constructor(compression) {
|
|
7
|
-
this.compression = compression;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export class NEEDLE_mesh_compression_model {
|
|
11
|
-
useSimplifier;
|
|
12
|
-
error;
|
|
13
|
-
ratio;
|
|
14
|
-
lockBorder;
|
|
15
|
-
}
|
|
16
|
-
const debugLog = false;
|
|
17
|
-
export class NEEDLE_mesh_compression extends Extension {
|
|
18
|
-
static EXTENSION_NAME = EXTENSION_NAME;
|
|
19
|
-
extensionName = EXTENSION_NAME;
|
|
20
|
-
create(model) {
|
|
21
|
-
const ext = new NEEDLE_mesh_compression_property(this.document.getGraph(), "");
|
|
22
|
-
ext.model = model;
|
|
23
|
-
return ext;
|
|
24
|
-
}
|
|
25
|
-
read(context) {
|
|
26
|
-
if (debugLog)
|
|
27
|
-
console.log("READ " + EXTENSION_NAME);
|
|
28
|
-
const root = context.jsonDoc.json.extensions?.[EXTENSION_NAME];
|
|
29
|
-
if (root) {
|
|
30
|
-
this.document.getRoot().setExtension(EXTENSION_NAME, this.create(root));
|
|
31
|
-
}
|
|
32
|
-
if (context.jsonDoc.json.meshes) {
|
|
33
|
-
context.meshes?.forEach((mesh, index) => {
|
|
34
|
-
const meshDefinition = context.jsonDoc.json.meshes[index];
|
|
35
|
-
if (!meshDefinition)
|
|
36
|
-
return;
|
|
37
|
-
const primitives = mesh.listPrimitives();
|
|
38
|
-
for (let i = 0; i < primitives.length; i++) {
|
|
39
|
-
const primitive = meshDefinition.primitives[i];
|
|
40
|
-
if (primitive.extensions && primitive.extensions[EXTENSION_NAME]) {
|
|
41
|
-
const model = primitive.extensions[EXTENSION_NAME];
|
|
42
|
-
primitives[i].setExtension(EXTENSION_NAME, this.create(model));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
write(ctx) {
|
|
50
|
-
if (debugLog)
|
|
51
|
-
console.log("WRITE " + EXTENSION_NAME);
|
|
52
|
-
const root = this.document.getRoot();
|
|
53
|
-
const rootExtension = root.getExtension(EXTENSION_NAME);
|
|
54
|
-
if (rootExtension) {
|
|
55
|
-
ctx.jsonDoc.json.extensions = ctx.jsonDoc.json.extensions || {};
|
|
56
|
-
ctx.jsonDoc.json.extensions[EXTENSION_NAME] = rootExtension.model;
|
|
57
|
-
}
|
|
58
|
-
for (const mesh of root.listMeshes()) {
|
|
59
|
-
const index = ctx.meshIndexMap.get(mesh);
|
|
60
|
-
const meshDef = ctx.jsonDoc.json.meshes[index];
|
|
61
|
-
const primitives = mesh.listPrimitives();
|
|
62
|
-
for (let i = 0; i < primitives.length; i++) {
|
|
63
|
-
const primitive = primitives[i];
|
|
64
|
-
const ext = primitive.getExtension(EXTENSION_NAME);
|
|
65
|
-
if (ext) {
|
|
66
|
-
const prim = meshDef.primitives[i];
|
|
67
|
-
if (prim) {
|
|
68
|
-
prim.extensions = prim.extensions || {};
|
|
69
|
-
prim.extensions[EXTENSION_NAME] = ext.model;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export class NEEDLE_mesh_compression_property extends ExtensionProperty {
|
|
78
|
-
static EXTENSION_NAME = EXTENSION_NAME;
|
|
79
|
-
extensionName = EXTENSION_NAME;
|
|
80
|
-
parentTypes = [PropertyType.ROOT, PropertyType.PRIMITIVE, PropertyType.MESH];
|
|
81
|
-
propertyType = EXTENSION_NAME;
|
|
82
|
-
init() { }
|
|
83
|
-
model;
|
|
84
|
-
copy(other, resolve = null) {
|
|
85
|
-
this.model = { ...other.model };
|
|
86
|
-
return super.copy(other, resolve);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./NEEDLE_mesh_compression.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./NEEDLE_mesh_compression.js";
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Extension, WriterContext, PropertyType } from '@gltf-transform/core';
|
|
2
|
-
declare interface IExtensibleProperty {
|
|
3
|
-
}
|
|
4
|
-
type DebugBreakPoint = boolean | "pointer:read";
|
|
5
|
-
export type Options = {
|
|
6
|
-
debug?: boolean;
|
|
7
|
-
breakpoint?: DebugBreakPoint;
|
|
8
|
-
write?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export interface IOpaqueExtension {
|
|
11
|
-
}
|
|
12
|
-
export interface IOpaqueProperty {
|
|
13
|
-
/** used by progressive texture extension to pass an extension between documents */
|
|
14
|
-
getExtensionDefinition(): object;
|
|
15
|
-
/** register a reference so gltf-transform will not remove it in e.g. dedup
|
|
16
|
-
* https://github.com/donmccurdy/glTF-Transform/issues/980#issuecomment-1585748202
|
|
17
|
-
*/
|
|
18
|
-
setReference(name: string, value: any, attributes?: Record<string, any>): void;
|
|
19
|
-
}
|
|
20
|
-
export interface IExtensionWriter {
|
|
21
|
-
/** used by progressive texture extension to pass an extension between documents */
|
|
22
|
-
assignTo?(obj: object): any;
|
|
23
|
-
write(context: WriterContext, prop: IExtensibleProperty): void;
|
|
24
|
-
}
|
|
25
|
-
export declare let currentGenerator: string;
|
|
26
|
-
export declare function createOpaqueExtension(name: string, types: PropertyType | PropertyType[], opts?: Options): typeof Extension;
|
|
27
|
-
export {};
|