$ node server
/Users/paradigm/Documents/Project/PRODUCTS/game.hwanyong.com/11.Server/Engine/Graphic/Babylon.js/babylon.max.js:10
})(window, function() {
^
ReferenceError: window is not defined
at Object. (/Users/paradigm/Documents/Project/PRODUCTS/game.hwanyong.com/11.Server/Engine/Graphic/Babylon.js/babylon.max.js:10:4)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (/Users/paradigm/Documents/Project/PRODUCTS/game.hwanyong.com/11.Server/server.js:1:79)
at Module._compile (internal/modules/cjs/loader.js:722:30)
If I know right, is the window object valid only on the client side?
I run the example as it is, but it is difficult to get an error.
I may not have enough knowledge of node.js, or maybe I do not know the basic way to use babylon.js on the server side (in node.js).
Is it because I mistaken the babylon.max file for another file?
It seems that babylon.max.js is definitely made to work on the client side.
ps. Things I’ve tried
I’ve Googled how to use the window object in node.js.
Set the window object value in babylon.max.js to an empty object (var window = {}).
… I did a lot of other searches but it did not help.
var BABYLON = require("../../dist/preview release/babylon.max");
var LOADERS = require("../../dist/preview release/loaders/babylonjs.loaders");
global.XMLHttpRequest = require('xhr2').XMLHttpRequest;
var engine = new BABYLON.NullEngine();
var scene = new BABYLON.Scene(engine);
var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene);
var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene);
BABYLON.SceneLoader.ImportMesh("", "https://playground.babylonjs.com/scenes/", "skull.babylon", scene, function (newMeshes) {
camera.target = newMeshes[0];
console.log("Meshes loaded from babylon file: " + newMeshes.length);
for (var index = 0; index < newMeshes.length; index++) {
console.log(newMeshes[index].toString());
}
BABYLON.SceneLoader.ImportMesh("", "https://www.babylonjs.com/Assets/DamagedHelmet/glTF/", "DamagedHelmet.gltf", scene, function (meshes) {
console.log("Meshes loaded from gltf file: " + meshes.length);
for (var index = 0; index < meshes.length; index++) {
console.log(meshes[index].toString());
}
});
console.log("render started")
engine.runRenderLoop(function() {
scene.render();
})
});
The file name was saved as server.js.
Executed with the following command. $ node server.js
I installed the required npm package.
Then, as you know, an error occurs.
I did not know, so I ran “npm i window”. And modified the babylon.max.js source. On the first line I entered:
var window = require (‘window’);
Thereafter, a “Blob is undefined” error occurs.
This method was not considered a fundamental solution.