SceneView / sceneform-android

Sceneform Maintained is an ARCore Android SDK with Google Filament as 3D engine. This is the continuation of the archived Sceneform
https://sceneview.github.io/sceneform-android/
Apache License 2.0
634 stars 146 forks source link

How to hide the white part and only keep the door that the ring enters? #404

Closed weijiaqi closed 1 year ago

weijiaqi commented 2 years ago

微信图片_20220812111822

weijiaqi commented 2 years ago

Only the entrance is kept, and the white part is hidden. How to do it?

grassydragon commented 2 years ago

Hi! It isn't a simple question. You should experiment with occlusion materials and rendering priority if you want the white shell to be invisible but hide objects inside it.

weijiaqi commented 2 years ago

AnchorNode anchorNode = new AnchorNode();

    Vector3 point = new Vector3(0, 0, -2);
    anchorNode.setWorldPosition(point);
    anchorNode.setParent(arFragment.getArSceneView().getScene());

    TransformableNode andy = new TransformableNode(transformationSystem);
    andy.setParent(anchorNode);
    andy.setRenderable(this.model4).animate(true).start();
    andy.setWorldScale(new Vector3(5f, 5f, 5f));
    andy.setLocalPosition(new Vector3(0f, 2f, -7f));
    andy.setLocalRotation(Quaternion.axisAngle(new Vector3(0f, 1f, 0f), 180f));

    andy.getScaleController().setEnabled(false);

 //   andy.getRotationController().setEnabled(false);

    //model4 is the inner object model3 is the white mask
    Node node = new Node();
    node.setParent(andy);
    node.setRenderable(this.model3).animate(true).start();
weijiaqi commented 2 years ago

Is it correct to write the rendering priority like this?

weijiaqi commented 2 years ago

https://download.redph.cn/meta/ar/q1.glb https://download.redph.cn/meta/ar/q2.glb With these two models it is not possible to achieve a white shell that is invisible but hides the objects inside it,Can you help me see if I'm missing any steps?

weijiaqi commented 2 years ago

ModelRenderable.builder() .setSource(this, Uri.parse("models/baike1.glb")) .setIsFilamentGltf(true) .setAsyncLoadEnabled(true) .build() .thenAccept(model -> { MainActivity activity = weakActivity.get(); if (activity != null) { activity.model3 = model; activity.model3.setRenderPriority(Renderable.RENDER_PRIORITY_LAST); activity.model3.setShadowCaster(true); activity.model3.setShadowReceiver(true); } }) .exceptionally(throwable -> { Toast.makeText( this, "Unable to load model", Toast.LENGTH_LONG).show(); return null; });

    ModelRenderable.builder()
            .setSource(this, Uri.parse("models/tiankongdimian1.glb"))
            .setIsFilamentGltf(true)
            .setAsyncLoadEnabled(true)
            .build()
            .thenAccept(model -> {
                MainActivity activity = weakActivity.get();
                if (activity != null) {
                    activity.model4 = model;
                    activity.model4.setRenderPriority(0);
                    activity.model4.setShadowCaster(true);
                    activity.model4.setShadowReceiver(true);
                }
            })
            .exceptionally(throwable -> {
                Toast.makeText(
                        this, "Unable to load model", Toast.LENGTH_LONG).show();
                return null;
            });
weijiaqi commented 2 years ago

The effect I want to achieve is ar portal, but I have been unable to make the white mask transparent

weijiaqi commented 2 years ago

hi, brother, please reply when you see it, give me some ideas to solve it

grassydragon commented 2 years ago

See how this is done for augmented faces: https://github.com/SceneView/sceneform-android/blob/master/ux/src/main/java/com/google/ar/sceneform/ux/AugmentedFaceNode.java#L243 I'm not sure if it is possible to achieve in glTF.

weijiaqi commented 2 years ago

When did you write a demo of an ar portal? There is very little Android-related information on git.

grassydragon commented 2 years ago

