1.4.2. fejezet, STL file betöltése

<!DOCTYPE html>
<html>
  <head>
    <style>
      canvas {
        width: 100%;
        height: 100%;
      }
      html, body {
        margin: 0;
      }
    </style>
    <script src="https://cdn.babylonjs.com/babylon.js"></script>
    <script src="https://cdn.babylonjs.com/loaders/babylon.stlFileLoader.js"></script>
    <script>
      const createScene = () => {
        let switched = false;
        var firsAnimation;
 
        //BABYLON.STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES = true;
 
        const canvas = document.getElementById("renderCanvas");
        const engine = new BABYLON.Engine(canvas, true);
        const scene = new BABYLON.Scene(engine);
        scene.clearColor = new BABYLON.Color3.FromHexString("#e5e5e5");
 
        const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 3, new BABYLON.Vector3(0, 0, 0), scene);
 
        camera.setTarget(BABYLON.Vector3.Zero());
        camera.position = new BABYLON.Vector3(5, 5, 5);
        camera.attachControl(canvas, true);
        var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene);
 
        var ground = BABYLON.MeshBuilder.CreateGround("ground", {width: 50, height: 50}, scene);
        var groundMaterial = new BABYLON.StandardMaterial("ground Material", scene);
        groundMaterial.specularColor = new BABYLON.Color3.Black();
 
        ground.material = groundMaterial;
 
        BABYLON.SceneLoader.ImportMesh(
        "",
        "http://localhost/",
        "test.stl",
        scene,
        function (meshes) {
          meshes[0].position = new BABYLON.Vector3(0,0,0);
          meshes[0].scaling.x = 0.05;
          meshes[0].scaling.y = 0.05;
          meshes[0].scaling.z = 0.05;
          camera.target = meshes[0];
        });
 
        scene.registerBeforeRender(function () {
          light.position = camera.position;
        });
 
        engine.runRenderLoop(() => {
          scene.render();
        });
      }
    </script>
  </head>
  <body onload="createScene()">
    <canvas id="renderCanvas" touch-action="none"></canvas>
 
  </body>
</html>