BabylonJS 5 release

Hi @Deltakosh!

I was thinking how could I help to move to BJS5 and I came up with an idea to automatically modify all the existing PGs so we can get rid of the deprecated BABYLON.Mesh.CreateXXX functions. I wrote a simple parser using acorn JS parser and created a simple node.js script which automatically rewrites the lines in the input string. There are still official examples using the deprecated methods and ton of custom PGs using them. I believe nobody is going to rewrite (I mean the custom ones) them so it would be cool to run this script on all PGs in the database.

The basic setup is:

Define the functions and parameters to be replaced:

const toReplace = [
  {
    name: "CreateTube",
    oldFunction:
      "name, path, radius, tesselation, radiusFunction, cap, scene, updatable, sideOrientation, instance",
    newFunction:
      "name, { path, radius, tesselation, radiusFunction, cap, updatable, sideOrientation, instance }, scene",
  },
  {
    name: "CreateBox",
    oldFunction: "name, size, scene, updatable, sideOrientation",
    newFunction: "name, { size, updatable, sideOrientation }, scene",
  },
// more to add
];

The script can handle optional parameters, inlined functions (arrow & classic as well) and pretty much everything thanks to acorn. :muscle:

An example input string:

const a = 3
BABYLON.Mesh.CreateTube("dd", myPath, 10, 4, function(o,p) {
    if (true) {
        function whatever(input1, input2) {
            return input1 + input2
        }
        return whatever(1, 2)
    } else {
        return dd
    }
}, 0, scene, true)
const y = 1

output:

const a = 3
BABYLON.MeshBuilder.CreateTube("dd", { path: myPath, radius: 10, tesselation: 4, radiusFunction: (o,p) => {
    if (true) {
        function whatever(input1, input2) {
            return input1 + input2
        }
        return whatever(1, 2)
    } else {
        return 10
    }
}, cap: 0, updatable: true  }, scene)
const y = 1

It is just a quick (under an hour) implementation but if you guys are interested in this stuff I can continue to work on it, test it thoroughly and dedicate it to the community.

:vulcan_salute:

2 Likes