Advertisement
metalx1000

Babylon JS load basic Blender 3D scene

Jun 30th, 2015
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <title>Using babylon.js - How to load a Blender 3D scene</title>
  5.     <script src="http://cdn.babylonjs.com/2-1/babylon.js"></script>
  6.     <style>
  7.         html, body {
  8.             width: 100%;
  9.             height: 100%;
  10.             padding: 0;
  11.             margin: 0;
  12.             overflow: hidden;
  13.         }
  14.  
  15.         #renderCanvas {
  16.             width: 100%;
  17.             height: 100%;
  18.         }
  19.     </style>
  20. </head>
  21. <body>
  22.     <canvas id="renderCanvas"></canvas>
  23.  </body>
  24. <script>
  25.     var scene, camera;
  26.     if (BABYLON.Engine.isSupported()) {
  27.         var canvas = document.getElementById("renderCanvas");
  28.         var engine = new BABYLON.Engine(canvas, true);
  29.  
  30.         BABYLON.SceneLoader.Load("", "scene.babylon", engine, function (newScene) {
  31.             scene=newScene;
  32.             // Wait for textures and shaders to be ready
  33.             newScene.executeWhenReady(function () {
  34.                 // Attach camera to canvas inputs
  35.                 camera = new BABYLON.ArcRotateCamera("ArcRotateCamera", 10, 1, 50, new BABYLON.Vector3(0, 0, 0), scene);
  36.                 scene.activeCamera = camera;
  37.                 scene.activeCamera.attachControl(canvas);
  38.  
  39.                 // Once the scene is loaded, just register a render loop to render it
  40.                 engine.runRenderLoop(function() {
  41.                     newScene.render();
  42.                 });
  43.             });
  44.         }, function (progress) {
  45.             // To do: give progress feedback to user
  46.             console.log(progress.loaded + " of " + progress.total + " loaded!!!");
  47.         });
  48.     }
  49. </script>
  50.  
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement