viromedia / virocore

ViroCore cross-platform AR/VR renderer
MIT License
370 stars 108 forks source link

Multiple ViroViewScene in a xml layout #351

Open arunavsikdershuvo opened 3 years ago

arunavsikdershuvo commented 3 years ago

Environment

  1. OS: Windows
  2. Version: ViroCore version 1.17.0
  3. Device(s): Any device

Description

I am using this library to show some animated models using vrx data without AR/VR. For requirement I need to have multiple ViroViewScene instance in a single xml layout. But when two or more ViroViewScene are loaded only the last ViroViewScene in the hierarchy shows the models, others remain blank. I'm sharing code snippet to what I'm doing `<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >

<com.viro.core.ViroViewScene
    android:id="@+id/viro_scene_left"
    android:layout_width="match_parent"
    android:layout_height="200dp"/>

<com.viro.core.ViroViewScene
    android:id="@+id/viro_scene_right"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_marginTop="15dp"
    android:layout_below="@+id/viro_scene_left"/>

`

This is the java file in where I'm trying to load models create3DSceneRight(); create3DSceneLeft();

` private void create3DSceneRight() { Scene scene = new Scene(); Node rootNode = scene.getRootNode(); rootNode.setPosition(new Vector(0, 0, 0));

    final Object3D model = new Object3D();
    model.loadModel(mViroViewRight.getViroContext(), Uri.parse("file:///android_asset/vrx_models_2/walking02.vrx"), Object3D.Type.FBX, new AsyncObject3DListener() {
        public void onObject3DFailed(String error) {
            Log.e("TAG_Bottom_right", "Failed to load the model");
        }

        public void onObject3DLoaded(Object3D object, Object3D.Type type) {
            Log.e("TAG_Bottom_Right", "Successfully loaded the model!");
        }
    });

    if (ambient == null) {
        ambient = new AmbientLight(Color.WHITE, 1000.0f);
        rootNode.addLight(ambient);
    }
    model.setPosition(new Vector(0, 0, 0));
    Node cameraNode = new Node();

    Camera camera = new Camera();
    camera.setRotationType(Camera.RotationType.STANDARD);
    cameraNode.setPosition(new Vector(0, 150, 500));
    cameraNode.setCamera(camera);
    rootNode.addChildNode(cameraNode);
    rootNode.addChildNode(model);
    mViroViewRight.setScene(scene);
    mViroViewRight.setPointOfView(cameraNode);

    mViroViewRight.setDebug(true);
}

private void create3DSceneLeft() {
    Scene scene = new Scene();
    Node rootNode = scene.getRootNode();
    rootNode.setPosition(new Vector(0, 0, 0));

    final Object3D model = new Object3D();
    model.loadModel(mViroViewLeft.getViroContext(), Uri.parse("file:///android_asset/vrx_models_3/gym.vrx"), Object3D.Type.FBX, new AsyncObject3DListener() {
        public void onObject3DFailed(String error) {
            Log.e("TAG", "Failed to load the model");
        }

        public void onObject3DLoaded(Object3D object, Object3D.Type type) {
            Log.e("TAG", "Successfully loaded the model!");
        }
    });

    if (ambient == null) {
        ambient = new AmbientLight(Color.WHITE, 1000.0f);
        rootNode.addLight(ambient);
    }
    model.setPosition(new Vector(0, 0, 0));
    Node cameraNode = new Node();
    Camera camera = new Camera();
    camera.setRotationType(Camera.RotationType.STANDARD);
    cameraNode.setPosition(new Vector(0, 150, 500));
    cameraNode.setCamera(camera);

    rootNode.addChildNode(cameraNode);

    rootNode.addChildNode(model);
    mViroViewLeft.setScene(scene);
    mViroViewLeft.setPointOfView(cameraNode);
}

`

Reproducible Demo

Just run this code snippet simply creating a project in android studio, you can see that only viro_scene_right is loading but viro_scene_left is not loading at all.

Can anyone give or suggest me any solution or a path to solution how can I achieve this? Thanks in advance.

parilyak commented 3 years ago

Hi! Have you got any progress on your issue? I might faced the same problem.

arunavsikdershuvo commented 3 years ago

Hi! Have you got any progress on your issue? I might faced the same problem.

@parilyak Hi, unfortunately not. I searched for solution but not found any. I solved it another way according to my requirements. Anyways I googled it more and found that viroviewscene actually uses surfaceview for 3D rendering.

You can go through this for better understanding.

You cannot place 2 SurfaceViews(SV) into one Activity. For understand why you should know how SVs works.

https://stackoverflow.com/questions/4991095/how-can-i-use-multiple-glsurfaceview-components-in-the-same-layout

parilyak commented 3 years ago

Hi! Thanks a lot! :)