google-ar / sceneform-android-sdk

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

fade out model renderable #381

Open basitsaleemmb opened 6 years ago

basitsaleemmb commented 6 years ago

hi! i want to fade out my modelRenderable when it is clicked is there any solution?

malik-at-work commented 5 years ago

In https://github.com/google-ar/sceneform-android-sdk/issues/426 I added sample code to create a ValueAnimator which adjusts the "color" property on a material.

For your modelRenderable, you will need to ensure it is using materials which can be transparent and that have a color property. You would then need to set the color for each material in the renderable to fade it out.

brako commented 5 years ago

Hello

I' m trying to do the same thing, but it's not working right now. @malik-at-work I tried your solution. but the alpha channel is not working properly for me. When I set the alpha to 0, my model is completely invisible. But when I set the alpha to something different from 0, my model is always visible at the same transparency.

MaterialFactory.makeTransparentWithColor(context, Color())
    .thenAccept {
        val model = ShapeFactory.makeCylinder(0.5f, 2f, Vector3(0.0f, 1f, 0.0f), it)
        model.isShadowCaster = false
        renderable = model
        model.material.setFloat4(
            MaterialFactory.MATERIAL_COLOR,
            Color(1f, 1f, 1f, 0.1f)
        )
    }

Also I tried to create a custom Material with the blending option to "fade" as suggested here #196. But I have the same problem. Any idea?