Sceneform-android-sdk: 小an not make a white background on SceneView

Created on 12 Aug 2018  路  13Comments  路  Source: google-ar/sceneform-android-sdk

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#FFF"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.google.ar.sceneform.SceneView
            android:id="@+id/preview_demo"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/view"
            android:padding="6dp"
            android:background="#FFF"/>

    <View android:id="@+id/view"
          android:layout_width="match_parent"
          android:layout_height="50dp"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintTop_toBottomOf="@id/preview_demo"/>

</android.support.constraint.ConstraintLayout>

photo_2018-08-12_18-24-10

bug

Most helpful comment

Still can't make white background in a normal way on SceneView with 1.7.

Creating a node and adding him to the scene with a white background is annoying a bit.

All 13 comments

I guess you experience the same issue setting the BG color programmatically with SceneView#setBackground(Drawable)?

Yes, this also does not work

Did you tried sceneView.pause() and sceneView.resume()?

Yes, i did

I tried this and worked OK for me.

My activity:

public class NonARActivity extends AppCompatActivity {

  SceneView sceneView;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_non_ar);
    sceneView = findViewById(R.id.preview_demo);

    ModelRenderable.builder().setSource(this, Uri.parse("andy.sfb"))
            .build().thenAccept(this::placeAndy);
  }

  private void placeAndy(ModelRenderable andy) {

    Node andyNode = new Node();
    andyNode.setRenderable(andy);
    andyNode.setWorldPosition(new Vector3(0,-.1f,-.25f));
    sceneView.getScene().addChild(andyNode);
  }

  @Override
  protected void onPause() {
    super.onPause();
    sceneView.pause();
  }

  @Override
  protected void onResume() {
    super.onResume();
    try {
      sceneView.resume();
    } catch (CameraNotAvailableException e) {
      e.printStackTrace();
    }
  }
}

My layout file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".NonARActivity">

    <com.google.ar.sceneform.SceneView
        android:id="@+id/preview_demo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFF"
        />
</android.support.constraint.ConstraintLayout>

Let me know if I should publish the complete sample.

Hello, I have the same issue, I can't get the background of the SceneView to be White, instead it's that gray white color.

So far the only difference between the implementation I see here and of my own, is that I have the SceneView in a Fragment rather than an Activity, and I am writing my code in Kotlin.

@Marunizer - Can you share a simple sample and I can take a quick look (it might be a couple days for me to make a Kotlin sample with a fragment)? The fragment should not make any difference, nor the language.

Thank you for the quick response !
Sure, here's a sample of my issue

Fragment:

class ModelSceneViewFragment : Fragment() {
    lateinit var sceneContext : Context
    lateinit var scene: Scene
    lateinit var sceneView : SceneView
    var containerActivity : FragmentActivity? = null

    companion object {
        fun newInstance(): ModelSceneViewFragment {
            return ModelSceneViewFragment()}}

    override fun onAttach(context: Context) {
        sceneContext = context
        super.onAttach(context)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {

        val view: View = inflater.inflate(activity_model_scene, container, false)
        containerActivity = activity
        return view
    }

    override fun onStart() {
        super.onStart()
        sceneView = new_scene
        scene = sceneView.scene // get current scene
        renderObject(Uri.parse("Hamburger.sfb"), "Hamburger")
    }

    private fun renderObject(parse: Uri, name: String?) {
        ModelRenderable.builder()
                .setSource(sceneContext, parse)
                .build()
                .thenAccept {
                    addNodeToScene(it,name)
                }
                .exceptionally {
                    val builder = AlertDialog.Builder(sceneContext)
                    builder.setMessage(it.message)
                            .setTitle("error!")
                    val dialog = builder.create()
                    dialog.show()
                    return@exceptionally null
                }
    }

    private fun addNodeToScene(model: ModelRenderable?, modelName : String?) {
        var bestNode :Node

        model?.let {
                bestNode = Node().apply {
                //setParent(scene)
                localPosition = Vector3(0f, -.4f, -1f)
                localScale = Vector3(3f, 3f, 3f)
                name = modelName
                renderable = it
                setParent(scene)
            }
        }
    }

    override fun onPause() {
        super.onPause()
        sceneView.pause()
    }

    override fun onResume() {
        super.onResume()
        sceneView.resume()
    }
}

Activity Holding Fragment:

class ContainerActivity : FragmentActivity() {

    private lateinit var currentFragment: Fragment

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.container)
        setFragmentView()
    }

    private fun setFragmentView() {

        currentFragment = ModelSceneViewFragment.newInstance()
        supportFragmentManager
                .beginTransaction()
                .add(R.id.model_frame, currentFragment)
                .commit()
    }
}

layout for fragment

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    tools:context = ".ModelSceneViewFragment">
>

    <com.google.ar.sceneform.SceneView
        android:id="@+id/new_scene"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFF" />

</android.support.constraint.ConstraintLayout>

OK the issue is that Sceneform uses a color to apply tone mapping to the rendered scene. This makes the white be slightly darker. I've marked this as a feature request to be able to turn it off, or control the color being applied.

Still can't make white background in a normal way on SceneView with 1.7.

Creating a node and adding him to the scene with a white background is annoying a bit.

Should now be resolved on 1.8.0 as the bug fixes state:
https://github.com/google-ar/sceneform-android-sdk/releases/tag/v1.8.0

Still got this issue in version 1.10.0 - any updates?

Well, finally I fixed it by code witch I completely not proud of...
Ugly, but works.

Hope google team will fix that annoying issue soon.

import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import com.google.ar.sceneform.SceneView

class FixedBackgroundSceneView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null
): SceneView(context, attrs) {

    override fun setBackground(drawable: Drawable?) {
        (drawable as? ColorDrawable)?.let { colorDrawable ->
            val argb = colorDrawable.color
            val alpha = android.graphics.Color.alpha(argb)
            val red = android.graphics.Color.red(argb)
            val green = android.graphics.Color.green(argb)
            val blue = android.graphics.Color.blue(argb)
            val sceneColor = com.google.ar.sceneform.rendering.Color(
                red / 256F,
                green / 256F,
                blue / 256F,
                alpha / 256F
            )
            this.renderer?.setClearColor(sceneColor.inverseTonemap())
        }
    }
}

Maybe it will help someone

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dementia2029 picture dementia2029  路  3Comments

LukasStancikas picture LukasStancikas  路  3Comments

peronecode picture peronecode  路  3Comments

tigran-babajanyan picture tigran-babajanyan  路  3Comments

JessHolle picture JessHolle  路  3Comments