Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Last active October 22, 2019 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flushpot1125/b35ac3e454ac9523a23b32c7b34b451c to your computer and use it in GitHub Desktop.
Save flushpot1125/b35ac3e454ac9523a23b32c7b34b451c to your computer and use it in GitHub Desktop.
define({
inputs: {
scriptLoaded: "string",
domElement: "domelement",
},
outputs: {
outputValue: "number"
},
destroy: function(inputs, outputs) {
},
setup: function(inputs, outputs) {
},
run: function(inputs, outputs, changedInputs) {
if (!inputs.scriptLoaded) {
return;
}
// Ref from :https://doc.babylonjs.com/babylon101/first
var canvas = document.getElementById("canvas");
var engine = new BABYLON.Engine(canvas, true);
var createScene = function () {
// Create the scene space
var scene = new BABYLON.Scene(engine);
// Add a camera to the scene and attach it to the canvas
var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 2, new BABYLON.Vector3(0,0,5), scene);
camera.attachControl(canvas, true);
// Add lights to the scene
var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene);
// Add and manipulate meshes in the scene
var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter:2}, scene);
return scene;
};
var scene = createScene(); //Call the createScene function
// Register a render loop to repeatedly render the scene
engine.runRenderLoop(function () {
scene.render();
});
// Watch for browser/canvas resize events
window.addEventListener("resize", function () {
engine.resize();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment