Here is what I tried to save, which doesn’t seem that long:
export const createScene = function () {
var scene = new BABYLON.Scene(engine);
let camera = new BABYLON.TargetCamera("topdown", new BABYLON.Vector3(0,0,-500), scene, true);
camera.setTarget(BABYLON.Vector3.Zero());
camera.fov = BABYLON.Tools.ToRadians(18.5);
let sceneSize = 500;
var ground = BABYLON.MeshBuilder.CreatePlane("ground", {size: sceneSize}, scene);
ground.receiveShadows = true;
let shadowOffset = 1;
let directionalLight = new BABYLON.DirectionalLight("directional light", new BABYLON.Vector3(shadowOffset, -shadowOffset, shadowOffset * 4), scene);
directionalLight.position = new BABYLON.Vector3(0, 0, -1000);
directionalLight.intensity = 0.7;
let shadowGenerator = new BABYLON.ShadowGenerator(2048, directionalLight);
shadowGenerator.useBlurExponentialShadowMap = true;
shadowGenerator.useKernelBlur = true;
shadowGenerator.blurKernel = 16;
createCubes(100, sceneSize, shadowGenerator, scene);
return scene;
};
function createCubes(num, size, shadowGenerator, scene) {
for (let i = 0; i < num; i++) {
let depth = 10 * 0.25;
var cube = BABYLON.MeshBuilder.CreateBox("p", {width: 10, height: 10, depth}, scene);
let randomx = Math.random() * size * 0.5;
let randomy = Math.random() * size * 0.5;
cube.position.x = Math.random() > 0.5 ? randomx : -randomx;
cube.position.y = Math.random() > 0.5 ? randomy : -randomy;
cube.position.z = -depth;
let m = new BABYLON.StandardMaterial("m", scene)
m.diffuseColor = new BABYLON.Color3.Random();
cube.material = m;
shadowGenerator.addShadowCaster(cube);
}
}
The console shows a CORS issue between https://www.babylonjs-playground.com/ and https://snippet.babylonjs.com/.