Search code examples
androidandroid-studioaugmented-realityarcoresceneform

Can I update an .sfb file while running the AR activity?


Using SceneForm, I am displaying a 3D object which I obtain from an SFB file stored externally and I need to change its color. Is there a way to modify the file so as to change its color?

The material is just color:

newmtl Steel_-_Satin

Kd 0.627451 0.627451 0.627451

I would like to avoid:

  • Storing one file for each color in the external repository. Not only is it impractical but I would have to download a new file (which can be big) every time a color change is needed and this could be tedious.
  • Having to store 1 OBJ and several MTL files and making a new SFB every time. Same as before, I would have to store less data but the time with which the colour would update would be even greater.

Thanks in advance!


Solution

  • One way to set the color of a renderable at runtime is by changing the "baseColorTint" material parameter. below is an example of how to tint a renderable red:

    renderable.getMaterial().setFloat4("baseColorTint", new Color(1.0f, 0.0f, 0.0f, 1.0f));
    

    Also, if you want to have multiple copies of the renderable each set to a different color, you can do this:

    Renderable tintedRenderable = originalRenderable.makeCopy();
    tintedRenderable.getMaterial().setFloat4("baseColorTint", new Color(1.0f, 0.0f, 0.0f, 1.0f));
    

    Note, this works by multiplying the "baseColor" coming from the object's texture. this will work best if the object is pure white before it is tinted.

    Also, different sfbs can have different sets of material parameters. You can get an idea of what material parameters exist in your sfb by looking at the "parameters" block of the .sfa file. You can also write a custom material with your own material parameters and use that to control how your sfb looks and feels at runtime.