three-usd-robot 0.3.0 → 0.4.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 +26 -9
- package/dist/{ThreeUsdRobot-C6uqpNZA.d.ts → ThreeUsdRobot-Deoh7zam.d.ts} +15 -1
- package/dist/{buildKinematicTree-BJuC_-5_.d.ts → buildKinematicTree-CZjBMA1I.d.ts} +27 -1
- package/dist/{chunk-XH3L7XDJ.js → chunk-FYVZ7YPW.js} +500 -347
- package/dist/chunk-FYVZ7YPW.js.map +1 -0
- package/dist/core.d.ts +23 -5
- package/dist/core.js +1 -1
- package/dist/extras.d.ts +2 -2
- package/dist/helpers.d.ts +2 -2
- package/dist/index.d.ts +40 -14
- package/dist/index.js +103 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-XH3L7XDJ.js.map +0 -1
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as AssetPath, B as BuildTreeOptions, C as CompositionArc, D as DEG2RAD, a as JointDescription, d as JointDriveDescription, e as KinematicNode, K as KinematicTree, L as LinkDescription, f as ListOp, h as PropertySpec, Q as Quat, i as RAD2DEG, T as TreeEdge, U as UsdDictionary,
|
|
1
|
+
import { o as UsdaFile, g as MetadataMap, n as UsdValue, P as PrimSpec, l as Specifier, j as RelationshipSpec, k as SdfPath, c as AttributeSpec, p as Variability, M as Mat4, R as RobotDescription, J as JointType, A as Axis } from './buildKinematicTree-CZjBMA1I.js';
|
|
2
|
+
export { b as AssetPath, B as BuildTreeOptions, C as CompositionArc, D as DEG2RAD, a as JointDescription, d as JointDriveDescription, e as KinematicNode, K as KinematicTree, L as LinkDescription, f as ListOp, h as PropertySpec, Q as Quat, i as RAD2DEG, S as SampleChannel, T as TreeEdge, U as UsdDictionary, m as UsdMatrix, q as Vec2, V as Vec3, r as Vec4, s as buildKinematicTree, t as channelFromSamples, u as fromUsdMatrix, v as getTranslation, w as identity4, x as interpolate, y as invert, z as makeEuler, E as makeRotationFromQuat, F as makeRotationX, G as makeRotationY, H as makeRotationZ, I as makeScale, N as makeTranslation, O as multiply, W as multiplyAll } from './buildKinematicTree-CZjBMA1I.js';
|
|
3
3
|
|
|
4
4
|
/** Package identity. Kept in one place so every entry point can re-export it. */
|
|
5
5
|
declare const PACKAGE_NAME = "three-usd-robot";
|
|
@@ -90,6 +90,12 @@ declare class Stage {
|
|
|
90
90
|
GetUpAxis(): UpAxis;
|
|
91
91
|
/** Stage linear unit (`metersPerUnit` metadata); defaults to {@link DEFAULT_METERS_PER_UNIT}. */
|
|
92
92
|
GetMetersPerUnit(): number;
|
|
93
|
+
/** Animation start time code, if authored. */
|
|
94
|
+
GetStartTimeCode(): number | undefined;
|
|
95
|
+
/** Animation end time code, if authored. */
|
|
96
|
+
GetEndTimeCode(): number | undefined;
|
|
97
|
+
/** Time codes per second for playback; defaults to 24. */
|
|
98
|
+
GetTimeCodesPerSecond(): number;
|
|
93
99
|
}
|
|
94
100
|
|
|
95
101
|
/**
|
|
@@ -211,8 +217,11 @@ declare class DefaultAssetResolver implements AssetResolver {
|
|
|
211
217
|
fetchText(url: string): Promise<string>;
|
|
212
218
|
fetchBytes(url: string): Promise<Uint8Array>;
|
|
213
219
|
}
|
|
214
|
-
/**
|
|
215
|
-
|
|
220
|
+
/**
|
|
221
|
+
* Resolver over an in-memory `{ path: contents }` map (text or bytes), with
|
|
222
|
+
* posix-style joins. Useful for tests and bundled assets.
|
|
223
|
+
*/
|
|
224
|
+
declare function createMemoryResolver(files: Record<string, string | Uint8Array>): AssetResolver;
|
|
216
225
|
/** Resolve `rel` against `baseUrl` using posix semantics, normalizing `.`/`..`. */
|
|
217
226
|
declare function joinPosix(baseUrl: string, rel: string): string;
|
|
218
227
|
|
|
@@ -234,7 +243,10 @@ type ComposeOptions = {
|
|
|
234
243
|
/** Guard against pathological recursion (default 64). */
|
|
235
244
|
maxDepth?: number;
|
|
236
245
|
};
|
|
246
|
+
/** Parse USDA text and fully compose it. */
|
|
237
247
|
declare function composeLayer(text: string, baseUrl: string, resolver: AssetResolver, options?: ComposeOptions, stack?: ReadonlySet<string>): Promise<UsdaFile>;
|
|
248
|
+
/** Compose an already-parsed layer (used by the binary-crate path too). */
|
|
249
|
+
declare function composeFile(file: UsdaFile, baseUrl: string, resolver: AssetResolver, options?: ComposeOptions, stack?: ReadonlySet<string>): Promise<UsdaFile>;
|
|
238
250
|
|
|
239
251
|
/**
|
|
240
252
|
* USDZ (zipped USD package) support.
|
|
@@ -331,6 +343,12 @@ declare class CrateReader {
|
|
|
331
343
|
private readIndexVector;
|
|
332
344
|
/** Read an SdfListOp; returns the effective (explicit ∪ prepended ∪ added ∪ appended) items. */
|
|
333
345
|
private readListOp;
|
|
346
|
+
/**
|
|
347
|
+
* Read a Reference/Payload list-op into composition arcs. Each item is
|
|
348
|
+
* `[assetPath: string-index][primPath: path-index][layerOffset: 2 doubles]`,
|
|
349
|
+
* and a Reference additionally carries a (usually empty) customData dict.
|
|
350
|
+
*/
|
|
351
|
+
private readArcListOp;
|
|
334
352
|
}
|
|
335
353
|
|
|
336
354
|
/**
|
|
@@ -459,4 +477,4 @@ declare function getJointDrive(prim: Prim, kind: "angular" | "linear"): {
|
|
|
459
477
|
/** Read `PhysicsJointStateAPI` position for the given instance, as authored. */
|
|
460
478
|
declare function getJointStatePosition(prim: Prim, kind: "angular" | "linear"): number | undefined;
|
|
461
479
|
|
|
462
|
-
export { ARTICULATION_ROOT_API, type AssetResolver, Attribute, AttributeSpec, Axis, COLLISION_API, type ComposeOptions, CrateReader, DEFAULT_METERS_PER_UNIT, DefaultAssetResolver, type ExtractOptions, JointType, Layer, Mat4, MetadataMap, PACKAGE_NAME, ParseError, Prim, PrimSpec, RIGID_BODY_API, Relationship, RelationshipSpec, type ResolvedXform, RobotDescription, SdfPath, Specifier, Stage, TokenizeError, type UpAxis, UsdValue, UsdaFile, type UsdzPackage, VERSION, Variability, composeLayer, computeLocalTransform, crateToUsdaFile, createMemoryResolver, driveKindFor, extractRobotDescription, gatherMeshDescendants, getJointAxis, getJointBodies, getJointDrive, getJointLimits, getJointLocalFrame, getJointStatePosition, getJointType, hasArticulationRootAPI, hasCollisionAPI, hasRigidBodyAPI, isMesh, isScope, isXform, iterDescendants, joinPosix, jointValueToSI, normalizeJointLimits, openUsdz, parseOpType, parseUsda, refineJointType, tokenize };
|
|
480
|
+
export { ARTICULATION_ROOT_API, type AssetResolver, Attribute, AttributeSpec, Axis, COLLISION_API, type ComposeOptions, CrateReader, DEFAULT_METERS_PER_UNIT, DefaultAssetResolver, type ExtractOptions, JointType, Layer, Mat4, MetadataMap, PACKAGE_NAME, ParseError, Prim, PrimSpec, RIGID_BODY_API, Relationship, RelationshipSpec, type ResolvedXform, RobotDescription, SdfPath, Specifier, Stage, TokenizeError, type UpAxis, UsdValue, UsdaFile, type UsdzPackage, VERSION, Variability, composeFile, composeLayer, computeLocalTransform, crateToUsdaFile, createMemoryResolver, driveKindFor, extractRobotDescription, gatherMeshDescendants, getJointAxis, getJointBodies, getJointDrive, getJointLimits, getJointLocalFrame, getJointStatePosition, getJointType, hasArticulationRootAPI, hasCollisionAPI, hasRigidBodyAPI, isMesh, isScope, isXform, iterDescendants, joinPosix, jointValueToSI, normalizeJointLimits, openUsdz, parseOpType, parseUsda, refineJointType, tokenize };
|
package/dist/core.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { ARTICULATION_ROOT_API, AssetPath, Attribute, COLLISION_API, CrateReader, DEFAULT_METERS_PER_UNIT, DEG2RAD, DefaultAssetResolver, Layer, PACKAGE_NAME, ParseError, Prim, Quat, RAD2DEG, RIGID_BODY_API, Relationship, Stage, TokenizeError, UsdMatrix, VERSION, buildKinematicTree, composeLayer, computeLocalTransform, crateToUsdaFile, createMemoryResolver, driveKindFor, extractRobotDescription, fromUsdMatrix, gatherMeshDescendants, getJointAxis, getJointBodies, getJointDrive, getJointLimits, getJointLocalFrame, getJointStatePosition, getJointType, getTranslation, hasArticulationRootAPI, hasCollisionAPI, hasRigidBodyAPI, identity4, invert, isMesh, isScope, isXform, iterDescendants, joinPosix, jointValueToSI, makeEuler, makeRotationFromQuat, makeRotationX, makeRotationY, makeRotationZ, makeScale, makeTranslation, multiply, multiplyAll, normalizeJointLimits, openUsdz, parseOpType, parseUsda, refineJointType, tokenize } from './chunk-
|
|
1
|
+
export { ARTICULATION_ROOT_API, AssetPath, Attribute, COLLISION_API, CrateReader, DEFAULT_METERS_PER_UNIT, DEG2RAD, DefaultAssetResolver, Layer, PACKAGE_NAME, ParseError, Prim, Quat, RAD2DEG, RIGID_BODY_API, Relationship, Stage, TokenizeError, UsdMatrix, VERSION, 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 } from './chunk-FYVZ7YPW.js';
|
|
2
2
|
//# sourceMappingURL=core.js.map
|
|
3
3
|
//# sourceMappingURL=core.js.map
|
package/dist/extras.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { T as ThreeUsdRobot } from './ThreeUsdRobot-
|
|
1
|
+
import { T as ThreeUsdRobot } from './ThreeUsdRobot-Deoh7zam.js';
|
|
2
2
|
import 'three';
|
|
3
|
-
import './buildKinematicTree-
|
|
3
|
+
import './buildKinematicTree-CZjBMA1I.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* `three-usd-robot/extras`
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import { J as JointObject, T as ThreeUsdRobot } from './ThreeUsdRobot-
|
|
3
|
-
import './buildKinematicTree-
|
|
2
|
+
import { J as JointObject, T as ThreeUsdRobot } from './ThreeUsdRobot-Deoh7zam.js';
|
|
3
|
+
import './buildKinematicTree-CZjBMA1I.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* An arrow drawn along a joint's motion axis (the rotation axis for
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
import { Stage, Prim
|
|
2
|
-
export { ARTICULATION_ROOT_API, Attribute, COLLISION_API, ComposeOptions, CrateReader, DEFAULT_METERS_PER_UNIT, DefaultAssetResolver, ExtractOptions, Layer, PACKAGE_NAME, ParseError, RIGID_BODY_API, Relationship, ResolvedXform, TokenizeError, UpAxis, UsdzPackage, VERSION, composeLayer, computeLocalTransform, crateToUsdaFile, createMemoryResolver, driveKindFor, extractRobotDescription, gatherMeshDescendants, getJointAxis, getJointBodies, getJointDrive, getJointLimits, getJointLocalFrame, getJointStatePosition, getJointType, hasArticulationRootAPI, hasCollisionAPI, hasRigidBodyAPI, isMesh, isScope, isXform, iterDescendants, joinPosix, jointValueToSI, normalizeJointLimits, openUsdz, parseOpType, parseUsda, refineJointType, tokenize } from './core.js';
|
|
1
|
+
import { AssetResolver, Stage, Prim } from './core.js';
|
|
2
|
+
export { ARTICULATION_ROOT_API, Attribute, COLLISION_API, ComposeOptions, CrateReader, DEFAULT_METERS_PER_UNIT, DefaultAssetResolver, ExtractOptions, Layer, PACKAGE_NAME, ParseError, RIGID_BODY_API, Relationship, ResolvedXform, TokenizeError, UpAxis, UsdzPackage, VERSION, composeFile, composeLayer, computeLocalTransform, crateToUsdaFile, createMemoryResolver, driveKindFor, extractRobotDescription, gatherMeshDescendants, getJointAxis, getJointBodies, getJointDrive, getJointLimits, getJointLocalFrame, getJointStatePosition, getJointType, hasArticulationRootAPI, hasCollisionAPI, hasRigidBodyAPI, isMesh, isScope, isXform, iterDescendants, joinPosix, jointValueToSI, normalizeJointLimits, openUsdz, parseOpType, parseUsda, refineJointType, tokenize } from './core.js';
|
|
3
3
|
import * as THREE from 'three';
|
|
4
|
-
import { A as Axis, R as RobotDescription, V as Vec3 } from './buildKinematicTree-
|
|
5
|
-
export { b as AssetPath, c as AttributeSpec, B as BuildTreeOptions, C as CompositionArc, D as DEG2RAD, a as JointDescription, d as JointDriveDescription, J as JointType, e as KinematicNode, K as KinematicTree, L as LinkDescription, f as ListOp, M as Mat4, g as MetadataMap, P as PrimSpec, h as PropertySpec, Q as Quat, i as RAD2DEG, j as RelationshipSpec, S as
|
|
6
|
-
import { T as ThreeUsdRobot } from './ThreeUsdRobot-
|
|
7
|
-
export { J as JointObject, L as LinkObject, a as ThreeUsdRobotOptions } from './ThreeUsdRobot-
|
|
4
|
+
import { A as Axis, R as RobotDescription, V as Vec3 } from './buildKinematicTree-CZjBMA1I.js';
|
|
5
|
+
export { b as AssetPath, c as AttributeSpec, B as BuildTreeOptions, C as CompositionArc, D as DEG2RAD, a as JointDescription, d as JointDriveDescription, J as JointType, e as KinematicNode, K as KinematicTree, L as LinkDescription, f as ListOp, M as Mat4, g as MetadataMap, P as PrimSpec, h as PropertySpec, Q as Quat, i as RAD2DEG, j as RelationshipSpec, S as SampleChannel, k as SdfPath, l as Specifier, T as TreeEdge, U as UsdDictionary, m as UsdMatrix, n as UsdValue, o as UsdaFile, p as Variability, q as Vec2, r as Vec4, s as buildKinematicTree, t as channelFromSamples, u as fromUsdMatrix, v as getTranslation, w as identity4, x as interpolate, y as invert, z as makeEuler, E as makeRotationFromQuat, F as makeRotationX, G as makeRotationY, H as makeRotationZ, I as makeScale, N as makeTranslation, O as multiply, W as multiplyAll } from './buildKinematicTree-CZjBMA1I.js';
|
|
6
|
+
import { T as ThreeUsdRobot } from './ThreeUsdRobot-Deoh7zam.js';
|
|
7
|
+
export { J as JointObject, L as LinkObject, a as ThreeUsdRobotOptions } from './ThreeUsdRobot-Deoh7zam.js';
|
|
8
8
|
|
|
9
9
|
/** Unit vector for a USD joint axis token. Returns a fresh vector each call. */
|
|
10
10
|
declare function axisVector(axis: Axis): THREE.Vector3;
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Loads texture image assets referenced by `UsdShade` materials.
|
|
14
|
+
*
|
|
15
|
+
* A {@link TextureProvider} maps an authored asset path to a `THREE.Texture`.
|
|
16
|
+
* The default provider resolves the path against the layer base URL and loads it
|
|
17
|
+
* with `THREE.TextureLoader` (so it works for textures served alongside the USD
|
|
18
|
+
* on the web). Textures load asynchronously and update the material when ready.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Resolve an authored texture asset path to a `THREE.Texture` (or `null`). */
|
|
22
|
+
type TextureProvider = (assetPath: string) => THREE.Texture | null;
|
|
23
|
+
/**
|
|
24
|
+
* A {@link TextureProvider} backed by `THREE.TextureLoader`, resolving paths via
|
|
25
|
+
* `resolver` against `baseUrl`. Results are cached per resolved URL and tagged
|
|
26
|
+
* as sRGB color textures.
|
|
27
|
+
*/
|
|
28
|
+
declare function createTextureProvider(resolver: AssetResolver, baseUrl: string): TextureProvider;
|
|
29
|
+
|
|
12
30
|
/**
|
|
13
31
|
* Binds `UsdGeom.Mesh` prims to Three.js geometry and attaches them under the
|
|
14
32
|
* robot's link objects.
|
|
@@ -23,15 +41,18 @@ type MeshKind = "visual" | "collision";
|
|
|
23
41
|
type BindMeshesOptions = {
|
|
24
42
|
loadVisuals?: boolean;
|
|
25
43
|
loadCollisions?: boolean;
|
|
44
|
+
/** Resolves diffuse texture asset paths to `THREE.Texture` (M-tex). */
|
|
45
|
+
textureProvider?: TextureProvider;
|
|
26
46
|
};
|
|
27
47
|
/** Build a `BufferGeometry` from a Mesh prim, or `null` if it has no points. */
|
|
28
48
|
declare function buildMeshGeometry(meshPrim: Prim): THREE.BufferGeometry | null;
|
|
29
49
|
/**
|
|
30
50
|
* Build a material for a Mesh prim. Color priority: bound `UsdShade` material
|
|
31
|
-
* (when `stage` is given) → `primvars:displayColor` → default gray.
|
|
32
|
-
*
|
|
51
|
+
* (when `stage` is given) → `primvars:displayColor` → default gray. A diffuse
|
|
52
|
+
* texture (via `textures`) becomes `material.map`; metalness / roughness /
|
|
53
|
+
* opacity come from the bound material when present.
|
|
33
54
|
*/
|
|
34
|
-
declare function buildMeshMaterial(meshPrim: Prim, stage?: Stage): THREE.Material;
|
|
55
|
+
declare function buildMeshMaterial(meshPrim: Prim, stage?: Stage, textures?: TextureProvider): THREE.Material;
|
|
35
56
|
/**
|
|
36
57
|
* Attach visual (and optionally collision) meshes to every link of a built
|
|
37
58
|
* {@link ThreeUsdRobot}. Each mesh is positioned by its transform relative to
|
|
@@ -44,9 +65,10 @@ declare function bindRobotMeshes(stage: Stage, robot3d: ThreeUsdRobot, desc: Rob
|
|
|
44
65
|
*
|
|
45
66
|
* Follows a prim's (or an ancestor's) `material:binding` to a `Material`, finds
|
|
46
67
|
* its surface `Shader`, and reads constant color/metalness/roughness/opacity
|
|
47
|
-
* inputs
|
|
48
|
-
*
|
|
49
|
-
*
|
|
68
|
+
* inputs plus the diffuse **texture** asset path. Handles both
|
|
69
|
+
* `UsdPreviewSurface` (`inputs:diffuseColor` constant or a `UsdUVTexture`
|
|
70
|
+
* network) and Omniverse `OmniPBR` MDL (`inputs:diffuse_color_constant`,
|
|
71
|
+
* `inputs:diffuse_texture`). Only the diffuse channel and constants are read.
|
|
50
72
|
*/
|
|
51
73
|
|
|
52
74
|
type ResolvedMaterial = {
|
|
@@ -54,6 +76,8 @@ type ResolvedMaterial = {
|
|
|
54
76
|
opacity?: number;
|
|
55
77
|
metalness?: number;
|
|
56
78
|
roughness?: number;
|
|
79
|
+
/** Authored asset path of the diffuse/albedo texture, if any. */
|
|
80
|
+
colorTexture?: string;
|
|
57
81
|
};
|
|
58
82
|
/** Resolve the bound material's flat parameters for `prim`, or `undefined`. */
|
|
59
83
|
declare function resolveBoundMaterial(stage: Stage, prim: Prim): ResolvedMaterial | undefined;
|
|
@@ -65,6 +89,8 @@ type ThreeUsdRobotLoaderOptions = {
|
|
|
65
89
|
loadVisuals?: boolean;
|
|
66
90
|
/** Render collision meshes (M6). */
|
|
67
91
|
loadCollisions?: boolean;
|
|
92
|
+
/** Load diffuse textures referenced by materials (default `true`). */
|
|
93
|
+
loadTextures?: boolean;
|
|
68
94
|
/** Up-axis correction strategy (M9). */
|
|
69
95
|
upAxisConversion?: "auto" | "Y" | "Z" | "none";
|
|
70
96
|
/** Extra uniform scale multiplied with `metersPerUnit` (M9). */
|
|
@@ -100,7 +126,7 @@ declare class ThreeUsdRobotLoader {
|
|
|
100
126
|
/** Build a robot from the bytes of a `.usdz` package. */
|
|
101
127
|
parseUsdz(bytes: Uint8Array): Promise<ThreeUsdRobot>;
|
|
102
128
|
/** Build a robot from the bytes of a binary crate (`.usdc` / binary `.usd`). */
|
|
103
|
-
parseCrate(bytes: Uint8Array): Promise<ThreeUsdRobot>;
|
|
129
|
+
parseCrate(bytes: Uint8Array, baseUrl?: string): Promise<ThreeUsdRobot>;
|
|
104
130
|
/** Parse + compose USDA source into the Three.js-independent robot IR. */
|
|
105
131
|
parseRobotDescription(text: string, baseUrl?: string): Promise<RobotDescription>;
|
|
106
132
|
private buildFromStage;
|
|
@@ -109,4 +135,4 @@ declare class ThreeUsdRobotLoader {
|
|
|
109
135
|
private extractOptions;
|
|
110
136
|
}
|
|
111
137
|
|
|
112
|
-
export { AssetResolver, Axis, type BindMeshesOptions, type MeshKind, Prim, type ResolvedMaterial, RobotDescription, Stage, ThreeUsdRobot, ThreeUsdRobotLoader, type ThreeUsdRobotLoaderOptions, Vec3, axisVector, bindRobotMeshes, buildMeshGeometry, buildMeshMaterial, resolveBoundMaterial };
|
|
138
|
+
export { AssetResolver, Axis, type BindMeshesOptions, type MeshKind, Prim, type ResolvedMaterial, RobotDescription, Stage, type TextureProvider, ThreeUsdRobot, ThreeUsdRobotLoader, type ThreeUsdRobotLoaderOptions, Vec3, axisVector, bindRobotMeshes, buildMeshGeometry, buildMeshMaterial, createTextureProvider, resolveBoundMaterial };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { identity4, multiply, computeLocalTransform, invert, DefaultAssetResolver, CrateReader, openUsdz, crateToUsdaFile, Stage, extractRobotDescription, buildKinematicTree, composeLayer } from './chunk-
|
|
2
|
-
export { ARTICULATION_ROOT_API, AssetPath, Attribute, COLLISION_API, CrateReader, DEFAULT_METERS_PER_UNIT, DEG2RAD, DefaultAssetResolver, Layer, PACKAGE_NAME, ParseError, Prim, Quat, RAD2DEG, RIGID_BODY_API, Relationship, Stage, TokenizeError, UsdMatrix, VERSION, buildKinematicTree, composeLayer, computeLocalTransform, crateToUsdaFile, createMemoryResolver, driveKindFor, extractRobotDescription, fromUsdMatrix, gatherMeshDescendants, getJointAxis, getJointBodies, getJointDrive, getJointLimits, getJointLocalFrame, getJointStatePosition, getJointType, getTranslation, hasArticulationRootAPI, hasCollisionAPI, hasRigidBodyAPI, identity4, invert, isMesh, isScope, isXform, iterDescendants, joinPosix, jointValueToSI, makeEuler, makeRotationFromQuat, makeRotationX, makeRotationY, makeRotationZ, makeScale, makeTranslation, multiply, multiplyAll, normalizeJointLimits, openUsdz, parseOpType, parseUsda, refineJointType, tokenize } from './chunk-
|
|
1
|
+
import { AssetPath, identity4, multiply, computeLocalTransform, invert, interpolate, DefaultAssetResolver, CrateReader, openUsdz, crateToUsdaFile, composeFile, Stage, extractRobotDescription, buildKinematicTree, composeLayer } from './chunk-FYVZ7YPW.js';
|
|
2
|
+
export { ARTICULATION_ROOT_API, AssetPath, Attribute, COLLISION_API, CrateReader, DEFAULT_METERS_PER_UNIT, DEG2RAD, DefaultAssetResolver, Layer, PACKAGE_NAME, ParseError, Prim, Quat, RAD2DEG, RIGID_BODY_API, Relationship, Stage, TokenizeError, UsdMatrix, VERSION, 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 } from './chunk-FYVZ7YPW.js';
|
|
3
3
|
import * as THREE4 from 'three';
|
|
4
4
|
|
|
5
5
|
function axisVector(axis) {
|
|
@@ -102,8 +102,24 @@ function resolveBoundMaterial(stage, prim) {
|
|
|
102
102
|
if (metalness !== void 0) result.metalness = metalness;
|
|
103
103
|
const roughness = firstNumber(shader, ROUGHNESS_INPUTS);
|
|
104
104
|
if (roughness !== void 0) result.roughness = roughness;
|
|
105
|
+
const texture = findDiffuseTexture(shader);
|
|
106
|
+
if (texture !== void 0) result.colorTexture = texture;
|
|
105
107
|
return result;
|
|
106
108
|
}
|
|
109
|
+
var DIFFUSE_TEXTURE_INPUTS = ["inputs:diffuse_texture", "inputs:diffuse_color_texture"];
|
|
110
|
+
function findDiffuseTexture(shader) {
|
|
111
|
+
for (const name of DIFFUSE_TEXTURE_INPUTS) {
|
|
112
|
+
const v = shader.GetAttribute(name).Get();
|
|
113
|
+
if (v instanceof AssetPath && v.path) return v.path;
|
|
114
|
+
}
|
|
115
|
+
const conn = shader.GetAttribute("inputs:diffuseColor").GetConnections()[0];
|
|
116
|
+
if (conn) {
|
|
117
|
+
const texPrim = shader.GetStage().GetPrimAtPath(conn.split(".")[0]);
|
|
118
|
+
const file = texPrim?.GetAttribute("inputs:file").Get();
|
|
119
|
+
if (file instanceof AssetPath && file.path) return file.path;
|
|
120
|
+
}
|
|
121
|
+
return void 0;
|
|
122
|
+
}
|
|
107
123
|
function findBinding(prim) {
|
|
108
124
|
let p = prim;
|
|
109
125
|
while (p) {
|
|
@@ -167,7 +183,7 @@ function buildMeshGeometry(meshPrim) {
|
|
|
167
183
|
}
|
|
168
184
|
return geometry;
|
|
169
185
|
}
|
|
170
|
-
function buildMeshMaterial(meshPrim, stage) {
|
|
186
|
+
function buildMeshMaterial(meshPrim, stage, textures) {
|
|
171
187
|
const color = new THREE4.Color(DEFAULT_COLOR);
|
|
172
188
|
let metalness = 0.1;
|
|
173
189
|
let roughness = 0.8;
|
|
@@ -185,6 +201,8 @@ function buildMeshMaterial(meshPrim, stage) {
|
|
|
185
201
|
if (bound?.metalness !== void 0) metalness = bound.metalness;
|
|
186
202
|
if (bound?.roughness !== void 0) roughness = bound.roughness;
|
|
187
203
|
if (bound?.opacity !== void 0) opacity = bound.opacity;
|
|
204
|
+
const map = bound?.colorTexture && textures ? textures(bound.colorTexture) : null;
|
|
205
|
+
if (map) color.setRGB(1, 1, 1);
|
|
188
206
|
const doubleSided = meshPrim.GetAttribute("doubleSided").Get() === true;
|
|
189
207
|
return new THREE4.MeshStandardMaterial({
|
|
190
208
|
color,
|
|
@@ -192,12 +210,14 @@ function buildMeshMaterial(meshPrim, stage) {
|
|
|
192
210
|
roughness,
|
|
193
211
|
transparent: opacity < 1,
|
|
194
212
|
opacity,
|
|
195
|
-
side: doubleSided ? THREE4.DoubleSide : THREE4.FrontSide
|
|
213
|
+
side: doubleSided ? THREE4.DoubleSide : THREE4.FrontSide,
|
|
214
|
+
...map ? { map } : {}
|
|
196
215
|
});
|
|
197
216
|
}
|
|
198
217
|
function bindRobotMeshes(stage, robot3d, desc, options = {}) {
|
|
199
218
|
const loadVisuals = options.loadVisuals ?? true;
|
|
200
219
|
const loadCollisions = options.loadCollisions ?? false;
|
|
220
|
+
const textures = options.textureProvider;
|
|
201
221
|
for (const [key, link] of Object.entries(desc.links)) {
|
|
202
222
|
const linkObj = robot3d.getLinkObject(key);
|
|
203
223
|
const linkPrim = stage.GetPrimAtPath(link.primPath);
|
|
@@ -206,22 +226,22 @@ function bindRobotMeshes(stage, robot3d, desc, options = {}) {
|
|
|
206
226
|
if (loadVisuals) {
|
|
207
227
|
for (const meshPath of link.visualPrims) {
|
|
208
228
|
if (collisionSet.has(meshPath)) continue;
|
|
209
|
-
attachMesh(stage, linkPrim, meshPath, linkObj, "visual");
|
|
229
|
+
attachMesh(stage, linkPrim, meshPath, linkObj, "visual", textures);
|
|
210
230
|
}
|
|
211
231
|
}
|
|
212
232
|
if (loadCollisions) {
|
|
213
233
|
for (const meshPath of link.collisionPrims ?? []) {
|
|
214
|
-
attachMesh(stage, linkPrim, meshPath, linkObj, "collision");
|
|
234
|
+
attachMesh(stage, linkPrim, meshPath, linkObj, "collision", textures);
|
|
215
235
|
}
|
|
216
236
|
}
|
|
217
237
|
}
|
|
218
238
|
}
|
|
219
|
-
function attachMesh(stage, linkPrim, meshPath, parent, kind) {
|
|
239
|
+
function attachMesh(stage, linkPrim, meshPath, parent, kind, textures) {
|
|
220
240
|
const meshPrim = stage.GetPrimAtPath(meshPath);
|
|
221
241
|
if (!meshPrim) return;
|
|
222
242
|
const geometry = buildMeshGeometry(meshPrim);
|
|
223
243
|
if (!geometry) return;
|
|
224
|
-
const mesh = new THREE4.Mesh(geometry, buildMeshMaterial(meshPrim, stage));
|
|
244
|
+
const mesh = new THREE4.Mesh(geometry, buildMeshMaterial(meshPrim, stage, textures));
|
|
225
245
|
mesh.name = meshPrim.GetName();
|
|
226
246
|
mesh.userData.kind = kind;
|
|
227
247
|
mesh.userData.primPath = meshPath;
|
|
@@ -287,6 +307,26 @@ function isVec3Array(v) {
|
|
|
287
307
|
function isVec2Array(v) {
|
|
288
308
|
return Array.isArray(v) && v.every((e) => Array.isArray(e) && e.length === 2);
|
|
289
309
|
}
|
|
310
|
+
function createTextureProvider(resolver, baseUrl) {
|
|
311
|
+
const loader = new THREE4.TextureLoader();
|
|
312
|
+
const cache = /* @__PURE__ */ new Map();
|
|
313
|
+
return (assetPath) => {
|
|
314
|
+
let url;
|
|
315
|
+
try {
|
|
316
|
+
url = resolver.resolve(assetPath, baseUrl);
|
|
317
|
+
} catch {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
const cached = cache.get(url);
|
|
321
|
+
if (cached) return cached;
|
|
322
|
+
const texture = loader.load(url);
|
|
323
|
+
texture.colorSpace = THREE4.SRGBColorSpace;
|
|
324
|
+
texture.wrapS = THREE4.RepeatWrapping;
|
|
325
|
+
texture.wrapT = THREE4.RepeatWrapping;
|
|
326
|
+
cache.set(url, texture);
|
|
327
|
+
return texture;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
290
330
|
var ThreeUsdRobot = class extends THREE4.Object3D {
|
|
291
331
|
isThreeUsdRobot = true;
|
|
292
332
|
robot;
|
|
@@ -438,6 +478,41 @@ var ThreeUsdRobot = class extends THREE4.Object3D {
|
|
|
438
478
|
getKinematicTree() {
|
|
439
479
|
return this.tree;
|
|
440
480
|
}
|
|
481
|
+
// -- Animation playback --------------------------------------------------
|
|
482
|
+
/** Playback rate in time codes per second (from the stage; default 24). */
|
|
483
|
+
getTimeCodesPerSecond() {
|
|
484
|
+
return this.robot.timeCodesPerSecond ?? 24;
|
|
485
|
+
}
|
|
486
|
+
/** Whether any joint has a time-sampled trajectory. */
|
|
487
|
+
hasAnimation() {
|
|
488
|
+
return Object.values(this.robot.joints).some((j) => j.valueSamples !== void 0);
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Animation range in time codes: the union of authored joint sample ranges,
|
|
492
|
+
* falling back to the stage `startTimeCode`/`endTimeCode`. `null` if neither.
|
|
493
|
+
*/
|
|
494
|
+
getTimeRange() {
|
|
495
|
+
let start = Number.POSITIVE_INFINITY;
|
|
496
|
+
let end = Number.NEGATIVE_INFINITY;
|
|
497
|
+
for (const joint of Object.values(this.robot.joints)) {
|
|
498
|
+
const times = joint.valueSamples?.times;
|
|
499
|
+
if (!times || times.length === 0) continue;
|
|
500
|
+
start = Math.min(start, times[0]);
|
|
501
|
+
end = Math.max(end, times[times.length - 1]);
|
|
502
|
+
}
|
|
503
|
+
if (start <= end) return { start, end };
|
|
504
|
+
const { startTimeCode, endTimeCode } = this.robot;
|
|
505
|
+
if (startTimeCode !== void 0 && endTimeCode !== void 0) {
|
|
506
|
+
return { start: startTimeCode, end: endTimeCode };
|
|
507
|
+
}
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
/** Sample every animated joint at time code `t` and apply the values. */
|
|
511
|
+
setTime(t) {
|
|
512
|
+
for (const [key, joint] of Object.entries(this.robot.joints)) {
|
|
513
|
+
if (joint.valueSamples) this.setJointValue(key, interpolate(joint.valueSamples, t));
|
|
514
|
+
}
|
|
515
|
+
}
|
|
441
516
|
// -- Display toggles -----------------------------------------------------
|
|
442
517
|
get showVisual() {
|
|
443
518
|
return this._showVisual;
|
|
@@ -513,7 +588,7 @@ var ThreeUsdRobotLoader = class {
|
|
|
513
588
|
return this.parseUsdz(await this.fetchRootBytes(url));
|
|
514
589
|
}
|
|
515
590
|
const bytes = await this.fetchRootBytes(url);
|
|
516
|
-
if (CrateReader.isCrate(bytes)) return this.parseCrate(bytes);
|
|
591
|
+
if (CrateReader.isCrate(bytes)) return this.parseCrate(bytes, url);
|
|
517
592
|
return this.parse(new TextDecoder().decode(bytes), url);
|
|
518
593
|
}
|
|
519
594
|
async fetchRootBytes(url) {
|
|
@@ -523,32 +598,44 @@ var ThreeUsdRobotLoader = class {
|
|
|
523
598
|
}
|
|
524
599
|
/** Build a robot (composed, with meshes) from USDA source text. */
|
|
525
600
|
async parse(text, baseUrl = "") {
|
|
526
|
-
return this.buildFromStage(
|
|
601
|
+
return this.buildFromStage(
|
|
602
|
+
await this.composeStage(text, baseUrl, this.resolver),
|
|
603
|
+
baseUrl,
|
|
604
|
+
this.resolver
|
|
605
|
+
);
|
|
527
606
|
}
|
|
528
607
|
/** Build a robot from the bytes of a `.usdz` package. */
|
|
529
608
|
async parseUsdz(bytes) {
|
|
530
609
|
const pkg = openUsdz(bytes);
|
|
531
610
|
const rootText = await pkg.resolver.fetchText(pkg.rootEntry);
|
|
532
|
-
|
|
611
|
+
const stage = await this.composeStage(rootText, pkg.rootEntry, pkg.resolver);
|
|
612
|
+
return this.buildFromStage(stage, pkg.rootEntry, pkg.resolver);
|
|
533
613
|
}
|
|
534
614
|
/** Build a robot from the bytes of a binary crate (`.usdc` / binary `.usd`). */
|
|
535
|
-
parseCrate(bytes) {
|
|
615
|
+
async parseCrate(bytes, baseUrl = "") {
|
|
536
616
|
const file = crateToUsdaFile(new CrateReader(bytes));
|
|
537
|
-
|
|
617
|
+
const composeOptions = this.options.onWarn ? { onWarn: this.options.onWarn } : {};
|
|
618
|
+
const composed = await composeFile(file, baseUrl, this.resolver, composeOptions);
|
|
619
|
+
return this.buildFromStage(Stage.OpenFromFile(composed), baseUrl, this.resolver);
|
|
538
620
|
}
|
|
539
621
|
/** Parse + compose USDA source into the Three.js-independent robot IR. */
|
|
540
622
|
async parseRobotDescription(text, baseUrl = "") {
|
|
541
623
|
const stage = await this.composeStage(text, baseUrl, this.resolver);
|
|
542
624
|
return extractRobotDescription(stage, this.extractOptions());
|
|
543
625
|
}
|
|
544
|
-
buildFromStage(stage) {
|
|
626
|
+
buildFromStage(stage, baseUrl, resolver) {
|
|
545
627
|
const robot = extractRobotDescription(stage, this.extractOptions());
|
|
546
628
|
const tree = buildKinematicTree(robot);
|
|
547
629
|
const robot3d = new ThreeUsdRobot(robot, tree, this.robotOptions());
|
|
548
630
|
const loadVisuals = this.options.loadVisuals ?? true;
|
|
549
631
|
const loadCollisions = this.options.loadCollisions ?? false;
|
|
550
632
|
if (loadVisuals || loadCollisions) {
|
|
551
|
-
|
|
633
|
+
const textureProvider = this.options.loadTextures ?? true ? createTextureProvider(resolver, baseUrl) : void 0;
|
|
634
|
+
bindRobotMeshes(stage, robot3d, robot, {
|
|
635
|
+
loadVisuals,
|
|
636
|
+
loadCollisions,
|
|
637
|
+
...textureProvider ? { textureProvider } : {}
|
|
638
|
+
});
|
|
552
639
|
}
|
|
553
640
|
return robot3d;
|
|
554
641
|
}
|
|
@@ -572,6 +659,6 @@ var ThreeUsdRobotLoader = class {
|
|
|
572
659
|
}
|
|
573
660
|
};
|
|
574
661
|
|
|
575
|
-
export { JointObject, LinkObject, ThreeUsdRobot, ThreeUsdRobotLoader, axisVector, bindRobotMeshes, buildMeshGeometry, buildMeshMaterial, resolveBoundMaterial };
|
|
662
|
+
export { JointObject, LinkObject, ThreeUsdRobot, ThreeUsdRobotLoader, axisVector, bindRobotMeshes, buildMeshGeometry, buildMeshMaterial, createTextureProvider, resolveBoundMaterial };
|
|
576
663
|
//# sourceMappingURL=index.js.map
|
|
577
664
|
//# sourceMappingURL=index.js.map
|