google-ar / sceneform-android-sdk

Sceneform SDK for Android
https://developers.google.com/sceneform/develop/
Apache License 2.0
1.23k stars 603 forks source link

Import GLTF that has no BaseColor Texture; unable to set BaseColor at runtime #617

Closed bobekos closed 5 years ago

bobekos commented 5 years ago

If I convert a gltf to sfb, which has no basecolor texture, the sfa file will show null. If you manually specify a texture in the sfa via the injections (see code below), then everything works correctly. But how can I set a new texture at runtime? I tested it with the code below but it doesn't work. It only works if the sfb has already a texture in the basecolor attribute. Be it via injections or from the original model.

injection:

{
     file: "sampledata/models/test.png",
     name: "texture",
     injections: [
       {usage: "Normal",},
     ],
  }

code:

Texture.builder()
                    .setSource(ctx, R.drawable.test)
                    .setUsage(Texture.Usage.NORMAL)
                    .setSampler(Texture.Sampler.builder()
                            .setMagFilter(Texture.Sampler.MagFilter.LINEAR)
                            .setMinFilter(Texture.Sampler.MinFilter.LINEAR_MIPMAP_LINEAR)
                            .build())
                    .build()
                    .thenAccept { texture ->
                        material.setTexture("baseColor", texture)
                    }
tpsiaki commented 5 years ago

For use in Base Color, you need to use the BaseColor usage rather than the Normal usage. An injected texture for use in Base Color should be added to the sfa like this:

{
  file: 'sampledata/models/test.png',
  name: 'texture',
  injections: [
    {
      usage: 'BaseColor',
    },
  ],
},

Note also that this will only work in the sfa if the base color is not specified in the gltf. If the base color is specified in the gltf, then instead of injections, you need to specify the pipeline name (which should already be present in the initially generated sfa).

bobekos commented 5 years ago

@tpsiaki thx for the info i thought the usage specified the sampler usage type not the model attribute