I haven't. It is just a similar functionality of hiding other objects with an invisible face mesh :sweat_smile:

weijiaqi commented 2 years ago

@grassydragon I exited and entered multiple times in my class, and then a black screen appeared in the interface rendering, but the click event of the model still existed. I checked all the related problems and could not solve it. How can I avoid this situation? How to write it in the onDestroy method

grassydragon commented 2 years ago

I actually haven't used any special code in the onDestroy method and haven't encountered this problem.

weijiaqi commented 2 years ago

On the Samsung Note10, I first entered the class class to render the model, and the screen went black when I exited and then entered. How do I destroy the previously rendered ones?

weijiaqi commented 2 years ago

Is the model too complicated?

grassydragon commented 2 years ago

Are you using a fragment or an activity for the AR screen?

weijiaqi commented 2 years ago

fragment

grassydragon commented 2 years ago

This can cause some problems if the fragment isn't destroyed. You can try using an activity.

weijiaqi commented 2 years ago

ok, thanks

weijiaqi commented 2 years ago

I tried to modify it, and I changed it to the same as the ar-model-viewer-java provided in the demo, but there will still be a black screen after exiting and re-entering

weijiaqi commented 2 years ago

https://download.redph.cn/meta/ar/shijie1.glb

weijiaqi commented 2 years ago

This is my model, will it have something to do with the material of the model?

grassydragon commented 2 years ago

I tried to modify it, and I changed it to the same as the ar-model-viewer-java provided in the demo, but there will still be a black screen after exiting and re-entering

If you see the same behavior when you replace the model in the sample application, it can be a problem with the model, yes.

weijiaqi commented 2 years ago

How can I turn off the ambient light, when I go to view the model at night, it is dark

weijiaqi commented 2 years ago

ArSceneViewKt.setLightEstimationConfig(this.arSceneView, LightEstimationConfig.DISABLED);

weijiaqi commented 2 years ago

After I turned it off, the model started to turn yellow

weijiaqi commented 2 years ago
    this.arSceneView.setFrameRateFactor(SceneView.FrameRate.FULL);
    ArSceneViewKt.setLightEstimationConfig(arSceneView, LightEstimationConfig.DISABLED);
    HDREnvironmentKt.loadEnvironmentAsync(
                          HDRLoader.INSTANCE,
                            this,
                            "environments/studio_small_09_2k.hdr",
                            false,
                           LifecycleOwnerKt.getLifecycleScope(this),
                            hdrEnvironment -> {
                                    float indirectLightIntensity = SceneViewKt.getEnvironment(arSceneView).getIndirectLight().getIntensity();
                                   SceneViewKt.setEnvironment(arSceneView, new Environment(hdrEnvironment.getSphericalHarmonics(), hdrEnvironment.getIndirectLight(), null));
                                   SceneViewKt.getEnvironment(arSceneView).getIndirectLight().setIntensity(indirectLightIntensity);
                                    return Unit.INSTANCE;
                               }
                            );
weijiaqi commented 2 years ago

I saw this part of the code you wrote, and I still have a problem after adding it

weijiaqi commented 2 years ago

After adding the effect 11

weijiaqi commented 2 years ago

the effect i want 222

grassydragon commented 2 years ago

After I turned it off, the model started to turn yellow

It comes from the default HDR environment.

I saw this part of the code you wrote, and I still have a problem after adding it

Rendering the occlusion shell shouldn't affect the materials of other objects.

weijiaqi commented 2 years ago

So how do I write it, I want my model not to be affected by any light, and the model will show what it looks like

grassydragon commented 2 years ago

Take a look at this issue: https://github.com/SceneView/sceneform-android/issues/322 I don't remember if it is actually possible to set the ambient light to a color instead of an HDR texture.

ThomasGorisse commented 2 years ago

You have to set the sceneView.environment.indirectLight to the same .hdr that was used inside your model.

