Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant load mode mode shift #547

Open
bpn-work opened this issue Aug 2, 2024 · 0 comments
Open

Instant load mode mode shift #547

bpn-work opened this issue Aug 2, 2024 · 0 comments

Comments

@bpn-work
Copy link

bpn-work commented Aug 2, 2024

Hi,
I want to load a model instantly where ever the camera is shown. It shows at the required position then shifts towards center . I have added zaxis value to bring it forwards in the camera view.
Here is my code flow:

val engine = rememberEngine()
                    val modelLoader = rememberModelLoader(engine)
                    val materialLoader = rememberMaterialLoader(engine)
                    val childNodes = rememberNodes()
                    val view = rememberView(engine)
                    val collisionSystem = rememberCollisionSystem(view)
                    // Store current view that can be used to capture image
                    var arSceneView by remember { mutableStateOf<ARSceneView?>(null) }
                    var trackingFailureReason by remember {
                        mutableStateOf<TrackingFailureReason?>(null)
                    }
                    var frame by remember { mutableStateOf<Frame?>(null) }
                    val scope = rememberCoroutineScope()
                    ARScene(
                        modifier = Modifier.fillMaxSize(),
                        childNodes = childNodes,
                        engine = engine,
                        view = view,
                        modelLoader = modelLoader,
                        collisionSystem = collisionSystem,
                        sessionConfiguration = { session, config ->
                            config.depthMode = Config.DepthMode.DISABLED
                            config.instantPlacementMode = Config.InstantPlacementMode.LOCAL_Y_UP
                            config.lightEstimationMode = Config.LightEstimationMode.DISABLED
                            config.planeFindingMode = Config.PlaneFindingMode.HORIZONTAL_AND_VERTICAL
                        },
                        planeRenderer = false, // Disable plane rendering
                        onTrackingFailureChanged = {
                            trackingFailureReason = it
                        },
                        onSessionUpdated = { session, updatedFrame ->
                            frame = updatedFrame
                            scope.launch {
                                if(frame?.camera?.isTracking == true){

                                    if (childNodes.isEmpty()) {
                                        val modelNode = ModelNode(
                                            modelInstance = modelLoader.createModelInstance(kModelFile),
                                        ).apply {
//                                    scale = Scale(0.7f/size.x)
                                            worldPosition = worldPosition.copy(z=-2f)
                                            // Set the initial position to the anchor's position
                                            // You can set the position if needed, but it defaults to (0, 0, 0) relative to the anchor
                                        }
                                        childNodes.add(modelNode)
                                    }
                                }
                            }
                        },
                    )
                    Text(
                        modifier = Modifier
                            .systemBarsPadding()
                            .fillMaxWidth()
                            .align(Alignment.TopCenter)
                            .padding(top = 16.dp, start = 32.dp, end = 32.dp),
                        textAlign = TextAlign.Center,
                        fontSize = 28.sp,
                        color = Color.White,
                        text = trackingFailureReason?.let {
                            it.getDescription(LocalContext.current)
                        } ?: "tap_anywhere_to_add_model"
                    )
                }
            }
        }
    }

Is there anything wrong here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant