three-usd-robot 0.5.0 → 0.6.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 +112 -40
- package/dist/{ThreeUsdRobot-D9AOUaVh.d.ts → ThreeUsdRobot-CajXJqYU.d.ts} +1 -1
- package/dist/{ThreeUsdRobotLoader-BgsnuJWd.d.ts → ThreeUsdRobotLoader-DrMMLzo-.d.ts} +8 -2
- package/dist/{buildKinematicTree-3oKG00Sc.d.ts → buildKinematicTree-wtZPzy0B.d.ts} +53 -16
- package/dist/{chunk-36T6YOEX.js → chunk-4MEZM763.js} +702 -168
- package/dist/chunk-4MEZM763.js.map +1 -0
- package/dist/chunk-JZMCABQO.js +864 -0
- package/dist/chunk-JZMCABQO.js.map +1 -0
- package/dist/{chunk-Y3NXBSX3.js → chunk-YVWSO27W.js} +51 -183
- package/dist/chunk-YVWSO27W.js.map +1 -0
- package/dist/core.d.ts +296 -108
- package/dist/core.js +2 -2
- package/dist/extras.d.ts +2 -2
- package/dist/helpers.d.ts +2 -2
- package/dist/index.d.ts +142 -8
- package/dist/index.js +302 -3
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +4 -4
- package/dist/react.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-36T6YOEX.js.map +0 -1
- package/dist/chunk-OFUMT72H.js +0 -7
- package/dist/chunk-OFUMT72H.js.map +0 -1
- package/dist/chunk-Y3NXBSX3.js.map +0 -1
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
import { unzipSync } from 'fflate';
|
|
2
2
|
|
|
3
|
+
// src/parser/ast.ts
|
|
4
|
+
var Quat = class _Quat {
|
|
5
|
+
constructor(real, imaginary) {
|
|
6
|
+
this.real = real;
|
|
7
|
+
this.imaginary = imaginary;
|
|
8
|
+
}
|
|
9
|
+
real;
|
|
10
|
+
imaginary;
|
|
11
|
+
/** Components in Three.js order `[x, y, z, w]`. */
|
|
12
|
+
toXYZW() {
|
|
13
|
+
return [this.imaginary[0], this.imaginary[1], this.imaginary[2], this.real];
|
|
14
|
+
}
|
|
15
|
+
static identity() {
|
|
16
|
+
return new _Quat(1, [0, 0, 0]);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var UsdMatrix = class _UsdMatrix {
|
|
20
|
+
constructor(values, dim) {
|
|
21
|
+
this.values = values;
|
|
22
|
+
this.dim = dim;
|
|
23
|
+
}
|
|
24
|
+
values;
|
|
25
|
+
dim;
|
|
26
|
+
static identity4() {
|
|
27
|
+
return new _UsdMatrix([
|
|
28
|
+
1,
|
|
29
|
+
0,
|
|
30
|
+
0,
|
|
31
|
+
0,
|
|
32
|
+
0,
|
|
33
|
+
1,
|
|
34
|
+
0,
|
|
35
|
+
0,
|
|
36
|
+
0,
|
|
37
|
+
0,
|
|
38
|
+
1,
|
|
39
|
+
0,
|
|
40
|
+
0,
|
|
41
|
+
0,
|
|
42
|
+
0,
|
|
43
|
+
1
|
|
44
|
+
], 4);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var AssetPath = class {
|
|
48
|
+
constructor(path) {
|
|
49
|
+
this.path = path;
|
|
50
|
+
}
|
|
51
|
+
path;
|
|
52
|
+
};
|
|
53
|
+
|
|
3
54
|
// src/kinematics/transforms.ts
|
|
4
55
|
var DEG2RAD = Math.PI / 180;
|
|
5
56
|
var RAD2DEG = 180 / Math.PI;
|
|
@@ -254,6 +305,208 @@ function fromUsdMatrix(m) {
|
|
|
254
305
|
function getTranslation(m) {
|
|
255
306
|
return [m[12], m[13], m[14]];
|
|
256
307
|
}
|
|
308
|
+
function toUsdMatrix(m) {
|
|
309
|
+
if (m.length !== 16) {
|
|
310
|
+
throw new Error(`expected 16 matrix elements but got ${m.length}`);
|
|
311
|
+
}
|
|
312
|
+
return new UsdMatrix([...m], 4);
|
|
313
|
+
}
|
|
314
|
+
function decomposeRigid(m) {
|
|
315
|
+
const position = [m[12], m[13], m[14]];
|
|
316
|
+
const b0 = [m[0], m[1], m[2]];
|
|
317
|
+
const b1 = [m[4], m[5], m[6]];
|
|
318
|
+
const b2 = [m[8], m[9], m[10]];
|
|
319
|
+
const EPS = 1e-6;
|
|
320
|
+
const rigid = Math.abs(norm(b0) - 1) < EPS && Math.abs(norm(b1) - 1) < EPS && Math.abs(norm(b2) - 1) < EPS && Math.abs(dot(b0, b1)) < EPS && Math.abs(dot(b1, b2)) < EPS && Math.abs(dot(b0, b2)) < EPS && dot(cross(b0, b1), b2) > 0;
|
|
321
|
+
const c0 = normalizeVec(b0);
|
|
322
|
+
const c1 = normalizeVec(subVec(b1, scaleVec(c0, dot(c0, b1))));
|
|
323
|
+
const c2 = cross(c0, c1);
|
|
324
|
+
const r11 = c0[0], r12 = c1[0], r13 = c2[0];
|
|
325
|
+
const r21 = c0[1], r22 = c1[1], r23 = c2[1];
|
|
326
|
+
const r31 = c0[2], r32 = c1[2], r33 = c2[2];
|
|
327
|
+
const trace = r11 + r22 + r33;
|
|
328
|
+
let w;
|
|
329
|
+
let x;
|
|
330
|
+
let y;
|
|
331
|
+
let z;
|
|
332
|
+
if (trace > 0) {
|
|
333
|
+
const s = 0.5 / Math.sqrt(trace + 1);
|
|
334
|
+
w = 0.25 / s;
|
|
335
|
+
x = (r32 - r23) * s;
|
|
336
|
+
y = (r13 - r31) * s;
|
|
337
|
+
z = (r21 - r12) * s;
|
|
338
|
+
} else if (r11 > r22 && r11 > r33) {
|
|
339
|
+
const s = 2 * Math.sqrt(1 + r11 - r22 - r33);
|
|
340
|
+
w = (r32 - r23) / s;
|
|
341
|
+
x = 0.25 * s;
|
|
342
|
+
y = (r12 + r21) / s;
|
|
343
|
+
z = (r13 + r31) / s;
|
|
344
|
+
} else if (r22 > r33) {
|
|
345
|
+
const s = 2 * Math.sqrt(1 + r22 - r11 - r33);
|
|
346
|
+
w = (r13 - r31) / s;
|
|
347
|
+
x = (r12 + r21) / s;
|
|
348
|
+
y = 0.25 * s;
|
|
349
|
+
z = (r23 + r32) / s;
|
|
350
|
+
} else {
|
|
351
|
+
const s = 2 * Math.sqrt(1 + r33 - r11 - r22);
|
|
352
|
+
w = (r21 - r12) / s;
|
|
353
|
+
x = (r13 + r31) / s;
|
|
354
|
+
y = (r23 + r32) / s;
|
|
355
|
+
z = 0.25 * s;
|
|
356
|
+
}
|
|
357
|
+
return { position, orientation: new Quat(w, [x, y, z]), rigid };
|
|
358
|
+
}
|
|
359
|
+
function dot(a, b) {
|
|
360
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
361
|
+
}
|
|
362
|
+
function norm(v) {
|
|
363
|
+
return Math.hypot(v[0], v[1], v[2]);
|
|
364
|
+
}
|
|
365
|
+
function subVec(a, b) {
|
|
366
|
+
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
367
|
+
}
|
|
368
|
+
function scaleVec(v, s) {
|
|
369
|
+
return [v[0] * s, v[1] * s, v[2] * s];
|
|
370
|
+
}
|
|
371
|
+
function normalizeVec(v) {
|
|
372
|
+
const n = norm(v);
|
|
373
|
+
return n > 0 ? scaleVec(v, 1 / n) : [1, 0, 0];
|
|
374
|
+
}
|
|
375
|
+
function cross(a, b) {
|
|
376
|
+
return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/schemas/usdGeom.ts
|
|
380
|
+
function isXform(prim) {
|
|
381
|
+
return prim.GetTypeName() === "Xform";
|
|
382
|
+
}
|
|
383
|
+
function isScope(prim) {
|
|
384
|
+
return prim.GetTypeName() === "Scope";
|
|
385
|
+
}
|
|
386
|
+
function isMesh(prim) {
|
|
387
|
+
return prim.GetTypeName() === "Mesh";
|
|
388
|
+
}
|
|
389
|
+
function getPurpose(prim) {
|
|
390
|
+
const v = prim.GetAttribute("purpose").Get();
|
|
391
|
+
return typeof v === "string" ? v : "default";
|
|
392
|
+
}
|
|
393
|
+
function isNonVisualPurpose(prim) {
|
|
394
|
+
const p = getPurpose(prim);
|
|
395
|
+
return p === "guide" || p === "proxy";
|
|
396
|
+
}
|
|
397
|
+
function* iterDescendants(prim) {
|
|
398
|
+
for (const child of prim.GetChildren()) {
|
|
399
|
+
yield child;
|
|
400
|
+
yield* iterDescendants(child);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function gatherMeshDescendants(prim) {
|
|
404
|
+
const paths = [];
|
|
405
|
+
for (const d of iterDescendants(prim)) {
|
|
406
|
+
if (isMesh(d)) paths.push(d.GetPath());
|
|
407
|
+
}
|
|
408
|
+
return paths;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// src/schemas/usdPhysics.ts
|
|
412
|
+
var JOINT_TYPE_BY_SCHEMA = {
|
|
413
|
+
PhysicsFixedJoint: "fixed",
|
|
414
|
+
PhysicsRevoluteJoint: "revolute",
|
|
415
|
+
PhysicsPrismaticJoint: "prismatic"
|
|
416
|
+
};
|
|
417
|
+
var ARTICULATION_ROOT_API = "PhysicsArticulationRootAPI";
|
|
418
|
+
var RIGID_BODY_API = "PhysicsRigidBodyAPI";
|
|
419
|
+
var COLLISION_API = "PhysicsCollisionAPI";
|
|
420
|
+
var MASS_API = "PhysicsMassAPI";
|
|
421
|
+
var MESH_COLLISION_API = "PhysicsMeshCollisionAPI";
|
|
422
|
+
var PHYSICS_MATERIAL_API = "PhysicsMaterialAPI";
|
|
423
|
+
function getJointType(prim) {
|
|
424
|
+
return JOINT_TYPE_BY_SCHEMA[prim.GetTypeName()] ?? null;
|
|
425
|
+
}
|
|
426
|
+
function getJointBodies(prim) {
|
|
427
|
+
const body0 = prim.GetRelationship("physics:body0").GetTargets()[0];
|
|
428
|
+
const body1 = prim.GetRelationship("physics:body1").GetTargets()[0];
|
|
429
|
+
return {
|
|
430
|
+
...body0 !== void 0 ? { body0 } : {},
|
|
431
|
+
...body1 !== void 0 ? { body1 } : {}
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
function getJointAxis(prim) {
|
|
435
|
+
const v = prim.GetAttribute("physics:axis").Get();
|
|
436
|
+
return v === "Y" || v === "Z" ? v : "X";
|
|
437
|
+
}
|
|
438
|
+
function getJointLimits(prim) {
|
|
439
|
+
const lower = readNumber(prim, "physics:lowerLimit");
|
|
440
|
+
const upper = readNumber(prim, "physics:upperLimit");
|
|
441
|
+
return {
|
|
442
|
+
...lower !== void 0 ? { lower } : {},
|
|
443
|
+
...upper !== void 0 ? { upper } : {}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function getJointLocalFrame(prim, index) {
|
|
447
|
+
const pos = readVec3(prim, `physics:localPos${index}`, [0, 0, 0]);
|
|
448
|
+
const rot = readQuat(prim, `physics:localRot${index}`, Quat.identity());
|
|
449
|
+
return multiply(makeTranslation(pos), makeRotationFromQuat(rot));
|
|
450
|
+
}
|
|
451
|
+
function hasArticulationRootAPI(prim) {
|
|
452
|
+
return prim.HasAPI(ARTICULATION_ROOT_API);
|
|
453
|
+
}
|
|
454
|
+
function hasRigidBodyAPI(prim) {
|
|
455
|
+
return prim.HasAPI(RIGID_BODY_API);
|
|
456
|
+
}
|
|
457
|
+
function hasCollisionAPI(prim) {
|
|
458
|
+
return prim.HasAPI(COLLISION_API);
|
|
459
|
+
}
|
|
460
|
+
function driveKindFor(type) {
|
|
461
|
+
return type === "prismatic" ? "linear" : "angular";
|
|
462
|
+
}
|
|
463
|
+
function getJointDrive(prim, kind) {
|
|
464
|
+
const targetPosition = readNumber(prim, `drive:${kind}:physics:targetPosition`);
|
|
465
|
+
const stiffness = readNumber(prim, `drive:${kind}:physics:stiffness`);
|
|
466
|
+
const damping = readNumber(prim, `drive:${kind}:physics:damping`);
|
|
467
|
+
const maxForce = readNumber(prim, `drive:${kind}:physics:maxForce`);
|
|
468
|
+
return {
|
|
469
|
+
...targetPosition !== void 0 ? { targetPosition } : {},
|
|
470
|
+
...stiffness !== void 0 ? { stiffness } : {},
|
|
471
|
+
...damping !== void 0 ? { damping } : {},
|
|
472
|
+
...maxForce !== void 0 ? { maxForce } : {}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
function getJointStatePosition(prim, kind) {
|
|
476
|
+
return readNumber(prim, `state:${kind}:physics:position`);
|
|
477
|
+
}
|
|
478
|
+
function getMassProperties(prim) {
|
|
479
|
+
const out = {};
|
|
480
|
+
const mass = readNumber(prim, "physics:mass");
|
|
481
|
+
if (mass !== void 0) out.mass = mass;
|
|
482
|
+
const density = readNumber(prim, "physics:density");
|
|
483
|
+
if (density !== void 0) out.density = density;
|
|
484
|
+
const centerOfMass = readVec3Opt(prim, "physics:centerOfMass");
|
|
485
|
+
if (centerOfMass) out.centerOfMass = centerOfMass;
|
|
486
|
+
const diagonalInertia = readVec3Opt(prim, "physics:diagonalInertia");
|
|
487
|
+
if (diagonalInertia) out.diagonalInertia = diagonalInertia;
|
|
488
|
+
const principalAxes = prim.GetAttribute("physics:principalAxes").Get();
|
|
489
|
+
if (principalAxes instanceof Quat) out.principalAxes = principalAxes;
|
|
490
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
491
|
+
}
|
|
492
|
+
function readNumber(prim, name) {
|
|
493
|
+
const v = prim.GetAttribute(name).Get();
|
|
494
|
+
return typeof v === "number" ? v : void 0;
|
|
495
|
+
}
|
|
496
|
+
function readVec3(prim, name, def) {
|
|
497
|
+
return readVec3Opt(prim, name) ?? def;
|
|
498
|
+
}
|
|
499
|
+
function readVec3Opt(prim, name) {
|
|
500
|
+
const v = prim.GetAttribute(name).Get();
|
|
501
|
+
if (Array.isArray(v) && v.length === 3 && v.every((n) => typeof n === "number")) {
|
|
502
|
+
return v;
|
|
503
|
+
}
|
|
504
|
+
return void 0;
|
|
505
|
+
}
|
|
506
|
+
function readQuat(prim, name, def) {
|
|
507
|
+
const v = prim.GetAttribute(name).Get();
|
|
508
|
+
return v instanceof Quat ? v : def;
|
|
509
|
+
}
|
|
257
510
|
|
|
258
511
|
// src/usd/xformOps.ts
|
|
259
512
|
var INVERT_PREFIX = "!invert!";
|
|
@@ -266,6 +519,15 @@ var ROTATE_ORDERS = /* @__PURE__ */ new Set([
|
|
|
266
519
|
"rotateZXY",
|
|
267
520
|
"rotateZYX"
|
|
268
521
|
]);
|
|
522
|
+
function computeWorldTransform(prim) {
|
|
523
|
+
const chain = [];
|
|
524
|
+
for (let p = prim; p && !p.IsPseudoRoot(); p = p.GetParent()) chain.push(p);
|
|
525
|
+
let m = identity4();
|
|
526
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
527
|
+
m = multiply(m, computeLocalTransform(chain[i]).matrix);
|
|
528
|
+
}
|
|
529
|
+
return m;
|
|
530
|
+
}
|
|
269
531
|
function computeLocalTransform(prim) {
|
|
270
532
|
const orderAttr = prim.GetAttribute("xformOpOrder");
|
|
271
533
|
const order = orderAttr.Get();
|
|
@@ -345,56 +607,177 @@ function asMatrix(v, where) {
|
|
|
345
607
|
throw new Error(`${where}: expected a matrix`);
|
|
346
608
|
}
|
|
347
609
|
|
|
348
|
-
// src/
|
|
349
|
-
var
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
610
|
+
// src/three/MaterialBinding.ts
|
|
611
|
+
var DIFFUSE_INPUTS = [
|
|
612
|
+
"inputs:diffuseColor",
|
|
613
|
+
// UsdPreviewSurface
|
|
614
|
+
"inputs:diffuse_color_constant",
|
|
615
|
+
// OmniPBR
|
|
616
|
+
"inputs:diffuse_tint",
|
|
617
|
+
"inputs:base_color",
|
|
618
|
+
"inputs:baseColor"
|
|
619
|
+
];
|
|
620
|
+
var OPACITY_INPUTS = ["inputs:opacity", "inputs:opacity_constant"];
|
|
621
|
+
var OPACITY_THRESHOLD_INPUTS = ["inputs:opacityThreshold", "inputs:opacity_threshold"];
|
|
622
|
+
var METALLIC_INPUTS = ["inputs:metallic", "inputs:metallic_constant"];
|
|
623
|
+
var ROUGHNESS_INPUTS = ["inputs:roughness", "inputs:reflection_roughness_constant"];
|
|
624
|
+
var EMISSIVE_INPUTS = ["inputs:emissiveColor", "inputs:emissive_color"];
|
|
625
|
+
var SURFACE_OUTPUTS = ["outputs:surface", "outputs:mdl:surface"];
|
|
626
|
+
var TEXTURE_LOOKUPS = {
|
|
627
|
+
color: {
|
|
628
|
+
surface: ["inputs:diffuseColor"],
|
|
629
|
+
direct: ["inputs:diffuse_texture", "inputs:diffuse_color_texture"]
|
|
630
|
+
},
|
|
631
|
+
opacity: {
|
|
632
|
+
surface: ["inputs:opacity"],
|
|
633
|
+
direct: ["inputs:opacity_texture", "inputs:opacity_color_texture"]
|
|
634
|
+
},
|
|
635
|
+
normal: {
|
|
636
|
+
surface: ["inputs:normal"],
|
|
637
|
+
direct: ["inputs:normalmap_texture", "inputs:normal_texture"]
|
|
638
|
+
},
|
|
639
|
+
roughness: {
|
|
640
|
+
surface: ["inputs:roughness"],
|
|
641
|
+
direct: ["inputs:reflectionroughness_texture", "inputs:roughness_texture"]
|
|
642
|
+
},
|
|
643
|
+
metalness: {
|
|
644
|
+
surface: ["inputs:metallic"],
|
|
645
|
+
direct: ["inputs:metallic_texture"]
|
|
646
|
+
},
|
|
647
|
+
occlusion: {
|
|
648
|
+
surface: ["inputs:occlusion"],
|
|
649
|
+
direct: ["inputs:ao_texture", "inputs:occlusion_texture"]
|
|
650
|
+
},
|
|
651
|
+
emissive: {
|
|
652
|
+
surface: ["inputs:emissiveColor"],
|
|
653
|
+
direct: ["inputs:emissive_color_texture", "inputs:emissive_mask_texture"]
|
|
353
654
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
655
|
+
};
|
|
656
|
+
function resolveBoundMaterial(stage, prim) {
|
|
657
|
+
const materialPath = findBinding(prim);
|
|
658
|
+
if (!materialPath) return void 0;
|
|
659
|
+
const material = stage.GetPrimAtPath(materialPath);
|
|
660
|
+
if (!material) return void 0;
|
|
661
|
+
const shader = findSurfaceShader(material);
|
|
662
|
+
if (!shader) return void 0;
|
|
663
|
+
const result = {};
|
|
664
|
+
const color = firstColor(shader, DIFFUSE_INPUTS);
|
|
665
|
+
if (color) result.color = color;
|
|
666
|
+
const opacity = firstNumber(shader, OPACITY_INPUTS);
|
|
667
|
+
if (opacity !== void 0) result.opacity = opacity;
|
|
668
|
+
const opacityThreshold = firstNumber(shader, OPACITY_THRESHOLD_INPUTS);
|
|
669
|
+
if (opacityThreshold !== void 0) result.opacityThreshold = opacityThreshold;
|
|
670
|
+
const metalness = firstNumber(shader, METALLIC_INPUTS);
|
|
671
|
+
if (metalness !== void 0) result.metalness = metalness;
|
|
672
|
+
const roughness = firstNumber(shader, ROUGHNESS_INPUTS);
|
|
673
|
+
if (roughness !== void 0) result.roughness = roughness;
|
|
674
|
+
const emissive = firstColor(shader, EMISSIVE_INPUTS);
|
|
675
|
+
if (emissive && shader.GetAttribute("inputs:enable_emission").Get() !== false) {
|
|
676
|
+
result.emissiveColor = emissive;
|
|
677
|
+
}
|
|
678
|
+
const colorTex = findTexture(shader, TEXTURE_LOOKUPS.color);
|
|
679
|
+
if (colorTex !== void 0) result.colorTexture = colorTex;
|
|
680
|
+
const opacityTex = findTexture(shader, TEXTURE_LOOKUPS.opacity);
|
|
681
|
+
if (opacityTex !== void 0) result.opacityTexture = opacityTex;
|
|
682
|
+
const normal = findTexture(shader, TEXTURE_LOOKUPS.normal);
|
|
683
|
+
if (normal !== void 0) result.normalTexture = normal;
|
|
684
|
+
const roughTex = findTexture(shader, TEXTURE_LOOKUPS.roughness);
|
|
685
|
+
if (roughTex !== void 0) result.roughnessTexture = roughTex;
|
|
686
|
+
const metalTex = findTexture(shader, TEXTURE_LOOKUPS.metalness);
|
|
687
|
+
if (metalTex !== void 0) result.metalnessTexture = metalTex;
|
|
688
|
+
const aoTex = findTexture(shader, TEXTURE_LOOKUPS.occlusion);
|
|
689
|
+
if (aoTex !== void 0) result.occlusionTexture = aoTex;
|
|
690
|
+
const emissiveTex = findTexture(shader, TEXTURE_LOOKUPS.emissive);
|
|
691
|
+
if (emissiveTex !== void 0) result.emissiveTexture = emissiveTex;
|
|
692
|
+
return result;
|
|
693
|
+
}
|
|
694
|
+
function findTexture(shader, lookup) {
|
|
695
|
+
for (const name of lookup.direct) {
|
|
696
|
+
const v = shader.GetAttribute(name).Get();
|
|
697
|
+
if (v instanceof AssetPath && v.path) return { path: v.path };
|
|
698
|
+
}
|
|
699
|
+
for (const name of lookup.surface) {
|
|
700
|
+
const conn = shader.GetAttribute(name).GetConnections()[0];
|
|
701
|
+
if (!conn) continue;
|
|
702
|
+
const texPrim = shader.GetStage().GetPrimAtPath(conn.split(".")[0]);
|
|
703
|
+
if (!texPrim) continue;
|
|
704
|
+
const file = texPrim.GetAttribute("inputs:file").Get();
|
|
705
|
+
if (file instanceof AssetPath && file.path) return readUvTexture(texPrim, file.path);
|
|
706
|
+
}
|
|
707
|
+
return void 0;
|
|
708
|
+
}
|
|
709
|
+
var WRAP_VALUES = /* @__PURE__ */ new Set(["repeat", "clamp", "mirror", "black"]);
|
|
710
|
+
function readUvTexture(texPrim, path) {
|
|
711
|
+
const tex = { path };
|
|
712
|
+
const wrapS = texPrim.GetAttribute("inputs:wrapS").Get();
|
|
713
|
+
if (typeof wrapS === "string" && WRAP_VALUES.has(wrapS)) tex.wrapS = wrapS;
|
|
714
|
+
const wrapT = texPrim.GetAttribute("inputs:wrapT").Get();
|
|
715
|
+
if (typeof wrapT === "string" && WRAP_VALUES.has(wrapT)) tex.wrapT = wrapT;
|
|
716
|
+
const scale = numArray(texPrim, "inputs:scale", 4);
|
|
717
|
+
if (scale) tex.scale = scale;
|
|
718
|
+
const bias = numArray(texPrim, "inputs:bias", 4);
|
|
719
|
+
if (bias) tex.bias = bias;
|
|
720
|
+
const transform = readTransform2d(texPrim);
|
|
721
|
+
if (transform) tex.transform = transform;
|
|
722
|
+
return tex;
|
|
723
|
+
}
|
|
724
|
+
function readTransform2d(texPrim) {
|
|
725
|
+
const conn = texPrim.GetAttribute("inputs:st").GetConnections()[0];
|
|
726
|
+
if (!conn) return void 0;
|
|
727
|
+
const node = texPrim.GetStage().GetPrimAtPath(conn.split(".")[0]);
|
|
728
|
+
if (!node || node.GetAttribute("info:id").Get() !== "UsdTransform2d") return void 0;
|
|
729
|
+
const transform = {};
|
|
730
|
+
const translation = numArray(node, "inputs:translation", 2);
|
|
731
|
+
if (translation) transform.translation = translation;
|
|
732
|
+
const scale = numArray(node, "inputs:scale", 2);
|
|
733
|
+
if (scale) transform.scale = scale;
|
|
734
|
+
const rotation = node.GetAttribute("inputs:rotation").Get();
|
|
735
|
+
if (typeof rotation === "number") transform.rotation = rotation;
|
|
736
|
+
return Object.keys(transform).length > 0 ? transform : void 0;
|
|
737
|
+
}
|
|
738
|
+
function numArray(prim, name, length) {
|
|
739
|
+
const v = prim.GetAttribute(name).Get();
|
|
740
|
+
if (Array.isArray(v) && v.length >= length && v.every((n) => typeof n === "number")) {
|
|
741
|
+
return v.slice(0, length);
|
|
359
742
|
}
|
|
360
|
-
|
|
361
|
-
|
|
743
|
+
return void 0;
|
|
744
|
+
}
|
|
745
|
+
function findBinding(prim) {
|
|
746
|
+
let p = prim;
|
|
747
|
+
while (p) {
|
|
748
|
+
const targets = p.GetRelationship("material:binding").GetTargets();
|
|
749
|
+
if (targets.length > 0) return targets[0];
|
|
750
|
+
p = p.GetParent();
|
|
362
751
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
752
|
+
return void 0;
|
|
753
|
+
}
|
|
754
|
+
function findSurfaceShader(material) {
|
|
755
|
+
for (const out of SURFACE_OUTPUTS) {
|
|
756
|
+
const conn = material.GetAttribute(out).GetConnections()[0];
|
|
757
|
+
if (conn) {
|
|
758
|
+
const shaderPath = conn.split(".")[0];
|
|
759
|
+
const shader = material.GetStage().GetPrimAtPath(shaderPath);
|
|
760
|
+
if (shader) return shader;
|
|
761
|
+
}
|
|
368
762
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
0,
|
|
376
|
-
|
|
377
|
-
0,
|
|
378
|
-
1,
|
|
379
|
-
0,
|
|
380
|
-
0,
|
|
381
|
-
0,
|
|
382
|
-
0,
|
|
383
|
-
1,
|
|
384
|
-
0,
|
|
385
|
-
0,
|
|
386
|
-
0,
|
|
387
|
-
0,
|
|
388
|
-
1
|
|
389
|
-
], 4);
|
|
763
|
+
return material.GetChildren().find((c) => c.GetTypeName() === "Shader") ?? void 0;
|
|
764
|
+
}
|
|
765
|
+
function firstColor(shader, names) {
|
|
766
|
+
for (const name of names) {
|
|
767
|
+
const v = shader.GetAttribute(name).Get();
|
|
768
|
+
if (Array.isArray(v) && v.length >= 3 && v.every((n) => typeof n === "number")) {
|
|
769
|
+
return [v[0], v[1], v[2]];
|
|
770
|
+
}
|
|
390
771
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
772
|
+
return void 0;
|
|
773
|
+
}
|
|
774
|
+
function firstNumber(shader, names) {
|
|
775
|
+
for (const name of names) {
|
|
776
|
+
const v = shader.GetAttribute(name).Get();
|
|
777
|
+
if (typeof v === "number") return v;
|
|
395
778
|
}
|
|
396
|
-
|
|
397
|
-
}
|
|
779
|
+
return void 0;
|
|
780
|
+
}
|
|
398
781
|
|
|
399
782
|
// src/kinematics/sampling.ts
|
|
400
783
|
function interpolate(channel, t) {
|
|
@@ -423,118 +806,6 @@ function channelFromSamples(samples) {
|
|
|
423
806
|
return { times, values };
|
|
424
807
|
}
|
|
425
808
|
|
|
426
|
-
// src/schemas/usdGeom.ts
|
|
427
|
-
function isXform(prim) {
|
|
428
|
-
return prim.GetTypeName() === "Xform";
|
|
429
|
-
}
|
|
430
|
-
function isScope(prim) {
|
|
431
|
-
return prim.GetTypeName() === "Scope";
|
|
432
|
-
}
|
|
433
|
-
function isMesh(prim) {
|
|
434
|
-
return prim.GetTypeName() === "Mesh";
|
|
435
|
-
}
|
|
436
|
-
function getPurpose(prim) {
|
|
437
|
-
const v = prim.GetAttribute("purpose").Get();
|
|
438
|
-
return typeof v === "string" ? v : "default";
|
|
439
|
-
}
|
|
440
|
-
function isNonVisualPurpose(prim) {
|
|
441
|
-
const p = getPurpose(prim);
|
|
442
|
-
return p === "guide" || p === "proxy";
|
|
443
|
-
}
|
|
444
|
-
function* iterDescendants(prim) {
|
|
445
|
-
for (const child of prim.GetChildren()) {
|
|
446
|
-
yield child;
|
|
447
|
-
yield* iterDescendants(child);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
function gatherMeshDescendants(prim) {
|
|
451
|
-
const paths = [];
|
|
452
|
-
for (const d of iterDescendants(prim)) {
|
|
453
|
-
if (isMesh(d)) paths.push(d.GetPath());
|
|
454
|
-
}
|
|
455
|
-
return paths;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// src/schemas/usdPhysics.ts
|
|
459
|
-
var JOINT_TYPE_BY_SCHEMA = {
|
|
460
|
-
PhysicsFixedJoint: "fixed",
|
|
461
|
-
PhysicsRevoluteJoint: "revolute",
|
|
462
|
-
PhysicsPrismaticJoint: "prismatic"
|
|
463
|
-
};
|
|
464
|
-
var ARTICULATION_ROOT_API = "PhysicsArticulationRootAPI";
|
|
465
|
-
var RIGID_BODY_API = "PhysicsRigidBodyAPI";
|
|
466
|
-
var COLLISION_API = "PhysicsCollisionAPI";
|
|
467
|
-
function getJointType(prim) {
|
|
468
|
-
return JOINT_TYPE_BY_SCHEMA[prim.GetTypeName()] ?? null;
|
|
469
|
-
}
|
|
470
|
-
function getJointBodies(prim) {
|
|
471
|
-
const body0 = prim.GetRelationship("physics:body0").GetTargets()[0];
|
|
472
|
-
const body1 = prim.GetRelationship("physics:body1").GetTargets()[0];
|
|
473
|
-
return {
|
|
474
|
-
...body0 !== void 0 ? { body0 } : {},
|
|
475
|
-
...body1 !== void 0 ? { body1 } : {}
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
function getJointAxis(prim) {
|
|
479
|
-
const v = prim.GetAttribute("physics:axis").Get();
|
|
480
|
-
return v === "Y" || v === "Z" ? v : "X";
|
|
481
|
-
}
|
|
482
|
-
function getJointLimits(prim) {
|
|
483
|
-
const lower = readNumber(prim, "physics:lowerLimit");
|
|
484
|
-
const upper = readNumber(prim, "physics:upperLimit");
|
|
485
|
-
return {
|
|
486
|
-
...lower !== void 0 ? { lower } : {},
|
|
487
|
-
...upper !== void 0 ? { upper } : {}
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
function getJointLocalFrame(prim, index) {
|
|
491
|
-
const pos = readVec3(prim, `physics:localPos${index}`, [0, 0, 0]);
|
|
492
|
-
const rot = readQuat(prim, `physics:localRot${index}`, Quat.identity());
|
|
493
|
-
return multiply(makeTranslation(pos), makeRotationFromQuat(rot));
|
|
494
|
-
}
|
|
495
|
-
function hasArticulationRootAPI(prim) {
|
|
496
|
-
return prim.HasAPI(ARTICULATION_ROOT_API);
|
|
497
|
-
}
|
|
498
|
-
function hasRigidBodyAPI(prim) {
|
|
499
|
-
return prim.HasAPI(RIGID_BODY_API);
|
|
500
|
-
}
|
|
501
|
-
function hasCollisionAPI(prim) {
|
|
502
|
-
return prim.HasAPI(COLLISION_API);
|
|
503
|
-
}
|
|
504
|
-
function driveKindFor(type) {
|
|
505
|
-
return type === "prismatic" ? "linear" : "angular";
|
|
506
|
-
}
|
|
507
|
-
function getJointDrive(prim, kind) {
|
|
508
|
-
const targetPosition = readNumber(prim, `drive:${kind}:physics:targetPosition`);
|
|
509
|
-
const stiffness = readNumber(prim, `drive:${kind}:physics:stiffness`);
|
|
510
|
-
const damping = readNumber(prim, `drive:${kind}:physics:damping`);
|
|
511
|
-
const maxForce = readNumber(prim, `drive:${kind}:physics:maxForce`);
|
|
512
|
-
return {
|
|
513
|
-
...targetPosition !== void 0 ? { targetPosition } : {},
|
|
514
|
-
...stiffness !== void 0 ? { stiffness } : {},
|
|
515
|
-
...damping !== void 0 ? { damping } : {},
|
|
516
|
-
...maxForce !== void 0 ? { maxForce } : {}
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
function getJointStatePosition(prim, kind) {
|
|
520
|
-
return readNumber(prim, `state:${kind}:physics:position`);
|
|
521
|
-
}
|
|
522
|
-
function readNumber(prim, name) {
|
|
523
|
-
const v = prim.GetAttribute(name).Get();
|
|
524
|
-
return typeof v === "number" ? v : void 0;
|
|
525
|
-
}
|
|
526
|
-
function readVec3(prim, name, def) {
|
|
527
|
-
const v = prim.GetAttribute(name).Get();
|
|
528
|
-
if (Array.isArray(v) && v.length === 3 && v.every((n) => typeof n === "number")) {
|
|
529
|
-
return v;
|
|
530
|
-
}
|
|
531
|
-
return def;
|
|
532
|
-
}
|
|
533
|
-
function readQuat(prim, name, def) {
|
|
534
|
-
const v = prim.GetAttribute(name).Get();
|
|
535
|
-
return v instanceof Quat ? v : def;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
809
|
// src/robot/buildKinematicTree.ts
|
|
539
810
|
var WORLD = "";
|
|
540
811
|
function buildKinematicTree(robot, options = {}) {
|
|
@@ -654,6 +925,9 @@ function normalizeJointLimits(type, rawLower, rawUpper) {
|
|
|
654
925
|
function jointValueToSI(angular, raw) {
|
|
655
926
|
return angular ? raw * DEG2RAD : raw;
|
|
656
927
|
}
|
|
928
|
+
function jointValueFromSI(angular, si) {
|
|
929
|
+
return angular ? si * RAD2DEG : si;
|
|
930
|
+
}
|
|
657
931
|
function refineJointType(base, lower, upper) {
|
|
658
932
|
if (base === "revolute" && lower === void 0 && upper === void 0) return "continuous";
|
|
659
933
|
return base;
|
|
@@ -723,13 +997,23 @@ function buildLink(path, prim) {
|
|
|
723
997
|
if (mp && (hasCollisionAPI(mp) || isNonVisualPurpose(mp))) collisionPrims.push(meshPath);
|
|
724
998
|
else visualPrims.push(meshPath);
|
|
725
999
|
}
|
|
1000
|
+
const inertial = getMassProperties(prim);
|
|
1001
|
+
const worldTransform = computeWorldTransform(prim);
|
|
726
1002
|
return {
|
|
727
1003
|
name,
|
|
728
1004
|
primPath: path,
|
|
729
1005
|
visualPrims,
|
|
730
|
-
...collisionPrims.length ? { collisionPrims } : {}
|
|
1006
|
+
...collisionPrims.length ? { collisionPrims } : {},
|
|
1007
|
+
...inertial ? { inertial } : {},
|
|
1008
|
+
...isIdentityMat4(worldTransform) ? {} : { worldTransform }
|
|
731
1009
|
};
|
|
732
1010
|
}
|
|
1011
|
+
function isIdentityMat4(m) {
|
|
1012
|
+
for (let i = 0; i < 16; i++) {
|
|
1013
|
+
if (m[i] !== (i % 5 === 0 ? 1 : 0)) return false;
|
|
1014
|
+
}
|
|
1015
|
+
return true;
|
|
1016
|
+
}
|
|
733
1017
|
function buildJoint(prim, linkKeyByPath, warn) {
|
|
734
1018
|
const base = getJointType(prim);
|
|
735
1019
|
if (!base) return null;
|
|
@@ -1523,12 +1807,237 @@ function parseDictionary(r) {
|
|
|
1523
1807
|
return dict;
|
|
1524
1808
|
}
|
|
1525
1809
|
|
|
1810
|
+
// src/writer/writeUsda.ts
|
|
1811
|
+
var INDENT = " ";
|
|
1812
|
+
var BARE_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1813
|
+
function serializeUsda(file) {
|
|
1814
|
+
const out = [`#usda ${file.version}`];
|
|
1815
|
+
const meta = Object.entries(file.metadata);
|
|
1816
|
+
if (meta.length > 0) {
|
|
1817
|
+
out.push("(");
|
|
1818
|
+
for (const [key, value] of meta) pushMetaEntry(out, key, value, 1);
|
|
1819
|
+
out.push(")");
|
|
1820
|
+
}
|
|
1821
|
+
for (const prim of file.prims) {
|
|
1822
|
+
out.push("");
|
|
1823
|
+
pushPrim(out, prim, 0);
|
|
1824
|
+
}
|
|
1825
|
+
return `${out.join("\n")}
|
|
1826
|
+
`;
|
|
1827
|
+
}
|
|
1828
|
+
function pushPrim(out, prim, level) {
|
|
1829
|
+
const pad = INDENT.repeat(level);
|
|
1830
|
+
const type = prim.typeName ? `${prim.typeName} ` : "";
|
|
1831
|
+
pushWithMetadata(
|
|
1832
|
+
out,
|
|
1833
|
+
`${pad}${prim.specifier} ${type}${quoteString(prim.name)}`,
|
|
1834
|
+
prim.metadata,
|
|
1835
|
+
level
|
|
1836
|
+
);
|
|
1837
|
+
out.push(`${pad}{`);
|
|
1838
|
+
pushPrimBody(out, prim.properties, prim.children, prim.variantSets, level + 1);
|
|
1839
|
+
out.push(`${pad}}`);
|
|
1840
|
+
}
|
|
1841
|
+
function pushPrimBody(out, properties, children, variantSets, level) {
|
|
1842
|
+
for (const prop of properties) pushProperty(out, prop, level);
|
|
1843
|
+
if (variantSets) {
|
|
1844
|
+
const pad = INDENT.repeat(level);
|
|
1845
|
+
for (const [setName, variants] of Object.entries(variantSets)) {
|
|
1846
|
+
out.push(`${pad}variantSet ${quoteString(setName)} = {`);
|
|
1847
|
+
for (const [variantName, content] of Object.entries(variants)) {
|
|
1848
|
+
out.push(`${pad}${INDENT}${quoteString(variantName)} {`);
|
|
1849
|
+
pushPrimBody(out, content.properties, content.children, void 0, level + 2);
|
|
1850
|
+
out.push(`${pad}${INDENT}}`);
|
|
1851
|
+
}
|
|
1852
|
+
out.push(`${pad}}`);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
for (let i = 0; i < children.length; i++) {
|
|
1856
|
+
if (i > 0 || properties.length > 0 || variantSets) out.push("");
|
|
1857
|
+
pushPrim(out, children[i], level);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
function pushProperty(out, prop, level) {
|
|
1861
|
+
if (prop.kind === "relationship") pushRelationship(out, prop, level);
|
|
1862
|
+
else pushAttribute(out, prop, level);
|
|
1863
|
+
}
|
|
1864
|
+
function pushRelationship(out, rel, level) {
|
|
1865
|
+
const pad = INDENT.repeat(level);
|
|
1866
|
+
const custom = rel.custom ? "custom " : "";
|
|
1867
|
+
const listOp = rel.listOp !== "explicit" ? `${rel.listOp} ` : "";
|
|
1868
|
+
let head = `${pad}${custom}${listOp}rel ${rel.name}`;
|
|
1869
|
+
if (rel.targets.length > 0) head += ` = ${formatTargets(rel.targets)}`;
|
|
1870
|
+
pushWithMetadata(out, head, rel.metadata, level);
|
|
1871
|
+
}
|
|
1872
|
+
function pushAttribute(out, attr, level) {
|
|
1873
|
+
const pad = INDENT.repeat(level);
|
|
1874
|
+
const custom = attr.custom ? "custom " : "";
|
|
1875
|
+
const uniform = attr.variability === "uniform" ? "uniform " : "";
|
|
1876
|
+
const decl = `${pad}${custom}${uniform}${attr.typeName}${attr.isArray ? "[]" : ""} ${attr.name}`;
|
|
1877
|
+
let first = true;
|
|
1878
|
+
const attach = (head) => {
|
|
1879
|
+
if (first) pushWithMetadata(out, head, attr.metadata, level);
|
|
1880
|
+
else out.push(head);
|
|
1881
|
+
first = false;
|
|
1882
|
+
};
|
|
1883
|
+
if (attr.value !== void 0) {
|
|
1884
|
+
attach(`${decl} = ${formatAttrValue(attr.value, attr.isArray)}`);
|
|
1885
|
+
}
|
|
1886
|
+
if (attr.timeSamples) {
|
|
1887
|
+
out.push(`${decl}.timeSamples = {`);
|
|
1888
|
+
for (const [time, value] of attr.timeSamples) {
|
|
1889
|
+
out.push(`${pad}${INDENT}${formatNumber(time)}: ${formatAttrValue(value, attr.isArray)},`);
|
|
1890
|
+
}
|
|
1891
|
+
attach(`${pad}}`);
|
|
1892
|
+
}
|
|
1893
|
+
if (attr.connections) {
|
|
1894
|
+
attach(
|
|
1895
|
+
`${decl}.connect = ${attr.connections.length > 0 ? formatTargets(attr.connections) : "None"}`
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
if (first) attach(decl);
|
|
1899
|
+
}
|
|
1900
|
+
function formatTargets(targets) {
|
|
1901
|
+
if (targets.length === 1) return `<${targets[0]}>`;
|
|
1902
|
+
return `[${targets.map((t) => `<${t}>`).join(", ")}]`;
|
|
1903
|
+
}
|
|
1904
|
+
function pushWithMetadata(out, head, meta, level) {
|
|
1905
|
+
const entries = Object.entries(meta);
|
|
1906
|
+
if (entries.length === 0) {
|
|
1907
|
+
out.push(head);
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
out.push(`${head} (`);
|
|
1911
|
+
for (const [key, value] of entries) pushMetaEntry(out, key, value, level + 1);
|
|
1912
|
+
out.push(`${INDENT.repeat(level)})`);
|
|
1913
|
+
}
|
|
1914
|
+
function pushMetaEntry(out, key, value, level) {
|
|
1915
|
+
const pad = INDENT.repeat(level);
|
|
1916
|
+
if (isDictionary(value)) {
|
|
1917
|
+
out.push(`${pad}${key} = {`);
|
|
1918
|
+
pushDictEntries(out, value, level + 1);
|
|
1919
|
+
out.push(`${pad}}`);
|
|
1920
|
+
return;
|
|
1921
|
+
}
|
|
1922
|
+
out.push(`${pad}${key} = ${formatMetaValue(value)}`);
|
|
1923
|
+
}
|
|
1924
|
+
function pushDictEntries(out, dict, level) {
|
|
1925
|
+
const pad = INDENT.repeat(level);
|
|
1926
|
+
for (const [key, value] of Object.entries(dict)) {
|
|
1927
|
+
const keyText = BARE_KEY_RE.test(key) ? key : quoteString(key);
|
|
1928
|
+
if (isDictionary(value)) {
|
|
1929
|
+
out.push(`${pad}dictionary ${keyText} = {`);
|
|
1930
|
+
pushDictEntries(out, value, level + 1);
|
|
1931
|
+
out.push(`${pad}}`);
|
|
1932
|
+
} else {
|
|
1933
|
+
out.push(`${pad}${dictEntryTypeName(value)} ${keyText} = ${formatMetaValue(value)}`);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
function dictEntryTypeName(v) {
|
|
1938
|
+
if (typeof v === "string") return "string";
|
|
1939
|
+
if (typeof v === "boolean") return "bool";
|
|
1940
|
+
if (typeof v === "number") return isInt32(v) ? "int" : "double";
|
|
1941
|
+
if (typeof v === "bigint") return "int64";
|
|
1942
|
+
if (v instanceof AssetPath) return "asset";
|
|
1943
|
+
if (v instanceof Quat) return "quatd";
|
|
1944
|
+
if (v instanceof UsdMatrix) return v.dim === 4 ? "matrix4d" : "matrix3d";
|
|
1945
|
+
if (Array.isArray(v)) {
|
|
1946
|
+
const elems = v;
|
|
1947
|
+
if (elems.every((e) => typeof e === "boolean")) return "bool[]";
|
|
1948
|
+
let allInt = true;
|
|
1949
|
+
for (const e of elems) {
|
|
1950
|
+
if (typeof e !== "number") return "string[]";
|
|
1951
|
+
if (!isInt32(e)) allInt = false;
|
|
1952
|
+
}
|
|
1953
|
+
return allInt ? "int[]" : "double[]";
|
|
1954
|
+
}
|
|
1955
|
+
return "string";
|
|
1956
|
+
}
|
|
1957
|
+
function isInt32(v) {
|
|
1958
|
+
return Number.isInteger(v) && Math.abs(v) <= 2147483647;
|
|
1959
|
+
}
|
|
1960
|
+
function formatMetaValue(v) {
|
|
1961
|
+
if (v === null) return "None";
|
|
1962
|
+
if (typeof v === "number") return formatNumber(v);
|
|
1963
|
+
if (typeof v === "bigint") return String(v);
|
|
1964
|
+
if (typeof v === "boolean") return v ? "true" : "false";
|
|
1965
|
+
if (typeof v === "string") return quoteString(v);
|
|
1966
|
+
if (v instanceof AssetPath) return formatAsset(v.path);
|
|
1967
|
+
if (v instanceof Quat) return formatQuat(v);
|
|
1968
|
+
if (v instanceof UsdMatrix) return formatMatrix(v);
|
|
1969
|
+
if (Array.isArray(v)) return `[${v.map(formatMetaValue).join(", ")}]`;
|
|
1970
|
+
if (isCompositionArc(v)) return formatArc(v);
|
|
1971
|
+
throw new Error("cannot serialize a nested dictionary in list/value context");
|
|
1972
|
+
}
|
|
1973
|
+
function formatArc(arc) {
|
|
1974
|
+
const asset = arc.assetPath ? formatAsset(arc.assetPath.path) : "";
|
|
1975
|
+
const prim = arc.primPath !== void 0 ? `<${arc.primPath}>` : "";
|
|
1976
|
+
return `${asset}${prim}`;
|
|
1977
|
+
}
|
|
1978
|
+
function formatAttrValue(v, isArray) {
|
|
1979
|
+
if (v === null) return "None";
|
|
1980
|
+
if (isArray && Array.isArray(v)) {
|
|
1981
|
+
return `[${v.map((el) => formatAttrScalar(el)).join(", ")}]`;
|
|
1982
|
+
}
|
|
1983
|
+
return formatAttrScalar(v);
|
|
1984
|
+
}
|
|
1985
|
+
function formatAttrScalar(v) {
|
|
1986
|
+
if (v === null) return "None";
|
|
1987
|
+
if (typeof v === "number") return formatNumber(v);
|
|
1988
|
+
if (typeof v === "bigint") return String(v);
|
|
1989
|
+
if (typeof v === "boolean") return v ? "true" : "false";
|
|
1990
|
+
if (typeof v === "string") return quoteString(v);
|
|
1991
|
+
if (v instanceof Quat) return formatQuat(v);
|
|
1992
|
+
if (v instanceof UsdMatrix) return formatMatrix(v);
|
|
1993
|
+
if (v instanceof AssetPath) return formatAsset(v.path);
|
|
1994
|
+
if (Array.isArray(v)) return `(${v.map((el) => formatAttrScalar(el)).join(", ")})`;
|
|
1995
|
+
throw new Error("cannot serialize a dictionary as an attribute value");
|
|
1996
|
+
}
|
|
1997
|
+
function formatQuat(q) {
|
|
1998
|
+
const [i, j, k] = q.imaginary;
|
|
1999
|
+
return `(${formatNumber(q.real)}, ${formatNumber(i)}, ${formatNumber(j)}, ${formatNumber(k)})`;
|
|
2000
|
+
}
|
|
2001
|
+
function formatMatrix(m) {
|
|
2002
|
+
const rows = [];
|
|
2003
|
+
for (let r = 0; r < m.dim; r++) {
|
|
2004
|
+
const row = m.values.slice(r * m.dim, (r + 1) * m.dim).map(formatNumber);
|
|
2005
|
+
rows.push(`(${row.join(", ")})`);
|
|
2006
|
+
}
|
|
2007
|
+
return `( ${rows.join(", ")} )`;
|
|
2008
|
+
}
|
|
2009
|
+
function formatNumber(v) {
|
|
2010
|
+
if (Number.isNaN(v)) return "nan";
|
|
2011
|
+
if (v === Number.POSITIVE_INFINITY) return "inf";
|
|
2012
|
+
if (v === Number.NEGATIVE_INFINITY) return "-inf";
|
|
2013
|
+
if (Object.is(v, -0)) return "-0";
|
|
2014
|
+
return String(v);
|
|
2015
|
+
}
|
|
2016
|
+
function quoteString(s) {
|
|
2017
|
+
const escaped = s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
|
|
2018
|
+
return `"${escaped}"`;
|
|
2019
|
+
}
|
|
2020
|
+
function formatAsset(path) {
|
|
2021
|
+
return path.includes("@") ? `@@@${path}@@@` : `@${path}@`;
|
|
2022
|
+
}
|
|
2023
|
+
function isDictionary(v) {
|
|
2024
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && !(v instanceof Quat) && !(v instanceof UsdMatrix) && !(v instanceof AssetPath) && !isCompositionArc(v);
|
|
2025
|
+
}
|
|
2026
|
+
function isCompositionArc(v) {
|
|
2027
|
+
const keys = Object.keys(v);
|
|
2028
|
+
return keys.length > 0 && keys.every((k) => k === "assetPath" || k === "primPath");
|
|
2029
|
+
}
|
|
2030
|
+
|
|
1526
2031
|
// src/usd/Layer.ts
|
|
1527
2032
|
var Layer = class {
|
|
1528
2033
|
constructor(_file) {
|
|
1529
2034
|
this._file = _file;
|
|
1530
2035
|
}
|
|
1531
2036
|
_file;
|
|
2037
|
+
/** Serialize this layer back to USDA text (`SdfLayer::ExportToString`-like). */
|
|
2038
|
+
ExportToString() {
|
|
2039
|
+
return serializeUsda(this._file);
|
|
2040
|
+
}
|
|
1532
2041
|
GetVersion() {
|
|
1533
2042
|
return this._file.version;
|
|
1534
2043
|
}
|
|
@@ -1712,7 +2221,9 @@ var Prim = class {
|
|
|
1712
2221
|
if (!this._attributes) {
|
|
1713
2222
|
this._attributes = /* @__PURE__ */ new Map();
|
|
1714
2223
|
for (const p of this._spec?.properties ?? []) {
|
|
1715
|
-
if (p.kind
|
|
2224
|
+
if (p.kind !== "attribute") continue;
|
|
2225
|
+
const prev = this._attributes.get(p.name);
|
|
2226
|
+
this._attributes.set(p.name, prev ? mergeAttributeSpecs(prev, p) : p);
|
|
1716
2227
|
}
|
|
1717
2228
|
}
|
|
1718
2229
|
return this._attributes;
|
|
@@ -1773,6 +2284,19 @@ var Prim = class {
|
|
|
1773
2284
|
return this.GetAppliedSchemas().some((s) => s === schemaName || s.startsWith(`${schemaName}:`));
|
|
1774
2285
|
}
|
|
1775
2286
|
};
|
|
2287
|
+
function mergeAttributeSpecs(a, b) {
|
|
2288
|
+
const merged = { ...a, metadata: { ...a.metadata, ...b.metadata } };
|
|
2289
|
+
if (b.typeName) merged.typeName = b.typeName;
|
|
2290
|
+
if (b.isArray) merged.isArray = true;
|
|
2291
|
+
if (b.variability === "uniform") merged.variability = "uniform";
|
|
2292
|
+
if (b.custom) merged.custom = true;
|
|
2293
|
+
if (b.value !== void 0) merged.value = b.value;
|
|
2294
|
+
if (b.timeSamples) {
|
|
2295
|
+
merged.timeSamples = a.timeSamples ? new Map([...a.timeSamples, ...b.timeSamples]) : b.timeSamples;
|
|
2296
|
+
}
|
|
2297
|
+
if (b.connections) merged.connections = b.connections;
|
|
2298
|
+
return merged;
|
|
2299
|
+
}
|
|
1776
2300
|
|
|
1777
2301
|
// src/usd/Stage.ts
|
|
1778
2302
|
var DEFAULT_METERS_PER_UNIT = 0.01;
|
|
@@ -1804,6 +2328,14 @@ var Stage = class _Stage {
|
|
|
1804
2328
|
GetRootLayer() {
|
|
1805
2329
|
return this._layer;
|
|
1806
2330
|
}
|
|
2331
|
+
/**
|
|
2332
|
+
* Serialize the stage's backing layer to USDA text. Loader-built stages wrap
|
|
2333
|
+
* the fully composed layer, so this is a flattened (`usdcat --flatten`-like)
|
|
2334
|
+
* export of everything that was read — including binary-crate sources.
|
|
2335
|
+
*/
|
|
2336
|
+
ExportToString() {
|
|
2337
|
+
return this._layer.ExportToString();
|
|
2338
|
+
}
|
|
1807
2339
|
GetPseudoRoot() {
|
|
1808
2340
|
return this._pseudoRoot;
|
|
1809
2341
|
}
|
|
@@ -2542,11 +3074,13 @@ function crateToUsdaFile(crate) {
|
|
|
2542
3074
|
}
|
|
2543
3075
|
function buildAttribute(crate, name, fm) {
|
|
2544
3076
|
const defaultRep = fm.get("default");
|
|
3077
|
+
const rawType = asString(crate, fm.get("typeName")) ?? "";
|
|
3078
|
+
const isArrayType = rawType.endsWith("[]");
|
|
2545
3079
|
const attr = {
|
|
2546
3080
|
kind: "attribute",
|
|
2547
3081
|
name,
|
|
2548
|
-
typeName:
|
|
2549
|
-
isArray: defaultRep !== void 0 ? decodeRepBits(defaultRep).isArray : false,
|
|
3082
|
+
typeName: isArrayType ? rawType.slice(0, -2) : rawType,
|
|
3083
|
+
isArray: isArrayType || (defaultRep !== void 0 ? decodeRepBits(defaultRep).isArray : false),
|
|
2550
3084
|
variability: asNumber2(crate, fm.get("variability")) === 1 ? "uniform" : "varying",
|
|
2551
3085
|
custom: false,
|
|
2552
3086
|
metadata: {},
|
|
@@ -2607,10 +3141,10 @@ function asNumber2(crate, rep) {
|
|
|
2607
3141
|
}
|
|
2608
3142
|
function splitProperty(path) {
|
|
2609
3143
|
const slash = path.lastIndexOf("/");
|
|
2610
|
-
const
|
|
2611
|
-
if (
|
|
3144
|
+
const dot2 = path.indexOf(".", slash < 0 ? 0 : slash);
|
|
3145
|
+
if (dot2 === -1) return null;
|
|
2612
3146
|
if (path.includes("[")) return null;
|
|
2613
|
-
return { primPath: path.slice(0,
|
|
3147
|
+
return { primPath: path.slice(0, dot2), propName: path.slice(dot2 + 1) };
|
|
2614
3148
|
}
|
|
2615
3149
|
function parentOf(path) {
|
|
2616
3150
|
const i = path.lastIndexOf("/");
|
|
@@ -2654,7 +3188,7 @@ async function resolvePrim(spec, parentPath, ctx) {
|
|
|
2654
3188
|
let properties = spec.properties;
|
|
2655
3189
|
let children = spec.children;
|
|
2656
3190
|
const selection = spec.metadata.variants;
|
|
2657
|
-
if (spec.variantSets &&
|
|
3191
|
+
if (spec.variantSets && isDictionary2(selection)) {
|
|
2658
3192
|
for (const [setName, variantName] of Object.entries(selection)) {
|
|
2659
3193
|
const variant = spec.variantSets[setName]?.[String(variantName)];
|
|
2660
3194
|
if (!variant) continue;
|
|
@@ -2881,7 +3415,7 @@ function toArcs(value) {
|
|
|
2881
3415
|
}
|
|
2882
3416
|
return arcs;
|
|
2883
3417
|
}
|
|
2884
|
-
function
|
|
3418
|
+
function isDictionary2(v) {
|
|
2885
3419
|
return typeof v === "object" && v !== null && !Array.isArray(v) && !(v instanceof Quat) && !(v instanceof UsdMatrix) && !(v instanceof AssetPath);
|
|
2886
3420
|
}
|
|
2887
3421
|
function stripKeys(meta, keys) {
|
|
@@ -2921,6 +3455,6 @@ function openUsdz(bytes) {
|
|
|
2921
3455
|
return { rootEntry, resolver };
|
|
2922
3456
|
}
|
|
2923
3457
|
|
|
2924
|
-
export { ARTICULATION_ROOT_API, AssetPath, Attribute, COLLISION_API, CrateReader, DEFAULT_METERS_PER_UNIT, DEG2RAD, DefaultAssetResolver, Layer, ParseError, Prim, Quat, RAD2DEG, RIGID_BODY_API, Relationship, Stage, TokenizeError, UsdMatrix, buildKinematicTree, channelFromSamples, composeFile, composeLayer, computeLocalTransform, crateToUsdaFile, createMemoryResolver, driveKindFor, extractRobotDescription, fromUsdMatrix, gatherMeshDescendants, getJointAxis, getJointBodies, getJointDrive, getJointLimits, getJointLocalFrame, getJointStatePosition, getJointType, getTranslation, hasArticulationRootAPI, hasCollisionAPI, hasRigidBodyAPI, identity4, interpolate, invert, isMesh, isScope, isXform, iterDescendants, joinPosix, jointValueToSI, makeEuler, makeRotationFromQuat, makeRotationX, makeRotationY, makeRotationZ, makeScale, makeTranslation, multiply, multiplyAll, normalizeJointLimits, openUsdz, parseOpType, parseUsda, refineJointType, tokenize };
|
|
2925
|
-
//# sourceMappingURL=chunk-
|
|
2926
|
-
//# sourceMappingURL=chunk-
|
|
3458
|
+
export { ARTICULATION_ROOT_API, AssetPath, Attribute, COLLISION_API, CrateReader, DEFAULT_METERS_PER_UNIT, DEG2RAD, DefaultAssetResolver, Layer, MASS_API, MESH_COLLISION_API, PHYSICS_MATERIAL_API, ParseError, Prim, Quat, RAD2DEG, RIGID_BODY_API, Relationship, Stage, TokenizeError, UsdMatrix, buildKinematicTree, channelFromSamples, composeFile, composeLayer, computeLocalTransform, computeWorldTransform, crateToUsdaFile, createMemoryResolver, decomposeRigid, driveKindFor, extractRobotDescription, fromUsdMatrix, gatherMeshDescendants, getJointAxis, getJointBodies, getJointDrive, getJointLimits, getJointLocalFrame, getJointStatePosition, getJointType, getMassProperties, getTranslation, hasArticulationRootAPI, hasCollisionAPI, hasRigidBodyAPI, identity4, interpolate, invert, isMesh, isNonVisualPurpose, isScope, isXform, iterDescendants, joinPosix, jointValueFromSI, jointValueToSI, makeEuler, makeRotationFromQuat, makeRotationX, makeRotationY, makeRotationZ, makeScale, makeTranslation, multiply, multiplyAll, normalizeJointLimits, openUsdz, parseOpType, parseUsda, refineJointType, resolveBoundMaterial, serializeUsda, toUsdMatrix, tokenize };
|
|
3459
|
+
//# sourceMappingURL=chunk-4MEZM763.js.map
|
|
3460
|
+
//# sourceMappingURL=chunk-4MEZM763.js.map
|