Creating a Mesh without adding to the scene

I can’t find a way to create a mesh before adding it to the scene. I found this issue 5 years ago that I have to remove it after creating; How to create a mesh without add it to the scene. · Issue #642 · BabylonJS/Babylon.js · GitHub

Is this still the case? It feels unintuitive to do it like this.
Could it not also cause side effects having meshes being part of the scene for a short time?

I don’t understand why I have to give the scene as a parameter in the first place, since leaving it out or setting it to null has the same effect as using “scene”.

Also with this approach my IDE complains that my variables (for example plate) are not used in the code.

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

what kind of mesh you wanna make?
like new mesh or box …

Boxes, Cylinders and Spheres

i have way for make geometry without any webgl dependency and you quickly can use
and attach the mesh when you want in the any scene is that what you want?

I’m looking for something like this:

let plate = BABYLON.MeshBuilder.CreateBox("plate1", { width: 30, depth: 30,height: 5});
.
.
.
scene.addChild(plate);

https://www.babylonjs-playground.com/#2LEYZZ

look may be that help
i make the sphere sample for you too

https://www.babylonjs-playground.com/#2LEYZZ#1

How about this Babylon.js Playground

The current scene is used as the default if none is given. When working with multiple scenes it is necessary to specify which scene an object has to be placed in, for example https://www.babylonjs-playground.com/#L0IMUD#1

1 Like

Is it possible to prevent the automatic adding to the scene?

https://www.babylonjs-playground.com/#XKMWDG#1

2 Likes

Is there any difference to the MeshBuilder method except the adding to the scene?

export class MeshBuilder {
    public static CreateBox(name: string, options: { size?: number, width?: number, height?: number, depth?: number, faceUV?: Vector4[], faceColors?: Color4[], sideOrientation?: number, frontUVs?: Vector4, backUVs?: Vector4, wrap?: boolean, topBaseAt?: number, bottomBaseAt?: number, updatable?: boolean }, scene: Nullable<Scene> = null): Mesh {
        return BoxBuilder.CreateBox(name, options, scene);
    }

export class BoxBuilder {
    public static CreateBox(name: string, options: { size?: number, width?: number, height?: number, depth?: number, faceUV?: Vector4[], faceColors?: Color4[], sideOrientation?: number, frontUVs?: Vector4, backUVs?: Vector4, wrap?: boolean, topBaseAt?: number, bottomBaseAt?: number, updatable?: boolean }, scene: Nullable<Scene> = null): Mesh {
        var box = new Mesh(name, scene);
        options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);
        box._originalBuilderSideOrientation = options.sideOrientation;
        var vertexData = VertexData.CreateBox(options);
        vertexData.applyToMesh(box, options.updatable);
        return box;
    }
}

No.

1 Like