thank you.
Your code works. But that does not help me here. I have a full working little project (sorry no playground - it is local only). I am still getting same error there. I copied all the Babylon script tags from your index as well.
I also do not have not much HTML code around.
Here is my init code:
function initCanvas(canvas) {
engine = new BABYLON.Engine(canvas, true, {
preserveDrawingBuffer: true,
stencil: true,
})
engine.enableOfflineSupport = false
engine.resize()
// This is really important to tell Babylon.js to use decomposeLerp and matrix interpolation
BABYLON.Animation.AllowMatricesInterpolation = true
scene = new BABYLON.Scene(engine)
clearColorDefault=scene.clearColor
// var camera = new BABYLON.ArcRotateCamera("camera1", Math.PI / 2, Math.PI / 4, 3, new BABYLON.Vector3(0, 1, 0), scene);
let camera = new BABYLON.ArcRotateCamera("camera1",Math.PI / 2,Math.PI / 2, 3,new BABYLON.Vector3(0, 1, 0),scene)
camera.attachControl(canvas, true)
camera.lowerRadiusLimit = 1.2
camera.upperRadiusLimit = 8
camera.wheelDeltaPercentage = 0.01
camera.onViewMatrixChangedObservable.add(() => {
dispatchChange({type:"camera",position:camera.position,rotation:camera.rotation})
})
let light = new BABYLON.HemisphericLight("light1",new BABYLON.Vector3(0, 1, 0),scene)
light.intensity = 0.6
light.specular = BABYLON.Color3.Black()
let light2 = new BABYLON.DirectionalLight( "dir01", new BABYLON.Vector3(0, -0.5, -1.0), scene)
light2.position = new BABYLON.Vector3(0, 5, 5)
// Shadows
let shadowGenerator = new BABYLON.ShadowGenerator(1024, light2)
shadowGenerator.useBlurExponentialShadowMap = true
shadowGenerator.blurKernel = 32
var groundMaterial = new BABYLON.GridMaterial("groundMaterial", scene);
groundMaterial.majorUnitFrequency = 1;
groundMaterial.minorUnitVisibility = 0.1;
groundMaterial.gridRatio = 1;
groundMaterial.backFaceCulling = false;
groundMaterial.mainColor = new BABYLON.Color3(0, 0, 0);
groundMaterial.lineColor = new BABYLON.Color3(0,0, 0);
groundMaterial.opacity = 0.2;
var ground = BABYLON.Mesh.CreateGround("ground1", 20, 20, 2, scene)
ground.material = groundMaterial
scene.debugLayer.show() // produces error
startRenderLoop(engine, canvas)
}
some vars like scene are defined outside that function. It is a Svelte project.
My Svelte template is just one line:
<canvas id="renderCanvas" {width} {height} bind:this={canvas} class="canvas"/>
and here I use it in my index.html
<fds-3d-scene camera_behaviour="" width="1000" height="1000" style="width:1000px;height:1000px;display:block" id="sceneEditor"></fds-3d-scene>
fds-3d-scene is my custom element tag here.