Last active
October 6, 2021 00:10
-
-
Save oismaelash/80081e9a380b931cdd3dbcecaa6924ba to your computer and use it in GitHub Desktop.
Import mesh into scene via url babylon.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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