sceneview-mcp 4.1.2 → 4.2.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.
@@ -4,12 +4,12 @@
4
4
  // build time so the MCP server, telemetry, and the install-snippet
5
5
  // generators all report the actually-published versions instead of
6
6
  // stale hardcoded constants. See #941.
7
- export const PACKAGE_VERSION = "4.1.2";
8
- export const LATEST_SCENEVIEW_RELEASE = "4.53.0";
7
+ export const PACKAGE_VERSION = "4.2.0";
8
+ export const LATEST_SCENEVIEW_RELEASE = "4.67.0";
9
9
  // The pub.dev coordinate for `flutter_sceneview`, read from the plugin's
10
10
  // README. Deliberately NOT LATEST_SCENEVIEW_RELEASE: pub.dev lags the SDK,
11
11
  // and a caret range against an unpublished version cannot be resolved.
12
- export const LATEST_FLUTTER_PUB_RELEASE = "4.39.0";
12
+ export const LATEST_FLUTTER_PUB_RELEASE = "4.63.0";
13
13
  // Web Filament runtimes, from ../gradle/libs.versions.toml (#3173).
14
14
  // FILAMENT_WEB_NPM_VERSION is the npm `filament` pin (CDN artifacts, Kotlin/JS);
15
15
  // FILAMENT_WEBSITE_VERSION is the runtime vendored for sceneview.js.
@@ -17,5 +17,5 @@ export const FILAMENT_WEB_NPM_VERSION = "1.52.3";
17
17
  export const FILAMENT_WEBSITE_VERSION = "1.72.1";
18
18
  // SceneViewSwift node types: every `public struct *Node` under
19
19
  // SceneViewSwift/Sources (#2999). Enum namespaces are not nodes.
