一键导入
lens-studio-marker-tracking
Learn how to track image markers and detach the tracked content into World Space in AR.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Learn how to track image markers and detach the tracked content into World Space in AR.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | lens-studio-marker-tracking |
| description | Learn how to track image markers and detach the tracked content into World Space in AR. |
Standard lens studio image tracking binds 3D content directly to a printed image marker, so when the marker is hidden, the object disappears. By combining the MarkerTrackingComponent with DeviceTrackingMode.World, you can execute the "World-Locked Marker" pattern.
The World-Locked pattern detects the marker once to calculate its physical coordinate in the room, and then deliberately unparents your 3D content so it stays permanently pinned to that location in World-Space, regardless of whether the camera is still looking at the physical marker.
Official docs: Spectacles Home
First, make sure your Main Camera has a DeviceTracking component set to World mode. Then construct a standard MarkerTrackingComponent.
// 1. Grab camera and assert tracking mode
const mainCamera = global.scene.getRootObject(0).getComponent("Component.Camera");
const deviceTracking = mainCamera.getSceneObject().getComponent("Component.DeviceTracking");
if (deviceTracking.getActualDeviceTrackingMode() === DeviceTrackingMode.World) {
// World space is active! We can use world-locked markers.
}
This involves initially parenting your AR content to the marker track, listening for the onMarkerFound event, and then instantly swapping parents to root-level while using setParentPreserveWorldTransform to prevent jumping.
@input
markerTrackingComponent: MarkerTrackingComponent;
@input
my3DPrefabParent: SceneObject;
onAwake() {
this.createEvent("OnStartEvent").bind(() => {
if (this.markerTrackingComponent) {
this.markerTrackingComponent.onMarkerFound = () => {
this.handleInitialDetection();
};
}
});
}
handleInitialDetection() {
// 1. Create a stable root parent at the scene origin
const worldRoot = global.scene.createSceneObject("WorldRoot");
// 2. Wait exactly half a second for the marker tracking to settle and avoid jittering
const delay = this.createEvent("DelayedCallbackEvent");
delay.bind(() => {
// 3. Re-parent WITHOUT changing visual position
this.my3DPrefabParent.setParentPreserveWorldTransform(worldRoot);
// 4. Disable the tracker to save performance now that we are localized
this.markerTrackingComponent.enabled = false;
});
delay.reset(0.5);
}
The code logic below is extracted from the official MarkerTrackingHelper.lspkg package, demonstrating exactly how Spectacles AR handles hybrid Image/World persistence tracking logic out of the box.
See the reference guide for details.
Reference guide for 2D UI and screen-space interaction in Lens Studio — covering ScreenTransform anchors/offsets/size/pivot and coordinate conversions (localPointToScreenPoint, screenPointToLocalPoint, localPointToWorldPoint), ScreenImage (texture, stretch mode, color tint), Text component (content, font, alignment, color, size), ScreenRegionComponent for defining tap/touch areas, TouchComponent with TouchStartEvent/TouchMoveEvent/TouchEndEvent, tap input for phone lenses, LSTween UI animations (colorTo, moveTo on screen elements), multi-swatch color picker pattern, undo stack pattern, and common gotchas. Use this skill whenever a lens needs a 2D UI panel, tap interaction, on-screen buttons, text labels, color pickers, swipeable menus, or undo/redo — covering Drawing, Quiz, TappableQuestion, MemeSticker, MusicVideo, and HighScore examples.
Learn how to programmatically request and manage raw camera textures and crops.
Reference guide for face and body AR tracking in Lens Studio — covering FaceTrackingComponent setup (multi-face, faceIndex), FaceInset and FaceMask effects, 2D and 3D Face Attachments (hat/mouth/left_eye/right_eye anchors), Face Mesh UV texturing, Face Landmarks (68 keypoints), Face Expression weights for mouth-open/eye-blink detection, Eye Tracking component (left/right eye direction), Upper Body Tracking 3D asset (hips/spine/shoulder attachment points), Upper Body Mesh for seamless selfie occlusion, and Face Retouch/Eye Color/Face Liquify/Face Stretch effects. Use this skill for any phone or front-camera lens involving faces, selfie effects, makeup, face masks, 3D head ornaments, body tracking, or expression-driven animations — covering the vast majority of Snapchat lens content.
Learn how to dynamically instantiate prefabs algorithmically in grid or spherical patterns.
Implement proximity-based triggers and smooth tethering behaviors for interactive objects.
Reference guide for materials and shaders in Lens Studio — covering runtime material property changes (clone-before-modify, mainPass.baseColor, mainPass.opacity, mainPass.baseTex), blend modes (Normal/Alpha/Add/Screen/Multiply), depth and cull settings (depthTest, depthWrite, twoSided, cullMode), render order, material variants, assigning textures and render targets, reading and writing RenderTarget textures for post-processing, the graph-based Material Editor node system, custom shader graph nodes, and common shader pitfalls. Use this skill for any lens that needs to change material colors or textures at runtime, implement custom visual effects with shaders, set up post-processing render pipelines, chain render targets, or debug material/blend-mode issues — covering MaterialEditor, Drawing, and HairSimulation examples.