1

I want to load a 3D *.glb file with babylonjs from a hidden file path like this

<html>
  <head>
    <title>Babylon.js Viewer - Display a 3D model</title>
    <script src="https://cdn.babylonjs.com/viewer/babylon.viewer.js"></script>
  </head>
  <body>
    <babylon model="https://example.com/view.php?id=blablabla.glb" templates.main.params.fill-screen="true"></babylon>
  </body>
</html>

view.php

<?php
if ($_GET['id'] != "blablabla.glb") {
    exit();
}
$file = '3dmodel.glb';
if (file_exists($file)) {   
    header('Content-type: model/gltf-binary');  
    header('Content-Disposition: attachment; filename="' . basename($file) . '"');  
    ob_clean();
    flush();
    readfile($file);
    exit; 
} 
?>

I got this error from the console "Load Error: There was an error loading the model. Unable to load from https://example.com/view.php?id=blablabla.glb: importMesh of undefined from undefined version: undefined, exporter version: undefined importMesh has failed JSON parse"

please help me, thanks.

6
  • Are there any messages in the server error log? Commented Mar 5, 2023 at 13:25
  • Does the glb file exist in the same directory as index.php? Commented Mar 5, 2023 at 13:28
  • Is your server responding to requests on the example.com domin? Commented Mar 5, 2023 at 13:29
  • yes file same dir with view.php, it fine if i load model direct without view.php Commented Mar 5, 2023 at 13:31
  • server fine i go example.com/view.php?id=blablabla.glb it download 3dmodel,glb Commented Mar 5, 2023 at 13:32

1 Answer 1

0

Add the status code to the header.

header( 'HTTP/1.1 200 OK' );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.