Using Javascript from SpiderBasic
falsam
 
Posts: 269
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
http://falsam.com

Sorry for my poor english
User avatar
Peter
 
Posts: 553
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
HPW
 
Posts: 34
Joined: Thu May 04, 2017 4:25 pm

Re: Babylon.js : Problem with the latest release

by HPW Mon Jun 04, 2018 2:50 pm

Helo falsam,

Did you find a solution for your problem?
Woud nice to know that te latest Version is usable with spiderbasic.

Regards
Hans-Peter
falsam
 
Posts: 269
Joined: Mon May 05, 2014 9:49 pm
Location: France

Re: Babylon.js : Problem with the latest release

by falsam Wed Jun 06, 2018 8:31 pm

Unfortunately, I don't have a solution to integrate the new version (3.2) of the babylon.js framework. The framework creator also has no solution at the moment.
Deltakosh@babylon.js wrote:it seems like the babylonjs file is loaded too late.
:arrow: Source (3 Mars)

➽ Windows 10 - JDK 1.8 - SB 2.20 - Android 5.5
http://falsam.com

Sorry for my poor english
HPW
 
Posts: 34
Joined: Thu May 04, 2017 4:25 pm

Re: Babylon.js : Problem with the latest release

by HPW Fri Aug 03, 2018 5:25 am

Hello falsam,

Any News about solving the problem?

Or news on this topic: viewtopic.php?f=8&t=1507


Regards
Hans-Peter
User avatar
Peter
 
Posts: 553
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Babylon.js : Problem with the latest release

by Peter Fri Aug 03, 2018 7:49 am

HPW wrote:Any News about solving the problem?

I'm afraid that only Fred can solve this problem.

Greetings ... Peter
HPW
 
Posts: 34
Joined: Thu May 04, 2017 4:25 pm

Re: Babylon.js : Problem with the latest release

by HPW Fri Aug 03, 2018 9:41 am

I'm afraid that only Fred can solve this problem.


So we hope that he will do it for next update. Currently he seems busy with purebasic 5.7

Regards
Hans-Peter
poshu
 
Posts: 73
Joined: Mon Feb 24, 2014 11:46 pm

Re: Babylon.js : Problem with the latest release

by poshu Fri Aug 03, 2018 10:03 am

Well, I'm working on the jankiest solution ever (it does work for web export though :3) but yeah, for a more robust and long term solution, we need Fred to fix it.
falsam
 
Posts: 269
Joined: Mon May 05, 2014 9:49 pm
Location: France

Re: Babylon.js : Problem with the latest release

by falsam Tue Aug 07, 2018 9:53 pm

Peter wrote:I'm afraid that only Fred can solve this problem.
Yes, I confirm ;)

➽ Windows 10 - JDK 1.8 - SB 2.20 - Android 5.5
http://falsam.com

Sorry for my poor english
falsam
 
Posts: 269
Joined: Mon May 05, 2014 9:49 pm
Location: France

Re: Babylon.js : Problem with the latest release

by falsam Thu Aug 09, 2018 3:21 pm

YeahHHHhhh ! Finally, the framework loads correctly in the DOM.

Babylonjs uses the require.js script which was not true in the previous version.

With previous versions of babylon.js I loaded the script like this
Code: Select all
require(["https://cdnjs.cloudflare.com/ajax/libs/babylonjs/3.0.0-alpha/babylon.js"]

With the new version
Code: Select all
require(["babylonjs", "https://cdnjs.cloudflare.com/ajax/libs/babylonjs/3.2.0/babylon.js"

New snippet without babylon.sbi
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(["babylonjs", "https://cdnjs.cloudflare.com/ajax/libs/babylonjs/3.2.0/babylon.js"], 
 
  ! function(BJS) {
  !   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

➽ Windows 10 - JDK 1.8 - SB 2.20 - Android 5.5
http://falsam.com

Sorry for my poor english
Return to Javascript

Who is online

Users browsing this forum: No registered users and 0 guests