ThomasGorisse commented 2 years ago

But anyway, this is more a not exported gltf texture issue.

weijiaqi commented 2 years ago

hi, my model doesn't use hdr textures, I use jpg or png, how can I avoid yellowing?@ThomasGorisse

grassydragon commented 2 years ago

hi, my model doesn't use hdr textures, I use jpg or png, how can I avoid yellowing?@ThomasGorisse

Hi! Maybe not inside your model but in the 3D modeling program that was used for creating and previewing the model.

weijiaqi commented 2 years ago

I found that the modeling program uses softUmbrella.hdr, but after I added it, the program could not run and crashed directly

weijiaqi commented 2 years ago

微信图片_20220825162007

weijiaqi commented 2 years ago

2222

weijiaqi commented 2 years ago

This is all the hdr in the modeling program, I tried each of them individually, but still didn't show the desired effect

weijiaqi commented 2 years ago

The problem of the black screen still exists. The following situation occurs on some Xiaomi phones and Samsung phones. I have not found a good solution. When I kill the app from the background and enter again, it is normal. I am exiting the current Do I need to do anything related to the class?

weijiaqi commented 2 years ago

https://user-images.githubusercontent.com/16206185/187160240-2527774f-1cc8-4cc8-85f9-bd9b4711a0d6.mp4

weijiaqi commented 2 years ago

I have hidden the cloud aiming point, which is directly presented by opening the current activity. I will send you the relevant code. Please help me to see

weijiaqi commented 2 years ago

This is the code for the layout

<androidx.fragment.app.FragmentContainerView
    android:id="@+id/arFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
weijiaqi commented 2 years ago

Below is the activity

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState == null) {
            if (Sceneform.isSupported(this)) {
                getSupportFragmentManager().beginTransaction()
                        .add(R.id.arFragment, CleanArFragment.class, null)
                        .commit();
            }
        }
        loadModels();
    }

    public void loadModels() {
        WeakReference<ArCenterConsoleActivity> weakActivity = new WeakReference<>(this);
        ModelRenderable.builder()
                .setSource(this, Uri.parse("models/shijieqiu.glb"))
                .setIsFilamentGltf(true)
                .setAsyncLoadEnabled(true)
                .build()
                .thenAccept(model -> {
                    ArCenterConsoleActivity activity = weakActivity.get();
                    if (activity != null) {
                        activity.model = model;
                    }
                })
                .exceptionally(throwable -> {
                    Toast.makeText(
                            this, "Unable to load model", Toast.LENGTH_LONG).show();
                    return null;
                });
          handlerModel = new Handler();
        handlerModel.postDelayed(mAdModel, 1000);
}

 Runnable mAdModel = () -> showObj();

private void showObj() {
        anchorNode = new AnchorNode();
        anchorNode.setParent(arFragment.getArSceneView().getScene());

        andy = new TransformableNode(transformationSystem);
        andy.setParent(anchorNode);
        andy.setRenderable(this.model).animate(true).start();
        andy.setWorldScale(new Vector3(0.3f, 0.3f, 0.3f));
        andy.setLocalPosition(new Vector3(0f, 3.7f, -10.5f));
        andy.getRenderableInstance().setCulling(false);
        andy.getScaleController().setEnabled(false);
        andy.getRotationController().setEnabled(false);
        andy.getTranslationController().setEnabled(false);
        andy.select();
}
grassydragon commented 2 years ago

Hi! While it isn't probably related to the issue with a black screen, I suggest not to use a timeout (handlerModel.postDelayed(mAdModel, 1000);) but to show the model in thenAccept.

grassydragon commented 2 years ago

Other than that Xiaomi and Samsung can modify Android more than other brands. Is the activity destroyed when going back from it?

weijiaqi commented 2 years ago

Ok thanks, I removed the handler and the phone started to get hot when loading multiple models. Is there a solution to this?

grassydragon commented 2 years ago

I don't think these things are related to each other.