Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Created November 30, 2024 10:50
Show Gist options
  • Select an option

  • Save flushpot1125/ab1078d3585fa8864cf2abeddaf1dd71 to your computer and use it in GitHub Desktop.

Select an option

Save flushpot1125/ab1078d3585fa8864cf2abeddaf1dd71 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Babylon.js sample code</title>
<script src="https://preview.babylonjs.com/babylon.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<canvas id="renderCanvas"></canvas>
<script src="index.js"></script>
</body>
</html>
//}
//emlist[style.css (CSS)][css]{
html, body {
overflow: hidden;
width: 100%; height: 100%;
margin: 0; padding: 0;
}
#renderCanvas {
width: 100%; height: 100%;
}
//}
//emlist[index.js (JavaScript)][js]{
const canvas = document.getElementById("renderCanvas");
const engine = new BABYLON.Engine(canvas, true);
const createScene = () => {
const scene = new BABYLON.Scene(engine);
const camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2,
Math.PI / 2, 2, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);
const light = new BABYLON.HemisphericLight("light",
new BABYLON.Vector3(1, 1, 0), scene);
const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {});
return scene;
}
const scene = createScene();
engine.runRenderLoop(() => { scene.render();});
window.addEventListener("resize", () => { engine.resize(); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment