원클릭으로
lens-studio-instantiation
Learn how to dynamically instantiate prefabs algorithmically in grid or spherical patterns.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Learn how to dynamically instantiate prefabs algorithmically in grid or spherical patterns.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
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.
Implement proximity-based triggers and smooth tethering behaviors for interactive objects.
Learn how to track image markers and detach the tracked content into World Space in AR.
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.
| name | lens-studio-instantiation |
| description | Learn how to dynamically instantiate prefabs algorithmically in grid or spherical patterns. |
In Lens Studio, standard objects are placed visually in the Hierarchy. However, for dynamic systems like particle generators, voxels, UI grids, or data visualization, you will need to rapidly spawn AR elements programmatically into specific volumetric geometric patterns at runtime using instantiate().
Official docs: Spectacles Home
To spawn a new object, you apply .instantiate() against a valid ObjectPrefab asset field.
@input
targetPrefab: ObjectPrefab;
// Spawn attached to the current script root
const newObject = this.targetPrefab.instantiate(this.sceneObject);
// Re-position via the Transform
newObject.getTransform().setWorldPosition(new vec3(10, 0, 0));
If you want to spawn X * Y * Z number of objects centering radially outwards in a voxel cube...
@input myPrefab: ObjectPrefab;
const gridWidth = 5;
const gridHeight = 5;
const gridDepth = 5;
const spacing = 1.0;
function buildGrid(centerPos: vec3) {
// 1. Calculate boundaries
const totalW = (gridWidth - 1) * spacing;
const totalH = (gridHeight - 1) * spacing;
const totalD = (gridDepth - 1) * spacing;
// 2. Compute Offset
const startPos = new vec3(
centerPos.x - (totalW / 2),
centerPos.y - (totalH / 2),
centerPos.z - (totalD / 2)
);
// 3. Loop along axes
for (let x = 0; x < gridWidth; x++) {
for (let y = 0; y < gridHeight; y++) {
for (let z = 0; z < gridDepth; z++) {
const spawnTarget = new vec3(
startPos.x + (x * spacing),
startPos.y + (y * spacing),
startPos.z + (z * spacing)
);
// 4. Fire spawn
const instance = myPrefab.instantiate(global.scene.getRootObject(0));
instance.getTransform().setWorldPosition(spawnTarget);
}
}
}
}
The same math logic can be configured to execute other common shapes using trigonometric algorithms instead of linear for loops. Look for existing TS implementation scripts inside Instantiation.lspkg in the official samples:
Math.sin(angle) and Math.cos(angle).Math.pow(Math.random(), 1/3) * maxRadius.The code logic below is extracted from the official Instantiation.lspkg package, demonstrating a production-ready volumetric 3D grid layout behaviour.
See the reference guide for details.