Mesh builder modules deprecated?

When importing the mesh builders I get this warning about them being deprecated: “Deprecated symbol used, consult docs for better alternative”.

I double-checked the doc and with @RaananW’s example straight from the GitHub repo I also get the same warnings (for SphereBuilder and GroundBuilder).

import { SphereBuilder } from "@babylonjs/core/Meshes/Builders/sphereBuilder";
import { GroundBuilder } from "@babylonjs/core/Meshes/Builders/groundBuilder";
1 Like

I think you should use the create… functions directly:

import { CreateSphere } from "@babylonjs/core/Meshes/Builders/sphereBuilder";
import { CreateGround } from "@babylonjs/core/Meshes/Builders/groundBuilder";
1 Like

Hmm on a related note, I wonder if there’s a better way to pack the create functions into a MeshBuilder object than like below? I’m not so savvy with modules. :blush:

import { CreateSphere } from "@babylonjs/core/Meshes/Builders/sphereBuilder";
import { CreateGround } from "@babylonjs/core/Meshes/Builders/groundBuilder";
const MeshBuilder = { CreateSphere,  CreateGround};
1 Like

There is always a better way :slight_smile:

But the MeshBuilder will be removed very soon from the esm version of the library and you will only have the different builders in their packages. We do need to make sure the documentation is updated when it gets to that, but the MeshBuilder (and all of the Mesh.Create???) functions) are deprecated and will be delivered only when using the current packages.
To truly support tree shaking we should never have a class like the mesh builder. It imports everything, including thins you don’t need. This is why it is deprecated, and this is why it was done this way.

I’m not talking about the MeshBuilder, I’m talking about the separate builders like the ones you use in your example project that I linked in the first post.

Not those, the builders like SphereBuilder and GroundBuilder that I included in the first post…

I’m not doing that in any of the code that I posted thou… I think maybe you missed my first post. :eyes:

But if the builders that you use in your example aren’t being deprecated then I’ll just continue using those, however it would be nice to get rid of the deprecated warning if they aren’t being deprecated, or to update your example if they are. :slight_smile:

1 Like

My comment was very general, and didn’t talk about anything you said or didn’t.
I just tried to explain the thought behind the current state and future architecture.
I should have maybe be a bit more specific about what “builders” are, and what stays or not. This was just an explanation. Please don’t that that as “you are doing something wrong”.

Every builder is in its own module. There won’t be builders, as they are not needed. there will be exported functions from modules. The create functions from the builders modules (i.e. from the builder files) will not be deprecated. The MeshBuilder and all other static-based classes will be deprecated. However, they will never be removed from our umd and @babylonjs packages, as we support backwards compatibility. We will eventually have a side-effects-free package which will not have those functions at all.

So for example then, are you saying that the groundBuilder module will continue to export the functions CreateGround, CreateGroundFromHeightMap, and CreateTiledGround, but will no longer have the below export which I’m getting warned is deprecated? Just to be sure we’re talking about the same thing…

export const GroundBuilder: {CreateGround: typeof CreateGround, CreateGroundFromHeightMap: typeof CreateGroundFromHeightMap, CreateTiledGround: typeof CreateTiledGround}

yes, that’s the plan. This export will not exist in the new package, but will continue residing in the UMD and current es packages, because of back-compat.

This is the plan! I still haven’t stqarted working out the little issues with that, so please bare with me if it changes with time. But an export const that exports existing functions feels a bit redundant, and not tree-shaking friendly.

2 Likes

Okay, thank you very much for bearing with me and clearing that up. I understood the MeshBuilder was being deprecated but not that the little wrappers in the individual modules were too.

Personally I would dislike having lots of related functions dangling around so will prob just put them in my own MeshBuilder module like below. :slight_smile:

import { CreateSphere } from "@babylonjs/core/Meshes/Builders/sphereBuilder";
import { CreateGround } from "@babylonjs/core/Meshes/Builders/groundBuilder";
export const MeshBuilder = { CreateSphere, CreateGround };

yeah, that’s the one downside of a single package. I will take that into account, and see if I can keep those little modules with a single export. we try to minimize the code needed to get started with the framework. Any redundant code should be removed, but it should also be easy to use…

1 Like