3D and AR for Android using Jetpack Compose and Layout View, powered by Google Filament and ARCore
SceneView enables developers to easily incorporate 3D and AR capabilities into Android applications using Google's Filament rendering engine and ARCore. The library offers two main components:
- Sceneview: 3D rendering capabilities using Filament
- ARSceneview: Augmented Reality capabilities using Filament and ARCore
Add the dependency to your app's build.gradle:
dependencies {
// Sceneview for 3D capabilities
implementation("io.github.sceneview:sceneview:2.3.0")
}
Here's a basic example of creating a 3D scene in Jetpack Compose:
// Filament 3D Engine
val engine = rememberEngine()
// Asset loaders
val modelLoader = rememberModelLoader(engine)
val materialLoader = rememberMaterialLoader(engine)
val environmentLoader = rememberEnvironmentLoader(engine)
Scene(
modifier = Modifier.fillMaxSize(),
engine = engine,
// Core rendering components
view = rememberView(engine),
renderer = rememberRenderer(engine),
scene = rememberScene(engine),
// Asset loaders
modelLoader = modelLoader,
materialLoader = materialLoader,
environmentLoader = environmentLoader,
// Collision System
collisionSystem = rememberCollisionSystem(view)
// Add a direct light source (required for shadows)
mainLightNode = rememberMainLightNode(engine) {
intensity = 100_000.0f
},
// Set up environment lighting and skybox from an HDR file
environment = rememberEnvironment(environmentLoader) {
environmentLoader.createHDREnvironment(
assetFileLocation = "environments/sky_2k.hdr"
)!!
},
// Configure camera position
cameraNode = rememberCameraNode(engine) {
position = Position(z = 4.0f)
},
// Enable user interaction with the camera
cameraManipulator = rememberCameraManipulator(),
// Add 3D models and objects to the scene
childNodes = rememberNodes {
// Add a glTF model
add(
ModelNode(
// Create a single instance model from assets file
modelInstance = modelLoader.createModelInstance(
assetFileLocation = "models/damaged_helmet.glb"
),
// Make the model fit into a 1 unit cube
scaleToUnits = 1.0f
)
)
// Add a 3D cylinder with custom material
add(
CylinderNode(
engine = engine,
radius = 0.2f,
height = 2.0f,
// Simple colored material with physics properties
materialInstance = materialLoader.createColorInstance(
color = Color.Blue,
metallic = 0.5f,
roughness = 0.2f,
reflectance = 0.4f
)
).apply {
// Define the node position and rotation
transform(
position = Position(y = 1.0f),
rotation = Rotation(x = 90.0f)
)
})
},
// Handle user interactions
onGestureListener = rememberOnGestureListener(
onDoubleTapEvent = { event, tappedNode ->
tappedNode?.let { it.scale *= 2.0f }
}
),
// Handle tap event on the scene
onTouchEvent = { event: MotionEvent, hitResult: HitResult? ->
hitResult?.let { println("World tapped : ${it.worldPosition}") }
false
},
// Frame update callback
onFrame = { frameTimeNanos ->
// Handle per-frame updates here
}
)
Add the dependency to your app's build.gradle:
dependencies {
// ARSceneview for augmented reality capabilities
implementation 'io.github.sceneview:arsceneview:2.3.0'
}
Here's a basic example of creating an AR scene:
ARScene(
// Configure AR session features
sessionFeatures = setOf(),
sessionCameraConfig = null,
// Configure AR session settings
sessionConfiguration = { session, config ->
// Enable depth if supported on the device
config.depthMode =
when (session.isDepthModeSupported(Config.DepthMode.AUTOMATIC)) {
true -> Config.DepthMode.AUTOMATIC
else -> Config.DepthMode.DISABLED
}
config.instantPlacementMode = Config.InstantPlacementMode.LOCAL_Y_UP
config.lightEstimationMode = Config.LightEstimationMode.ENVIRONMENTAL_HDR
},
// Enable plane detection visualization
planeRenderer = true,
// Configure camera stream
cameraStream = rememberARCameraStream(materialLoader),
// Session lifecycle callbacks
onSessionCreated = { session ->
// Handle session creation
},
onSessionResumed = { session ->
// Handle session resume
},
onSessionPaused = { session ->
// Handle session pause
},
// Frame update callback
onSessionUpdated = { session, updatedFrame ->
// Process AR frame updates
},
// Error handling
onSessionFailed = { exception ->
// Handle ARCore session errors
},
// Track camera tracking state changes
onTrackingFailureChanged = { trackingFailureReason ->
// Handle tracking failures
}
)
- AR Model Viewer (Compose)
- AR Model Viewer (Layout)
- AR Augmented Image
- AR Cloud Anchors
- AR Point Cloud
- Open Collective Donations
- GitHub Sponsorship
- Buy SceneView Merchandise
- Create a Pull Request
⚠️ Geospatial API Note: Be sure to follow the official Google Geospatial Developer guide to enable Geospatial API in your application.