Skip to content

Instantly share code, notes, and snippets.

@kmorin
Created June 15, 2020 23:54
Show Gist options
  • Save kmorin/9530a34311c404d0696cf371ff64faed to your computer and use it in GitHub Desktop.
Save kmorin/9530a34311c404d0696cf371ff64faed to your computer and use it in GitHub Desktop.
glb loader babylonjs
import { Engine } from '@babylonjs/core/Engines/engine';
import { Scene } from '@babylonjs/core/scene';
import { SceneLoader, Vector3, HemisphericLight, ArcRotateCamera } from '@babylonjs/core';
import '@babylonjs/loaders/glTF';
import 'pepjs';
window.addEventListener('DOMContentLoaded', function () {
let glbFile = "sci-fi-room.glb";
// let glbFile = "pbr-spheres.gltf";
const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
const engine = new Engine(canvas);
let scene = new Scene(engine);
let camera = new ArcRotateCamera("camera1", 0, 0, 10, new Vector3(0, 0, 0), scene);
// This targets the camera to scene origin
camera.setPosition(new Vector3(0, 0, 20));
// This attaches the camera to the canvas
camera.attachControl(canvas, true);
camera.speed = 5;
// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
let light = new HemisphericLight("light1", new Vector3(0, 1, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
// Append the glb/gltf file to the scene
SceneLoader.Append("./", glbFile, scene, (scene) => {
//do more stuff if needed
});
engine.runRenderLoop(() => {
scene.render();
});
window.addEventListener('resize', function () {
engine.resize();
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment