I have a problem (again) when adding Babylon modules in Magento whether it’s GUI library or GLTFLoader. Babylon itself loads fine.
For example when I get the error message "Uncaught TypeError: Cannot read properties of null (reading ‘_getComponent’)"
at this point var adt = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI(‘UI’);
Magento uses requirejs to load javascript files and uses AMD technology. That’s why it reads this part of the code upon reading the babylon.gui.js files
Here is my requirejs-config.js settings in Magento
var config = {
paths: {
“babylonjs”: “Threedwebco_Stardust/js/babylon”,
“babylonjs-gui”: “Threedwebco_Stardust/js/babylon.gui”
}
};
And here is how I access the files in my phtml file require([‘jquery’,‘babylonjs’,‘babylonjs-gui’],function($){ }
Thanks for the reply. After making your suggested change I get this error
babylon.gui.js:16018 Uncaught TypeError: Cannot read properties of undefined (reading ‘Vector2’)
at …/…/…/lts/gui/dist/2D/measure.js (babylon.gui.js:16018:72)
at webpack_require (babylon.gui.js:26669:41)
at …/…/…/lts/gui/dist/2D/controls/control.js (babylon.gui.js:4325:66)
at webpack_require (babylon.gui.js:26669:41)
at …/…/…/lts/gui/dist/2D/controls/container.js (babylon.gui.js:3730:66)
at webpack_require (babylon.gui.js:26669:41)
at …/…/…/lts/gui/dist/2D/controls/rectangle.js (babylon.gui.js:10823:68)
at webpack_require (babylon.gui.js:26669:41)
at …/…/…/lts/gui/dist/2D/controls/button.js (babylon.gui.js:1783:68)
at webpack_require (babylon.gui.js:26669:41)
We define a module name, then define its dependencies, and then run the require function with the first variable in the factory function to be the dependency (i.e. BABYLON).
I wonder - what would happen if you actually define the variables like this:
If I run console.log(BJS) , it returns the following
Module {…}
AbstractActionManager: (…)
AbstractAssetTask: (…)
AbstractMesh: (…)
AbstractScene: (…)
AcquireNativeObjectAsync: (…)
Action: (…)
ActionEvent: (…)
and all the rest of functions
OK I found out that when mapping the javascript libraries in Magento, I have to use the same name that the Babylon library exports, otherwise it won’t work