Using Javascript from SpiderBasic
falsam
 
Posts: 253
Joined: Mon May 05, 2014 9:49 pm
Location: France

Babylon.js : Problem with the latest release

by falsam Thu May 10, 2018 5:47 pm

I can't use the latest release of Babylon.js (3.2.0)

I have this error in the console.
Uncaught ReferenceError: BABYLON is not defined
The auhor of this framework says that babylon.js is not loaded correctly in the DOM.

With the old version there is no problem.

I did this test code. It is functional with the old release of Babylon.js
I commented on the latest version. Decomment her to try.
Code: Select all
Enumeration
  #mf
  #mfRender
EndEnumeration

Global BJSEngine, BJSCanvas, Scene

Declare InitEngine(Callback, CanvasGadget = #PB_Ignore)
Declare Start()
Declare InitGame()
Declare CreateScene()

Procedure InitEngine(Callback, CanvasGadget = #PB_Ignore)   
 
  ! require(["https://cdnjs.cloudflare.com/ajax/libs/babylonjs/3.0.0-alpha/babylon.js"], //Ok with this old release
 
  ;! require(["https://cdnjs.cloudflare.com/ajax/libs/babylonjs/3.2.0/babylon.js"], 
 
  ! function(t) {
  !   if (BABYLON.Engine.isSupported()) {
       
        If CanvasGadget = #PB_Ignore   
          !$('<canvas>').attr('id', 'renderCanvas')
          ! .css({ width : '100%', height : '100%' })
          ! .appendTo('body');
        Else
          !var selector = $(spider_GadgetID(v_canvasgadget))[0].gadget
          !selector.id = "renderCanvas"
          !selector.style.width = '100%'
          !selector.style.height = '100%'
        EndIf
 
  !     v_bjscanvas = document.getElementById('renderCanvas');
  !     v_bjsengine = new BABYLON.Engine(v_bjscanvas, true, { preserveDrawingBuffer: true, stencil: true });
  !     window.addEventListener('resize', function(){v_bjsengine.resize(); }); 
  !     v_callback()
  !   } else {return false}
  ! }
  !);   
EndProcedure 

Start()

Procedure Start()
  OpenWindow(#mf, 0, 0, 800, 600, "Test", #PB_Window_ScreenCentered)
  CanvasGadget(#mfRender, 0, 0, 800, 600, #PB_Canvas_Transparent)
  InitEngine(@InitGame(), #mfRender)
EndProcedure

Procedure InitGame()
  Scene = CreateScene()
  !v_bjsengine.runRenderLoop(f_renderscene)
EndProcedure

Procedure CreateScene()
  !var scene = new BABYLON.Scene(v_bjsengine);
 
  !var camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 4, Math.PI / 4, 4, BABYLON.Vector3.Zero(), scene);
  !camera.attachControl(v_bjscanvas, true);
 
  !var light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0), scene);
 
  !var box = BABYLON.MeshBuilder.CreateBox("box", {}, scene);
  !return scene
EndProcedure

Procedure RenderScene()
    !v_scene.render();
EndProcedure
If you can help me. Thank you ;)
Last edited by falsam on Fri May 11, 2018 1:57 am, edited 1 time in total.
➽ Windows 10 - JDK 1.8 - SB 2.20 - Android 5.5
Mood
http://falsam.com

Sorry for my poor english
User avatar
Peter
 
Posts: 479
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Babylon.js : Problem with the latest release

by Peter Thu May 10, 2018 9:27 pm

Hello falsam,

i have often noticed that some JS libraries cannot be loaded using require (for example https://fullcalendar.io/).
In this case, the function returns only the number 3 (instead of the object). It seems that babylon.js would belong to it also.
If you do a little research, you'll find some posts from people who have the same problem.
Unfortunately I can't tell you how to fix it.

Greetings ... Peter
Return to Javascript

Who is online

Users browsing this forum: No registered users and 0 guests