Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

argCustomPlaneTexturePath?.let { val loader: FlutterLoader =…

  1. User

    argCustomPlaneTexturePath?.let { val loader: FlutterLoader = FlutterInjector.instance().flutterLoader() val key: String = loader.getLookupKeyForAsset(it)

            val sampler =
                Texture.Sampler.builder()
                    .setMinFilter(Texture.Sampler.MinFilter.LINEAR)
                    .setWrapMode(Texture.Sampler.WrapMode.REPEAT)
                    .build()
            Texture.builder()
                .setSource(viewContext, Uri.parse(key))
                .setSampler(sampler)
                .build()
                .thenAccept { texture: Texture? ->
                    arSceneView!.planeRenderer.material.thenAccept { material: Material ->
                        material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture)
                        material.setFloat(PlaneRenderer.MATERIAL_SPOTLIGHT_RADIUS, 10f)
                    }
                }
            // Set radius to render planes in
            arSceneView!.scene!.addOnUpdateListener { frameTime: FrameTime? ->
                val planeRenderer = arSceneView!.planeRenderer
                planeRenderer.material.thenAccept { material: Material ->
                    material.setFloat(
                        PlaneRenderer.MATERIAL_SPOTLIGHT_RADIUS,
                        10f) // Sets the radius in which to visualize planes
                }
            }
        }
    
  2. Assistant

    The code provided is using ARCore to display custom textures on detected planes in the AR scene. Let me explain each part of the code:

    1. argCustomPlaneTexturePath?.let { }: This checks if the argCustomPlaneTexturePath variable is not null before executing the code inside the let block. This variable is likely used to specify the path to a custom texture for the AR planes.

    2. Inside the let block, the FlutterLoader instance is obtained using FlutterInjector, and the lookup key for the asset is retrieved using the FlutterLoader's getLookupKeyForAsset method. This key will be used to load the texture from the asset at the specified path.

    3. A texture sampler is created with the specified filtering and wrapping options.

    4. A texture is built using the Flutter loader's setSource method, passing the viewContext and the Uri of the asset.

    5. The texture is then built asynchronously using the thenAccept method. Inside the thenAccept block, the AR plane renderer's material is obtained using the planeRenderer.material property. The texture is set as the texture of the material using the setTexture method, and the spotlight radius is set to 10f using the setFloat method.

    6. An addOnUpdateListener is added to the AR scene's scene property, allowing the code inside the listener to be executed on each frame update. Inside the listener block, the plane renderer's material is obtained again, and the spotlight radius is set to 10f to ensure that planes within that radius are visualized.

    Overall, this code sets a custom texture on detected AR planes and ensures that the planes are visualized within a specific radius in the AR scene.