Untitled
unknown
plain_text
a year ago
3.2 kB
7
Indexable
onSessionUpdated = { session, updatedFrame ->
frame = updatedFrame
// if (childNodes.isEmpty()) {
// updatedFrame.getUpdatedPlanes().firstOrNull { it.type == Plane.Type.HORIZONTAL_UPWARD_FACING }
// ?.let { it.createAnchorOrNull(it.centerPose) }?.let { anchor ->
// childNodes += createAnchorNode(
// engine = engine,
// modelLoader = modelLoader,
// materialLoader = materialLoader,
// anchor = anchor
// )
// }
// }
val earth = session.earth
if (earth?.earthState == Earth.EarthState.ENABLED) {
val latitude = destinationLatLng!!.latitude
val longitude = destinationLatLng.longitude
val altitude = 0.0 // Set desired altitude
Log.d("tag", "ARSceneContent: "+longitude)
val anchor = earth.createAnchor(
longitude,
altitude,
latitude,
0.0f, // Quaternion x
0.0f, // Quaternion y
0.0f, // Quaternion z
1.0f // Quaternion w (no rotation)
)
childNodes += createAnchorNode(
engine = engine,
modelLoader = modelLoader,
materialLoader = materialLoader,
anchor = anchor
)
}
fun createAnchorNode(
engine: Engine,
modelLoader: ModelLoader,
materialLoader: MaterialLoader,
anchor: Anchor
): AnchorNode {
val anchorNode = AnchorNode(engine = engine, anchor = anchor)
val modelNode = ModelNode(
modelInstance = modelLoader.createModelInstance(kModelFile),
// Scale to fit in a 0.5 meters cube
scaleToUnits = 0.5f
).apply {
// Model Node needs to be editable for independent rotation from the anchor rotation
isEditable = true
editableScaleRange = 0.2f..0.75f
}
val boundingBoxNode = CubeNode(
engine,
size = modelNode.extents,
center = modelNode.center,
materialInstance = materialLoader.createColorInstance(Color.White.copy(alpha = 0.5f))
).apply {
isVisible = false
}
modelNode.addChildNode(boundingBoxNode)
anchorNode.addChildNode(modelNode)
listOf(modelNode, anchorNode).forEach {
it.onEditingChanged = { editingTransforms ->
boundingBoxNode.isVisible = editingTransforms.isNotEmpty()
}
}
return anchorNode
}Editor is loading...
Leave a Comment