Sceneform-android-sdk: How to change plane detection colour?

Created on 28 May 2018  路  11Comments  路  Source: google-ar/sceneform-android-sdk

Hello,

When I scan surface using this SDK I have found white dot plane. Now instead of white dot plane, I have to change it to blue dot plane so how to do this.
screenshot_20180528-184755_augment 3d

question

Most helpful comment

@mistrydarshan99 Hi, try this code:

         // Build texture sampler
        Texture.Sampler sampler = Texture.Sampler.builder()
                .setMinFilter(Texture.Sampler.MinFilter.LINEAR)
                .setMagFilter(Texture.Sampler.MagFilter.LINEAR)
                .setWrapMode(Texture.Sampler.WrapMode.REPEAT).build();

        // Build texture with sampler
        CompletableFuture<Texture> trigrid = Texture.builder()
                .setSource(this, R.drawable.trigrid_0)
                .setSampler(sampler).build();

        // Set plane texture
        this.sceneformFragment.getArSceneView()
                .getPlaneRenderer()
                .getMaterial()
                .thenAcceptBoth(trigrid, (material, texture) -> {
                    material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture);
                });

Result :
screenshot_20180605-144612

All 11 comments

You can change the color of the plane by setting the color parameter of the plane's material like this:

arSceneView.getPlaneRenderer().getMaterial().thenAccept(material -> material.setFloat3(PlaneRenderer.MATERIAL_COLOR, new Color(0.0f, 0.0f, 1.0f, 1.0f)) );

For information about all of the material parameters available for the plane, see the PlaneRenderer documentation here.

@dsternfeld7 plane color changes successfully. But now I have to try to render texture image instead of color while plane detected but it will not work as expected. Here is my texture image.

CompletableFuture<Texture> build = Texture.builder().setSource(this, R.drawable.images).build();
arFragment.getArSceneView()
        .getPlaneRenderer()
        .getMaterial()
        .thenAcceptBoth(build, (material, texture) -> {
          material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture);
          //material.setFloat3(PlaneRenderer.MATERIAL_COLOR, new Color(0.0f, 0.0f, 1.0f, 1.0f));
        });

images
Output:
screenshot_20180531-185240_augment 3d

Another issue is that horizontal and vertical surface detected successfully when I detect a ceiling plane is not visible on ceiling detection, but I put android anchor on it see screenshot:
screenshot_20180531-185936_augment 3d

I believe you can get the behavior you expect by changing the MATERIAL_UV_SCALE parameter. This parameter is used to control the size at which the texture is tiled in world-space, the default values are setup for the default texture. Try this and see what happens:

CompletableFuture<Texture> build = Texture.builder().setSource(this, R.drawable.images).build();
arFragment.getArSceneView()
        .getPlaneRenderer()
        .getMaterial()
        .thenAcceptBoth(build, (material, texture) -> {
          material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture);
          material.setFloat2(PlaneRenderer.MATERIAL_UV_SCALE, 50.0f, 50.0f);
        });

The plane not rendering on ceiling planes sounds like a bug. Can you open a new issue specifically to track that bug?

Hi,

I have used your code still issue is not fixed. Below is a screenshot.
screenshot_20180601-112457_augment 3d

@mistrydarshan99 Hi, try this code:

         // Build texture sampler
        Texture.Sampler sampler = Texture.Sampler.builder()
                .setMinFilter(Texture.Sampler.MinFilter.LINEAR)
                .setMagFilter(Texture.Sampler.MagFilter.LINEAR)
                .setWrapMode(Texture.Sampler.WrapMode.REPEAT).build();

        // Build texture with sampler
        CompletableFuture<Texture> trigrid = Texture.builder()
                .setSource(this, R.drawable.trigrid_0)
                .setSampler(sampler).build();

        // Set plane texture
        this.sceneformFragment.getArSceneView()
                .getPlaneRenderer()
                .getMaterial()
                .thenAcceptBoth(trigrid, (material, texture) -> {
                    material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture);
                });

Result :
screenshot_20180605-144612

@KamikX Thanks, bro. it works very well.

Hi. I think that this issue is not fixed properly. Custom texture have wrong proportions.

We also need to set uvScale for Image like this:
material.setFloat2("uvScale", 1f, 1.19245f);

FYI, this doesn't work w/ vector drawables...you can stick the PNG into the drawables-nodpi folder though.

How can i apply texture on an object

Hi, try this code:

         // Build texture sampler
        Texture.Sampler sampler = Texture.Sampler.builder()
                .setMinFilter(Texture.Sampler.MinFilter.LINEAR)
                .setMagFilter(Texture.Sampler.MagFilter.LINEAR)
                .setWrapMode(Texture.Sampler.WrapMode.REPEAT).build();

        // Build texture with sampler
        CompletableFuture<Texture> trigrid = Texture.builder()
                .setSource(this, R.drawable.trigrid_0)
                .setSampler(sampler).build();

        // Set plane texture
        this.sceneformFragment.getArSceneView()
                .getPlaneRenderer()
                .getMaterial()
                .thenAcceptBoth(trigrid, (material, texture) -> {
                    material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture);
                });

Result :
screenshot_20180605-144612

Hey @KamikX. Thanks for the code. I want to replicate the same for the model. I'm trying to apply a picture to the model. I tried the above code for the plane and it worked. I was applying the texture using modelrenderable.setMaterial(), but I didn't find success the texture is extended. Kindly help me with this.
Thanks in Advance
Chandu.

Was this page helpful?
0 / 5 - 0 ratings