No slash command · from ls-clad
Access real-time depth frames from Specs DepthModule: per-pixel depth, back-projection to world space, camera intrinsics, and depth+color snapshot cache. Use for AR placement, occlusion, or spatial queries.
Ships in ls-clad. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Requirements: Experimental API — requires camera access; see the Project settings note below.
Reference: Spatial Image/, Depth Cache/
Choose your pattern:
Combining depth with AI vision models (cache a frame, send to AI, project returned pixel coords to 3D) → see references/docs/depth-and-ai.mdx for the end-to-end flow and the skill boundary.
Skill hand-offs (don't duplicate here):
specs-ai-remote-service. This skill stops at producing a Texture and a pixel→world function; the AI side lives there.specs-world-query.CameraTextureProvider) → load specs-camera.private depthModule: DepthModule = require('LensStudio:DepthModule')
createDepthFrameSession()must NOT be called insideonAwake. UseOnStartEvent.
@component
export class DepthFrameReader extends BaseScriptComponent {
private depthModule: DepthModule = require('LensStudio:DepthModule')
private session: DepthFrameSession
private frameRegistration: EventRegistration
onAwake(): void {
this.createEvent('OnStartEvent').bind(() => this.startSession())
this.createEvent('OnDestroyEvent').bind(() => this.stopSession())
}
private startSession(): void {
this.session = this.depthModule.createDepthFrameSession()
this.frameRegistration = this.session.onNewFrame.add(
(data: DepthFrameData) => this.onDepthFrame(data)
)
this.session.start()
}
private onDepthFrame(data: DepthFrameData): void {
const cam = data.deviceCamera
// --- Sample depth at a specific pixel ---
const px = 112, py = 80
const idx = Math.floor(px + py * cam.resolution.x)
const depthValue = data.depthFrame[idx] // depth in centimeters
// --- Back-project pixel to 3D in device reference space ---
const uv = new vec2(px / cam.resolution.x, py / cam.resolution.y)
const point3dDeviceRef = cam.unproject(uv, depthValue)
// --- Transform to world space ---
const worldFromDeviceRef = data.toWorldTrackingOriginFromDeviceRef
const point3dWorld = worldFromDeviceRef.multiplyPoint(point3dDeviceRef)
print("[Depth] 3D point in world: " + point3dWorld)
}
private stopSession(): void {
if (this.session && this.frameRegistration) {
this.session.onNewFrame.remove(this.frameRegistration)
this.session.stop()
}
}
}
session.onNewFrame.add((data: DepthFrameData) => {
// Camera info for this depth frame
const cam = data.deviceCamera
print("Resolution: " + cam.resolution) // vec2 in pixels
print("Focal length: " + cam.focalLength) // vec2
print("Principal point: " + cam.principalPoint) // vec2
print("Camera pose: " + cam.pose) // mat4
// Depth array — Float32Array per pixel, in centimeters
const depth: Float32Array = data.depthFrame
// Transform: device reference → world tracking origin (mat4)
const worldFromDevice: mat4 = data.toWorldTrackingOriginFromDeviceRef
// Timestamp — use to sync with CameraModule color frames
const ts: number = data.timestampSeconds
})
Depth is estimated from the left color camera on Spectacles '24. Sync frames by comparing timestamps:
// From CameraModule (color) frame:
provider.onNewFrame.add((colorFrame) => {
const colorTs = colorFrame.timestampMillis / 1000 // convert to seconds
// Match with depthFrame.timestampSeconds
})
private onDepthFrame(data: DepthFrameData): void {
const cam = data.deviceCamera
const w = cam.resolution.x
const h = cam.resolution.y
const depth = data.depthFrame
const world = data.toWorldTrackingOriginFromDeviceRef
for (let py = 0; py < h; py += 4) { // sample every 4th row for perf
for (let px = 0; px < w; px += 4) {
const d = depth[Math.floor(px + py * w)]
if (d <= 0) continue // invalid depth
const uv = new vec2(px / w, py / h)
const p = cam.unproject(uv, d)
const worldPt = world.multiplyPoint(p)
// use worldPt...
}
}
}
Reusable component: references/scripts/DepthCache.ts — drop into Assets/Scripts/.
It does three things:
saveDepthFrame() → returns an ID; freezes the latest pair so the color frame and the depth+pose data stay aligned even after the user finishes "thinking" / awaiting an API response.getWorldPositionWithID(pixelPos, id) → remaps color UV → depth UV, samples a 3×3 median depth (robust to noise/holes), then unprojects + multiplies by the cached pose to return a vec3 in world space.Usage:
@input depthCache: DepthCache
private async onUserAsk(prompt: string) {
const depthFrameID = this.depthCache.saveDepthFrame()
const camImage = this.depthCache.getCamImageWithID(depthFrameID)
// Hand off to specs-ai-remote-service skill for the vision call
const response = await this.gemini.makeGeminiRequest(camImage, prompt)
for (const point of response.points) {
const worldPos = this.depthCache.getWorldPositionWithID(point.pixelPos, depthFrameID)
if (worldPos != null) this.placeLabel(point.label, worldPos)
}
this.depthCache.disposeDepthFrame(depthFrameID)
}
DepthCache.ts uses 3×3 median sampling, deep-copies the depth buffer + pose (.slice() the Float32Array and mat4.fromColumns(...) the matrix at capture time, or the cached entry silently mutates to the latest frame), and remaps color UV → depth UV (on Spectacles '24 the depth frame is a cropped, downscaled view of the left color frame, not the same image) — see the JSDoc in references/scripts/DepthCache.ts for the full rationale.
For the snapshot pattern (mirrors specs-samples/Depth Cache):
Scene
├── Camera (Perspective, Device Tracking: World)
├── DepthCache (SceneObject)
│ └── DepthCache.ts @input camModule → Camera Module asset
├── SceneController (SceneObject)
│ └── YourController.ts @input depthCache → DepthCache component
└── (your AR content roots — labels, markers, etc.)
Required assets in Asset Browser:
Camera Module asset (created via Asset Browser → "+" → Camera Module)DepthModule is require()'d at runtime — no asset needed.Project settings:
Render the live depth feed as a point cloud locked to real surfaces — the best way to see that depth is working and to debug placement, since it doesn't depend on reading log values.
Reusable components: references/scripts/DepthTextureHandler.ts + references/scripts/CameraModel.ts.
How it works:
CameraModel from the frame's intrinsics and feed the inverse intrinsic matrix + deviceCamera.pose into a custom instanced material (mainPass.cameraFromDepthPixel, mainPass.deviceRefFromCamera).R32Float ProceduralTexture (setPixelsFloat32) — one instanced plane per depth pixel (instanceCount = w*h).getTransform().setWorldTransform(depthFrameData.toWorldTrackingOriginFromDeviceRef) each frame so the cloud stays anchored in world space.Hard dependency: this script only renders with a matching custom "Depth Texture" material (a vertex shader that displaces each instance by the sampled depth using cameraFromDepthPixel / deviceRefFromCamera). The .ts alone draws nothing — copy the material from the sample. If the cloud is invisible, first confirm the instanceCount is non-zero and the host SceneObject + its Render Mesh Visual are enabled.
Gravity-aligned pose (important): on current Specs the depth frame's pose is gravity-aligned, so always feed depthFrameData.deviceCamera.pose into your pixel math (deviceRefFromCamera = depthDeviceCamera.pose). Skipping it doesn't stop frames — it just makes projected points drift/tilt.
Freeze pattern: call session.stop() / session.start() (e.g. on pinch) to freeze and resume the cloud — useful for inspecting a single capture.
Depth has bitten every integration in this skill at the setup layer, not the code layer. Before debugging your math, confirm the feed:
Device only. Lens Studio Preview never streams depth — onNewFrame simply won't fire in Preview. Test on Specs.
Experimental API must be SAVED, not just checked. Toggling Project Settings → "Allow Experimental API" is not enough — the project must be saved so the .esproj lensDescriptors list actually contains EXPERIMENTAL_API. An unsaved checkbox builds a Lens with no depth and onNewFrame never fires. Verify with: grep -A3 lensDescriptors *.esproj.
Accept the on-device camera prompt. Depth needs the camera frame (which disables open internet for the Lens — use Extended Permissions if you also need network).
Use a delivery probe, not load logs. Frames arrive ~5 Hz after startup. A one-shot probe distinguishes "platform isn't delivering depth" from a Lens-side bug far faster than scrolling logs (see the DelayedCallbackEvent 5 s probe in DepthTextureHandler.ts):
let frames = 0
session.onNewFrame.add(() => frames++)
session.start()
const probe = this.createEvent("DelayedCallbackEvent")
probe.bind(() => print(frames === 0
? "[Depth] NO frames 5s after start — platform not delivering depth"
: `[Depth] ${frames} frames in 5s — pipeline OK`))
probe.reset(5.0)
Prefer a visual over prints. A no-visual Lens lets the compositor throttle (you'll see ~9 FPS and "Output has not changed, skipping rendering") and gives nothing to look at. The Depth Texture point cloud answers "is it working?" by looking.
Failed to get tracked device pose! Code -1 at startup is transient/benign — it appears even in working depth Lenses and is not the cause of a dead feed.
references/docs/depth-and-ai.mdx (opens in a new tab)references/docs/depth-module.mdx (opens in a new tab)references/scripts/CameraModel.ts (opens in a new tab)references/scripts/DepthCache.ts (opens in a new tab)references/scripts/DepthTextureHandler.ts (opens in a new tab)references/scripts/ExampleDepth.ts (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
specs, depth-module, ar-depth, spatial-computing, depth-frame
npx claudepluginhub lens-studio-devs/ls-extensions --plugin ls-clad74 skills in this plugin
/build-imageGenerate a 2D image from a text prompt via SPECS text-to-image, to Assets/GeneratedImages/<Name>.png (build-mesh reference, texture, or screen-space). Transparent RGBA cutout, cropped tight, by default; opt out for an opaque image.
/build-meshGenerate a 3D mesh, model, or asset for a Lens — build, create, or make props, characters, scenery. Four peer backends chosen per asset: SPECS text-to-3D (static default — best texture fidelity, async minutes-long jobs), FAST3D (faster static AI props), code-authored MeshBuilder via the mesh-builder-scripting skill (articulated, animated, parametric TypeScript content), and Blender voxel (blocky aesthetic; the only source of rigged GLBs). GLB backends return the file plus AABB metadata so the caller can size colliders and place the mesh in the world.
/build-musicGenerate musical phrases, chord progressions, beats, jingles, and short pieces via local algorithmic synthesis. Sample-free, license-clean, fully offline. Scale-degree composition, pattern-based arrangement, frequency-separated mixing rules. Outputs 44.1 kHz stereo WAV to Assets/GeneratedSFX/./build-sfxGenerate non-pitched sound effects (UI, impacts, sweeps, foley, ambient textures, retro 8-bit) via local algorithmic synthesis. Outputs 44.1 kHz WAV to Assets/GeneratedSFX/. For musical phrases or chord progressions use /build-music instead./camera-and-renderingCamera configuration, 2D/screen-space rendering, RenderMeshVisual patterns, and visibility debugging for Lens Studio scene construction. Use when setting up cameras (orthographic/perspective), creating screen-space content (ScreenTransform, Image, Text), debugging invisible objects, or planning any scene involving rendering config./editor-apiExecuteEditorCode contract and Editor API paradigms — runtime, access patterns, gotchas, references. Use before writing Editor API TS (`pluginSystem.findInterface`, `LensStudio:*`), grepping `editor.d.ts`, or routing to scene/asset-graphql.Other plugins' skills for the same job