-
-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathllms.txt
More file actions
3126 lines (2629 loc) · 111 KB
/
llms.txt
File metadata and controls
3126 lines (2629 loc) · 111 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SceneView
SceneView is a declarative 3D and AR SDK for Android (Jetpack Compose, Filament, ARCore) and Apple platforms — iOS, macOS, visionOS (SwiftUI, RealityKit, ARKit) — with shared core logic via Kotlin Multiplatform. Each platform uses its native renderer: Filament on Android, RealityKit on Apple.
**Android — Maven artifacts (version 4.0.1):**
- 3D only: `io.github.sceneview:sceneview:4.0.1`
- AR + 3D: `io.github.sceneview:arsceneview:4.0.1`
**Apple (iOS 17+ / macOS 14+ / visionOS 1+) — Swift Package:**
- `https://github.com/sceneview/sceneview-swift.git` (from: "4.0.0")
**Min SDK:** 24 | **Target SDK:** 36 | **Kotlin:** 2.3.20 | **Compose BOM compatible**
---
## Setup
### build.gradle (app module)
```kotlin
dependencies {
implementation("io.github.sceneview:sceneview:4.0.1") // 3D only
implementation("io.github.sceneview:arsceneview:4.0.1") // AR (includes sceneview)
}
```
### AndroidManifest.xml (AR apps)
```xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.ar" android:required="true" />
<application>
<meta-data android:name="com.google.ar.core" android:value="required" />
</application>
```
---
## Core Composables
### SceneView — 3D viewport
Full signature:
```kotlin
@Composable
fun SceneView(
modifier: Modifier = Modifier,
surfaceType: SurfaceType = SurfaceType.Surface,
engine: Engine = rememberEngine(),
modelLoader: ModelLoader = rememberModelLoader(engine),
materialLoader: MaterialLoader = rememberMaterialLoader(engine),
environmentLoader: EnvironmentLoader = rememberEnvironmentLoader(engine),
view: View = rememberView(engine),
isOpaque: Boolean = true,
renderer: Renderer = rememberRenderer(engine),
scene: Scene = rememberScene(engine),
environment: Environment = rememberEnvironment(environmentLoader, isOpaque = isOpaque),
mainLightNode: LightNode? = rememberMainLightNode(engine),
cameraNode: CameraNode = rememberCameraNode(engine),
collisionSystem: CollisionSystem = rememberCollisionSystem(view),
cameraManipulator: CameraGestureDetector.CameraManipulator? = rememberCameraManipulator(cameraNode.worldPosition),
viewNodeWindowManager: ViewNode.WindowManager? = null,
onGestureListener: GestureDetector.OnGestureListener? = rememberOnGestureListener(),
onTouchEvent: ((e: MotionEvent, hitResult: HitResult?) -> Boolean)? = null,
permissionHandler: ARPermissionHandler? = /* auto from ComponentActivity */,
lifecycle: Lifecycle = LocalLifecycleOwner.current.lifecycle,
onFrame: ((frameTimeNanos: Long) -> Unit)? = null,
content: (@Composable SceneScope.() -> Unit)? = null
)
```
Minimal usage:
```kotlin
@Composable
fun My3DScreen() {
val engine = rememberEngine()
val modelLoader = rememberModelLoader(engine)
val environmentLoader = rememberEnvironmentLoader(engine)
SceneView(
modifier = Modifier.fillMaxSize(),
engine = engine,
modelLoader = modelLoader,
cameraManipulator = rememberCameraManipulator(),
environment = rememberEnvironment(environmentLoader) {
environmentLoader.createHDREnvironment("environments/sky_2k.hdr")
?: createEnvironment(environmentLoader)
},
mainLightNode = rememberMainLightNode(engine) { intensity = 100_000f }
) {
rememberModelInstance(modelLoader, "models/helmet.glb")?.let { instance ->
ModelNode(modelInstance = instance, scaleToUnits = 1.0f)
}
}
}
```
### ARSceneView — AR viewport
Full signature:
```kotlin
@Composable
fun ARSceneView(
modifier: Modifier = Modifier,
surfaceType: SurfaceType = SurfaceType.Surface,
engine: Engine = rememberEngine(),
modelLoader: ModelLoader = rememberModelLoader(engine),
materialLoader: MaterialLoader = rememberMaterialLoader(engine),
environmentLoader: EnvironmentLoader = rememberEnvironmentLoader(engine),
sessionFeatures: Set<Session.Feature> = setOf(),
sessionCameraConfig: ((Session) -> CameraConfig)? = null,
sessionConfiguration: ((session: Session, Config) -> Unit)? = null,
planeRenderer: Boolean = true,
cameraStream: ARCameraStream? = rememberARCameraStream(materialLoader),
view: View = rememberARView(engine),
isOpaque: Boolean = true,
cameraExposure: Float? = null,
renderer: Renderer = rememberRenderer(engine),
scene: Scene = rememberScene(engine),
environment: Environment = rememberAREnvironment(engine),
mainLightNode: LightNode? = rememberMainLightNode(engine),
cameraNode: ARCameraNode = rememberARCameraNode(engine),
collisionSystem: CollisionSystem = rememberCollisionSystem(view),
viewNodeWindowManager: ViewNode.WindowManager? = null,
onSessionCreated: ((session: Session) -> Unit)? = null,
onSessionResumed: ((session: Session) -> Unit)? = null,
onSessionPaused: ((session: Session) -> Unit)? = null,
onSessionFailed: ((exception: Exception) -> Unit)? = null,
onSessionUpdated: ((session: Session, frame: Frame) -> Unit)? = null,
onTrackingFailureChanged: ((trackingFailureReason: TrackingFailureReason?) -> Unit)? = null,
onGestureListener: GestureDetector.OnGestureListener? = rememberOnGestureListener(),
onTouchEvent: ((e: MotionEvent, hitResult: HitResult?) -> Boolean)? = null,
permissionHandler: ARPermissionHandler? = /* auto from ComponentActivity */,
lifecycle: Lifecycle = LocalLifecycleOwner.current.lifecycle,
content: (@Composable ARSceneScope.() -> Unit)? = null
)
```
Minimal usage:
```kotlin
@Composable
fun MyARScreen() {
val engine = rememberEngine()
val modelLoader = rememberModelLoader(engine)
ARSceneView(
modifier = Modifier.fillMaxSize(),
engine = engine,
modelLoader = modelLoader,
planeRenderer = true,
sessionConfiguration = { session, config ->
config.depthMode = Config.DepthMode.AUTOMATIC
config.instantPlacementMode = Config.InstantPlacementMode.LOCAL_Y_UP
config.lightEstimationMode = Config.LightEstimationMode.ENVIRONMENTAL_HDR
},
onSessionCreated = { session -> /* ARCore session ready */ },
onSessionResumed = { session -> /* session resumed */ },
onSessionFailed = { exception -> /* ARCore init error — show fallback UI */ },
onSessionUpdated = { session, frame -> /* per-frame AR logic */ },
onTrackingFailureChanged = { reason -> /* camera tracking lost/restored */ }
) {
// ARSceneScope DSL here — AnchorNode, AugmentedImageNode, etc.
}
}
```
---
## SceneScope — Node DSL
All content inside `SceneView { }` or `ARSceneView { }` is a `SceneScope`. Available properties:
- `engine: Engine`
- `modelLoader: ModelLoader`
- `materialLoader: MaterialLoader`
- `environmentLoader: EnvironmentLoader`
### Node — empty pivot/group
```kotlin
@Composable fun Node(
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(x = 1f),
isVisible: Boolean = true,
isEditable: Boolean = false,
apply: Node.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
Usage — group nodes:
```kotlin
SceneView(...) {
Node(position = Position(y = 1f)) {
ModelNode(modelInstance = instance, position = Position(x = -1f))
CubeNode(size = Size(0.1f), position = Position(x = 1f))
}
}
```
### ModelNode — 3D model
```kotlin
@Composable fun ModelNode(
modelInstance: ModelInstance,
autoAnimate: Boolean = true,
animationName: String? = null,
animationLoop: Boolean = true,
animationSpeed: Float = 1f,
scaleToUnits: Float? = null,
centerOrigin: Position? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(x = 1f),
isVisible: Boolean = true,
isEditable: Boolean = false,
apply: ModelNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
Key behaviors:
- `scaleToUnits`: uniformly scales to fit within a cube of this size (meters). `null` = original size.
- `centerOrigin`: `Position(0,0,0)` = center model. `Position(0,-1,0)` = center horizontal, bottom-aligned. `null` = keep original.
- `autoAnimate = true` + `animationName = null`: plays ALL animations.
- `animationName = "Walk"`: plays only that named animation (stops previous). Reactive to Compose state.
Reactive animation example:
```kotlin
var isWalking by remember { mutableStateOf(false) }
SceneView(...) {
instance?.let {
ModelNode(
modelInstance = it,
autoAnimate = false,
animationName = if (isWalking) "Walk" else "Idle",
animationLoop = true,
animationSpeed = 1f
)
}
}
// When animationName changes, the previous animation stops and the new one starts.
```
ModelNode class properties (available via `apply` block):
- `renderableNodes: List<RenderableNode>` — submesh nodes
- `lightNodes: List<LightNode>` — embedded lights
- `cameraNodes: List<CameraNode>` — embedded cameras
- `boundingBox: Box` — glTF AABB
- `animationCount: Int`
- `isShadowCaster: Boolean`
- `isShadowReceiver: Boolean`
- `materialVariantNames: List<String>`
- `skinCount: Int`, `skinNames: List<String>`
- `playAnimation(index: Int, speed: Float = 1f, loop: Boolean = true)`
- `playAnimation(name: String, speed: Float = 1f, loop: Boolean = true)`
- `stopAnimation(index: Int)`, `stopAnimation(name: String)`
- `setAnimationSpeed(index: Int, speed: Float)`
- `scaleToUnitCube(units: Float = 1.0f)`
- `centerOrigin(origin: Position = Position(0f, 0f, 0f))`
- `onFrameError: ((Exception) -> Unit)?` — callback for frame errors (default: logs via Log.e)
### LightNode — light source
**CRITICAL: `apply` is a named parameter (`apply = { ... }`), NOT a trailing lambda.**
```kotlin
@Composable fun LightNode(
type: LightManager.Type,
intensity: Float? = null, // lux (directional/sun) or candela (point/spot)
direction: Direction? = null, // for directional/spot/sun
position: Position = Position(x = 0f),
apply: LightManager.Builder.() -> Unit = {}, // advanced: color, falloff, spotLightCone, etc.
nodeApply: LightNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
`LightManager.Type` values: `DIRECTIONAL`, `POINT`, `SPOT`, `FOCUSED_SPOT`, `SUN`.
```kotlin
SceneView(...) {
// Simple — use explicit params (recommended):
LightNode(
type = LightManager.Type.SUN,
intensity = 100_000f,
direction = Direction(0f, -1f, 0f),
apply = { castShadows(true) }
)
// Advanced — use apply for full Builder access:
LightNode(
type = LightManager.Type.SPOT,
intensity = 50_000f,
position = Position(2f, 3f, 0f),
apply = { falloff(5.0f); spotLightCone(0.1f, 0.5f) }
)
}
```
### CubeNode — box geometry
```kotlin
@Composable fun CubeNode(
size: Size = Cube.DEFAULT_SIZE, // Size(1f, 1f, 1f)
center: Position = Cube.DEFAULT_CENTER, // Position(0f, 0f, 0f)
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: CubeNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### SphereNode — sphere geometry
```kotlin
@Composable fun SphereNode(
radius: Float = Sphere.DEFAULT_RADIUS, // 0.5f
center: Position = Sphere.DEFAULT_CENTER,
stacks: Int = Sphere.DEFAULT_STACKS, // 24
slices: Int = Sphere.DEFAULT_SLICES, // 24
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: SphereNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### CylinderNode — cylinder geometry
```kotlin
@Composable fun CylinderNode(
radius: Float = Cylinder.DEFAULT_RADIUS, // 0.5f
height: Float = Cylinder.DEFAULT_HEIGHT, // 2.0f
center: Position = Cylinder.DEFAULT_CENTER,
sideCount: Int = Cylinder.DEFAULT_SIDE_COUNT, // 24
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: CylinderNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### ConeNode — cone geometry
```kotlin
@Composable fun ConeNode(
radius: Float = Cone.DEFAULT_RADIUS, // 1.0f
height: Float = Cone.DEFAULT_HEIGHT, // 2.0f
center: Position = Cone.DEFAULT_CENTER,
sideCount: Int = Cone.DEFAULT_SIDE_COUNT, // 24
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: ConeNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### TorusNode — torus (donut) geometry
```kotlin
@Composable fun TorusNode(
majorRadius: Float = Torus.DEFAULT_MAJOR_RADIUS, // 1.0f (ring centre)
minorRadius: Float = Torus.DEFAULT_MINOR_RADIUS, // 0.3f (tube thickness)
center: Position = Torus.DEFAULT_CENTER,
majorSegments: Int = Torus.DEFAULT_MAJOR_SEGMENTS, // 32
minorSegments: Int = Torus.DEFAULT_MINOR_SEGMENTS, // 16
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: TorusNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### CapsuleNode — capsule (cylinder + hemisphere caps)
```kotlin
@Composable fun CapsuleNode(
radius: Float = Capsule.DEFAULT_RADIUS, // 0.5f
height: Float = Capsule.DEFAULT_HEIGHT, // 2.0f (cylinder section; total = h + 2r)
center: Position = Capsule.DEFAULT_CENTER,
capStacks: Int = Capsule.DEFAULT_CAP_STACKS, // 8
sideSlices: Int = Capsule.DEFAULT_SIDE_SLICES, // 24
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: CapsuleNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### PlaneNode — flat quad
```kotlin
@Composable fun PlaneNode(
size: Size = Plane.DEFAULT_SIZE,
center: Position = Plane.DEFAULT_CENTER,
normal: Direction = Plane.DEFAULT_NORMAL,
uvScale: UvScale = UvScale(1.0f),
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: PlaneNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### Geometry nodes — material creation
Geometry nodes accept `materialInstance: MaterialInstance?`. Create materials via `materialLoader`:
```kotlin
SceneView(...) {
val redMaterial = remember(materialLoader) {
materialLoader.createColorInstance(Color.Red, metallic = 0f, roughness = 0.6f)
}
CubeNode(size = Size(0.5f), center = Position(0f, 0.25f, 0f), materialInstance = redMaterial)
SphereNode(radius = 0.3f, materialInstance = blueMaterial)
CylinderNode(radius = 0.2f, height = 1.0f, materialInstance = greenMaterial)
ConeNode(radius = 0.3f, height = 0.8f, materialInstance = yellowMaterial)
TorusNode(majorRadius = 0.5f, minorRadius = 0.15f, materialInstance = purpleMaterial)
CapsuleNode(radius = 0.2f, height = 0.6f, materialInstance = orangeMaterial)
PlaneNode(size = Size(5f, 5f), materialInstance = greyMaterial)
}
```
### ImageNode — image on plane (3 overloads)
```kotlin
// From Bitmap
@Composable fun ImageNode(
bitmap: Bitmap,
size: Size? = null, // null = auto from aspect ratio
center: Position = Plane.DEFAULT_CENTER,
normal: Direction = Plane.DEFAULT_NORMAL,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: ImageNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
// From asset file path
@Composable fun ImageNode(
imageFileLocation: String,
size: Size? = null,
center: Position = Plane.DEFAULT_CENTER,
normal: Direction = Plane.DEFAULT_NORMAL,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: ImageNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
// From drawable resource
@Composable fun ImageNode(
@DrawableRes imageResId: Int,
size: Size? = null,
center: Position = Plane.DEFAULT_CENTER,
normal: Direction = Plane.DEFAULT_NORMAL,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: ImageNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### TextNode — 3D text label (faces camera)
```kotlin
@Composable fun TextNode(
text: String,
fontSize: Float = 48f,
textColor: Int = android.graphics.Color.WHITE,
backgroundColor: Int = 0xCC000000.toInt(),
widthMeters: Float = 0.6f,
heightMeters: Float = 0.2f,
position: Position = Position(x = 0f),
scale: Scale = Scale(1f),
cameraPositionProvider: (() -> Position)? = null,
apply: TextNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
Reactive: `text`, `fontSize`, `textColor`, `backgroundColor`, `position`, `scale` update on recomposition.
### BillboardNode — always-facing-camera sprite
```kotlin
@Composable fun BillboardNode(
bitmap: Bitmap,
widthMeters: Float? = null,
heightMeters: Float? = null,
position: Position = Position(x = 0f),
scale: Scale = Scale(1f),
cameraPositionProvider: (() -> Position)? = null,
apply: BillboardNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### VideoNode — video on 3D plane
```kotlin
// Simple — asset path (recommended):
@ExperimentalSceneViewApi
@Composable fun VideoNode(
videoPath: String, // e.g. "videos/promo.mp4"
autoPlay: Boolean = true,
isLooping: Boolean = true,
chromaKeyColor: Int? = null,
size: Size? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: VideoNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
// Advanced — bring your own MediaPlayer:
@Composable fun VideoNode(
player: MediaPlayer,
chromaKeyColor: Int? = null,
size: Size? = null, // null = auto-sized from video aspect ratio
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: VideoNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
Usage (simple):
```kotlin
SceneView {
VideoNode(videoPath = "videos/promo.mp4", position = Position(z = -2f))
}
```
Usage (advanced — custom MediaPlayer):
```kotlin
val player = rememberMediaPlayer(context, assetFileLocation = "videos/promo.mp4")
SceneView(...) {
player?.let { VideoNode(player = it, position = Position(z = -2f)) }
}
```
### ViewNode — Compose UI in 3D
**Requires `viewNodeWindowManager` on the parent `Scene`.**
```kotlin
@Composable fun ViewNode(
windowManager: ViewNode.WindowManager,
unlit: Boolean = false,
invertFrontFaceWinding: Boolean = false,
apply: ViewNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null,
viewContent: @Composable () -> Unit // the Compose UI to render
)
```
Usage:
```kotlin
val windowManager = rememberViewNodeManager()
SceneView(viewNodeWindowManager = windowManager) {
ViewNode(windowManager = windowManager) {
Card { Text("Hello 3D World!") }
}
}
```
### LineNode — single line segment
```kotlin
@Composable fun LineNode(
start: Position = Line.DEFAULT_START,
end: Position = Line.DEFAULT_END,
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: LineNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### PathNode — polyline through points
```kotlin
@Composable fun PathNode(
points: List<Position> = Path.DEFAULT_POINTS,
closed: Boolean = false,
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: PathNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### MeshNode — custom geometry
```kotlin
@Composable fun MeshNode(
primitiveType: RenderableManager.PrimitiveType,
vertexBuffer: VertexBuffer,
indexBuffer: IndexBuffer,
boundingBox: Box? = null,
materialInstance: MaterialInstance? = null,
apply: MeshNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### ShapeNode — 2D polygon shape
```kotlin
@Composable fun ShapeNode(
polygonPath: List<Position2> = listOf(),
polygonHoles: List<Int> = listOf(),
delaunayPoints: List<Position2> = listOf(),
normal: Direction = Shape.DEFAULT_NORMAL,
uvScale: UvScale = UvScale(1.0f),
color: Color? = null,
materialInstance: MaterialInstance? = null,
position: Position = Position(x = 0f),
rotation: Rotation = Rotation(x = 0f),
scale: Scale = Scale(1f),
apply: ShapeNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
Renders a triangulated 2D polygon in 3D space. Supports holes, Delaunay refinement, and vertex colors.
### PhysicsNode — simple rigid-body physics
```kotlin
@Composable fun PhysicsNode(
node: Node,
mass: Float = 1f,
restitution: Float = 0.6f,
linearVelocity: Position = Position(0f, 0f, 0f),
floorY: Float = 0f,
radius: Float = 0f
)
```
Attaches gravity + floor bounce to an existing node. Does NOT add the node to the scene — the node
must already exist. Uses Euler integration at 9.8 m/s² with configurable restitution and floor.
```kotlin
SceneView {
val sphere = remember(engine) { SphereNode(engine, radius = 0.15f) }
PhysicsNode(node = sphere, restitution = 0.7f, linearVelocity = Position(0f, 3f, 0f), radius = 0.15f)
}
```
### DynamicSkyNode — time-of-day sun lighting
```kotlin
@Composable fun SceneScope.DynamicSkyNode(
timeOfDay: Float = 12f, // 0-24: 0=midnight, 6=sunrise, 12=noon, 18=sunset
turbidity: Float = 2f, // atmospheric haze [1.0, 10.0]
sunIntensity: Float = 110_000f // lux at solar noon
)
```
Creates a SUN light whose colour, intensity and direction update with `timeOfDay`.
Sun rises at 6h, peaks at 12h, sets at 18h. Colour: cool blue (night) → warm orange (horizon) → white-yellow (noon).
```kotlin
SceneView {
DynamicSkyNode(timeOfDay = 14.5f)
ModelNode(modelInstance = instance!!)
}
```
### SecondaryCamera — secondary camera (formerly CameraNode)
```kotlin
@Composable fun SecondaryCamera(
apply: CameraNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
**Note:** Does NOT become the active rendering camera. The main camera is set via `SceneView(cameraNode = ...)`.
`CameraNode()` composable is deprecated — use `SecondaryCamera()` instead.
### ReflectionProbeNode — local IBL override
```kotlin
@Composable fun ReflectionProbeNode(
filamentScene: FilamentScene,
environment: Environment,
position: Position = Position(0f, 0f, 0f),
radius: Float = 0f, // 0 = global (always active)
priority: Int = 0,
cameraPosition: Position = Position(0f, 0f, 0f)
)
```
---
## ARSceneScope — AR Node DSL
`ARSceneScope` extends `SceneScope` with AR-specific composables. All `SceneScope` nodes (ModelNode, CubeNode, etc.) are also available.
**⚠️ Important nesting rule:** AR composables (`AnchorNode`, `CloudAnchorNode`, `AugmentedImageNode`, etc.) can only be declared at the `ARSceneView { }` root level — they are NOT available inside `Node { content }` or other node's `content` blocks. To nest models under an anchor, use `AnchorNode(anchor) { ModelNode(...) }` — the `content` block of `AnchorNode` provides a regular `NodeScope`.
### AnchorNode — pin to real world
```kotlin
@Composable fun AnchorNode(
anchor: Anchor,
updateAnchorPose: Boolean = true,
visibleTrackingStates: Set<TrackingState> = setOf(TrackingState.TRACKING),
onTrackingStateChanged: ((TrackingState) -> Unit)? = null,
onAnchorChanged: ((Anchor) -> Unit)? = null,
onUpdated: ((Anchor) -> Unit)? = null,
apply: AnchorNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
Usage:
```kotlin
var anchor by remember { mutableStateOf<Anchor?>(null) }
ARSceneView(
onSessionUpdated = { _, frame ->
if (anchor == null) {
anchor = frame.getUpdatedPlanes()
.firstOrNull { it.type == Plane.Type.HORIZONTAL_UPWARD_FACING }
?.let { frame.createAnchorOrNull(it.centerPose) }
}
}
) {
anchor?.let { a ->
AnchorNode(anchor = a) {
ModelNode(modelInstance = instance!!, scaleToUnits = 0.5f, isEditable = true)
}
}
}
```
### PoseNode — position at ARCore Pose
```kotlin
@Composable fun PoseNode(
pose: Pose = Pose.IDENTITY,
visibleCameraTrackingStates: Set<TrackingState> = setOf(TrackingState.TRACKING),
onPoseChanged: ((Pose) -> Unit)? = null,
apply: PoseNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### HitResultNode — surface cursor (2 overloads)
**Recommended — screen-coordinate hit test** (most common for placement cursors):
```kotlin
@Composable fun HitResultNode(
xPx: Float, // screen X in pixels (use viewWidth / 2f for center)
yPx: Float, // screen Y in pixels (use viewHeight / 2f for center)
planeTypes: Set<Plane.Type> = Plane.Type.entries.toSet(),
point: Boolean = true,
depthPoint: Boolean = true,
instantPlacementPoint: Boolean = true,
// ... other filters with sensible defaults ...
apply: HitResultNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
**Custom hit test** (full control):
```kotlin
@Composable fun HitResultNode(
hitTest: HitResultNode.(Frame) -> HitResult?,
apply: HitResultNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
Typical center-screen placement cursor:
```kotlin
ARSceneView(modifier = Modifier.fillMaxSize()) {
// Place a cursor at screen center — follows detected surfaces
HitResultNode(xPx = viewWidth / 2f, yPx = viewHeight / 2f) {
CubeNode(size = Size(0.05f)) // small indicator cube
}
}
```
### AugmentedImageNode — image tracking
```kotlin
@Composable fun AugmentedImageNode(
augmentedImage: AugmentedImage,
applyImageScale: Boolean = false,
visibleTrackingMethods: Set<TrackingMethod> = setOf(TrackingMethod.FULL_TRACKING, TrackingMethod.LAST_KNOWN_POSE),
onTrackingStateChanged: ((TrackingState) -> Unit)? = null,
onTrackingMethodChanged: ((TrackingMethod) -> Unit)? = null,
onUpdated: ((AugmentedImage) -> Unit)? = null,
apply: AugmentedImageNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### AugmentedFaceNode — face mesh
```kotlin
@Composable fun AugmentedFaceNode(
augmentedFace: AugmentedFace,
meshMaterialInstance: MaterialInstance? = null,
onTrackingStateChanged: ((TrackingState) -> Unit)? = null,
onUpdated: ((AugmentedFace) -> Unit)? = null,
apply: AugmentedFaceNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### CloudAnchorNode — cross-device persistent anchors
```kotlin
@Composable fun CloudAnchorNode(
anchor: Anchor,
cloudAnchorId: String? = null,
onTrackingStateChanged: ((TrackingState) -> Unit)? = null,
onUpdated: ((Anchor?) -> Unit)? = null,
onHosted: ((cloudAnchorId: String?, state: Anchor.CloudAnchorState) -> Unit)? = null,
apply: CloudAnchorNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
### TrackableNode — generic trackable
```kotlin
@Composable fun TrackableNode(
trackable: Trackable,
visibleTrackingStates: Set<TrackingState> = setOf(TrackingState.TRACKING),
onTrackingStateChanged: ((TrackingState) -> Unit)? = null,
onUpdated: ((Trackable) -> Unit)? = null,
apply: TrackableNode.() -> Unit = {},
content: (@Composable NodeScope.() -> Unit)? = null
)
```
---
## Node Properties & Interaction
All composable node types share these properties (settable via `apply` block or the parameters):
```kotlin
// Transform
node.position = Position(x = 1f, y = 0f, z = -2f) // meters
node.rotation = Rotation(x = 0f, y = 45f, z = 0f) // degrees
node.scale = Scale(x = 1f, y = 1f, z = 1f)
node.quaternion = Quaternion(...)
node.transform = Transform(position, quaternion, scale)
// World-space transforms (read/write)
node.worldPosition, node.worldRotation, node.worldScale, node.worldQuaternion, node.worldTransform
// Visibility
node.isVisible = true // also hides all children when false
// Interaction
node.isTouchable = true
node.isEditable = true // pinch-scale, drag-move, two-finger-rotate
node.isPositionEditable = false // requires isEditable = true
node.isRotationEditable = true // requires isEditable = true
node.isScaleEditable = true // requires isEditable = true
node.editableScaleRange = 0.1f..10.0f
node.scaleGestureSensitivity = 0.5f
// Smooth transform
node.isSmoothTransformEnabled = false
node.smoothTransformSpeed = 5.0f
// Hit testing
node.isHittable = true
// Naming
node.name = "myNode"
// Orientation
node.lookAt(targetWorldPosition, upDirection)
node.lookTowards(lookDirection, upDirection)
// Animation utilities (on any Node)
node.animatePositions(...)
node.animateRotations(...)
```
---
## Resource Loading
### rememberModelInstance (composable, async)
```kotlin
// Load from local asset
@Composable
fun rememberModelInstance(
modelLoader: ModelLoader,
assetFileLocation: String
): ModelInstance?
// Load from any location (local asset, file path, or HTTP/HTTPS URL)
@Composable
fun rememberModelInstance(
modelLoader: ModelLoader,
fileLocation: String,
resourceResolver: (resourceFileName: String) -> String = { ModelLoader.getFolderPath(fileLocation, it) }
): ModelInstance?
```
Returns `null` while loading, recomposes when ready. **Always handle the null case.**
The `fileLocation` overload auto-detects URLs (http/https) and routes through Fuel HTTP client for download. Use it for remote model loading:
```kotlin
val model = rememberModelInstance(modelLoader, "https://example.com/model.glb")
```
### ModelLoader (imperative)
```kotlin
class ModelLoader(engine: Engine, context: Context) {
// Synchronous — MUST be called on main thread
fun createModelInstance(assetFileLocation: String): ModelInstance
fun createModelInstance(buffer: Buffer): ModelInstance
fun createModelInstance(@RawRes rawResId: Int): ModelInstance
fun createModelInstance(file: File): ModelInstance
// releaseSourceData (default true): frees the raw buffer after Filament parses the model.
// Set to false only when you need to re-instantiate the same model multiple times.
fun createModel(assetFileLocation: String, releaseSourceData: Boolean = true): Model
fun createModel(buffer: Buffer, releaseSourceData: Boolean = true): Model
fun createModel(@RawRes rawResId: Int, releaseSourceData: Boolean = true): Model
fun createModel(file: File, releaseSourceData: Boolean = true): Model
// Async — safe from any thread
suspend fun loadModel(fileLocation: String): Model?
fun loadModelAsync(fileLocation: String, onResult: (Model?) -> Unit): Job
suspend fun loadModelInstance(fileLocation: String): ModelInstance?
fun loadModelInstanceAsync(fileLocation: String, onResult: (ModelInstance?) -> Unit): Job
}
```
### MaterialLoader
```kotlin
class MaterialLoader(engine: Engine, context: Context) {
// Color material — MUST be called on main thread
fun createColorInstance(
color: Color,
metallic: Float = 0.0f, // 0 = dielectric, 1 = metal
roughness: Float = 0.4f, // 0 = mirror, 1 = matte
reflectance: Float = 0.5f // Fresnel reflectance
): MaterialInstance
// Also accepts:
fun createColorInstance(color: androidx.compose.ui.graphics.Color, ...): MaterialInstance
fun createColorInstance(color: Int, ...): MaterialInstance
// Texture material
fun createTextureInstance(texture: Texture, ...): MaterialInstance
// Custom .filamat material
fun createMaterial(assetFileLocation: String): Material
fun createMaterial(payload: Buffer): Material
suspend fun loadMaterial(fileLocation: String): Material?
fun createInstance(material: Material): MaterialInstance
}
```
### EnvironmentLoader
```kotlin
class EnvironmentLoader(engine: Engine, context: Context) {
// HDR environment — MUST be called on main thread
fun createHDREnvironment(
assetFileLocation: String,
indirectLightSpecularFilter: Boolean = true,
createSkybox: Boolean = true
): Environment?
fun createHDREnvironment(buffer: Buffer, ...): Environment?
// KTX environment
fun createKTXEnvironment(assetFileLocation: String): Environment
fun createEnvironment(
indirectLight: IndirectLight? = null,
skybox: Skybox? = null
): Environment
}
```
---
## Remember Helpers Reference
All `remember*` helpers create and memoize Filament objects, destroying them on disposal.
Most are default parameter values in `SceneView`/`ARSceneView` — call them explicitly only when sharing resources or customizing.
| Helper | Returns | Purpose |
|--------|---------|---------|
| `rememberEngine()` | `Engine` | Root Filament object — one per process |
| `rememberModelLoader(engine)` | `ModelLoader` | Loads glTF/GLB models |
| `rememberMaterialLoader(engine)` | `MaterialLoader` | Creates material instances |
| `rememberEnvironmentLoader(engine)` | `EnvironmentLoader` | Loads HDR/KTX environments |
| `rememberModelInstance(modelLoader, path)` | `ModelInstance?` | Async model load — null while loading |
| `rememberEnvironment(environmentLoader, isOpaque)` | `Environment` | IBL + skybox environment |
| `rememberEnvironment(environmentLoader) { ... }` | `Environment` | Custom environment from lambda |
| `rememberCameraNode(engine) { ... }` | `CameraNode` | Custom camera with apply block |
| `rememberMainLightNode(engine) { ... }` | `LightNode` | Primary directional light with apply block |
| `rememberCameraManipulator(orbitHomePosition?, targetPosition?)` | `CameraManipulator?` | Orbit/pan/zoom camera controller |
| `rememberOnGestureListener(...)` | `OnGestureListener` | Gesture callbacks for tap/drag/pinch |
| `rememberViewNodeManager()` | `ViewNode.WindowManager` | Required for ViewNode composables |
| `rememberView(engine)` | `View` | Filament view (one per viewport) |
| `rememberARView(engine)` | `View` | AR-tuned view (linear tone mapper) |