SceneView / sceneview-android

SceneView is a 3D and AR Android Composable and View with Google Filament and ARCore. This is a Sceneform replacement in Kotlin
Apache License 2.0
849 stars 161 forks source link

Instant load mode mode shift #547

Closed bpn-work closed 2 weeks ago

bpn-work commented 3 months ago

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?

github-actions[bot] commented 3 weeks ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 2 weeks ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.