three-usd-robot 0.10.0 → 0.12.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 +108 -8
- package/dist/MeshBinding-DQKXuYNr.d.ts +288 -0
- package/dist/ThreeUsdRobot-C3N6-XBJ.d.ts +347 -0
- package/dist/{ThreeUsdRobotLoader-NdFAVN96.d.ts → ThreeUsdRobotLoader-D2fEo9_p.d.ts} +17 -3
- package/dist/{buildKinematicTree-BCySuZZn.d.ts → buildKinematicTree-iFqaw0Jl.d.ts} +1 -1
- package/dist/bytes-CxGRGry_.d.ts +14 -0
- package/dist/{chunk-NFKK5LJK.js → chunk-6W4LQVEQ.js} +33 -307
- package/dist/chunk-6W4LQVEQ.js.map +1 -0
- package/dist/{chunk-CDQPWWMQ.js → chunk-7GGSIA6M.js} +50 -28
- package/dist/chunk-7GGSIA6M.js.map +1 -0
- package/dist/{chunk-SSSDVLUK.js → chunk-CK5MTMYR.js} +6 -4
- package/dist/chunk-CK5MTMYR.js.map +1 -0
- package/dist/chunk-JGIVJXBU.js +54 -0
- package/dist/chunk-JGIVJXBU.js.map +1 -0
- package/dist/chunk-KYBHWDX5.js +701 -0
- package/dist/chunk-KYBHWDX5.js.map +1 -0
- package/dist/chunk-PPPRB6KE.js +963 -0
- package/dist/chunk-PPPRB6KE.js.map +1 -0
- package/dist/{chunk-IYKPVUZ2.js → chunk-YGJ23CG3.js} +40 -53
- package/dist/chunk-YGJ23CG3.js.map +1 -0
- package/dist/core.d.ts +74 -5
- package/dist/core.js +5 -3
- package/dist/extras.d.ts +2 -2
- package/dist/helpers.d.ts +2 -2
- package/dist/helpers.js +3 -2
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +10 -237
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/dist/nodes.d.ts +49 -0
- package/dist/nodes.js +439 -0
- package/dist/nodes.js.map +1 -0
- package/dist/parseMdl-vfzBGoMr.d.ts +87 -0
- package/dist/react.d.ts +6 -4
- package/dist/react.js +6 -4
- package/dist/react.js.map +1 -1
- package/package.json +6 -2
- package/dist/ThreeUsdRobot-B7Z4oORO.d.ts +0 -185
- package/dist/bytes-MOJ2oN-u.d.ts +0 -42
- package/dist/chunk-CDQPWWMQ.js.map +0 -1
- package/dist/chunk-IYKPVUZ2.js.map +0 -1
- package/dist/chunk-NFKK5LJK.js.map +0 -1
- package/dist/chunk-SSSDVLUK.js.map +0 -1
- package/dist/chunk-WROYLUSS.js +0 -393
- package/dist/chunk-WROYLUSS.js.map +0 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves USD asset paths (from references / payloads / sublayers) to URLs and
|
|
3
|
+
* fetches their text. Composition (`composition.ts`) is I/O-agnostic and goes
|
|
4
|
+
* through an {@link AssetResolver}, so the same engine works in the browser, in
|
|
5
|
+
* Node, or against an in-memory file map in tests.
|
|
6
|
+
*/
|
|
7
|
+
interface AssetResolver {
|
|
8
|
+
/** Resolve an authored asset path against the layer's base URL to an absolute key. */
|
|
9
|
+
resolve(assetPath: string, baseUrl: string): string;
|
|
10
|
+
/** Fetch the text of a resolved asset; rejects if it cannot be read. */
|
|
11
|
+
fetchText(url: string): Promise<string>;
|
|
12
|
+
/** Fetch the raw bytes of a resolved asset (for binary USDC / USDZ). Optional. */
|
|
13
|
+
fetchBytes?(url: string): Promise<Uint8Array>;
|
|
14
|
+
}
|
|
15
|
+
/** URL-based resolver using the global `fetch` (browser / Node 18+). */
|
|
16
|
+
declare class DefaultAssetResolver implements AssetResolver {
|
|
17
|
+
resolve(assetPath: string, baseUrl: string): string;
|
|
18
|
+
fetchText(url: string): Promise<string>;
|
|
19
|
+
fetchBytes(url: string): Promise<Uint8Array>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolver over an in-memory `{ path: contents }` map (text or bytes), with
|
|
23
|
+
* posix-style joins. Useful for tests and bundled assets.
|
|
24
|
+
*/
|
|
25
|
+
declare function createMemoryResolver(files: Record<string, string | Uint8Array>): AssetResolver;
|
|
26
|
+
/** Resolve `rel` against `baseUrl` using posix semantics, normalizing `.`/`..`. */
|
|
27
|
+
declare function joinPosix(baseUrl: string, rel: string): string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Minimal `.mdl` **declaration** parser (M20) — reads material signatures, not
|
|
31
|
+
* the MDL language.
|
|
32
|
+
*
|
|
33
|
+
* USD stores only the *overridden* inputs of an MDL shader; every other
|
|
34
|
+
* parameter value lives in the referenced `.mdl` module. Two declaration
|
|
35
|
+
* shapes carry the values we can recover without executing MDL:
|
|
36
|
+
*
|
|
37
|
+
* - parameter defaults —
|
|
38
|
+
* `export material OmniPBR(color diffuse_color_constant = color(0.2), …)`
|
|
39
|
+
* - wrapper materials (the usual shape of per-asset `Materials/*.mdl`) —
|
|
40
|
+
* `export material Steel(*) = OmniPBR::OmniPBR(diffuse_color_constant: color(…), …);`
|
|
41
|
+
*
|
|
42
|
+
* Only literal values are extracted: numbers, bools, strings, `color(…)` /
|
|
43
|
+
* `floatN(…)` vectors, and `texture_2d("path", ::tex::gamma_*)`. Defaults that
|
|
44
|
+
* are expressions, function calls, or cross-module references are skipped, as
|
|
45
|
+
* are comments and `[[ … ]]` annotation blocks. Executing MDL stays out of
|
|
46
|
+
* scope — this is a fidelity aid, not an interpreter.
|
|
47
|
+
*/
|
|
48
|
+
/** A literal value read from an MDL declaration. */
|
|
49
|
+
type MdlValue = number | boolean | string | number[] | MdlTextureValue;
|
|
50
|
+
/** A `texture_2d("path", ::tex::gamma_*)` literal. */
|
|
51
|
+
interface MdlTextureValue {
|
|
52
|
+
/** Path as written in the module — relative paths anchor at the `.mdl` file. */
|
|
53
|
+
assetPath: string;
|
|
54
|
+
/** From the gamma argument: `gamma_srgb` → `"sRGB"`, `gamma_linear` → `"raw"`. */
|
|
55
|
+
sourceColorSpace?: "sRGB" | "raw";
|
|
56
|
+
}
|
|
57
|
+
/** Narrow an {@link MdlValue} to a texture literal. */
|
|
58
|
+
declare function isMdlTexture(value: MdlValue | undefined): value is MdlTextureValue;
|
|
59
|
+
/** One `export material` declaration. */
|
|
60
|
+
interface MdlMaterialDecl {
|
|
61
|
+
name: string;
|
|
62
|
+
/** Literal defaults from the declaration's own parameter list (empty for `(*)`). */
|
|
63
|
+
defaults: Map<string, MdlValue>;
|
|
64
|
+
/** Base material of the wrapper form `X(…) = Base(args…)` (last `::` segment). */
|
|
65
|
+
base?: string;
|
|
66
|
+
/** Literal named arguments of the wrapper's base call. */
|
|
67
|
+
args: Map<string, MdlValue>;
|
|
68
|
+
}
|
|
69
|
+
/** The exported material declarations of one `.mdl` file. */
|
|
70
|
+
interface MdlModule {
|
|
71
|
+
materials: Map<string, MdlMaterialDecl>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Look up the parsed module for an authored `info:mdl:sourceAsset` path.
|
|
75
|
+
* Returning `undefined` means "module unavailable" — resolution then falls
|
|
76
|
+
* back to authored USD inputs alone.
|
|
77
|
+
*/
|
|
78
|
+
type MdlModuleProvider = (assetPath: string) => MdlModule | undefined;
|
|
79
|
+
/** Parse the `export material` declarations of an `.mdl` module's source text. */
|
|
80
|
+
declare function parseMdl(text: string): MdlModule;
|
|
81
|
+
/**
|
|
82
|
+
* Evaluate one MDL literal expression, or `undefined` for anything beyond the
|
|
83
|
+
* supported literal subset (identifiers, arithmetic, function calls, …).
|
|
84
|
+
*/
|
|
85
|
+
declare function parseMdlLiteral(src: string): MdlValue | undefined;
|
|
86
|
+
|
|
87
|
+
export { type AssetResolver as A, DefaultAssetResolver as D, type MdlMaterialDecl as M, type MdlModule as a, type MdlModuleProvider as b, type MdlTextureValue as c, type MdlValue as d, createMemoryResolver as e, parseMdlLiteral as f, isMdlTexture as i, joinPosix as j, parseMdl as p };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as _react_three_fiber from '@react-three/fiber';
|
|
2
2
|
import { ThreeElements } from '@react-three/fiber';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { T as ThreeUsdRobot } from './ThreeUsdRobot-
|
|
5
|
-
import { T as ThreeUsdRobotLoaderOptions } from './ThreeUsdRobotLoader-
|
|
4
|
+
import { T as ThreeUsdRobot } from './ThreeUsdRobot-C3N6-XBJ.js';
|
|
5
|
+
import { T as ThreeUsdRobotLoaderOptions } from './ThreeUsdRobotLoader-D2fEo9_p.js';
|
|
6
6
|
import 'three';
|
|
7
|
-
import './buildKinematicTree-
|
|
8
|
-
import './
|
|
7
|
+
import './buildKinematicTree-iFqaw0Jl.js';
|
|
8
|
+
import './parseMdl-vfzBGoMr.js';
|
|
9
|
+
import './bytes-CxGRGry_.js';
|
|
10
|
+
import './MeshBinding-DQKXuYNr.js';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Load a robot for use under `<Suspense>`. Throws the load promise until ready
|
package/dist/react.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ThreeUsdRobotLoader } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
4
|
-
import './chunk-
|
|
1
|
+
import { ThreeUsdRobotLoader } from './chunk-7GGSIA6M.js';
|
|
2
|
+
import './chunk-6W4LQVEQ.js';
|
|
3
|
+
import './chunk-KYBHWDX5.js';
|
|
4
|
+
import './chunk-YGJ23CG3.js';
|
|
5
|
+
import './chunk-PPPRB6KE.js';
|
|
6
|
+
import './chunk-JGIVJXBU.js';
|
|
5
7
|
import { useFrame } from '@react-three/fiber';
|
|
6
8
|
import * as React from 'react';
|
|
7
9
|
import { jsx } from 'react/jsx-runtime';
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx"],"names":["UsdRobot"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx"],"names":["UsdRobot"],"mappings":";;;;;;;;;;AAwBA,IAAM,KAAA,uBAAY,GAAA,EAAwB;A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AM,gBAAU,MAAM;AACpB,MAAA,IAAI,UAAA,KAAe,MAAA,EAAW,KAAA,CAAM,UAAA,GAAa,UAAA;AAAA,IACnD,CAAA,EAAG,CAAC,KAAA,EAAO,UAAU,CAAC,CAAA;AACtB,IAAM,gBAAU,MAAM;AACpB,MAAA,IAAI,aAAA,KAAkB,MAAA,EAAW,KAAA,CAAM,aAAA,GAAgB,aAAA;AAAA,IACzD,CAAA,EAAG,CAAC,KAAA,EAAO,aAAa,CAAC,CAAA;AACzB,IAAM,gBAAU,MAAM;AACpB,MAAA,IAAI,aAAA,KAAkB,MAAA,EAAW,KAAA,CAAM,aAAA,GAAgB,aAAA;AAAA,IACzD,CAAA,EAAG,CAAC,KAAA,EAAO,aAAa,CAAC,CAAA;AACzB,IAAM,gBAAU,MAAM;AACpB,MAAA,IAAI,cAAA,KAAmB,MAAA,EAAW,KAAA,CAAM,cAAA,GAAiB,cAAA;AAAA,IAC3D,CAAA,EAAG,CAAC,KAAA,EAAO,cAAc,CAAC,CAAA;AAI1B,IAAA,uBACE,GAAA,CAAC,WAAA,EAAA,EAAU,MAAA,EAAQ,KAAA,EAAQ,GAAG,IAAA,EAC3B,QAAA,EAAA,OAAA,mBAAU,GAAA,CAAC,aAAA,EAAA,EAAc,KAAA,EAAc,CAAA,GAAK,IAAA,EAC/C,CAAA;AAAA,EAEJ;AACF;AAEA,SAAS,aAAA,CAAc,EAAE,KAAA,EAAM,EAAmC;AAChE,EAAA,iBAAA,CAAkB,OAAO,IAAI,CAAA;AAC7B,EAAA,OAAO,IAAA;AACT","file":"react.js","sourcesContent":["/**\n * `three-usd-robot/react`\n *\n * React Three Fiber bindings: a `<UsdRobot>` component plus hooks. `react` and\n * `@react-three/fiber` are optional peer dependencies — non-React consumers are\n * unaffected. A {@link ThreeUsdRobot} is a `THREE.Object3D`, so it mounts via\n * R3F's `<primitive>`; joint values, toggles and animation are driven through\n * effects/`useFrame` (R3F does not re-render on object mutation).\n */\n\nimport { type ThreeElements, useFrame } from \"@react-three/fiber\";\nimport * as React from \"react\";\nimport type { ThreeUsdRobot } from \"./three/ThreeUsdRobot.js\";\nimport {\n ThreeUsdRobotLoader,\n type ThreeUsdRobotLoaderOptions,\n} from \"./three/ThreeUsdRobotLoader.js\";\n\ntype CacheEntry = {\n promise: Promise<ThreeUsdRobot>;\n robot?: ThreeUsdRobot;\n error?: unknown;\n};\n\nconst cache = new Map<string, CacheEntry>();\n\nfunction loadEntry(url: string, options?: ThreeUsdRobotLoaderOptions): CacheEntry {\n const cached = cache.get(url);\n if (cached) return cached;\n\n const entry = {} as CacheEntry;\n entry.promise = new ThreeUsdRobotLoader(options).loadAsync(url).then(\n (robot) => {\n entry.robot = robot;\n return robot;\n },\n (error) => {\n entry.error = error;\n throw error;\n },\n );\n cache.set(url, entry);\n return entry;\n}\n\n/**\n * Load a robot for use under `<Suspense>`. Throws the load promise until ready\n * (suspends) and the error if it fails (for an error boundary). Cached by `url`.\n */\nexport function useUsdRobot(url: string, options?: ThreeUsdRobotLoaderOptions): ThreeUsdRobot {\n const entry = loadEntry(url, options);\n if (entry.error) throw entry.error;\n if (!entry.robot) throw entry.promise;\n return entry.robot;\n}\n\n/** Warm the cache so a later `<UsdRobot>`/`useUsdRobot` resolves instantly. */\nexport function preloadUsdRobot(url: string, options?: ThreeUsdRobotLoaderOptions): void {\n loadEntry(url, options);\n}\n\n/** Drop one cached robot (or the whole cache) so it reloads next time. */\nexport function clearUsdRobotCache(url?: string): void {\n if (url) cache.delete(url);\n else cache.clear();\n}\n\n/**\n * Advance a robot's time-sampled animation every frame while `playing`. No-op\n * for robots without an authored time range.\n */\nexport function useRobotAnimation(robot: ThreeUsdRobot | null | undefined, playing = true): void {\n const range = robot?.getTimeRange() ?? null;\n const time = React.useRef(range?.start ?? 0);\n useFrame((_, delta) => {\n if (!robot || !range || !playing) return;\n time.current += delta * robot.getTimeCodesPerSecond();\n if (time.current > range.end) time.current = range.start;\n robot.setTime(time.current);\n });\n}\n\n/**\n * Transform / event props forwarded to the underlying `<primitive>`. Picked\n * explicitly so R3F's broad element index signature doesn't widen our own props.\n */\ntype ForwardedProps = Partial<\n Pick<\n ThreeElements[\"primitive\"],\n | \"position\"\n | \"rotation\"\n | \"quaternion\"\n | \"scale\"\n | \"visible\"\n | \"renderOrder\"\n | \"name\"\n | \"userData\"\n | \"onClick\"\n | \"onPointerOver\"\n | \"onPointerOut\"\n | \"onPointerMove\"\n >\n>;\n\nexport type UsdRobotProps = ForwardedProps & {\n /** Asset URL (`.usda` / `.usdc` / binary `.usd` / `.usdz`). */\n url: string;\n /** Loader options (resolver, up-axis, textures, …). */\n loaderOptions?: ThreeUsdRobotLoaderOptions;\n /** Controlled joint values (re-applied when this object changes). */\n jointValues?: Record<string, number>;\n /** Auto-play time-sampled joint animation (default `false`). */\n animate?: boolean;\n showVisual?: boolean;\n showCollision?: boolean;\n showJointAxes?: boolean;\n showLinkFrames?: boolean;\n /** Called once the robot has loaded. */\n onLoad?: (robot: ThreeUsdRobot) => void;\n};\n\n/**\n * Declaratively mount a USD robot in an R3F `<Canvas>`. Wrap in `<Suspense>`.\n *\n * @example\n * ```tsx\n * <Suspense fallback={null}>\n * <UsdRobot url=\"/robot.usda\" jointValues={{ joint1: 0.4 }} showJointAxes />\n * </Suspense>\n * ```\n */\nexport const UsdRobot = React.forwardRef<ThreeUsdRobot, UsdRobotProps>(\n function UsdRobot(props, ref) {\n const {\n url,\n loaderOptions,\n jointValues,\n animate = false,\n showVisual,\n showCollision,\n showJointAxes,\n showLinkFrames,\n onLoad,\n ...rest\n } = props;\n\n const robot = useUsdRobot(url, loaderOptions);\n React.useImperativeHandle(ref, () => robot, [robot]);\n\n React.useEffect(() => {\n onLoad?.(robot);\n }, [robot, onLoad]);\n\n React.useEffect(() => {\n if (jointValues) robot.setJointValues(jointValues);\n }, [robot, jointValues]);\n\n React.useEffect(() => {\n if (showVisual !== undefined) robot.showVisual = showVisual;\n }, [robot, showVisual]);\n React.useEffect(() => {\n if (showCollision !== undefined) robot.showCollision = showCollision;\n }, [robot, showCollision]);\n React.useEffect(() => {\n if (showJointAxes !== undefined) robot.showJointAxes = showJointAxes;\n }, [robot, showJointAxes]);\n React.useEffect(() => {\n if (showLinkFrames !== undefined) robot.showLinkFrames = showLinkFrames;\n }, [robot, showLinkFrames]);\n\n // `useFrame` only runs inside a Canvas, so gate it behind a child component —\n // this keeps <UsdRobot> renderable (and testable) without an R3F frame loop.\n return (\n <primitive object={robot} {...rest}>\n {animate ? <RobotAnimator robot={robot} /> : null}\n </primitive>\n );\n },\n);\n\nfunction RobotAnimator({ robot }: { robot: ThreeUsdRobot }): null {\n useRobotAnimation(robot, true);\n return null;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "three-usd-robot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Kinematic OpenUSD robot loader for Three.js — load Isaac Sim / OpenUSD robot assets, extract joints and links, and control articulations in the browser.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"types": "./dist/extras.d.ts",
|
|
41
41
|
"import": "./dist/extras.js"
|
|
42
42
|
},
|
|
43
|
+
"./nodes": {
|
|
44
|
+
"types": "./dist/nodes.d.ts",
|
|
45
|
+
"import": "./dist/nodes.js"
|
|
46
|
+
},
|
|
43
47
|
"./react": {
|
|
44
48
|
"types": "./dist/react.d.ts",
|
|
45
49
|
"import": "./dist/react.js"
|
|
@@ -49,7 +53,7 @@
|
|
|
49
53
|
"module": "./dist/index.js",
|
|
50
54
|
"types": "./dist/index.d.ts",
|
|
51
55
|
"scripts": {
|
|
52
|
-
"build": "tsup",
|
|
56
|
+
"build": "tsup && node scripts/verify-bundle.mjs",
|
|
53
57
|
"dev": "tsup --watch",
|
|
54
58
|
"test": "vitest run",
|
|
55
59
|
"test:watch": "vitest",
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { J as JointType, A as Axis, a as JointDescription, L as LinkDescription, R as RobotDescription, K as KinematicTree, S as Stage } from './buildKinematicTree-BCySuZZn.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The articulated "motion" node of a joint, inserted between the joint's two
|
|
6
|
-
* fixed frames (`jointFrame0` and `inverse(jointFrame1)`). {@link setValue}
|
|
7
|
-
* rotates it about the axis (revolute/continuous) or slides it along the axis
|
|
8
|
-
* (prismatic); fixed joints are inert.
|
|
9
|
-
*/
|
|
10
|
-
declare class JointObject extends THREE.Object3D {
|
|
11
|
-
readonly isJointObject = true;
|
|
12
|
-
readonly jointName: string;
|
|
13
|
-
/** Full USD prim path of the joint — the collision-proof address. */
|
|
14
|
-
readonly primPath: string;
|
|
15
|
-
readonly jointType: JointType;
|
|
16
|
-
readonly axisToken: Axis;
|
|
17
|
-
readonly axis: THREE.Vector3;
|
|
18
|
-
readonly lower: number | undefined;
|
|
19
|
-
readonly upper: number | undefined;
|
|
20
|
-
private _value;
|
|
21
|
-
constructor(joint: JointDescription);
|
|
22
|
-
get value(): number;
|
|
23
|
-
get articulated(): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Set the joint value (radians for revolute/continuous, length for prismatic).
|
|
26
|
-
* Optionally clamps to authored limits. Returns the value actually applied.
|
|
27
|
-
*/
|
|
28
|
-
setValue(value: number, clampToLimits?: boolean): number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Three.js node for a robot link. Its frame is the USD link prim's frame;
|
|
33
|
-
* visual/collision meshes (M6) attach as children relative to it. Placement
|
|
34
|
-
* relative to the parent is supplied by the joint chain, so a link's own local
|
|
35
|
-
* matrix is identity (except the root, which carries the world-fixed placement).
|
|
36
|
-
*/
|
|
37
|
-
declare class LinkObject extends THREE.Object3D {
|
|
38
|
-
readonly isLinkObject = true;
|
|
39
|
-
readonly linkName: string;
|
|
40
|
-
readonly primPath: string;
|
|
41
|
-
constructor(link: LinkDescription);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Target world up-axis: normalize to Y-up / Z-up, or keep the authored orientation. */
|
|
45
|
-
type WorldUpAxis = "Y" | "Z" | "keep";
|
|
46
|
-
type ThreeUsdRobotOptions = {
|
|
47
|
-
/** Clamp `setJointValue` to authored limits (default `true`). */
|
|
48
|
-
clampJointLimits?: boolean;
|
|
49
|
-
/** Size of the built-in joint-axis / link-frame helpers (stage units, default `0.15`). */
|
|
50
|
-
helperSize?: number;
|
|
51
|
-
/**
|
|
52
|
-
* Target world up-axis. The root is rotated so the stage's authored `upAxis`
|
|
53
|
-
* lands in that convention: `"Y"` for a standard three.js scene, `"Z"` for a
|
|
54
|
-
* robotics-style Z-up world, `"keep"` for no correction. Takes precedence
|
|
55
|
-
* over the deprecated {@link ThreeUsdRobotOptions.upAxisConversion}.
|
|
56
|
-
*/
|
|
57
|
-
worldUp?: WorldUpAxis;
|
|
58
|
-
/**
|
|
59
|
-
* Legacy up-axis correction: `"auto"` ≡ `worldUp: "Y"`, `"Y"` / `"none"` ≡
|
|
60
|
-
* `worldUp: "keep"`, and `"Z"` forces the Z-up→Y-up rotation regardless of
|
|
61
|
-
* stage metadata. Default `"none"` (the loader defaults to `"auto"`).
|
|
62
|
-
* @deprecated Use {@link ThreeUsdRobotOptions.worldUp}.
|
|
63
|
-
*/
|
|
64
|
-
upAxisConversion?: "auto" | "Y" | "Z" | "none";
|
|
65
|
-
/** Extra uniform scale multiplied with the stage `metersPerUnit` (default `1`). */
|
|
66
|
-
unitScale?: number;
|
|
67
|
-
/** Seed joints from their authored initial value (drive target / joint state). Default `true`. */
|
|
68
|
-
applyInitialPose?: boolean;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* A Three.js `Object3D` that realizes a {@link RobotDescription} as a kinematic
|
|
72
|
-
* hierarchy and drives forward kinematics via {@link setJointValue}.
|
|
73
|
-
*
|
|
74
|
-
* Per joint the hierarchy is
|
|
75
|
-
* `parentLink → jointFrame0 → jointMotion → jointFrame1⁻¹ → childLink`,
|
|
76
|
-
* where only `jointMotion` (a {@link JointObject}) changes with the joint value;
|
|
77
|
-
* world poses then fall out of Three.js's `updateMatrixWorld`.
|
|
78
|
-
*
|
|
79
|
-
* **Naming contract** — a link/joint's key is its prim's leaf name when that
|
|
80
|
-
* is unique across the robot, else its full prim path (deterministic; see the
|
|
81
|
-
* extractor). Every accessor taking a name equally accepts the full prim path,
|
|
82
|
-
* which is stable regardless of collisions; {@link getLinkObjectsByPath} /
|
|
83
|
-
* {@link getJointObjectsByPath} enumerate the path-keyed tables.
|
|
84
|
-
*/
|
|
85
|
-
declare class ThreeUsdRobot extends THREE.Object3D {
|
|
86
|
-
readonly isThreeUsdRobot = true;
|
|
87
|
-
readonly robot: RobotDescription;
|
|
88
|
-
readonly tree: KinematicTree;
|
|
89
|
-
readonly clampJointLimits: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* The composed USD stage this robot was built from — the full prim tree, for
|
|
92
|
-
* inspection tooling (structure panels, attribute browsers). Attached by
|
|
93
|
-
* {@link ThreeUsdRobotLoader}; `undefined` for programmatically-built robots.
|
|
94
|
-
*/
|
|
95
|
-
stage?: Stage;
|
|
96
|
-
private readonly linkObjects;
|
|
97
|
-
private readonly jointObjects;
|
|
98
|
-
private readonly linkKeyByPath;
|
|
99
|
-
private readonly jointKeyByPath;
|
|
100
|
-
private dirty;
|
|
101
|
-
private readonly helperSize;
|
|
102
|
-
private _showVisual;
|
|
103
|
-
private _showCollision;
|
|
104
|
-
private _showJointAxes;
|
|
105
|
-
private _showLinkFrames;
|
|
106
|
-
private jointAxesHelpers;
|
|
107
|
-
private linkFrameHelpers;
|
|
108
|
-
constructor(robot: RobotDescription, tree: KinematicTree, options?: ThreeUsdRobotOptions);
|
|
109
|
-
/** Orient (authored upAxis → target world up) and scale (metersPerUnit × unitScale) the root. */
|
|
110
|
-
private applyStageNormalization;
|
|
111
|
-
/** Apply each joint's authored initial value, if any. */
|
|
112
|
-
private applyInitialPose;
|
|
113
|
-
private attachRoot;
|
|
114
|
-
private attachTreeEdges;
|
|
115
|
-
/** Build `parent → frame0 → motion → frame1⁻¹ → child` for one joint. */
|
|
116
|
-
private attachJointChain;
|
|
117
|
-
private attachIsolatedLinks;
|
|
118
|
-
/** Resolve a link reference — key or full prim path — to the extractor key. */
|
|
119
|
-
private linkKey;
|
|
120
|
-
/** Resolve a joint reference — key or full prim path — to the extractor key. */
|
|
121
|
-
private jointKey;
|
|
122
|
-
/**
|
|
123
|
-
* Set one joint value, addressed by key or full prim path. Unknown joints
|
|
124
|
-
* are ignored. Returns whether it applied.
|
|
125
|
-
*/
|
|
126
|
-
setJointValue(name: string, value: number): boolean;
|
|
127
|
-
/** Set several joint values at once (matrix update is coalesced). */
|
|
128
|
-
setJointValues(values: Record<string, number>): void;
|
|
129
|
-
getJointValue(name: string): number | undefined;
|
|
130
|
-
/** Recompute world matrices. Called lazily by the getters; safe to call directly. */
|
|
131
|
-
updateKinematics(): void;
|
|
132
|
-
private ensureUpdated;
|
|
133
|
-
/** World matrix of a link, addressed by key or full prim path. */
|
|
134
|
-
getLinkWorldMatrix(name: string): THREE.Matrix4;
|
|
135
|
-
getLinkWorldPosition(name: string): THREE.Vector3;
|
|
136
|
-
/** Link object by key or full prim path. */
|
|
137
|
-
getLinkObject(name: string): LinkObject | undefined;
|
|
138
|
-
/** Joint object by key or full prim path. */
|
|
139
|
-
getJointObject(name: string): JointObject | undefined;
|
|
140
|
-
/**
|
|
141
|
-
* Table of link prim path → {@link LinkObject}. Prim paths are the
|
|
142
|
-
* collision-proof way to pin a link (e.g. to attach tools or gizmos).
|
|
143
|
-
*/
|
|
144
|
-
getLinkObjectsByPath(): Map<string, LinkObject>;
|
|
145
|
-
/**
|
|
146
|
-
* Table of joint prim path → {@link JointObject}, covering the joints
|
|
147
|
-
* realized in the kinematic tree (loop joints have no motion node).
|
|
148
|
-
*/
|
|
149
|
-
getJointObjectsByPath(): Map<string, JointObject>;
|
|
150
|
-
getJoints(): JointDescription[];
|
|
151
|
-
getLinks(): LinkDescription[];
|
|
152
|
-
/** Names of the articulated (controllable) joints. */
|
|
153
|
-
getJointNames(): string[];
|
|
154
|
-
getLinkNames(): string[];
|
|
155
|
-
getKinematicTree(): KinematicTree;
|
|
156
|
-
/** Authored stage up-axis (`"Y"` or `"Z"`) — unaffected by `worldUp` normalization. */
|
|
157
|
-
get upAxis(): "Y" | "Z";
|
|
158
|
-
/** Authored stage scale in meters per unit (already applied to the root). */
|
|
159
|
-
get metersPerUnit(): number;
|
|
160
|
-
/** Playback rate in time codes per second (from the stage; default 24). */
|
|
161
|
-
getTimeCodesPerSecond(): number;
|
|
162
|
-
/** Whether any joint has a time-sampled trajectory. */
|
|
163
|
-
hasAnimation(): boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Animation range in time codes: the union of authored joint sample ranges,
|
|
166
|
-
* falling back to the stage `startTimeCode`/`endTimeCode`. `null` if neither.
|
|
167
|
-
*/
|
|
168
|
-
getTimeRange(): {
|
|
169
|
-
start: number;
|
|
170
|
-
end: number;
|
|
171
|
-
} | null;
|
|
172
|
-
/** Sample every animated joint at time code `t` and apply the values. */
|
|
173
|
-
setTime(t: number): void;
|
|
174
|
-
get showVisual(): boolean;
|
|
175
|
-
set showVisual(v: boolean);
|
|
176
|
-
get showCollision(): boolean;
|
|
177
|
-
set showCollision(v: boolean);
|
|
178
|
-
get showJointAxes(): boolean;
|
|
179
|
-
set showJointAxes(v: boolean);
|
|
180
|
-
get showLinkFrames(): boolean;
|
|
181
|
-
set showLinkFrames(v: boolean);
|
|
182
|
-
private setKindVisibility;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export { JointObject as J, LinkObject as L, ThreeUsdRobot as T, type WorldUpAxis as W, type ThreeUsdRobotOptions as a };
|
package/dist/bytes-MOJ2oN-u.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolves USD asset paths (from references / payloads / sublayers) to URLs and
|
|
3
|
-
* fetches their text. Composition (`composition.ts`) is I/O-agnostic and goes
|
|
4
|
-
* through an {@link AssetResolver}, so the same engine works in the browser, in
|
|
5
|
-
* Node, or against an in-memory file map in tests.
|
|
6
|
-
*/
|
|
7
|
-
interface AssetResolver {
|
|
8
|
-
/** Resolve an authored asset path against the layer's base URL to an absolute key. */
|
|
9
|
-
resolve(assetPath: string, baseUrl: string): string;
|
|
10
|
-
/** Fetch the text of a resolved asset; rejects if it cannot be read. */
|
|
11
|
-
fetchText(url: string): Promise<string>;
|
|
12
|
-
/** Fetch the raw bytes of a resolved asset (for binary USDC / USDZ). Optional. */
|
|
13
|
-
fetchBytes?(url: string): Promise<Uint8Array>;
|
|
14
|
-
}
|
|
15
|
-
/** URL-based resolver using the global `fetch` (browser / Node 18+). */
|
|
16
|
-
declare class DefaultAssetResolver implements AssetResolver {
|
|
17
|
-
resolve(assetPath: string, baseUrl: string): string;
|
|
18
|
-
fetchText(url: string): Promise<string>;
|
|
19
|
-
fetchBytes(url: string): Promise<Uint8Array>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Resolver over an in-memory `{ path: contents }` map (text or bytes), with
|
|
23
|
-
* posix-style joins. Useful for tests and bundled assets.
|
|
24
|
-
*/
|
|
25
|
-
declare function createMemoryResolver(files: Record<string, string | Uint8Array>): AssetResolver;
|
|
26
|
-
/** Resolve `rel` against `baseUrl` using posix semantics, normalizing `.`/`..`. */
|
|
27
|
-
declare function joinPosix(baseUrl: string, rel: string): string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* In-memory input normalization for the loader entry points. Callers hold USD
|
|
31
|
-
* content in many shapes — a `fetch` response's `ArrayBuffer`, a `Uint8Array`
|
|
32
|
-
* (or any typed-array view), a dropped `File` / `Blob` — and every byte-eating
|
|
33
|
-
* API here funnels through {@link toBytes} so all of them are accepted.
|
|
34
|
-
*/
|
|
35
|
-
/** Binary USD content: an `ArrayBuffer`, any typed-array view, or a `Blob`/`File`. */
|
|
36
|
-
type BinarySource = ArrayBuffer | ArrayBufferView | Blob;
|
|
37
|
-
/** In-memory USD content: USDA source text, or {@link BinarySource} bytes. */
|
|
38
|
-
type UsdSource = string | BinarySource;
|
|
39
|
-
/** Normalize a {@link BinarySource} to bytes, honoring a view's offset/length. */
|
|
40
|
-
declare function toBytes(data: BinarySource): Promise<Uint8Array>;
|
|
41
|
-
|
|
42
|
-
export { type AssetResolver as A, type BinarySource as B, DefaultAssetResolver as D, type UsdSource as U, createMemoryResolver as c, joinPosix as j, toBytes as t };
|