Node material from external file

hello everyone…
I was trying to use the code generated in nodeMaterial Editor… but save it in an external file.

how should I call this file? and how can I call it in?
don’t know how to proceed on this one.

thanks for your support

const myNodeMaterial = BABYLON.NodeMaterial.Parse(myJson, scene)

Example -


or if you store the json as a file: BABYLON,NodeMaterial.ParseFromFileAsync(“”, url… might come handy :slight_smile:


thanks a lot for your help!
sorry it took time to get back at you… i was trying to make that work…

Yeah I was trying to save a code in a json as a file, but couldn’'t make it work.
I need it to be externaly in a file… cause I cant use an external link outside from my folders.

I tried saving the data generated by the nodeMaterial editor and saved as a file called “myMaterial.js”

then, inside my code

 BABYLON,NodeMaterial.ParseFromFileAsync(“”,“myMaterial.json”, scene).then( (nodeMaterial) => {
        var newMaterial= nodeMaterial;
        sphere.material = newMaterial;

should it be something like this?

  1. You have ‘,’ instead of ‘.’ after BABYLON.
  2. For this function you need to provide json URL and also build node material itself.
  3. Here is the example -
    I saved slightly greened material to json and then load it to the left sphere. Seems it works :slight_smile:
    BABYLON.NodeMaterial.ParseFromFileAsync('testJson', "", scene).then((nodeMaterial) => {;
        shield3.material = nodeMaterial;

Thanks a lot!
Now working like charm!
I wanted to use several materials in a project that will be chosen from variables…
So now I can have the material code in separated files and will have a cleaner code…

Thanks a lot… will be sharing my results soon!

1 Like