unable to load Renderable registryId, No RCB file at uri

39 views Asked by At

I am getting glb format model from firebase with logs i can tell it's being downlaoded successfully. But its not loading in the scene.Here is some code provided for downloading and creating the model using nodes from firebase.

I am not sure what to do to fix this. Some help would be grealty appreciated.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FirebaseApp.initializeApp(MainActivity.this);
    FirebaseStorage storage = FirebaseStorage.getInstance();
    StorageReference modelRef = storage.getReference().child("cute_animal_penguin.glb");

    arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.arFragment);
    onUpdateListener = frameTime -> {
        if (arFragment == null || modelRenderable == null) {
            return;
        }
        ArSceneView arSceneView = arFragment.getArSceneView();
        if (arSceneView.getSession() == null) {
            return;
        }
        arSceneView.getScene().removeOnUpdateListener(onUpdateListener);
        placeModel();
    };

    findViewById(R.id.loadButton).setOnClickListener(view -> {
        try {
            File file = File.createTempFile("cute_animal_penguin", "glb");
            modelRef.getFile(file)
                    .addOnSuccessListener(taskSnapshot -> {
                        Log.d("FirebaseStorage", "Model downloaded successfully");
                        buildModel(file);
                    })
                    .addOnFailureListener(e -> {
                        Log.e("FirebaseStorage", "Failed to download the model", e);
                    });
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this, "Failed to create a temporary file", Toast.LENGTH_SHORT).show();
        }
    });
}

private void buildModel(File file) {
    Uri modelUri = Uri.fromFile(file);
    Log.d("ModelLoading", "Model URI: " + modelUri.toString());
    ModelRenderable.builder()
            .setSource(this, modelUri)
            .build()
            .thenAccept(renderable -> {
                modelRenderable = renderable;
                if (arFragment != null) {
                    arFragment.getArSceneView().getScene().addOnUpdateListener(onUpdateListener);
                }

            })
            .exceptionally(throwable -> {
                Toast.makeText(this, "Error building the model", Toast.LENGTH_SHORT).show();
                return null;
            });
}

private void placeModel() {
    if (arFragment != null) {
        ArSceneView arSceneView = arFragment.getArSceneView();
        if (arSceneView.getArFrame() != null) {
            // Create a node and attach the model to it
            TransformableNode modelNode = new TransformableNode(arFragment.getTransformationSystem());
            modelNode.setRenderable(modelRenderable);
            arSceneView.getScene().addChild(modelNode);
        }
    }
}

}

0

There are 0 answers