Jump to content

Help with SceneLoader.Load in .Net Core


boston160
 Share

Recommended Posts

Hi,

I've got a problem with loading scene with .babylon extension. I making project in .NET Core with BabylonJS addon and I got a problem with this script:

      // Get the canvas element from our HTML below
      var canvas = document.querySelector("#renderCanvas");
      // Load the BABYLON 3D engine
      var engine = new BABYLON.Engine(canvas, true);
      // -------------------------------------------------------------
      
      engine.enableOfflineSupport = false;

      var scene = new BABYLON.Scene(engine);

      BABYLON.SceneLoader.Load("./js/", "babilon_blender.babylon", engine, function(newScene){
          var scene = newScene;

          scene.executeWhenReady(function(){
              scene.activeCamera.attachControl(canvas);

              engine.runRenderLoop(function(){
                  scene.render();
              });
          });
      });

Page is build and start loading scene, but this is over. Neverending loading with Babylon mark.
Could someone help me and advice what should I do to make a load scene properly?
Thanks for help :)

004.png

Link to comment
Share on other sites

Try this :

// Get the canvas element from our HTML below
      var canvas = document.getElementById("renderCanvas");
      // Load the BABYLON 3D engine
      var engine = new BABYLON.Engine(canvas, true);
      // -------------------------------------------------------------
      
      engine.enableOfflineSupport = false;

      var scene = new BABYLON.Scene(engine);

      BABYLON.SceneLoader.Append("js/", "babilon_blender.babylon", scene, function(newScene){
          scene = newScene;

          scene.executeWhenReady(function(){
              scene.activeCamera.attachControl(canvas);

              engine.runRenderLoop(function(){
                  scene.render();
              });
          });
      });

 

Link to comment
Share on other sites

Check the network logs for 404s.  For your .NET project make sure your wwwroot has the files - you may need a postbuild event to copy.  Like DK said - you can enable specific mime types in your config, but try this to start and then lock it down more after (in startup.cs):
 

app.UseStaticFiles(
    new StaticFileOptions
    {   /* unknown mime types (ie: .fx) files will not be served, otherwise! */
        ServeUnknownFileTypes = true
    }
);

edit:

Serving unknown file types is not recommended security-wise, so once you get it working switch over to FileExtensionContentTypeProvider
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files

Link to comment
Share on other sites

  • 2 weeks later...

Hi guys. I have new problem with SceneLoader. I have in Startup.cs:

            app.UseStaticFiles(new StaticFileOptions
            {
                ServeUnknownFileTypes = true
            });

And scene is loading correctly in Index.cshtml. But how do i throw a new scene in a new view (not Index.cshtml), this new scene does not load and I get an error from the console.

While I adding a new scene in Index.cshtml, it is loaded correctly.

Could someone help me and advice what should I do to make a load scene properly?
Thanks for help :)

 

Zrzut ekranu z 2017-10-04 14-53-32.png

Link to comment
Share on other sites

It looks like you are using traditional NetCore MVC full page-load.  I did a BabylonJS SPA example that works with multiple canvas/scene using "dotnet new" MVC (.NET core 2.0): https://github.com/brianzinn/dotnet-new-babylonjs-starter

The screenshot you have provided doesn't really show what the problem could be.  Show the web browser dev tools (network/console) where the issue is instead.  If there is an issue with the .babylon file then you can create a PG (playground) and lots of people available to help with reproducible errors.

Link to comment
Share on other sites

Error processing XML: no master element found Area: http: // localhost: 3262 / Home / scenes / quiz / escape.babylon

Row number: 1, column 1: escape.babylon: 1: 1

Error: Error status: 404 - Unable to load scenes / quiz / escape.babylon babylon.js: 3: 5023
t.LoadFile / l / e.onreadystatechange

I get this error with the web browser dev tools.

I work on VisualCode on Debian 9. I have .NET Core 2.0 installed and the project was created in the console: dotnet new mvc.
Link to comment
Share on other sites

This is my project: https://1drv.ms/u/s!ApEWaFgXVeBEg-1R_mD2yJUGcNTPhA

I've just thrown a new project with 3D views, because the project is large and weighs a lot. Can someone peek at what I'm doing wrong in the files: Index.cshtml, QuizReception.cshtml, recepton.js and quiz_reception.js?

I just started with babylon.js and I don't know how I can add scenes in other views. The point is that as I type in the browser bar: http://localhost:5000/ - works correctly but: http://localhost:5000/Home/QuizReception - does not load scenes.

In addition, I have a problem with collision and gravity.

Link to comment
Share on other sites

It looks like the file does not exists (404).  I think that error message is Firefox specific if you return content-type "text/xml".  The network tab in dev tools is more helpful than the console in this case.

I think you need to set the .babylon file to be included as output (it's a project file property BuildAction->Content and CopyToOutputDirectory-> Copy If Newer).
Make sure that there is no "MVC" route matching /Home/scenes/quiz/escape.babylon, otherwise I believe that will activate before the static file handler.  In other words, if you try this .babylon file in the same directory as the other working scene then it will likely work.  MVC routes are handled in the order they are added.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...