Importing NodeMaterial with tree shaking

Hi all! We are doing some tree-shaking of our babylon bundle, so doing specific imports for required classes, etc. When I import the NodeMaterial class like this

import { NodeMaterial } from “@babylonjs/core/Materials/Node/nodeMaterial”;

and then use this method:

      NodeMaterial.ParseFromSnippetAsync("#CA2RY8#21", RFS.scene).then(
        nodeMaterial => {
          m.material = nodeMaterial;
        }
      );

I get this error in console:

 **Uncaught (in promise) Build of NodeMaterial failed:**

input vector from block worldPos[TransformBlock] is not connected and is not optional.
input rgba from block FragmentOutput[FragmentOutputBlock] is not connected and is not optional.

But when I’m using the Babylon namespace and not the specific import, there are no errors. Any ideas?

1 Like

cc @RaananW

PS: not a full solution, but I was able to get it to work from importing from whole /Node directory rather than /Node/nodeMaterial

Wondering if I need to import that whole folder or just certain bits?

Seems like we are missing some imports.
The temporary solution to load everything from /Node would be what I would suggest until I find the time to fully analyze this :slight_smile:

4 Likes

Just a follow up on this one - currently there is no way around importing the entire node module when parsing, since we don’t know beforehand which blocks will be used when parsing.

I hope to address this soon with a new type of package that will be more import-on-demand-friendly.

2 Likes