Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple ViroViewScene in a xml layout #351

Open
arunavsikdershuvo opened this issue Mar 27, 2021 · 3 comments
Open

Multiple ViroViewScene in a xml layout #351

arunavsikdershuvo opened this issue Mar 27, 2021 · 3 comments

Comments

@arunavsikdershuvo
Copy link

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
`

<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
Copy link

parilyak commented Jun 1, 2021

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

@arunavsikdershuvo
Copy link
Author

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
Copy link

parilyak commented Jun 2, 2021

Hi! Thanks a lot! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants