Example of connecting nodeGeometry.json to the project page. NGE

I’m trying to learn NGE. Embarrassed to ask, but I can’t find a simple example of connecting nodeGeometry.json to the project page. Can someone tell me how to do this or give me a link?
Babylon.js Node Geometry Editor (babylonjs.com)

Here is a playground loading a node geometry from the snippet server:

If you want to load from a file simply replace:
ParseFromSnippetAsync
By:
NodeGeometry.Parse

Doc: Babylon.js docs

2 Likes

Thanks!
But maybe there are simpler examples for beginners?

This is the entry point you want to digest:
https://doc.babylonjs.com/features/featuresDeepDive/mesh/nodeGeometry#loading-and-updating-from-file

1 Like

Of course, I apologize for distracting you from your business. But I’m not sure if this is the solution. Because such a design does not work. Or I misunderstood something.

It works - const nodeGeometry = await BABYLON.NodeGeometry.ParseFromSnippetAsync(“IJA02K#14”, “”, true);

It doesn’t work - const nodeGeometry = await BABYLON.NodeGeometry.Parse(“nodeGeometry_7.json”, “”, true);

Okay, I’ll try to figure it out on my own. I’m sorry again.

If you look at the doc I shared you will see that there is an example to read from a Jason. You cannot provide the url of the json file to Parse. You need to fetch the file first and then provide the json OBJECT to the function

Please read the doc, everything is there

Of course, I substituted his file, saving it to my computer. Okay, I think there’s no point in further correspondence. I’ll study the documentation. Thanks, bye.

1 Like

It is all Jason 's fault cc @PirateJC

I wouldn’t trust any Jason examples. That feels risky. Referencing JSON on the other hand. That’s probably smarter.

I Trust Jason Seal Team GIF - I Trust Jason Seal Team Ray Perry GIFs

1 Like

Jason is a real genius. Apparently only he can figure it out. Apart from his town, I don’t see any examples on the subject of NGE at all

ok let me copy paste the code from the doc for you:

const assetsManager = new BABYLON.AssetsManager(scene);
const nodeGeometryFile = assetsManager.addTextFileTask("load my node geometry", "https://yoururl.com/nodeGeometry.json");

// callback
assetsManager.onFinish = async (tasks) {
    console.log("all tasks successful", tasks);

    // files loaded as text need to be parsed to JSON to use
    const nodeGeometryJSON = JSON.parse(nodeGeometryFile.text);

    // parse json object into node geometry
    const nodeGeometry = await BABYLON.NodeGeometry.Parse(nodeGeometryJSON);
}

// load all tasks
assetsManager.load();


1 Like

Thank you Deltakosh. You helped me a lot!
I think there is a small error in the code.
It must be so - assetsManager.onFinish = async (tasks) => {}
I added a box from the starting example (https://nge.babylonjs.com/) on my own.
Maybe it will help someone figure it out faster:

const assetsManager = new BABYLON.AssetsManager(scene);
const nodeGeometryFile = assetsManager.addTextFileTask("load my node geometry", "nodeGeometry.json");

// callback
assetsManager.onFinish = async (tasks) => {
console.log("all tasks successful", tasks);

// files loaded as text need to be parsed to JSON to use
const nodeGeometryJSON = JSON.parse(nodeGeometryFile.text);

// parse json object into node geometry
const nodeGeometry = await BABYLON.NodeGeometry.Parse(nodeGeometryJSON);

// material
var myMaterial = new BABYLON.StandardMaterial("myMaterial", scene);
myMaterial.diffuseColor = new BABYLON.Color3(1, 0, 1);

// BoxBlock
const Box = nodeGeometry.createMesh("Box");
Box.material = myMaterial;
}
// load all tasks
assetsManager.load();