Skip to main content
New Participant
April 21, 2025
Solved

How to change appearance(baseColorTexture) of a preload glb runtime?

  • April 21, 2025
  • 1 reply
  • 352 views
Im a beginner in 3D development. I import a glb object into environment.env with predefined textures(baseColorTexture, normalTexture, occlusionTexture), and I try to change the appearance(runtime) when clicking buttons.
 
Here are my code,  but It didn't work to change the texture (baseColor or baseColorTexture).
 
Is there anyone could help me? Thank you very much.

private fun changeMaterial(node : SceneObject) {
        val material = node.mesh?.materials?.get(0)
        var mesh = node.mesh
        var meshMaterial = node.mesh?.getMaterial(0) as SceneMaterial
        var test_texture = SceneTexture(activity.getDrawable(R.drawable.test_texture))
       //var texture_name = "baseColor" //--> exception: baseColor not found
        var texture_name = "occlusion" //--> worked and texture is changed
        meshMaterial.setTexture(texture_name, test_texture)
}
    This topic has been closed for replies.
    Best answer by davs

    Hi! The recommended way is to use SceneMaterial.setAlbedoTexture(). Albedo textures are supposed to represent base color without any light additions. If you need to set it via setTexture as a string, you can use "albedo".

     

    Hope this helps!

    1 reply

    davsAnswer
    Meta Employee
    July 7, 2025

    Hi! The recommended way is to use SceneMaterial.setAlbedoTexture(). Albedo textures are supposed to represent base color without any light additions. If you need to set it via setTexture as a string, you can use "albedo".

     

    Hope this helps!