lundi 27 janvier 2020

Sceneform ARCore load and build a random 3D asset

I have a method that builds and spawns a 3D asset in an AR environment. The 3D asset is .sfb file stored in the metadata folder. I have multiple 3D assets in the metadata folder, and I wish to have an asset selected at random when this function is called. This is the code I have for spawning a specific asset:

private void addCreatureToScene() {

    ModelRenderable
            .builder()
            **.setSource(this, Uri.parse("20170219_Dragon_small.sfb"))**
            .build()
            .thenAccept(renderable -> {

                    Node node = new Node();
                    node.setRenderable(renderable);
                    scene.addChild(node);

                    Random random = new Random();
                    int x = random.nextInt(6);
                    int z = random.nextInt(6);
                    int y = random.nextInt(5);

                    z = -z;

                    node.setWorldPosition(new Vector3(
                            (float) x,
                            y / 10f,
                            (float) z
                    )); 
            });
} 

The .setSource code in bold is where a specific 3D asset is referenced. Is there a way to randomly select a 3D asset from the metadata folder? Thank you for your help.




Aucun commentaire:

Enregistrer un commentaire