you are mixing to concepts here , frontend and backend.
Nodejs is backend , there is no problem using any nodejs code for nodejs purposes , meaning backend scripts/code.
All files that are front end files of your application would not use any nodejs code. They would communicate with the backend via requests.
Of coure a front end can make a request to a file using a *relative path , browser technology handles this via requests and so babylonjs does not need the fs module to do this , it would be using the built in file request methods of javascript engines.
( on the same domain ) or using absolute paths to some other domain (so long it is not restricted by CORS ) , but they remain sandboxed browser requests non the less, You cannot execute file system code ( like reading a directory or file ) from a front end application.
Thanks. Maybe I should better explain what I am trying to do.
I have a set of model files stored in a database, some of which have a mesh with a particular name. If a mesh in the model satisfies a specific condition, I will store the pose matrix of that mesh, dispose it, then serialize the model again to override the subject model.
If the models were glTF, I could try to mathematically obtain the pose matrix of the mesh by interpreting its JSON fields, however I’d prefer utilizing Babylon JS for that, also files are stored as glb and obtaining the glTF file from that would be troublesome.
I would like to implement a Node JS function to be called by backend between acquiring the blob/file and exporting the newly generated scene hierarchy. I am basically trying to avoid implementing getPoseMatrix in C#
ok sorry i didnt read what you were asking in detail , im not sure why you note you cant use ‘require’ ?
you have to require the fs module in some way , i use the promises version myself , eg
const fs = require("fs").promises;
i see node documentation showing this :
const fs = require('node:fs');
i prefer the promises version because i can use await , eg :
try {
var result = await fs.readFile(filePath, "utf-8");
return result;
} catch (error) {
logger.error(error.message);
logger.info("error trying to read file " + filePath);
}
Oh that require detail was a little unnecessary. What I wanted to point out was I cannot find “dist/preview release” and therefore cannot import (require) them in my code.
If your model is across multiple physical files - then your approach of loading data with fs will not work. if you are loading only .glb (single file) then you need to specify “binary” encoding (instead of utf-8). The sceneLoader appendAsync accepts File, but also data:... and array buffer view.
The actual code will depend on your version of Node.js as well as the physical file locations - assuming something like an expressjs server - they are deployed with the server. If you are using something like cloud storage to serve via HTTP (like a gateway) then you can bypass HTTP and access cloud storage directly from Node as well.