camera_anim_JSON.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <html>
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>camera_anim</title>
  5. <!-- edit path - name of babylon library as required -->
  6. <script src="./lib/babylon.js"></script>
  7. <style>
  8. html, body { width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; }
  9. #renderCanvas{ width: 100%; height: 100%; }
  10. #button {
  11. color: white; background-color: Dimgray;
  12. font-size: 14pt; font-weight: bold;
  13. padding-left:4pt; padding-right:4pt;
  14. border: black outset 2pt; line-height: 2em;
  15. cursor: pointer;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div id="buttonbar" style="background-color: Darkorange;">
  21. <span id="button" onclick="pausePlay()"> Pause - Play </span>
  22. </div>
  23. <canvas id="renderCanvas"></canvas>
  24. <script>
  25. if (BABYLON.Engine.isSupported()) {
  26. var canvas = document.getElementById("renderCanvas");
  27. var engine = new BABYLON.Engine(canvas, true);
  28. console.log("Babylon version: " + BABYLON.Engine.Version);
  29. var running = true;
  30. var myCam;
  31. var scene;
  32. var url = "./TOB-out/" // edit when .babylon / texture files in a different dir than html
  33. BABYLON.SceneLoader.Load(url, "camera_anim.babylon", engine,
  34. function (newScene) {
  35. scene = newScene; // assign so visible external function
  36. newScene.executeWhenReady(function () {
  37. myCam = newScene.getCameraByName("Camera");
  38. var myLight = newScene.getLightByID("Point");
  39. myLight.parent = myCam;
  40. // Attach camera to canvas inputs
  41. newScene.activeCamera.attachControl(canvas);
  42. // Once the scene is loaded, register a render loop
  43. engine.runRenderLoop(function() {
  44. newScene.render();
  45. });
  46. });
  47. },
  48. function (progress) {
  49. // To do: give progress feedback to user
  50. }
  51. );
  52. }else{
  53. alert("WebGL not supported in this browser.\n\n" +
  54. "If in Safari browser, check 'Show Develop menu in menu bar' on the Advanced tab of Preferences. " +
  55. "On the 'Develop' menu, check the 'Enable WebGL' menu item.");
  56. }
  57. // Resize
  58. window.addEventListener("resize", function () {
  59. engine.resize();
  60. });
  61. function pausePlay() {
  62. var animatable = scene.getAnimatableByTarget(myCam);
  63. if (!running)animatable.restart();
  64. else animatable.pause();
  65. running = !running;
  66. }
  67. </script>
  68. </body>
  69. </html>