usd-gltf 0.1.0 → 0.3.0
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/README.md +36 -3
- package/package.json +12 -2
- package/src/convert/gltf-to-usd.js +166 -46
- package/src/convert/usd-material.js +7 -2
- package/src/convert/usd-to-gltf.js +8 -4
- package/src/gltf/document.js +109 -19
- package/src/gltf/draco.js +191 -0
- package/src/gltf/glb.js +2 -2
- package/src/image/index.js +52 -1
- package/src/image/inflate.js +14 -12
- package/src/image/png.js +1 -1
- package/src/index.d.ts +30 -4
- package/src/index.js +33 -14
- package/src/limits.js +101 -0
- package/src/usd/stage.js +13 -9
- package/src/usd/usda/writer.js +16 -1
- package/src/usd/usdc/reader.js +63 -13
- package/src/usd/usdc/writer.js +53 -3
- package/src/usd/usdz.js +9 -3
package/src/usd/usdz.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { crc32 } from '../util/crc32.js';
|
|
5
5
|
import { inflate } from '../image/inflate.js';
|
|
6
|
+
import { Budget } from '../limits.js';
|
|
6
7
|
|
|
7
8
|
const LOCAL = 0x04034b50;
|
|
8
9
|
const CENTRAL = 0x02014b50;
|
|
@@ -12,9 +13,10 @@ const ALIGN = 64;
|
|
|
12
13
|
/**
|
|
13
14
|
* Lists the files in a zip, in archive order.
|
|
14
15
|
* @param {Uint8Array} bytes
|
|
16
|
+
* @param {{ budget?: import('../limits.js').Budget }} [options]
|
|
15
17
|
* @returns {Map<string, Uint8Array>}
|
|
16
18
|
*/
|
|
17
|
-
export function readZip( bytes ) {
|
|
19
|
+
export function readZip( bytes, { budget = new Budget() } = {} ) {
|
|
18
20
|
|
|
19
21
|
const view = new DataView( bytes.buffer, bytes.byteOffset, bytes.byteLength );
|
|
20
22
|
const files = new Map();
|
|
@@ -33,6 +35,7 @@ export function readZip( bytes ) {
|
|
|
33
35
|
|
|
34
36
|
const method = view.getUint16( offset + 10, true );
|
|
35
37
|
const compressedSize = view.getUint32( offset + 20, true );
|
|
38
|
+
const size = view.getUint32( offset + 24, true );
|
|
36
39
|
const nameLength = view.getUint16( offset + 28, true );
|
|
37
40
|
const extraLength = view.getUint16( offset + 30, true );
|
|
38
41
|
const commentLength = view.getUint16( offset + 32, true );
|
|
@@ -40,12 +43,13 @@ export function readZip( bytes ) {
|
|
|
40
43
|
const name = decoder.decode( bytes.subarray( offset + 46, offset + 46 + nameLength ) );
|
|
41
44
|
|
|
42
45
|
const dataStart = localOffset + 30 + view.getUint16( localOffset + 26, true ) + view.getUint16( localOffset + 28, true );
|
|
46
|
+
if ( dataStart + compressedSize > bytes.length ) throw new Error( 'usd-gltf: truncated zip archive' );
|
|
43
47
|
const data = bytes.subarray( dataStart, dataStart + compressedSize );
|
|
44
48
|
|
|
45
49
|
if ( ! name.endsWith( '/' ) ) {
|
|
46
50
|
|
|
47
51
|
if ( method === 0 ) files.set( name, data );
|
|
48
|
-
else if ( method === 8 ) files.set( name, inflate( data ) );
|
|
52
|
+
else if ( method === 8 ) { budget.decode( size, 'zip' ); files.set( name, inflate( data, size, size ) ); }
|
|
49
53
|
else throw new Error( `usd-gltf: unsupported zip compression ${ method } for ${ name }` );
|
|
50
54
|
|
|
51
55
|
}
|
|
@@ -61,9 +65,10 @@ export function readZip( bytes ) {
|
|
|
61
65
|
/**
|
|
62
66
|
* Writes a USDZ package. The first entry must be the root layer.
|
|
63
67
|
* @param {Array<{ name: string, data: Uint8Array }>} entries
|
|
68
|
+
* @param {{ budget?: import('../limits.js').Budget }} [options]
|
|
64
69
|
* @returns {Uint8Array}
|
|
65
70
|
*/
|
|
66
|
-
export function writeUSDZ( entries ) {
|
|
71
|
+
export function writeUSDZ( entries, { budget = new Budget() } = {} ) {
|
|
67
72
|
|
|
68
73
|
const encoder = new TextEncoder();
|
|
69
74
|
const locals = [];
|
|
@@ -127,6 +132,7 @@ export function writeUSDZ( entries ) {
|
|
|
127
132
|
ev.setUint32( 12, centralSize, true );
|
|
128
133
|
ev.setUint32( 16, offset, true );
|
|
129
134
|
|
|
135
|
+
budget.output( offset + centralSize + 22, 'usdz' );
|
|
130
136
|
const out = new Uint8Array( offset + centralSize + 22 );
|
|
131
137
|
let p = 0;
|
|
132
138
|
for ( const part of [ ...locals, ...centrals, end ] ) {
|