Skip to content

Instantly share code, notes, and snippets.

@oismaelash
Last active October 6, 2021 00:10
Show Gist options
  • Save oismaelash/80081e9a380b931cdd3dbcecaa6924ba to your computer and use it in GitHub Desktop.
Save oismaelash/80081e9a380b931cdd3dbcecaa6924ba to your computer and use it in GitHub Desktop.
Import mesh into scene via url babylon.js
// Playground with Typescript
// Video: https://youtu.be/rveqYRRO-lo
// Author: Ismael Ash
// www.ismaelnascimento.com
class Playground {
public static CreateScene(
engine: BABYLON.Engine,
canvas: HTMLCanvasElement): BABYLON.Scene
{
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
// This creates and positions a free camera (non-mesh)
var camera = new BABYLON.FreeCamera(
"camera1",
new BABYLON.Vector3(0, 5, -10),
scene);
// This targets the camera to scene origin
camera.setTarget(BABYLON.Vector3.Zero());
// This attaches the camera to the canvas
camera.attachControl(canvas, true);
// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
var light = new BABYLON.HemisphericLight(
"light1",
new BABYLON.Vector3(0, 1, 0),
scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
const SCENE_URL = "https://raw.githubusercontent.com/mateuscondefeitosa/Archives/main/"
BABYLON.SceneLoader.ImportMesh(
"",
SCENE_URL,
"sieel_stand_1.glb",
scene,
onModelImported);
function onModelImported(){
console.log(scene.meshes[0].name)
// scene.meshes[0] = "root"
const ROOT_OBJ = scene.meshes[0]
ROOT_OBJ.getChildren().forEach(mesh => {
mesh.parent = null
})
ROOT_OBJ.dispose()
}
return scene;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment