Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
BigMac1771's avatar
BigMac1771
Honored Guest
8 months ago
Solved

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

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)
}
  • 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

Replies have been turned off for this discussion
  • dav-s's avatar
    dav-s
    Meta Employee

    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!