@Composable
fun Sample() {
Box(
modifier = Modifier
.fillMaxSize()
.safeDrawingPadding()
) {
val currentScope = rememberCoroutineScope()
// Core Filament/SceneView objects.
val engine: Engine = rememberEngine()
val modelLoader: ModelLoader = rememberModelLoader(engine = engine)
val childNodes: MutableList = rememberNodes()
// State variables for AR configuration and tracking.
val earth = remember { mutableStateOf(null) }
val latitude = remember { mutableStateOf(null) }
val longitude = remember { mutableStateOf(null) }
val altitude = remember { mutableStateOf(null) }
// Store the ARCore Session for later use.
val arSession = remember { mutableStateOf(null) }
// Asset info.
val modelAsset = "models/simple_satellite.glb"
val modelScale = 10f
ARScene(
modifier = Modifier.fillMaxSize(),
engine = engine,
modelLoader = modelLoader,
sessionFeatures = setOf(),
sessionCameraConfig = null,
sessionConfiguration = { session, config ->
config.depthMode = Config.DepthMode.DISABLED
config.instantPlacementMode = Config.InstantPlacementMode.LOCAL_Y_UP
config.lightEstimationMode = Config.LightEstimationMode.ENVIRONMENTAL_HDR
config.geospatialMode = Config.GeospatialMode.ENABLED
config.semanticMode = Config.SemanticMode.ENABLED
},
planeRenderer = true,
childNodes = childNodes,
onSessionCreated = { session ->
},
)
Button(onClick = {
currentScope.launch {
// Wait until tracking is active.
while (earth.value?.trackingState != TrackingState.TRACKING) {
delay(1000)
}
val session = arSession.value
if (session == null) {
Log.e("Sample", "AR Session is not available.")
return@launch
}
// Create an anchor using the Pose.
try {
val anchor = earth.value?.createAnchor(
latitude.value!!, longitude.value!!, altitude.value!!, 0f, 0f, 0f, 1f
)
anchor?.let {
// Create an AnchorNode with the created anchor.
val anchorNode = AnchorNode(engine = engine, anchor = anchor)
// Create the ModelNode for the satellite model.
val satelliteNode = ModelNode(
modelInstance = modelLoader.createModelInstance(
assetFileLocation = modelAsset
), scaleToUnits = modelScale, centerOrigin = Position(0f, 0f, 0f)
)
// Attach the ModelNode as a child of the AnchorNode
anchorNode.addChildNode(satelliteNode)
// Add the AnchorNode to debug value
childNodes.add(anchorNode)
}
} catch (e: NotTrackingException) {
Log.e("Sample", "Error creating anchor: ${e.message}")
} catch (e: NullPointerException) {
Log.e("Sample", "Error creating anchor: ${e.message}")
}
}
}) {
Text("Add Satellite Model")
}
}
}
< /code>
Может ли кто -нибудь помочь мне с этим, пожалуйста? Он работает, когда вместо использования Земли. Createanchor Я использую сцену. Createanchor? Есть ли шаг, который мне не хватает?
Подробнее здесь: https://stackoverflow.com/questions/794 ... id-compose
Мобильная версия