Extend or diagnose LunCoSim's USD-to-ECS projection: add a supported prim or attribute, trace an ignored field, or fix edits that fail to persist, undo, replicate, or render. Use for `lunco-usd*` machinery and document-owned ECS state. Prefer this skill for projection internals; use edit-usd-assembly for live headful assembly authoring, build-usd-scene for scene authoring, and luncosim-architecture for cross-domain ownership.
112 stars
0 votes
0 copies
1 view
Added November 7, 2026
toolspythonrustgoreactnodeexpressawsgitapibackend
Works with
cursor
terminal
cli
api
mcp
Security analysis
B75/100
criticalAccesses sensitive system or user directories
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Usd Projection?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/luncosim-usd-projection)
---
name: usd-projection
description: >
Extend or diagnose LunCoSim's USD-to-ECS projection: add a supported prim or
attribute, trace an ignored field, or fix edits that fail to persist, undo,
replicate, or render. Use for `lunco-usd*` machinery and document-owned ECS
state. Prefer this skill for projection internals; use edit-usd-assembly for
live headful assembly authoring, build-usd-scene for scene authoring, and
luncosim-architecture for cross-domain ownership.
---
# USD → ECS projection
Before adding a field or reader branch, use
[`luncosim-architecture`](../luncosim-architecture/SKILL.md) and the
[standard-schema boundary](../../docs/architecture/clean-architecture-and-usd-standards.md).
Prefer the OpenUSD schema that owns the concept. A migration is a clean
cutover: update the authored source and all readers, delete the superseded spelling
and compatibility branch, regenerate schema artifacts, and add a negative
test. Never make the ECS projection a second source of truth.
Mobility roots with a direct Modelica/Python program publish solver outputs on
`SimComponent`; only imperative producers allocate `OutputPorts`. Classify the
composed source through `lunco-usd-bevy-core::program::resolve_program` during
immutable topology preparation, independently of executor loading order. Source
wires retain the prim and named port so the shared registry selects its owner;
do not redirect them to an actuator child. Verify initial mass/inertia with
`test_vehicle_program_outputs.py`, including its rejected-zero case.
Keep projection completion owner-specific: `UsdSourcedCosim` belongs to source
discovery; only the native projector sets or clears `UsdSimProcessed`. A source
facet, source error, or source reset must not suppress native mobility/physics
work on the same prim. Co-simulation source I/O starts at
`UsdPrimProjectionSet`. Wiring waits for native body, joint and wheel port
surfaces. Check the real consumer with
`test_native_vehicle_projection.py --twin <path> --subject-path <prim> --minimum-support-contacts <count>`:
ready source-backed raycast vehicles must expose their wheel-support footprint
and current support samples through `QueryPhysicsState`.
Use `MoveProperty` through `ApplyUsdOp(s)` to rename authored properties while
preserving metadata, samples, and namespace-dependent connections. Inspect the
exact source document and property authorship before editing; composed values
can originate in a different layer.
**USD is the source of truth. The ECS is a projection of it.** Every entity you
see is a rendering of a prim. Nothing is authoritative because it is in the
world; it is in the world because it is in the document.
Apply that rule to authored facts. The current simulation and presentation
values belong to their runtime owners. For example, use `SetSceneView` for a
billboard's computed text and `SetPortsBatch` for named simulation inputs.
Use `ApplyUsdTransientOps` when an actual composed `@view@` prim or opinion
is required. See the
[live update routes](../../docs/architecture/50-usd-driven-visuals.md#live-values-and-saved-settings).
For live physical mount edits, follow the notice-driven owner in
[USD Domain](../../docs/architecture/21-domain-usd.md). Check both native mount
metadata and any generated allocator source; both consume the committed USD
revision. Do not rebuild a scene or clear a one-shot projection marker for a
mount transform edit. The third-pass production gates exercise native refresh,
ancestor edits, wheel units and non-crashing invalid authored state.
That single sentence generates every rule below.
Native USD dependencies are pinned at Rust `openusd` 0.8.0 with
`openusd-schemas` and `openusd-build`. Use `schema::native_registry` for stage
construction and native `ResolveInfo` for asset provenance. Standard schema
fallbacks and metadata are read through the composed stage; inspector/unit
metadata is derived by `SchemaMetadata`. Its property-name groups retain exact
schema-qualified declarations and reject ambiguous unqualified metadata; do not
scan the complete registry per prim attribute or choose one conflicting schema.
Project schema declarations are
generated at build time from `schema/schema.usda`.
## The pipeline, end to end
```
UsdOp ──► UsdDocumentRegistry::apply (journals + inverts)
│
▼
openusd Stage (the live CanonicalStage, NonSend)
│ StageSink fires → RawStageChange { resynced, info_only }
▼
project_stage_changes (lunco-usd-commands/src/live_consume.rs)
├── resynced → structural: spawn / despawn prims
└── info_only → attribute-only: translate, rotate, domes …
│
▼
UsdVisualProjectionQueued (bounded ECS binding queue)
│
▼
UsdVisualPlugin (lunco-usd-bevy/src/lib.rs)
└── match reader.type_name(path) → visual components
│
▼
UsdAnimationPlugin (lunco-usd-bevy-animation)
└── sample authored timeSamples into visual intent
```
The asset loader composes the fetched layer closure and snapshots the complete
default-time `UsdRead` surface into `UsdStageProjectionPlan` on its worker. The
`Add, UsdPrimPath` observer and `sync_usd_visuals` both feed the same
`UsdVisualProjectionQueued` marker. `process_queued_usd_visuals` drains that
queue with its configured per-frame budget, but the extractor reads only the
owned plan during initial materialisation; it does not parse USD, walk a live
stage, or resolve composed bindings on the UI thread. CPU mesh-data geometry
uses the render-free `lunco-usd-geometry` package, while its existing async
compute path and only Bevy asset insertion remain on the main thread. After the initial asset generation, explicit live edits use the
canonical `StageView` and the same extractor contract.
Truck owns NURBS evaluation and generated clamped uniform knots. Parametric
lathe construction calls `KnotVec::uniform_knot` directly; imported NURBS curves
must supply their authored knots and reject insufficient data. Do not infer
knots during import or add an application knot generator.
Native `UsdGeomXformable` owns transform evaluation. Static projection and
animation use the shared `local_transform_at` reader, including matrix,
quaternion, Euler, inverse, and reset-stack operations. Do not add a rotation
decoder or select an unordered transform attribute as an alternate pose.
The immutable snapshot derives its render transform and `f64` geometry matrix
from one native composition. Preserve both conversion orders: decompose and
narrow before convention conversion for rendering, and convert the full matrix
without narrowing for geometry. Do not derive geometry from a render transform.
Animation topology helpers identify sampled channels; they do not evaluate
their transforms or define an unconsumed clip-range policy.
Use fallible `UsdRead::transform_might_be_time_varying` for transform admission.
The worker plan captures the native ordered-stack result, including suffixed
operations. Samples outside `xformOpOrder` do not admit transform animation;
live order edits must remove `UsdAnimated` when no consumed channel remains.
The animation owner claims order edits through `UsdLiveEditRegistry`, classifies
the committed native stage, and reconciles its marker and cached plan in place.
Retiring and restoring the order must preserve the projected entity and geometry.
Unreadable authored order values fail at the shared transform validator. The
production scenario `lunco://scenarios/tests/native_xform_animation.rhai`
checks suffix sampling, unordered inputs, marker retirement/restoration, stable
entity identity, and rejected
malformed-order commands on the settled replacement fixture.
Reset-stack facts also come from fallible native `UsdRead::resets_xform_stack`.
The sentinel may appear after other operations; native USD discards those
earlier operations and the ancestor stack. Both double world-geometry reads
and visual frame projection consume this fact. Visual projection retains the
authored parent while reset is active, restores it when reset retires, and
re-expresses a changed reset pose once. Traverse the complete stage ancestry;
cycles and retired parents must terminate with a projection diagnostic.
`lunco://scenarios/tests/native_reset_stack.rhai` checks middle/deep reset stacks,
ordinary parent-relative transforms, live removal/restoration, and malformed
command rejection on the settled replacement fixture.
Trim controls are standard `double3[]` homogeneous coordinates. Keep them in
`f64` through loop assembly and Truck's rational 2D evaluation; narrowing before
parameter-space normalization can collapse a valid hole. The production gate
`scripts/api/test_native_trim_precision.py --port <free-port>` exercises authored
Rhai verdicts for collision cooking, zero-weight rejection, and rejection of a
truncated later loop. A malformed curve invalidates the complete trim domain.
`QueryUsdPrim` serializes the native Sdf value directly with the shared typed
API serializer. Its inspection adapter must preserve precision, integer kinds,
and empty arrays; render-oriented readers such as `points3` do not belong at
that boundary. Native serialization errors reject the query visibly.
Curve type, basis, wrap, orientation, and camera-path clock tokens come from
native composed values, including registered schema opinions. The shared
`read_curve_token` validates the consumer's supported set and rejects a missing
value; callers do not supply a duplicate schema default. Camera-path schema
opinions require the authored `LunCoCameraPathAPI` application.
Read composition-arc identity through fallible `UsdRead::has_composition_arc`.
The worker snapshots the native fact; live authoring uses
`CanonicalStages::reader_for_composed_query` to consume the admitted prepared
plan before a canonical stage opens and live state after edits. Missing lazy
stage state does not imply that a projected referenced child is uneditable.
Use native traversal activity facts when preparing a projection snapshot and
fallible `UsdRead::is_active` at live read boundaries. Native errors reject worker
snapshot admission, visual hierarchy admission, structural reconciliation,
physics bounds/collider reads and inspection. Use
`UsdStageProjectionPlan::prepare_recipe` for asset-backed plans so the asset
requirements and consumers share the prepared path identities.
Program-owner activation errors retire its executable binding and raise the
runtime fault. `scripts/api/test_native_activity.py --port <free-port>` exercises
subtree deactivation/reactivation and terminal malformed-command rejection.
Read inherited Imageable purpose through `UsdRead::purpose`, which exposes the
native SDK type and `ImageableExt::compute_purpose` semantics in both live and
prepared readers. Preserve its error result at physics, bounds, query, and lint
boundaries. The production gate
`lunco://scenarios/tests/native_purpose_inheritance.rhai`, attached through
`RunScenarioAsset` to the settled replacement fixture, verifies guide exclusion,
proxy/render selection, explicit-default overrides, collision bounds, lint,
live ancestor edits, and terminal malformed-type rejection without mutation.
Read presentation visibility through `UsdRead::effective_visibility` and keep
its error result. The SDK applies overall subtree pruning and standard
`VisibilityAPI` purpose opinions. A failed read terminates and hides visual
projection; inspect `UsdSceneProjectionFailed` through the shared reflection
surface and use document topology diagnostics for failed composed reads.
The focused production gate is `lunco://scenarios/tests/native_visibility.rhai`,
attached to the settled replacement fixture through `RunScenarioAsset`. Require
the visible-guide, ancestor-edit, malformed-type rejection, and native-read
failure checks, including unknown visibility in inspection.
Wheel projection may bind one centered `purpose=render` child while its proxy
is hidden through `VisibilityAPI`. It waits for direct-child structural
admission, then binds the existing entity; mesh baking remains asynchronous.
The wheel's mechanical axle controls roll independently of that render root's
rest rotation. See `build-vehicle` and the production `wheel_render_root` gate.
The scene transaction closes from asset and structural-projection outcomes.
Document-source publication uses the shared `DocumentStageInputs` weak reader
index and its document-owned lease, not a one-time asset-settings callback.
Preserve the exact source identity, current native recipe, revision fence, and
retirement boundary on reload. Use
`scripts/api/test_native_input_reload.py --port <free-port>` with `LUNCOSIM_BIN`
to require the authored runtime-only geometry verdict before and after a fresh
scene restart. The native input asset test covers late admission into an
already loaded handle and the lease test covers duplicate ownership and stale
capture rejection.
`UsdSceneProjectionFailed` on the running mount must fail and clear that
transaction before a generation can commit; preview errors are separately
owned. Missing default roots and nonexistent or non-prim explicit targets are
visible projection failures. Verify the failure edge as well as queue drainage.
Incremental structural reconciliation resolves a live path through the
`UsdPrimPath` lifecycle index keyed by stage asset and prim path. Insert and
removal observers maintain it, including component replacement and preview
duplicates; do not add a per-frame `Added` query or scan the full scene for each
changed path. The canonical stage records a weak identity for each merged
`Arc<StageRecipe>` so subsequent instances of that loaded revision skip cloning
and comparing its full layer closure. A reloaded recipe has a new identity and
must merge its current bytes before authoring the reference. Live instance
handles own asset lifetime; the index and weak recipe cache are derived state.
Transform edits update every indexed entity sharing that stage/path, including
preview copies. Scale is applied only beneath `UsdPreviewOnly`; a live body's
scale remains unchanged. Structural reconciliation still excludes previews.
For a document-backed reference batch, admit the native closure before replay
and author the native arc before sibling relationships or joints. Instance
snapshots own bounded ECS materialization; composed reads use the scene-stage
reader. Edits and deletion stay on that owner throughout the instance lifecycle.
Resolve schema through the entity's stage/prim identity, because different
stage assets may share a path but have different types.
Changes to a document's root scene are projected by its canonical stage. Only
different recipe roots that compose the changed layer are dependent refresh
targets; the root scene never refreshes itself as a dependent stage.
For a bounded typed edit, the dependent owner composes the current persistent
document layers directly to `Sdf Data` on a worker, then patches only the
affected prim specs and fields in the existing canonical stage with one
`Stage::batch_edit`. The normal sink projects those paths into ECS before an
active-stage progress hold is released. Afterward, a background worker
serializes the changed source and composes the immutable asset plan for a later
mount. That plan refresh does not hold simulation progress or reset the live
scene. Coarse composition edits and updates that span multiple changed source
layers use the full-stage reset owner.
The remaining dependent-source authored-layer transport delegates dictionary
composition to native `sdf::Dictionary::over` and list operations to native
`ListOp::combined_with`. An irreducible composition returns an error with its
field and path before publication; never replace the weaker operation silently.
Preserve nested metadata and stronger scalar opinions;
do not implement a shallow map merge or substitute stage flattening, which
consumes composition arcs.
Source replacement bytes use the native format's editability capability.
`author::layer_bytes` rejects formats without `FileFormatCaps::EDIT`, including
USDZ, whose single-layer writer cannot preserve other package members. A fresh
package export is a separate native operation. Do not admit editable packages
until their member identity and provenance are wired through storage and documents.
Native asset inputs follow the [shared preparation gate](../../docs/architecture/55-scene-addressing-and-roots.md#native-payload-and-source-admission): preserve the reader's current prepared table, retain edits/hints across superseded jobs, and release `UsdNativeAssetPreparation` only after that exact stage revision reaches live consumption or teardown. A queued visual or installed policy must remain deferred while native preparation holds its generation.
Doc-backed Twin admission is also asset-event driven. `UsdSourceBytes` is loaded
through the shared typed `load_asset_path` address and registered source scheme;
scene, preview, schema, reference and transitive layer readers preserve literal
filename characters and attach Bevy labels separately. `AssetEvent` and
`AssetLoadFailedEvent` advance or fail the pending document transaction. The
default Twin path parses the exact source revision through native
`AsyncWorkAdmission`, commits it through `DocumentRegistry::open_prepared_file`,
restores the runtime overlay, and serializes a cloned persistent document on
the worker pool. Exact source bytes and document generation are checked again before
the Twin overlay is published and `LoadScene` is submitted. Runtime sidecar
read/parse and editor-preview initial serialization remain synchronous; wasm
worker transport for this path is not installed, so the owner reports that
boundary visibly. The live USD stage stays with its thread-affine owner.
Document composition copies authored base specs into the identified root through
native Sdf operations; separate runtime and view layers use native USDC buffers.
Binary document
preparation does not serialize text; a source-display or USDA-export failure is
reported by the consumer requesting that representation.
Scene Files dependency traversal passes bounded raw bytes to the native USD
format owner, so USDC is decoded by OpenUSD rather than a UTF-8 gate. Native
format diagnostics remain terminal at the traversal owner.
Referenced stage closures follow the same event boundary before a reference is
authored onto the live stage. `ReferenceLayerInputs` retains the real source
handle and admitted canonical recipe/plan for the scene lifetime. Its existing
bounded preparation entries reuse settled facts only while the source revision,
stage and live mount match. Native
file-URI references prepare confined typed addresses and `StageRecipe::reanchor`
composition on the shared bounded reference lane, used by incremental spawns
and coarse rebuilds. Preserve authored layer bytes and absolute identifiers;
never inject transport aliases into the resolver. Publication rechecks exact
stage lifetime/generation, source, operation, live mount and loaded source
revision; worker panics become terminal completion errors. Current reference
and document-projection holds remain through ordered projection, and replaced
requests cannot consume outgoing completions. Native USD composition owns
reference namespaces, relationship and connection targets, material bindings,
and root opinions. Prepared asset plans snapshot those composed facts without
remapping or overriding them; runtime entity reads use the live scene stage.
Relationship names come from native typed relationship enumeration, including
empty and schema-declared properties. Enumeration errors must propagate through
snapshot admission and queries. Prepared plans preserve those names in
composed property order; never infer property kinds by attempting target reads
or discard a relationship because it has no targets. Keep attribute connections
separate and qualify changes through the `native_relationships` production gate.
Collection snapshots reuse native-equivalent membership queries only during
one immutable preparation. Their owned member lists may be shared; the native
queries remain worker-local and are discarded. Native evaluator queries are
not equivalent under OpenUSD's equality contract. A live edit or later snapshot
must read its current stage rather than a previous snapshot's membership.
Do not add frame-count timeouts, per-frame load polls, or direct filesystem
reads to this path. After admission,
`DocumentChanged` and stage-asset lifecycle events wake the single
`sync_twin_overlays` owner; do not add a per-frame generation scan or a
viewport-specific edit/reload path.
On first projection, the `twin://` stage already contains the document's current
base and runtime layers. Replay transient view edits from the document's bounded
view-operation suffix since its current source baseline. Do not query the global
op ring from generation zero: runtime restores are non-op generation changes,
and persistent edits do not belong in the view replay. If the view suffix has
expired, rebuild from the complete composed document.
For the mounted primary scene, reference fetches stay parallel but live-stage
mutation and terminal failure publication follow reference operation order. A
later completed reference remains prepared until every earlier active
reference for that scene resolves. Keep its ready or failed outcome while
deferred; never let asset completion order choose composition or fault order.
Preview stages do not acquire this simulation-specific commit barrier. The
production `route_lifecycle` Rhai scene gate covers the fixed-tick readiness
contract with multiple live references; low-level owner tests cover the
ready-prefix ordering seam.
The Editor is document-scoped. `DocumentId` from the existing
`DocumentRegistry<UsdDocument>` identifies the file being edited; the Twin
Browser opens the explicit `OpenUsdPreview { preview, doc_id, edit_target }`
session and can later use `FocusUsdPreview` or `CloseUsdPreview`. A session
owns one projected composed stage; `OpenUsdPreviewView { preview, view }`
adds a camera/render target over that stage for another dock tab or split.
`FocusUsdPreviewView` and `CloseUsdPreviewView` address the exact view.
Native editor view-model resources are keyed by `UsdPreviewId` and derive one
entry per open session; panels paint the focused view's session entry. Visible
preview targets are bounded by `UsdPreviewRenderBudget` (2048 px per axis,
4,194,304 pixels per view, and 8,388,608 visible pixels per frame by default),
while hidden view cameras stay inactive. The shared ECS selection is a
focused-session projection restored from editor-owned session selection, not a
document identity. Panel writes use the session's explicit `DocumentId`,
`LayerId`, and projection generation.
The active Twin's asynchronous workspace restore recreates saved view tabs over
the same document-scoped preview session and restores each view's camera and
presentation settings. A restored session acquires its stage when a tab becomes
visible or an explicit open requests the preview. A hidden restored tab has no
stage asset or projected prim hierarchy. Reopening the same file reuses the registered document;
use the explicit **Open view** action to add another perspective. A view tab
without a restored session is dropped from the saved dock layout rather than
shown empty.
Preview projection is a presentation scope over the same composed stage. It
owns one session-local light and excludes authored scene-wide
`DistantLight`/`DomeLight` prims from that render layer; authored local
`SphereLight`/`RectLight` prims remain part of the assembly. A preview is
ready only after its root and descendants are synced and that subtree's visual
queue plus asynchronous mesh phase have settled. Consumers use the typed
`projection_ready` state from `InspectUsdViewport`. Its `stage_asset_id`
is absent while the restored session waits for presentation. Consumers do not infer
readiness from a document generation or camera state.
Each `UsdPreviewView` also exposes Visual and Text modes over that same
session. Visual mode renders the projected stage; Text mode displays an
asynchronous, generation-matched authored or composed USDA snapshot as
read-only text. `SetUsdPreviewViewMode` and `SetUsdPreviewTextLayer` change
only view presentation, so they preserve the document, projected stage,
selection, camera, and lifecycle identity. Text snapshots are coalesced per
session and discarded when the document generation or preview lease changes;
they do not create a second parser, document registry, or source writer.
When an agent needs to answer “what is visible?” or edit the item a user has
open, call the UI-owned `InspectUsdViewport` query (or
`assembly_edit::viewport()`) and correlate its explicit preview/view handles
with `CaptureScreenshot`. The query is presentation context, not a second
document registry: use the returned `doc_id`, `edit_target`, and projection
generation with document inspection and typed edit commands. Never infer
identity from a tab title, filesystem basename, entity order, or the live
simulation viewport.
The Files section sends a `.usda`, `.usd`, or `.usdc` click through
`BrowserAction::OpenFile`. The USD route opens files in the emitting mounted
Twin through the additive document pipeline and preserves that Twin's
absolute source path. External scene commands mount through the workspace's
owning Twin scan. `OpenTwinScene` looks up the selected Twin's live asset
authority by its logical source identity. A private preview may share its
directory. Use `OpenUsdSourceDocument` for an explicit source-only inspection.
Once the document is admitted, the viewport derives its document-backed
`UsdPreviewId::for_document` with `LayerId::root()`, opens the session's primary
`UsdPreviewView` as an instance-backed dock tab, and focuses that exact tab.
File reads capture `FileDocumentAdmission` before dispatch and validate the
resolved runtime owner before publication. A retired owner cannot install a
late source; repeated requests coalesce only with the same admission snapshot.
Indexed Twin source requests and leases retire by exact `TwinId`, and stored
document ownership fences deletion after a source rebind. Preview admission
rejects retired document owners; private restored snapshots explicitly belong
to Application. See the [source lifetime contract](../../docs/architecture/55-scene-addressing-and-roots.md#document-source-admission-and-lifetime).
Browser file picks carry request-owned bytes into this same asynchronous preparation pipeline.
Each successful import installs a fresh pathless Application document; the
filename is display data, even when another pick has the same name. Native
Save-As requests pin the exact source owner before the backend starts. Browser
Save-As uses a fallible download and only publishes saved state after admission.
Repeated admitted clicks reuse the same document, preview session and view tab. Explicit
`FocusUsdPreview` and `FocusUsdPreviewView` commands foreground their matching
instance tab as well; replacing or closing a session removes its view tabs with
the presentation resources.
The preview root carries `UsdPreviewOnly`, the USD projection ownership fence.
Consumers that can create simulation side effects must use the shared bounded
`is_preview_only` ancestry helper rather than names, stage handles, or missing
physics components. Authored controls and program projection use that same
ancestry fence. Cosim discovery marks preview prims examined without loading
their programs, and wire derivation excludes preview descendants so duplicate
USD paths cannot claim mounted-scene endpoints. Live operator entities are
admitted only through their `UsdSceneRoot` ownership. The USD DEM bridge marks
preview terrain prims examined without creating `DemTerrainRequest`; preview
DEMs must not create collider rings, analytic query sources, or hold mission
physics. Relief in an isolated Editor terrain preview still needs a separate
render-only terrain realization and spatial demand. Mounted-scene live-edit
reconciliation ignores preview copies when looking up an entity by stage and
USD path, so a preview duplicate cannot satisfy the mounted scene's structural
spawn or refresh. Procedural scene backgrounds are also excluded from previews
because the skybox renderer has one scene-wide owner. Unscoped `QueryUsdPrim`
reads select the mounted scene by ignoring
`UsdPreviewOnly` roots; preview roots do not make live queries ambiguous.
Never choose an editor stage by entity count, insertion order, or the current
simulation viewport, and never use an active-viewport fallback for an entity
that lacks an explicit document binding.
When an agent is creating or modifying a reusable assembly, use the dedicated
[interactive Assembly Editor runbook](../edit-usd-assembly/SKILL.md). It
requires a headful production window, explicit document/preview handles,
typed USD edits, a screenshot after each coherent change, and a user-feedback
checkpoint. This projection skill owns the implementation boundary behind that
workflow; it does not authorize direct USDA or ECS edits.
For agent or editor synchronization, call `SyncUsdDocument` with the explicit
document generation. Use its typed delta while the cursor is covered; consume
the returned base/runtime layer snapshot when a full reload or expired history
window breaks the authored-operation stream. Full reloads advance the projection
generation without adding a fabricated authored operation. Reject future cursors.
To edit a composed path, call
`ResolveUsdTarget` with the explicit document id, prim path, and `@root@` or
`@runtime@` target. A referenced or payloaded path that has a local authored
opinion in the current document is valid from that document layer. Resolution
uses the current native document layer stack and its admitted dependency recipe;
`InspectUsdDocument` uses the same composition for types, schema defaults,
metadata, and reference lists/spec sites. Both report `document_composition`
and observe committed edits before the preview projection settles. Document
inspection reads parsed authored dependencies and native authored spec counts;
it does not require USDA text serialization, including for binary inheritance.
Use the returned `edit_scope` and
typed-operation validation rather than treating a composed read as permission
to move or remove a referenced/variant prim. Do not inspect flat layer data as
a replacement for OpenUSD PCP resolution or use it to invent a composed-only
target.
For a transient edit target that a tool has just authored, pass
`authored_children: true` to `ResolveUsdTarget` when it needs that layer's direct
child paths before scene projection settles. This returns the selected layer's
`primChildren` paths only; it does not resolve or enumerate composed children.
Agents and editor automation should use the built-in `assembly_edit` Rhai
library. It is a thin wrapper over `OpenFile`, `InspectUsdDocument`,
`InspectUsdViewport`, `ResolveUsdTarget`, `SyncUsdDocument`,
`ApplyUsdOp`/`ApplyUsdOps` (including
`SetTimeSample` and `RemoveTimeSample` for keyframes),
`AttachComponent`, `DetachComponent`, `UndoDocument`/`RedoDocument`,
`CreateUsdProposal`, `InspectUsdEditSession`, `ReviewUsdProposal`, and
`CommitUsdProposal`; it does not create another document registry, resolver,
USDA writer, or operation log. `open`
returns the normal asynchronous command acknowledgement and callers discover
the resulting id through `ListOpenDocuments`. Read helpers require an explicit
`doc_id`; authored helpers require `doc_id`, an edit target, and a USD path. Their
optional `parent_gen` is the existing stale-write precondition, and `batch`,
`transform`, or a keyframe change land as typed journal/undo operations. A
proposal requires a generation and explicit `SourceAsset`/`Assembly`/
`InstanceOverride` scope, validates without mutating the document, and is
visible through `InspectUsdEditSession`. Mute/unmute and reject are review-only;
commit rechecks generation, layer revision, origin, file watermark, scope, and
typed validation before using the ordinary grouped journal/undo path. A
conflict requires a fresh proposal; no automatic rebase or overwrite exists.
Use the tool catalog and completion query to discover the source and
signatures.
A scene loaded from disk and a prim authored at runtime therefore produce
identical entities without one heavy deferred-command flush monopolising the
window. The queue marker is the projection ownership fence: one prepared
hierarchy creates one child under its USD parent, so the projector does not
scan the world for duplicate stage paths. The same composed path is valid in
separate scene mounts and runtime instances; hierarchy and instance identity
scope those projections.
Generated Modelica domain projection follows the same ownership and change
set rule: apply the shared `is_domain_network_root` predicate before selecting
a synthesizer, then revisit only queued root entities. Live USD changes arrive
as typed `UsdSceneChangeBatch` path sets and are routed through the canonical
stage/root/member reverse index; stage-asset changes and generation gaps only
requeue roots on that stage. Reserve the all-prim pass for initial discovery.
Do not use the USD wiring latch as a membership signal, add a second stage scan,
or use a name-based candidate list.
After validation, publish the generated source and interface, link the source
to its normal Modelica document, then let lifecycle compile admission dispatch
it. Do not send a worker compile directly from USD projection; the standard
path owns document-generation and session fencing for generated and authored
models alike.
Lifecycle projection is followed by stable identity admission and API/path
index publication before the time spine releases simulation. Newly projected
references must resolve by path on their first resumed tick through that
ordered runtime path.
The generated-source browser/API projection has its own source/document
invalidation boundary. Do not gate it on live `ModelicaModel` output or clock
changes; those are solver state and must stay in the Modelica runtime owner.
Member class discovery is driven by `ModelicaSource` asset load, failure, and
modification events. Do not add a time-based give-up deadline or poll pending
sources on stable frames; an unavailable source remains explicitly pending
until the asset owner publishes a terminal outcome.
### Scene precision boundary
The mounted `UsdSceneRoot` is a nested BigSpace `Grid` below the active site
frame. Its top-level USD prims are direct Grid children and carry their own
`CellCoord`; their visual and collision descendants remain ordinary children
under the prim root and use `LowPrecisionRoot`. Terrain and rover/lander roots
are siblings in this scene frame. Terrain is never the parent of a vehicle,
because it does not own vehicle identity, physics, or lifecycle. Runtime and
replicated catalog spawns must enter through the same cell/local placement
boundary as authored top-level prims.
## Law 1 — every edit goes through `ApplyUsdOp`
An authored edit that does not lower to a `UsdOp` is absent from **save,
journal, undo, and network replication**. Route every authored editor/runtime
mutation through the same projection boundary.
```rust
commands.trigger(ApplyUsdOp { doc_id: doc, parent_gen: None, op }); // one op
commands.trigger(ApplyUsdOps {
doc_id: doc, parent_gen: None, label: "Edit material".into(), ops,
}); // one atomic edit and undo unit
```
Use `ApplyUsdOps` whenever an intent lowers to more than one op —
a loop of `ApplyUsdOp` journals N independent entries, and undo then peels off
one and leaves the object half-edited.
This law is for authored edits. A derived presentation may use the typed
`ApplyUsdTransientOps` command after resolving its source from the composed
stage when it needs a USD prim identity, schema, or picking contract. That path
is generation-checked and projected through OpenUSD, but is explicitly outside
save, undo/redo, and the Twin journal. Do not use it for a user edit or to
refresh dense per-edit geometry. Keep high-frequency or terrain-sampled view
geometry in its transient render owner; snapshot inputs, coalesce per target,
bound worker admission, and commit only current results to the existing render
entity. For example, route edits update their normal authored projection once,
then `UpdateUsdCurveView` prepares sparse surface strokes without a second USD
generation. Terrain fragments own the drape, so LOD/elevation changes need no
route tessellation. Stable segment identities preserve unchanged legs across
route edits. Inspect current publication and dirty-range work through
`InspectUsdCurveView`.
Incremental index patches keep the displayed surface texture until the current
patch commits; removing the last annotation clears it immediately.
`usd.document.projected` includes the reconciled `changed_prim_paths` in its
typed event data. A policy that caches composed facts should check this path set
before issuing document queries; unrelated document edits are not a request to
rescan the whole owned subtree. The event closes the live handoff only after
active referenced roots changed by that edit and their native ECS projections
have reached the ECS scene. Typed reference-add intents seed this required-root
set before the asynchronous asset admission emits a stage notice; pending
references elsewhere in the mounted stage do not delay this edit or retain its
document-projection hold. The document-projection key remains held until those active roots are in ECS.
Partial ancestor sink notices are accumulated into that one completion event.
The reference admission owner retains the source asset handle and prepares
the layer closure before authoring its native arc. The canonical stage sink
projects the resulting composed namespace through the normal ECS queues.
Document commands prepare newly introduced layer dependencies before the atomic
journal transaction through `lunco-usd-commands` and shared bounded admission.
Reuse `UsdOp::composition_dependencies` and the native composition owner; do not
fetch bytes or split the plan in a UI/tool. A pending `cmd` result carries a ticket,
not a successful edit: await `command_result(id)` before dependent commands or a
verdict. Preparation uses the shared render-free `is_authoritative_scene_stage`
check for its simulation hold and `PinnedDocumentRuntimeOwner` for its runtime
lease. Preview work cannot hold the active scene. Verify cold reference-child
overrides and warm restoration with
`scripts/api/test_route_runtime_persistence.py`, plus `route_authoring_history`.
Unmounted file documents must prepare existing dependencies on the same worker;
command dispatch must not read the dependency closure synchronously. Pending
discards share the document preparation lease and retire on document close or save.
Preparation and discard work for registered scene mounts also retires on scene
teardown. Independent document work retains its result and completion channel
across unrelated scene transitions; its owning Twin's close retires it immediately.
Verify that a newer edit makes an in-flight discard reject without
resetting its opinions or history.
Cancellation must reject the receipt, release its progress hold and drop its
callback/result slot; a matching revision alone cannot authorize publication into
a replaced document or stage.
Writing an ECS component directly is legitimate **only** for state that is
genuinely not part of the document (a camera's current yaw, a hover highlight).
If a user would expect it to survive save-and-reload, it belongs in USD.
`AttachProgram { doc_id, spec }` is the canonical multi-op authoring intent for a
source-backed Modelica, Python, Rhai, or behaviour-tree program. It lowers the
complete `LunCoProgramAPI` child, source asset, scalar ports, defaults, and
connections through this same change-set path. A palette or script must call
that command; it must not create an ECS marker or write a parallel registry.
An empty contract is source-only and remains visibly distinct from a running
cosim participant.
Composed asset I/O uses `UsdRead::asset_identifier`, the canonical identifier
annotated by the maintained strongest-default OpenUSD resolver. Keep `asset`
for raw authoring/query text. Never reanchor a child layer's asset string against
the scene root. Initial/live preparation carries the same context; missing
consumed context is an error. Time-sampled assets without that annotation are
not admitted. Render consumers retain typed `load_asset_path` addresses and
reuse admitted handles. Binary arc classification preserves the full logical
filename; URL query/fragment semantics apply only to explicit HTTP addresses.
Browser default/library readers and worker fetches encode literal filename
components at the shared asset HTTP transport boundary. Keep authored logical
addresses literal; do not pre-encode them or decode existing HTTP URLs.
DEM directory lookup uses the existing I/O worker and
asset owner's directory transport, with exact mount checks before publication.
See [asset provenance](../../docs/architecture/55-scene-addressing-and-roots.md#native-payload-and-source-admission).
## Law 2 — ask the scene root, never guess
To author a new top-level prim you need the target document *and* the parent
path. Both come from the scene root:
```rust
roots: Query<&UsdPrimPath, With<lunco_usd_bevy::UsdSceneRoot>>
let doc = lunco_usd_bevy_twin::scene_document_for(&backed, root.stage_handle.id())?;
let parent = &root.path; // "/SandboxScene", "/World", …
```
`DocBackedTwinScenes` resolves the exact current stage asset lease. The
shared composed reader supplies native prim existence and composition-arc ownership for
live persistence. Editor focus, file-name suffixes and an unprepared document
composition cache do not identify the destination of a scene edit.
Two failure modes this exists to prevent:
- **Counting the registry** ("there's only one document") — false. The registry
also holds terrain and script documents.
- **Hardcoding `/World`** — the luncosim scene is rooted at `/SandboxScene`. A
prim authored outside the mounted `defaultPrim` subtree *composes into the
layer and is then never mounted*: it saves, it journals, and it is invisible.
This failure is completely silent.
## Law 3 — spell it the way USD spells it
Use the real schema. `UsdLuxDomeLight` for an HDRI, `UsdPreviewSurface` for a
material, `UsdPhysics*` for physics. Before inventing anything, check whether
USD already defines it — a scene that leaves this app must still mean what it
said.
- `inputs:*` is the **UsdShade** namespace: it lives on a `Shader` prim, reached
through native `UsdRead::bound_shader`, which follows the universal surface
terminal through NodeGraphs. Both live and prepared readers retain native
material-binding and terminal errors; a connected graph without a producing
Shader rejects projection and material editing. A `float inputs:metallic` on a
Sphere is not valid USD, and no DCC will read it back. Use
`lunco_usd_core::material::ensure_preview_surface_ops()` — it builds the
Material+Shader+binding for you, and it is deliberately in `lunco-usd-core` so
every crate authors materials the same way.
- `primvars:displayColor` / `displayOpacity` are the *only* Gprim display
attributes. There is no "display emissive" — **emission requires a material**.
- Genuinely new concepts get the `lunco:` vendor namespace (`lunco:dome:skybox`,
`LunCoProceduralSkyAPI`, `lunco:terrain:*`). That is the correct, spec-sanctioned way to extend USD. What
is *not* correct is inventing a second spelling for something USD already has.
The procedural camera-background contract is an `Xform` with
`LunCoProceduralSkyAPI` and a standard `UsdShade` material binding. Read
that API once in `lunco-usd-bevy` and stamp the existing render-free
`ProceduralSkybox` component. Do not project a `UsdGeomGprim` for the
background, carry `info:wesl:vertexAsset`, or read the API again in a
downstream shader projector. `UsdLuxDomeLight` remains the standard path for
textured environment lighting.
**Never add an alias to make a file load.** A tolerant reader (`inputs:roughness`
*or* `perceptual_roughness` *or* bare `roughness`) is not robustness — it is a
trap. It teaches callers the invalid spelling and hides the bug: the writer
authors garbage, the reader accepts it, and the two conceal each other until the
file opens in Houdini and the material is gone. If the wrong form is authored,
the right behaviour is for it to visibly do nothing.
## Adding support for a new prim type or attribute
1. **Read it.** Extractors use the `UsdRead` trait
(`lunco-usd-bevy-stage/src/read.rs`), implemented by both `StageView` (the live
composed stage) and `UsdStageProjectionPlan` (the worker-produced initial
snapshot). Authoring-layer reads use `UsdDataExt` separately; runtime
extractors never switch to that source.
- Floats: use `real` / `real_f32`, **never** `scalar::<f64>` — a `float`-
authored value silently reads `None` through the f64 path.
- Asset paths: `read_token` (it coerces `String`/`Token`/`AssetPath`), then
`resolve_texture_path` to make it relative to the stage layer. Downloaded
assets are `lunco://textures/…` (declared in a crate's `Assets.toml`).
2. **Dispatch it.** Prim types are a `match` on `reader.type_name(&path)` inside
`instantiate_usd_prim_from_reader`. There is no registry to add to.
3. **Project it.** Insert components. Keep render-bound types out of
`lunco-usd-bevy` — it is render-free by contract (`cargo tree -p lunco-usd-bevy
-i wgpu` must be empty). `bevy_light` / `bevy_image` / `bevy_camera` are fine;
`bevy_pbr` / `bevy_render` are not, and belong in `lunco-render-bevy`.
4. **Re-project it on edit.** *This is the step people forget.* A structural
change (new prim) reconciles automatically. An **attribute-only** edit arrives
as `info_only`. Standard transforms and lights stay on the generic path; a
domain-specific in-place refresh registers a typed `UsdLiveEditOwner` with
`lunco_usd_bevy_core::live_edit::UsdLiveEditRegistry`. The owner claims only
its attributes, invalidates its own projection marker when required, and
refreshes from the composed stage. The notice consumer calls `refresh_prims`
once with unique, ordered native prim paths after the complete batch has
been authored; the writer must not also refresh ECS state. Property resyncs
use the same attribute consumer and prepare only that property's asset
values. Structural prim resyncs also invalidate prepared simulation topology
and candidate inventories through their bounded worker owner, including an
empty prior inventory or a new reference subtree. Exact-root candidate
updates cannot certify new descendants. Prim resyncs retain structural subtree preparation; native USD asset
types select provenance/time-sample reads. Property/transform notices for a
prim removed in the completed batch leave deletion to structural reconciliation.
Billboard edits reuse their initial reader
and preserve child state; exercise `usd_billboard_live.usda` when changing
that boundary. Owners also promote a local subtree reset
to a stage reset when their runtime topology crosses that subtree. Before a
full reset, each owner retires its derived state synchronously; a rejection
leaves the current projection in place and faults the active simulation.
Keep `live_consume.rs` generic: if you add an editable attribute and skip both
paths, `SetFoo` will journal and save correctly and **nothing will move on
screen** until reload.
5. **Author it.** Add a command that lowers to `UsdOp`s (Law 1) and register it
with `register_commands!` — a command is only reachable from the HTTP API /
MCP / rhai if its *type* is in the reflect registry.
6. **Test it.** Because extractors use the shared composed-reader contract,
unit-test the prepared `UsdStageProjectionPlan` for initial-load behavior
and use a live `StageView` only for explicit authored-edit behavior — no App,
no renderer. Keep pure animation topology/transform-reader tests in
`lunco-usd-bevy-core/src/animation.rs`; runtime animation-system tests belong
to `lunco-usd-bevy-animation`, and observable scene/policy assertions belong
in Rhai. Do not create a test-only crate or import animation readers into the
visual test target.
## Worked example
`crates/lunco-usd-bevy/src/dome.rs` (HDRI environment) is the whole checklist in
one file: standard schema (`UsdLuxDomeLight`), `lunco:` only for the two knobs
UsdLux genuinely lacks, a shared reader used by both the load path and the live-
edit path, an `info_only` refresh so runtime edits appear, a `SetDomeLight`
command that lowers to ops, and pure-function tests.
## Gotchas
- `bevy::init_asset::<A>()` is **destructive**, not idempotent — it wipes
`Assets<A>` and swaps the allocator. Guard with `contains_resource`.
- The `CanonicalStage` is `NonSend` (openusd `Stage` is `!Send`). Read it under a
short borrow and release it *before* mutating the world.
- `reconcile_structural_live` does nothing for a prim that exists **and** already
has an entity — it spawns and despawns only. Refreshing an existing entity is
your job.
Active `TwinClosed` retires the scene mount and publishes `SceneOwnerRetired`
before deferred teardown. Scene-time readiness closes immediately; pending
admissions and scene requests are discarded, the active transaction fails, and
`ClearScene` runs at the next lifecycle phase. Inactive Twin closure must not
clear another Twin's scene. See architecture 61 for the shared owner contract.
Native path verification uses the asset owner's typed `AssetPath` throughout
loading and handle lookup, including literal `#` filenames. Windows drive and
UNC USD references normalize to `file:` at composition; they are rejected
explicitly on a foreign host. Dataset output ownership uses worker-prepared
`lunco-storage::FilePathIdentity` snapshots rather than lexical path prefixes.
`ResolveUsdTarget` reports `document_composition` from the current native
document layer stack and its loaded dependency recipe. Verify prim validity,
edit scope, and native spec sites; do not wait for a lazy derived stage to open.