google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.91k stars 1.2k forks source link

How to change sun direction towards the model in front camera as model looks dull on invert #1610

Open gptshubham595 opened 9 months ago

gptshubham595 commented 9 months ago

Hi, I was working with arcore v1.38 in android

I've have 3d model as badge.glb

On back camera it looks perfect but on front camera it seems to be mirror image in Y direction.

So to fix this whole loading the model I tried localScale and add negative sign for Y so it gets inverted.

Now its looks good in front camera but there is a lighting issue as it looks dull. I tried add badgeNode.sundirection but still that doesn't worked. I tried adding a spotlight Yellow but still I cannot figure out any difference.

This is how I'm doing for front sections

val scene = faceArFrontFragment?.arSceneView?.scene
            val session = faceArFrontFragment?.arSceneView?.session

            scene?.addOnUpdateListener {
                if (viewModel.model != null) {

                    val allDetectedFaces = session
                        ?.getAllTrackables(AugmentedFace::class.java)

                    allDetectedFaces?.let {
                        for (face in it) {
                            //found a new face

                            if (!faceNodeMap.containsKey(face)) {
                                val faceNode = AugmentedFaceNode(face)
                                faceNode.setParent(scene)

// We can place our 3d model at any position we need

                                faceModel?.thenAccept {
                                    val badge = Node()
                                    val localPosition = Vector3()
                                    localPosition.set(0.0f, -0.3f, 0.0f)
                                    badge.localScale = Vector3(0.1f, 0.1f, 0.1f)
                                    badge.localPosition = localPosition
                                    badge.setParent(faceNode)
                                    badge.renderable = it
                                    badge.light = viewModel.spotLightYellow
                                    scene.sunlight?.setLookDirection(Vector3(0.0f, 0.0f, -2.0f))
                                 }

                                faceNode.faceMeshTexture = faceMeshTexture
                                faceNodeMap[face] = faceNode
                            }
                         }

                        // Remove any AugmentedFaceNodes associated with an AugmentedFace that stopped tracking.
                        val iter = viewModel.faceNodeMap.entries.iterator()
                        while (iter.hasNext()) {
                            val entry = iter.next()
                            val face = entry.key
                            if (face.trackingState == TrackingState.STOPPED) {
                                val faceNode = entry.value
                                faceNode.setParent(null)
                                iter.remove()
                            }
                        }
                    }
                }
            }

I tried creating sunlight

spotLightYellow =
            Light.builder(Light.Type.FOCUSED_SPOTLIGHT)
                .setColor(com.google.ar.sceneform.rendering.Color(Color.YELLOW))
                .setShadowCastingEnabled(true)
                .build()