ES6 Mesh.CreateTiledGround arguments issue

I have npm build of babylon locally, and it wont work as docs and demo suggests:

import { Mesh, SubMesh } from '@babylonjs/core/Meshes';

entity.tiledGround = Mesh.CreateTiledGround(
	'ground',
	{ xmin, zmin, xmax, zmax, subdivisions, precision },
	scene
);

gives console.log(entity.tiledGround.getIndices().length); >> 6

Its only works with big arguments list as (I can’t put more than two links) “Full explanation of creating a tiled ground by its original code writer” in docs suggests and his demos:

Mesh.CreateTiledGround("Tiled Ground", xmin, zmin, xmax, zmax, subdivisions, precision, scene);

According to es6 docs it something works different in es6?
Shouldn’t it be written everywhere or at least throw some exceptions?

The signature in the mesh class looks like this:

public static CreateTiledGround(name: string, xmin: number, zmin: number, xmax: number, zmax: number, subdivisions: { w: number; h: number; }, precision: { w: number; h: number; }, scene: Scene, updatable?: boolean): Mesh

Apart from that, there is the MeshBuilder, which has a slightly different signature (requiring GroundBuilder:

public static CreateTiledGround(name: string, options: { xmin: number, zmin: number, xmax: number, zmax: number, subdivisions?: { w: number; h: number; }, precision?: { w: number; h: number; }, updatable?: boolean }, scene: Nullable<Scene> = null): Mesh;

I am not sure which one you are trying to use, but it all depends on which class you are addressing. The es6 issue you are referring to is just about importing the GroundBuilder in order for this to work.

If I misunderstood, please let me know!

1 Like

@RaananW thanks for reply!

I use Mesh class from doc example. Copied lines from there for example:

import { Mesh } from "@babylonjs/core/Meshes/mesh";
// Required side effects to populate the Create methods on the mesh class. Without this, the bundle would be smaller but the createXXX methods from mesh would not be accessible.
import "@babylonjs/core/Meshes/meshBuilder";

var ground = Mesh.CreateGround("ground1", 6, 6, 2, scene);

So i’m not sure which one i use too. Looks like it uses Mesh.CreateTiledGround but requires MeshBuilder.CreateTiledGround somehow

All of the Mesh.Create*** functions are very outdated and should be slowly replaced in your code. we left them there for backwards compatibility, and they will stay there further.
Internally, they use the MeshBuilder"s function. So you do need both :slight_smile:
I would recommend to anyhow use the mesh builder. they are usually better and have more configuration parameters.

1 Like

Thanks. I guess it’s better to remove outdated code from example?

pinging @sebavan for the doc remark :wink:

Actually @RaananW and @tynrare I would also tend to avoid MeshBuilder directly as it loads all the builders.

You could for more granularity only imports the required Builders like SphereBuilder and so on as detailed in the ES6 doc FAQ: ES6 - Babylon.js Documentation

How do I efficiently use the Mesh.Create… methods ?
The simplest is to load only the builder corresponding to your construction method. If you wish to use the CreateBox method, you can simply import "@babylonjs/core/Meshes/Builders/boxBuilder"; to ensure that the dependant modules have been loaded. Except if you are relying on all the MeshBuilder methods, we would recommend to not use it directly but favor the smaller builders .

1 Like