2
votes

I was trying to cover the whole surface of the detected plane with a texture. Using OpenGl (like in the HelloAr sample) enables me do this like this screenshot . However i want to switch to Sceneform and i only could get something like this by following other questions in the Github. These are the codes that i used currently for texture rendering. To conclude, i do not want this spotlight texture on the plane. I want to cover whole detected plane like my first screenshot. Can you give some information about how can i achieve this? Thank you!

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

    CompletableFuture<Texture> trigrid = Texture.builder()
            .setSource(this, R.drawable.gray)
            .setSampler(sampler).build();

    PlaneRenderer planeRenderer = arSceneView.getPlaneRenderer();
    planeRenderer.getMaterial().thenAcceptBoth(trigrid, (material, texture) -> {
        material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture);
    });`
4
I'm trying to make the same on my code to test, but is crashing on the setSource, can you show a little more where you put this part of the code? Until there, one suggestion, did you tried to make gray more transparent? like: #78ABABABCanato
Actually gray is just a 8x8 gray rectangle image. These codes are just after the setting the arscene at onCreateAlperen Kantarcı

4 Answers

2
votes

I found the solution both using other answers and combine them. Proper plane rendering can be done like below. Important point is this renderable should be called at every frame otherwise ARCore overrides it and you don't see the effect that you want. Here is a code that solves my problem.

arSceneView.getScene().addOnUpdateListener(frameTime -> {
            PlaneRenderer planeRenderer = arSceneView.getPlaneRenderer();
            planeRenderer.getMaterial().thenAcceptBoth(trigrid, (material, texture) -> {
                material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture);
                material.setFloat(PlaneRenderer.MATERIAL_SPOTLIGHT_RADIUS, Float.MAX_VALUE);
            });

});
1
votes

You can control the radius of the spotlight on the material. To make the spotlight effect go away, you can set the radius to a large number:

planeRenderer.getMaterial().thenAcceptBoth(trigrid, (material, texture) -> {
    material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture);
    material.setFloat(PlaneRenderer.MATERIAL_SPOTLIGHT_RADIUS,1000);
});
0
votes

From this, probably is the size of your texture that are a little strange.

Change the MATERIAL_UV_SCALE parameter. This parameter is used to control the size at which the texture.

planeRenderer.getMaterial()
.thenAcceptBoth(trigrid, (material, texture) -> {
    material.setTexture(PlaneRenderer.MATERIAL_TEXTURE, texture);
    material.setFloat2(PlaneRenderer.MATERIAL_UV_SCALE, 50.0f, 50.0f);

});
0
votes

this code is work on device with one camera but on device with more than one camera surface detect is work but not show texture on it. how can fix this!?