createProceduralTexture not working with Generated NodeMaterial

Hi

I wanted to follow one of the tutorials (YouTube - Node-Based Procedural Textures) that you have and all work nice up to some point.

So this is working PG:

https://playground.babylonjs.com/#L8IJYI#1

All works nicely when NodeMaterial is used as a snippet and loaded from here:

https://nme.babylonjs.com/#BU5JEQ#1

anim_1

So the default PB as it is.

Now

When I “generate code” from that snippet and use this as my nodeMaterial:

Switch if in line 96 to false:

image

I got this error in a Console:

image

I started to investigate this and it’s this mode selector in NME:

image

But this option is not passed with Generated Code. When I use Inspector in my PG I got that my NodeMaterial is normal default Material and all my nodes from snippet are reset to default settings of NodeMaterial Procedural:

Alsoe this code that I found:

nodeMaterial.setToDefaultProceduralTexture();

I tried to use it here at the beginning of my PG but its also not doing much:

image

The mode is read-only so I was thinking this method will set my NodeMaterial editor mode to Procedural, and code after that will be used as desired creating procedural mode NodeMaterial but no.

When you uncomment this line it creates something even weirder. It has my all nodes plus default nodes from NME new material. I got double Vertex output and double FragmentOutput after that. And of course, it’s not working:

I really do not get it. How to make this code run from Generated Code.

I’m using BabylonJS 4.2 but the result is the same as in Playground.

setToDefaultProceduralTexture is indeed not what you want as it creates the default blocks for a procedural texture node material that are just added to the existing blocks: it is used by the NME itself to create the starting state when you click on “Reset to default”.

Regarding your problem, it seems first that you did not generate the code corresponding to your latest iteration in the NME, some blocks are missing. Also, the “xy” input of the VectorMerger is named “xyIn” internally, so the generated code positiond.output.connectTo(PositionD.xy ); should be positiond.output.connectTo(PositionD.xyIn ); instead. Making those changes and adding nodeMaterial._mode = BABYLON.NodeMaterialModes.ProceduralTexture; does work:

https://playground.babylonjs.com/#L8IJYI#3

Of course, you should not have to do those changes yourself (and updating a private property is not a solution, anyway).

Pinging @Deltakosh as I don’t really understand the code of VectorMergerBlock (the inputs are registered as "xyz " and "xy " with a space in them and not as “xyzIn” / “xyIn”) and I’m not sure how to fix those problems…

Ohh. Thank you.

It actually works now.

But like you said I should not need to change the private variable. But also it’s not set properly during Code Generation.

Thanks, Peter