20
- export const IOS_NODE_TYPES = ["AnchorNode", "AugmentedImageNode", "BillboardNode", "CameraNode", "DynamicSkyNode", "FogNode", "GeometryNode", "ImageNode", "LightNode", "LineNode", "MeshNode", "ModelNode", "PathNode", "PhysicsNode", "ReflectionProbeNode", "ShapeNode", "SpatialAudioNode", "TextNode", "VideoNode", "ViewNode"];
21
- export const IOS_NODE_TYPE_COUNT = 20;
20
+ export const IOS_NODE_TYPES = ["AnchorNode", "AugmentedImageNode", "BillboardNode", "CameraNode", "ContactShadowNode", "DynamicSkyNode", "FogNode", "GeometryNode", "ImageNode", "LightNode", "LineNode", "MeshNode", "ModelNode", "PathNode", "PhysicsNode", "ReflectionProbeNode", "ShapeNode", "SpatialAudioNode", "TextNode", "TubeNode", "VideoNode", "ViewNode"];
21
+ export const IOS_NODE_TYPE_COUNT = 22;
package/dist/guides.js CHANGED
@@ -199,7 +199,7 @@ viewModelScope.launch(Dispatchers.IO) {
199
199
 
200
200
  ### ARCore Threading
201
201
  - \`Session.update()\` must run on the main thread (SceneView handles this via \`onSessionUpdated\`).
202
- - \`hitResult.createAnchor()\` is safe on the main thread (called from \`onTouchEvent\` which runs on main).
202
+ - \`createAnchorOrNull()\` on an ARCore hit from \`frame.hitTest(event)\` is safe on the main thread (gesture callbacks such as \`onSingleTapConfirmed\` run on main).
203
203
  - Cloud anchor hosting/resolving is async — SceneView's \`CloudAnchorNode\` handles the callbacks correctly.
204
204
  `;
205
205
  export const BEST_PRACTICES = {
@@ -234,7 +234,7 @@ export const TROUBLESHOOTING_GUIDE = `# SceneView Troubleshooting Guide
234
234
  1. \`rememberModelInstance\` returns null while loading — are you null-checking it?
235
235
  2. Is the model path correct? Assets go in \`src/main/assets/models/\`
236
236
  3. Is \`scaleToUnits\` too small or too large? Try \`1.0f\`
237
- 4. Is there a light in the scene? Add a directional light: \`LightNode(apply = { intensity(100_000.0f); direction(0f, -1f, 0f) })\`
237
+ 4. Is there a light in the scene? Add a directional light: \`LightNode(type = LightManager.Type.DIRECTIONAL, apply = { intensity(100_000.0f); direction(0f, -1f, 0f) })\`
238
238
  5. Is the camera pointing at the model? Default camera is at origin looking -Z
239
239
 
240
240
  ### AR Camera Feed Shows but No Planes Detected
@@ -246,7 +246,7 @@ export const TROUBLESHOOTING_GUIDE = `# SceneView Troubleshooting Guide
246
246
 
247
247
  ### "ARCore not installed" on Device
248
248
  **Fix:**
249
- - Ensure \`<meta-data android:name="com.google.ar.core" android:value="required" />\` is in manifest
249
+ - Ensure \`<meta-data android:name="com.google.ar.core" android:value="required" tools:replace="android:value" />\` is in manifest (with \`xmlns:tools\` on \`<manifest>\`: arsceneview declares "optional", so the merge fails without the override)
250
250
  - Install Google Play Services for AR from Play Store
251
251
  - Some emulators don't support ARCore — test on a real device
252
252
 
@@ -268,7 +268,7 @@ export const TROUBLESHOOTING_GUIDE = `# SceneView Troubleshooting Guide
268
268
  - Reduce model polygon count (< 100K triangles)
269
269
  - Use KTX2 compressed textures (1024x1024 max)
270
270
  - Avoid per-frame allocations in \`onFrame\` callbacks
271
- - Disable post-processing if not needed: \`SceneView(postProcessing = false)\`
271
+ - Lighten or disable post-processing if not needed: \`SceneView(renderQuality = RenderQuality.Performance)\`, or \`view.isPostProcessingEnabled = false\` on the Filament \`View\`
272
272
  - Profile with Android GPU Inspector
273
273
 
274
274
  ### High Memory Usage
@@ -457,7 +457,8 @@ dependencies {
457
457
  <!-- Required: tells Play Store this app needs ARCore -->
458
458
  <!-- Use "required" to block installs on non-AR devices -->
459
459
  <!-- Use "optional" to allow install but degrade gracefully -->
460
- <meta-data android:name="com.google.ar.core" android:value="required" />
460
+ <!-- arsceneview declares "optional": overriding it needs xmlns:tools="http://schemas.android.com/tools" on <manifest> -->
461
+ <meta-data android:name="com.google.ar.core" android:value="required" tools:replace="android:value" />
461
462
 
462
463
  <!-- Required ONLY for Cloud Anchors / Geospatial / Streetscape.
463
464
  Inject via manifestPlaceholders in app/build.gradle (read from
@@ -561,18 +562,34 @@ ARSceneView(
561
562
 
562
563
  ### Tap-to-Place with Anchor
563
564
  \`\`\`kotlin
565
+ import com.google.ar.core.Anchor
566
+ import com.google.ar.core.Frame
567
+ import com.google.ar.core.Plane
568
+ import io.github.sceneview.ar.arcore.createAnchorOrNull
569
+ import io.github.sceneview.rememberOnGestureListener
570
+ // …plus androidx.compose.runtime.* and the io.github.sceneview entry points (ARSceneView, rememberEngine, …)
571
+
564
572
  var anchor by remember { mutableStateOf<Anchor?>(null) }
573
+ var latestFrame by remember { mutableStateOf<Frame?>(null) }
565
574
 
566
575
  ARSceneView(
567
576
  engine = engine,
568
577
  modelLoader = modelLoader,
569
578
  planeRenderer = true,
570
- onTouchEvent = { event, hitResult ->
571
- if (event.action == MotionEvent.ACTION_UP && hitResult != null) {
572
- anchor = hitResult.createAnchor()
579
+ onSessionUpdated = { _, frame -> latestFrame = frame },
580
+ // A confirmed single tap, never a raw ACTION_UP: the end of a drag or a pinch on the
581
+ // placed model must not move it. Leaving onTouchEvent unset keeps the model's gestures.
582
+ onGestureListener = rememberOnGestureListener(
583
+ onSingleTapConfirmed = { event, node ->
584
+ if (node == null) { // empty space, not the placed model
585
+ latestFrame?.hitTest(event)
586
+ ?.firstOrNull { (it.trackable as? Plane)?.isPoseInPolygon(it.hitPose) == true }
587
+ ?.createAnchorOrNull()
588
+ // Replacing the state key disposes the old AnchorNode, which detaches its anchor.
589
+ ?.let { anchor = it }
590
+ }
573
591
  }
574
- true
575
- }
592
+ )
576
593
  ) {
577
594
  anchor?.let { a ->
578
595
  AnchorNode(anchor = a) {
package/dist/http.js CHANGED
@@ -40,7 +40,7 @@
40
40
  *
41
41
  * Configuration (environment): PORT (default 3333), HOST (default
42
42
  * 127.0.0.1 — bind 0.0.0.0 explicitly to expose it), and the same
43
- * SCENEVIEW_TELEMETRY / SKETCHFAB_API_KEY / TRIPO_API_KEY knobs as stdio.
43
+ * SCENEVIEW_TELEMETRY / SKETCHFAB_API_KEY / TRIPO_API_KEY / RUNWARE_API_KEY knobs as stdio.
44
44
  */
45
45
  import { createServer as createNodeServer, } from "node:http";
46
46
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
package/dist/issues.js CHANGED
@@ -61,7 +61,7 @@ export const COMMON_ISSUES = [
61
61
  title: "AR objects drift / slide when moving phone",
62
62
  symptom: "Objects placed in AR slowly drift or jump to different positions as the user walks around.",
63
63
  cause: "Using `node.worldPosition = ...` instead of `AnchorNode`. ARCore remaps its coordinate system during tracking, and plain nodes don't compensate.",
64
- solution: "Always use `AnchorNode(anchor = hitResult.createAnchor())` to place AR objects. Anchors automatically compensate for coordinate system changes.",
64
+ solution: "Always place AR objects under `AnchorNode(anchor = anchor)`, with `anchor` from `createAnchorOrNull()` on an in-polygon ARCore plane hit (`latestFrame?.hitTest(event)` in `onSingleTapConfirmed`). Anchors automatically compensate for coordinate system changes.",
65
65
  category: "ar",
66
66
  },
67
67
  {
@@ -42,7 +42,7 @@ const MIGRATION_RULES = [
42
42
  id: "replace-placement-node",
43
43
  pattern: /\bPlacementNode\b/g,
44
44
  replacement: "/* PlacementNode removed — use AnchorNode + HitResultNode */",
45
- explanation: "`PlacementNode` removed. Use `AnchorNode(anchor = hitResult.createAnchor())` + `HitResultNode`.",
45
+ explanation: "`PlacementNode` removed. Use `HitResultNode` for the cursor and `AnchorNode(anchor = anchor)` for the placed model, with `anchor` created by `latestFrame?.hitTest(event)?.firstOrNull { … }?.createAnchorOrNull()` in `rememberOnGestureListener(onSingleTapConfirmed = { event, node -> if (node == null) … })`.",
46
46
  },
47
47
  {
48
48
  id: "replace-view-renderable",
@@ -95,8 +95,8 @@ const MIGRATION_RULES = [
95
95
  {
96
96
  id: "replace-worldPosition-ar",
97
97
  pattern: /(\w+)\.worldPosition\s*=\s*(.+)/g,
98
- replacement: "// $1.worldPosition = $2 ← replaced by AnchorNode(anchor = hitResult.createAnchor()) in 3.0",
99
- explanation: "Manual `worldPosition` in AR causes drift. Use `AnchorNode(anchor = hitResult.createAnchor())` instead.",
98
+ replacement: "// $1.worldPosition = $2 ← replaced by AnchorNode(anchor = anchor) in 3.0 (anchor from an ARCore plane hit's createAnchorOrNull())",
99
+ explanation: "Manual `worldPosition` in AR causes drift. Use `AnchorNode(anchor = anchor)` instead, with `anchor` from `createAnchorOrNull()` on an in-polygon ARCore plane hit (`latestFrame?.hitTest(event)`).",
100
100
  },
101
101
  // ── Camera manipulator ─────────────────────────────────────────────────
102
102
  {
@@ -147,12 +147,12 @@ const MIGRATION_RULES = [
147
147
  replacement: "/* ArFragment removed — use ARSceneView composable in Jetpack Compose */",
148
148
  explanation: "`ArFragment` (Android View-based) removed. Use `ARSceneView(...)` composable in Jetpack Compose.",
149
149
  },
150
- // ── onTapArPlane → onTouchEvent ─────────────────────────────────────
150
+ // ── onTapArPlane → onSingleTapConfirmed ────────────────────────────
151
151
  {
152
152
  id: "replace-onTapArPlane",
153
153
  pattern: /\.onTapArPlane\s*\{/g,
154
- replacement: "// .onTapArPlane removed — use ARSceneView(onTouchEvent = { hitResult, motionEvent ->",
155
- explanation: "`.onTapArPlane` removed. Use `ARSceneView(onTouchEvent = { hitResult, motionEvent -> ... })` and call `hitResult.createAnchor()` yourself.",
154
+ replacement: "// .onTapArPlane removed — use ARSceneView(onSessionUpdated = { _, frame -> latestFrame = frame }, onGestureListener = rememberOnGestureListener(onSingleTapConfirmed = { motionEvent, node -> if (node == null) latestFrame?.hitTest(motionEvent)?.firstOrNull { (it.trackable as? Plane)?.isPoseInPolygon(it.hitPose) == true }?.createAnchorOrNull()?.let { anchor = it } }))",
155
+ explanation: "`.onTapArPlane` removed. Keep the latest `Frame` from `onSessionUpdated`, then in `ARSceneView(onGestureListener = rememberOnGestureListener(onSingleTapConfirmed = { motionEvent, node -> if (node == null) ... }))` call `latestFrame?.hitTest(motionEvent)?.firstOrNull { (it.trackable as? Plane)?.isPoseInPolygon(it.hitPose) == true }?.createAnchorOrNull()`. Never place on a raw `ACTION_UP` in `onTouchEvent`: it also fires when a drag or a pinch ends. Imports: `com.google.ar.core.Plane`, `io.github.sceneview.ar.arcore.createAnchorOrNull`, `io.github.sceneview.rememberOnGestureListener`.",
156
156
  },
157
157
  ];
158
158
  export function migrateCode(code) {
@@ -222,7 +222,7 @@ export function migrateCode(code) {
222
222
  warnings.push("`.setParent()` removed in 3.0. Declare child nodes as composables inside the parent's content block instead.");
223
223
  }
224
224
  if (code.includes("onTapArPlane")) {
225
- warnings.push("`onTapArPlane` callback removed. In 3.0, use `onTouchEvent` on `ARScene` and call `hitResult.createAnchor()` yourself.");
225
+ warnings.push("`onTapArPlane` callback removed. In 3.0, use `onGestureListener = rememberOnGestureListener(onSingleTapConfirmed = { motionEvent, node -> if (node == null) … })` on `ARSceneView`, hit-test the latest ARCore `Frame` (`frame.hitTest(motionEvent)`), then `createAnchorOrNull()` on the in-polygon plane hit.");
226
226
  }
227
227
  return {
228
228
  originalCode: code,
package/dist/migration.js CHANGED
@@ -103,9 +103,9 @@ SceneView(engine = engine, modelLoader = modelLoader) {
103
103
  | 2.x | 3.0 replacement |
104
104
  |-----|-----------------|
105
105
  | \`TransformableNode\` | Set \`isEditable = true\` on \`ModelNode\` |
106
- | \`PlacementNode\` | \`AnchorNode(anchor = hitResult.createAnchor())\` + \`HitResultNode\` |
106
+ | \`PlacementNode\` | \`HitResultNode\` cursor + \`AnchorNode(anchor = anchor)\` (anchor from \`createAnchorOrNull()\` on a tapped plane hit) |
107
107
  | \`ViewRenderable\` | \`ViewNode\` with a \`@Composable\` content lambda |
108
- | \`AnchorNode()\` (no-arg) | \`AnchorNode(anchor = hitResult.createAnchor())\` |
108
+ | \`AnchorNode()\` (no-arg) | \`AnchorNode(anchor = anchor)\` (anchor from \`createAnchorOrNull()\` on a tapped plane hit) |
109
109
 
110
110
  **TransformableNode:**
111
111
  \`\`\`kotlin
@@ -206,7 +206,7 @@ ARSceneView(
206
206
 
207
207
  | 2.x pattern | 3.0 |
208
208
  |-------------|-----|
209
- | \`node.worldPosition = hitResult.hitPose.position\` | \`AnchorNode(anchor = hitResult.createAnchor())\` |
209
+ | \`node.worldPosition = hitResult.hitPose.position\` | \`AnchorNode(anchor = anchor)\`, \`anchor = hitResult.createAnchorOrNull()\` |
210
210
 
211
211
  Plain nodes whose \`worldPosition\` is set manually will drift when ARCore remaps its coordinate system. \`AnchorNode\` compensates automatically.
212
212
 
@@ -243,11 +243,11 @@ SceneView(
243
243
  - [ ] Replace \`TransformableNode\` → \`isEditable = true\`
244
244
  - [ ] Replace \`PlacementNode\` → \`AnchorNode\` + \`HitResultNode\`
245
245
  - [ ] Replace \`ViewRenderable\` → \`ViewNode\` with Compose lambda
246
- - [ ] Fix \`LightNode { … }\` → \`LightNode(apply = { … })\`
246
+ - [ ] Fix \`LightNode { … }\` → \`LightNode(type = LightManager.Type.POINT, apply = { … })\` (\`type\` is required)
247
247
  - [ ] Remove manual \`engine.destroy()\` calls
248
248
  - [ ] Replace manual \`worldPosition\` in AR → \`AnchorNode\`
249
249
  - [ ] Replace \`ArFragment\` → \`ARSceneView()\` composable
250
- - [ ] Replace \`onTapArPlane\` → \`onTouchEvent\`
250
+ - [ ] Replace \`onTapArPlane\` → \`rememberOnGestureListener(onSingleTapConfirmed = { event, node -> if (node == null) … })\` + \`latestFrame?.hitTest(event)\`
251
251
  - [ ] Replace \`setRenderable\` → \`ModelNode(modelInstance = ...)\`
252
252
  - [ ] Replace \`setParent\` → nest composable nodes inside parent
253
253
  - [ ] Move all Filament calls to main thread (no Dispatchers.IO)
@@ -275,7 +275,7 @@ SceneView(
275
275
  | 2.x | 3.0 |
276
276
  |-----|-----|
277
277
  | \`ArFragment\` in XML layout | \`ARSceneView()\` composable |
278
- | \`arFragment.setOnTapArPlaneListener\` | \`ARSceneView(onTouchEvent = { … })\` |
278
+ | \`arFragment.setOnTapArPlaneListener\` | \`ARSceneView(onGestureListener = rememberOnGestureListener(onSingleTapConfirmed = { event, node -> … }))\` |
279
279
  | \`arFragment.arSceneView\` | Direct access via composable params |
280
280
 
281
281
  ---
@@ -107,7 +107,8 @@ dependencies {
107
107
  <uses-feature android:name="android.hardware.camera.ar" android:required="true" />
108
108
 
109
109
  <application>
110
- <meta-data android:name="com.google.ar.core" android:value="required" />
110
+ <!-- arsceneview declares "optional": overriding it needs xmlns:tools="http://schemas.android.com/tools" on <manifest> -->
111
+ <meta-data android:name="com.google.ar.core" android:value="required" tools:replace="android:value" />
111
112
  </application>
112
113
  \`\`\`
113
114
 
@@ -126,11 +127,20 @@ LaunchedEffect(Unit) {
126
127
  ### 4. Basic AR Scene
127
128
 
128
129
  \`\`\`kotlin
130
+ import com.google.ar.core.Anchor
131
+ import com.google.ar.core.Config
132
+ import com.google.ar.core.Frame
133
+ import com.google.ar.core.Plane
134
+ import io.github.sceneview.ar.arcore.createAnchorOrNull
135
+ import io.github.sceneview.rememberOnGestureListener
136
+ // …plus androidx.compose.runtime.* and the io.github.sceneview entry points (ARSceneView, rememberEngine, …)
137
+
129
138
  @Composable
130
139
  fun MyARScreen() {
131
140
  val engine = rememberEngine()
132
141
  val modelLoader = rememberModelLoader(engine)
133
142
  var anchor by remember { mutableStateOf<Anchor?>(null) }
143
+ var latestFrame by remember { mutableStateOf<Frame?>(null) }
134
144
 
135
145
  val modelInstance = rememberModelInstance(modelLoader, "models/robot.glb")
136
146
 
@@ -146,12 +156,20 @@ fun MyARScreen() {
146
156
  config.lightEstimationMode = Config.LightEstimationMode.ENVIRONMENTAL_HDR
147
157
  config.planeFindingMode = Config.PlaneFindingMode.HORIZONTAL_AND_VERTICAL
148
158
  },
149
- onTouchEvent = { event, hitResult ->
150
- if (event.action == MotionEvent.ACTION_UP && hitResult != null) {
151
- anchor = hitResult.createAnchor()
159
+ onSessionUpdated = { _, frame -> latestFrame = frame },
160
+ // A confirmed single tap, never a raw ACTION_UP: the end of a drag or a pinch on the
161
+ // placed model must not move it. Leaving onTouchEvent unset keeps the model's gestures.
162
+ onGestureListener = rememberOnGestureListener(
163
+ onSingleTapConfirmed = { event, node ->
164
+ if (node == null) { // empty space, not the placed model
165
+ latestFrame?.hitTest(event)
166
+ ?.firstOrNull { (it.trackable as? Plane)?.isPoseInPolygon(it.hitPose) == true }
167
+ ?.createAnchorOrNull()
168
+ // Replacing the state key disposes the old AnchorNode, which detaches its anchor.
169
+ ?.let { anchor = it }
170
+ }
152
171
  }
153
- true
154
- }
172
+ )
155
173
  ) {
156
174
  anchor?.let { a ->
157
175
  AnchorNode(anchor = a) {
@@ -267,8 +285,10 @@ SceneViewSwift provides ${IOS_NODE_TYPE_COUNT} node types:
267
285
  | \`BillboardNode\` | Camera-facing nodes (labels, health bars, icons) |
268
286
  | \`VideoNode\` | Video playback on a 3D plane |
269
287
  | \`ImageNode\` | Image display on a 3D plane |
288
+ | \`ContactShadowNode\` | Soft contact shadow decal that grounds an object on a floor, table or wall |
270
289
  | \`LineNode\` | Line segments between 3D points |
271
290
  | \`PathNode\` | Connected line paths through multiple points |
291
+ | \`TubeNode\` | Solid tube swept along a polyline (one continuous mesh) |
272
292
  | \`MeshNode\` | Custom mesh geometry with vertex data |
273
293
  | \`ShapeNode\` | 2D polygon shapes, flat or extruded |
274
294
  | \`ViewNode\` | Placeholder plane for embedding a SwiftUI view (content not rendered yet) |
@@ -400,7 +420,7 @@ fun main() {
400
420
  directional()
401
421
  intensity(100_000.0)
402
422
  }
403
- model("models/DamagedHelmet.glb")
423
+ model("https://sceneview.github.io/models/platforms/moto_helmet_v2.glb") // Motorcycle Helmet by sayedgamal655, CC-BY 4.0
404
424
  autoRotate()
405
425
  },
406
426
  onReady = { sceneView ->
@@ -533,7 +553,8 @@ dependencies:
533
553
  <uses-permission android:name="android.permission.CAMERA" />
534
554
  <uses-feature android:name="android.hardware.camera.ar" android:required="true" />
535
555
  <application>
536
- <meta-data android:name="com.google.ar.core" android:value="required" />
556
+ <!-- arsceneview declares "optional": overriding it needs xmlns:tools="http://schemas.android.com/tools" on <manifest> -->
557
+ <meta-data android:name="com.google.ar.core" android:value="required" tools:replace="android:value" />
537
558
  </application>
538
559
  \`\`\`
539
560
 
@@ -679,7 +700,8 @@ Add to \`AndroidManifest.xml\`:
679
700
  <uses-permission android:name="android.permission.CAMERA" />
680
701
  <uses-feature android:name="android.hardware.camera.ar" android:required="true" />
681
702
  <application>
682
- <meta-data android:name="com.google.ar.core" android:value="required" />
703
+ <!-- arsceneview declares "optional": overriding it needs xmlns:tools="http://schemas.android.com/tools" on <manifest> -->
704
+ <meta-data android:name="com.google.ar.core" android:value="required" tools:replace="android:value" />
683
705
  </application>
684
706
  \`\`\`
685
707
 
package/dist/preview.js CHANGED
@@ -5,7 +5,8 @@
5
5
  // 1. Model URL → direct model-viewer embed link
6
6
  // 2. Code snippet → embed link with default model + code panel
7
7
  const PREVIEW_BASE = "https://sceneview.github.io/preview";
8
- const DEFAULT_MODEL_URL = "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Assets/main/Models/DamagedHelmet/glTF-Binary/DamagedHelmet.glb";
8
+ // Motorcycle Helmet by sayedgamal655, CC-BY 4.0, served from the SceneView website.
9
+ const DEFAULT_MODEL_URL = "https://sceneview.github.io/models/platforms/moto_helmet_v2.glb";
9
10
  /**
10
11
  * Build a sceneview.github.io/preview URL from the given options.
11
12
  *
package/dist/samples.js CHANGED
@@ -41,12 +41,31 @@ fun ModelViewerScreen() {
41
41
  tags: ["ar", "model", "anchor", "plane-detection", "placement", "gestures"],
42
42
  dependency: "io.github.sceneview:arsceneview:" + LATEST_SCENEVIEW_RELEASE + "",
43
43
  prompt: `Create an AR screen that detects surfaces and lets the user tap to place a GLB model. Support pinch-to-scale and drag-to-rotate. Use SceneView \`io.github.sceneview:arsceneview:${LATEST_SCENEVIEW_RELEASE}\`.`,
44
- code: `@Composable
44
+ code: `import androidx.compose.foundation.layout.fillMaxSize
45
+ import androidx.compose.runtime.Composable
46
+ import androidx.compose.runtime.getValue
47
+ import androidx.compose.runtime.mutableStateOf
48
+ import androidx.compose.runtime.remember
49
+ import androidx.compose.runtime.setValue
50
+ import androidx.compose.ui.Modifier
51
+ import com.google.ar.core.Anchor
52
+ import com.google.ar.core.Config
53
+ import com.google.ar.core.Frame
54
+ import com.google.ar.core.Plane
55
+ import io.github.sceneview.ar.ARSceneView
56
+ import io.github.sceneview.ar.arcore.createAnchorOrNull
57
+ import io.github.sceneview.rememberEngine
58
+ import io.github.sceneview.rememberModelInstance
59
+ import io.github.sceneview.rememberModelLoader
60
+ import io.github.sceneview.rememberOnGestureListener
61
+
62
+ @Composable
45
63
  fun ARModelViewerScreen() {
46
64
  val engine = rememberEngine()
47
65
  val modelLoader = rememberModelLoader(engine)
48
66
  val modelInstance = rememberModelInstance(modelLoader, "models/toy_car.glb")
49
67
  var anchor by remember { mutableStateOf<Anchor?>(null) }
68
+ var latestFrame by remember { mutableStateOf<Frame?>(null) }
50
69
 
51
70
  ARSceneView(
52
71
  modifier = Modifier.fillMaxSize(),
@@ -59,11 +78,20 @@ fun ARModelViewerScreen() {
59
78
  Config.DepthMode.AUTOMATIC else Config.DepthMode.DISABLED
60
79
  config.lightEstimationMode = Config.LightEstimationMode.ENVIRONMENTAL_HDR
61
80
  },
62
- onTouchEvent = { event, hitResult ->
63
- if (event.action == MotionEvent.ACTION_UP && hitResult != null)
64
- anchor = hitResult.createAnchor()
65
- true
66
- }
81
+ onSessionUpdated = { _, frame -> latestFrame = frame },
82
+ // A confirmed single tap, never a raw ACTION_UP: the end of a drag or a pinch on the
83
+ // placed model must not move it. Leaving onTouchEvent unset keeps the model's gestures.
84
+ onGestureListener = rememberOnGestureListener(
85
+ onSingleTapConfirmed = { event, node ->
86
+ if (node == null) { // empty space, not the placed model
87
+ latestFrame?.hitTest(event)
88
+ ?.firstOrNull { (it.trackable as? Plane)?.isPoseInPolygon(it.hitPose) == true }
89
+ ?.createAnchorOrNull()
90
+ // Replacing the state key disposes the old AnchorNode, which detaches its anchor.
91
+ ?.let { anchor = it }
92
+ }
93
+ }
94
+ )
67
95
  ) {
68
96
  anchor?.let { a ->
69
97
  AnchorNode(anchor = a) {
@@ -286,8 +314,10 @@ fun CameraManipulatorScreen() {
286
314
  engine = engine,
287
315
  modelLoader = modelLoader,
288
316
  cameraNode = cameraNode,
317
+ // A fixed eye, never a live value such as cameraNode.worldPosition: the manipulator
318
+ // is keyed on it, and the camera node moves on every orbit.
289
319
  cameraManipulator = rememberCameraManipulator(
290
- orbitHomePosition = cameraNode.worldPosition,
320
+ orbitHomePosition = Position(z = 4f),
291
321
  targetPosition = Position(0f)
292
322
  )
293
323
  ) {
@@ -691,6 +721,7 @@ fun LinePathScreen() {
691
721
  code: `@Composable
692
722
  fun TextLabelsScreen() {
693
723
  val engine = rememberEngine()
724
+ val cameraNode = rememberCameraNode(engine)
694
725
  val materialLoader = rememberMaterialLoader(engine)
695
726
  val environmentLoader = rememberEnvironmentLoader(engine)
696
727
 
@@ -704,6 +735,7 @@ fun TextLabelsScreen() {
704
735
  SceneView(
705
736
  modifier = Modifier.fillMaxSize(),
706
737
  engine = engine,
738
+ cameraNode = cameraNode,
707
739
  cameraManipulator = rememberCameraManipulator(
708
740
  orbitHomePosition = Position(x = 0f, y = 1.5f, z = 5f),
709
741
  targetPosition = Position(0f, 0.5f, 0f)
@@ -733,7 +765,9 @@ fun TextLabelsScreen() {
733
765
  backgroundColor = 0xCC000000.toInt(),
734
766
  widthMeters = 0.6f,
735
767
  heightMeters = 0.2f,
736
- position = Position(x = planet.x, y = 0.9f, z = 0f)
768
+ position = Position(x = planet.x, y = 0.9f, z = 0f),
769
+ // Without a provider a TextNode does not turn toward the camera.
770
+ cameraPositionProvider = { cameraNode.worldPosition }
737
771
  )
738
772
  }
739
773
  }
@@ -806,36 +840,27 @@ fun PostProcessingScreen() {
806
840
  "video-texture": {
807
841
  id: "video-texture",
808
842
  title: "Video Texture",
809
- description: "Video playback on a 3D plane using VideoNode with MediaPlayer — supports looping, chroma-key, and auto-sizing.",
843
+ description: "Video playback on a 3D plane using VideoNode — prepared off the main thread, with play/pause, looping, chroma-key, auto-sizing and an error callback.",
810
844
  tags: ["3d", "video", "model"],
811
845
  dependency: "io.github.sceneview:sceneview:" + LATEST_SCENEVIEW_RELEASE + "",
812
846
  prompt: `Create a 3D scene with a video playing on a floating 3D plane. Include play/pause controls and chroma-key support. Use SceneView \`io.github.sceneview:sceneview:${LATEST_SCENEVIEW_RELEASE}\`.`,
813
- code: `@Composable
847
+ code: `@OptIn(ExperimentalSceneViewApi::class)
848
+ @Composable
814
849
  fun VideoTextureScreen() {
815
- val context = LocalContext.current
816
- val engine = rememberEngine()
817
850
  var isPlaying by remember { mutableStateOf(true) }
818
-
819
- val player = remember {
820
- MediaPlayer().apply {
821
- setDataSource(context, Uri.parse("android.resource://\${context.packageName}/raw/video"))
822
- isLooping = true
823
- prepare()
824
- start()
825
- }
826
- }
827
- DisposableEffect(Unit) { onDispose { player.release() } }
851
+ var error by remember { mutableStateOf<Exception?>(null) }
828
852
 
829
853
  Column {
830
- SceneView(
831
- modifier = Modifier.weight(1f).fillMaxWidth(),
832
- engine = engine
833
- ) {
854
+ SceneView(modifier = Modifier.weight(1f).fillMaxWidth()) {
855
+ // Prepared off the main thread: the node appears once the video is ready.
834
856
  VideoNode(
835
- player = player,
857
+ videoPath = "videos/promo.mp4", // under assets/, or an https:// URL
858
+ autoPlay = isPlaying, // reactive: true plays, false pauses
859
+ isLooping = true,
836
860
  // size = null auto-sizes from video aspect ratio (longer edge = 1 unit)
837
861
  position = Position(z = -2f),
838
- chromaKeyColor = null // set to android.graphics.Color.GREEN for green-screen
862
+ chromaKeyColor = null, // set to android.graphics.Color.GREEN for green-screen
863
+ onError = { cause -> error = cause } // missing file, unsupported codec, broken stream
839
864
  )
840
865
  }
841
866
  Row(
@@ -843,11 +868,12 @@ fun VideoTextureScreen() {
843
868
  horizontalArrangement = Arrangement.Center,
844
869
  verticalAlignment = Alignment.CenterVertically
845
870
  ) {
846
- Button(onClick = {
847
- if (isPlaying) player.pause() else player.start()
848
- isPlaying = !isPlaying
849
- }) {
850
- Text(if (isPlaying) "Pause" else "Play")
871
+ if (error != null) {
872
+ Text("This video cannot be played.")
873
+ } else {
874
+ Button(onClick = { isPlaying = !isPlaying }) {
875
+ Text(if (isPlaying) "Pause" else "Play")
876
+ }
851
877
  }
852
878
  }
853
879
  }
@@ -1969,7 +1995,28 @@ fun SpringAnimationScreen() {
1969
1995
  tags: ["ar", "cursor", "plane-detection", "placement"],
1970
1996
  dependency: "io.github.sceneview:arsceneview:" + LATEST_SCENEVIEW_RELEASE + "",
1971
1997
  prompt: `Create an AR screen with a surface cursor (reticle) in the center of the screen that follows detected surfaces, using HitResultNode. Tap to place a model at the cursor position. Use SceneView \`io.github.sceneview:arsceneview:${LATEST_SCENEVIEW_RELEASE}\`.`,
1972
- code: `@Composable
1998
+ code: `import androidx.compose.foundation.layout.fillMaxSize
1999
+ import androidx.compose.runtime.Composable
2000
+ import androidx.compose.runtime.getValue
2001
+ import androidx.compose.runtime.mutableStateOf
2002
+ import androidx.compose.runtime.remember
2003
+ import androidx.compose.runtime.setValue
2004
+ import androidx.compose.ui.Modifier
2005
+ import androidx.compose.ui.graphics.Color
2006
+ import androidx.compose.ui.platform.LocalView
2007
+ import com.google.ar.core.Anchor
2008
+ import com.google.ar.core.Config
2009
+ import com.google.ar.core.Frame
2010
+ import com.google.ar.core.Plane
2011
+ import io.github.sceneview.ar.ARSceneView
2012
+ import io.github.sceneview.ar.arcore.createAnchorOrNull
2013
+ import io.github.sceneview.rememberEngine
2014
+ import io.github.sceneview.rememberMaterialLoader
2015
+ import io.github.sceneview.rememberModelInstance
2016
+ import io.github.sceneview.rememberModelLoader
2017
+ import io.github.sceneview.rememberOnGestureListener
2018
+
2019
+ @Composable
1973
2020
  fun ARSurfaceCursorScreen() {
1974
2021
  val engine = rememberEngine()
1975
2022
  val modelLoader = rememberModelLoader(engine)
@@ -1977,6 +2024,7 @@ fun ARSurfaceCursorScreen() {
1977
2024
  val view = LocalView.current
1978
2025
  val modelInstance = rememberModelInstance(modelLoader, "models/chair.glb")
1979
2026
  var placedAnchors by remember { mutableStateOf(listOf<Anchor>()) }
2027
+ var latestFrame by remember { mutableStateOf<Frame?>(null) }
1980
2028
 
1981
2029
  ARSceneView(
1982
2030
  modifier = Modifier.fillMaxSize(),
@@ -1988,19 +2036,33 @@ fun ARSurfaceCursorScreen() {
1988
2036
  Config.DepthMode.AUTOMATIC else Config.DepthMode.DISABLED
1989
2037
  config.lightEstimationMode = Config.LightEstimationMode.ENVIRONMENTAL_HDR
1990
2038
  },
1991
- onTouchEvent = { event, hitResult ->
1992
- if (event.action == MotionEvent.ACTION_UP && hitResult != null) {
1993
- placedAnchors = placedAnchors + hitResult.createAnchor()
2039
+ onSessionUpdated = { _, frame -> latestFrame = frame },
2040
+ // A confirmed single tap, never a raw ACTION_UP: the end of a drag or a pinch on a
2041
+ // placed model must not drop another one. Leaving onTouchEvent unset keeps those gestures.
2042
+ onGestureListener = rememberOnGestureListener(
2043
+ onSingleTapConfirmed = { _, node ->
2044
+ if (node == null) { // empty space, not a placed model
2045
+ // Place at the cursor (screen centre), wherever the finger landed.
2046
+ latestFrame?.hitTest(view.width / 2f, view.height / 2f)
2047
+ ?.firstOrNull { (it.trackable as? Plane)?.isPoseInPolygon(it.hitPose) == true }
2048
+ ?.createAnchorOrNull()
2049
+ ?.let { placedAnchors = placedAnchors + it } // keep every placed model
2050
+ }
1994
2051
  }
1995
- true
1996
- }
2052
+ )
1997
2053
  ) {
1998
2054
  // Surface cursor — follows the center of the screen
1999
2055
  val cursorMat = remember(materialLoader) {
2000
2056
  materialLoader.createColorInstance(Color.White.copy(alpha = 0.6f))
2001
2057
  }
2002
2058
  HitResultNode(xPx = view.width / 2f, yPx = view.height / 2f) {
2003
- CylinderNode(radius = 0.03f, height = 0.005f, materialInstance = cursorMat)
2059
+ CylinderNode(
2060
+ radius = 0.03f,
2061
+ height = 0.005f,
2062
+ materialInstance = cursorMat,
2063
+ // Not touchable, so a tap on the reticle still counts as empty space.
2064
+ apply = { isTouchable = false }
2065
+ )
2004
2066
  }
2005
2067
 
2006
2068
  // Placed models
@@ -2050,7 +2112,7 @@ fun main() {
2050
2112
  intensity(100_000.0)
2051
2113
  direction(0.0f, -1.0f, -0.5f)
2052
2114
  }
2053
- model("models/DamagedHelmet.glb")
2115
+ model("https://sceneview.github.io/models/platforms/moto_helmet_v2.glb") // Motorcycle Helmet by sayedgamal655, CC-BY 4.0
2054
2116
  },
2055
2117
  onReady = { sceneView ->
2056
2118
  sceneView.startRendering()
@@ -2094,7 +2156,7 @@ fun main() {
2094
2156
  iblUrl = "environments/pillars_2k_ibl.ktx",
2095
2157
  skyboxUrl = "environments/pillars_2k_skybox.ktx"
2096
2158
  )
2097
- model("models/DamagedHelmet.glb")
2159
+ model("https://sceneview.github.io/models/platforms/moto_helmet_v2.glb") // Motorcycle Helmet by sayedgamal655, CC-BY 4.0
2098
2160
  },
2099
2161
  onReady = { sceneView ->
2100
2162
  sceneView.startRendering()
@@ -603,7 +603,7 @@ export const TOOL_DEFINITIONS = [
603
603
  },
604
604
  {
605
605
  name: "get_collision_guide",
606
- description: "Returns a comprehensive guide for collision detection, hit testing, and physics in SceneView — node tapping (onTouchEvent), AR surface hit testing (frame.hitTest), ray-box/ray-sphere intersection (KMP core), bounding boxes, and basic rigid body physics. Use this when a user asks about tapping 3D objects, collision detection, physics simulation, ray casting, or hit testing.",
606
+ description: "Returns a comprehensive guide for collision detection, hit testing, and physics in SceneView — node tapping (onSingleTapConfirmed), AR tap-to-place (frame.hitTest on a confirmed tap), ray-box/ray-sphere intersection (KMP core), bounding boxes, and basic rigid body physics. Use this when a user asks about tapping 3D objects, collision detection, physics simulation, ray casting, or hit testing.",
607
607
  inputSchema: {
608
608
  type: "object",
609
609
  properties: {},
@@ -680,7 +680,7 @@ export const TOOL_DEFINITIONS = [
680
680
  },
681
681
  {
682
682
  name: "generate_3d_model",
683
- description: 'Generates a brand-new 3D model (GLB) from a text prompt OR a source image using the Tripo AI API — use this when `search_models` finds no suitable existing asset and the user needs a custom one ("a low-poly cactus in a striped pot"). Returns a direct GLB download URL (expires ~5 minutes — download it immediately and self-host it) plus license/attribution metadata, ready for `rememberModelInstance(modelLoader, ...)` and AR placement. Quality tiers: "fast" (default, Tripo P1 low-poly — AR-ready, ~25-30 s) or "hd" (Tripo H3.1 quad topology with detailed geometry/textures — up to ~100 s, pricier). Requires a `TRIPO_API_KEY` environment variable (BYOK — generations are billed to the USER\'S Tripo account, roughly $0.10-0.25 per fast generation and ~$0.41 per hd generation as of July 2026; nothing is charged by SceneView). If the key is missing, the tool returns setup instructions for platform.tripo3d.ai/api-keys.',
683
+ description: 'Generates a brand-new 3D model (GLB) from a text prompt OR a source image, with TRELLIS.2 on Runware or with Tripo AI — use this when `search_models` finds no suitable existing asset and the user needs a custom one ("a low-poly cactus in a striped pot"). Returns a direct GLB download URL (expires ~5 minutes — download it immediately and self-host it) plus license/attribution metadata, ready for `rememberModelInstance(modelLoader, ...)` and AR placement. Providers (BYOK — billed to the USER\'S own account, nothing is charged by SceneView): "trellis" = Microsoft TRELLIS.2 on Runware, needs `RUNWARE_API_KEY` (my.runware.ai/keys), roughly $0.01-0.03 per model as of November 2026, ~40-90 s, text→3D renders a FLUX concept image first; "tripo" = Tripo AI, needs `TRIPO_API_KEY` (platform.tripo3d.ai/api-keys), roughly $0.10-0.25 per fast and ~$0.41 per hd generation as of July 2026. Without `provider`, Tripo is used when `TRIPO_API_KEY` is set, otherwise TRELLIS.2 when `RUNWARE_API_KEY` is set. Quality tiers: "fast" (default — Tripo P1 low-poly, or TRELLIS.2 at 1024³) or "hd" (Tripo H3.1 quad topology, or TRELLIS.2 at 1536³ — slower, pricier). If no key is set, the tool returns setup instructions for both providers.',
684
684
  inputSchema: {
685
685
  type: "object",
686
686
  properties: {
@@ -695,7 +695,12 @@ export const TOOL_DEFINITIONS = [
695
695
  quality: {
696
696
  type: "string",
697
697
  enum: ["fast", "hd"],
698
- description: '"fast" (default): Tripo P1 low-poly — cheap, AR-ready, ~25-30 s. "hd": Tripo H3.1 quad topology + detailed geometry/textures — up to ~100 s, higher credit cost.',
698
+ description: '"fast" (default): Tripo P1 low-poly (~25-30 s) or TRELLIS.2 1024³ — cheap, AR-ready. "hd": Tripo H3.1 quad topology (up to ~100 s) or TRELLIS.2 1536³ — more detail, higher cost.',
699
+ },
700
+ provider: {
701
+ type: "string",
702
+ enum: ["trellis", "tripo"],
703
+ description: '"trellis": Microsoft TRELLIS.2 on Runware (`RUNWARE_API_KEY`, a few US cents per model, image-faithful PBR mesh). "tripo": Tripo AI (`TRIPO_API_KEY`). Omit to pick whichever key is configured (Tripo first).',
699
704
  },
700
705
  },
701
706
  required: [],