Multiple files for mesh creation:

I have a huge scene and want to break it up into multiple files for certain meshes. Like classes. But I cannot seem to find the right way to do this.

I am in vuetify.js and right now I am sending all my values from the vuetify components to one babylon scene file.

I would like to send only the values needed for each set of meshes to a file where they will be created then send those meshes over to the main scene.

Everything I try just ends up returning a blank white page and no vuetify or babylon. I suspect it is vuetify.

Is anyone else doing this?

I’m not familiar with vuetify. But anyhow without the code it’s really hard to say what’s wrong and how to help you.

1 Like

I just want to create meshes in a separate file and have a mesh builder class rather than do it all in one lengthy babylon.js scene file.

For what I am about to do I will need to be organized so I was just playing with primitive shapes for now but I cannot even get a mesh to load intot he main scene without a bunch of “scene name cannot be found” or “the mesh generator class doesn’t have a scene exporter” and no matter what I try….everything errors out…

Even just taking the start up scene code and adding a

getScene(): Scene
return this.scene;

to expor the scene doesn’t work….it still says no scene exporter.

export default scene;

Won’t work in my main scene file anywhere to be used by the mesh generator file.

I thought this would be easy….but cannot find any examples of this.

But seems that something I did was right….now it is working….although the values I am passing are the initial values and not the new values.

Please share some code :slight_smile:
The repo would be great.

At least for what you wrote already I’m guessing that you might have problems with ‘this’ keyword in JS.

But as I said, without the code it’s really hard to say.

1 Like

Not sure why this is so complicated. In other platforms/frameworks you can just pass things back and forth. It’s almost like I have to reference everything in both places for this to work….making me think it isn’t even worth the hassle…

It wasn’t the “this” deal……it’s the scene and having one in the “mesh generator” file to reference the scene in the main scene file where I am initializing the scene.

I have it working for now……but it still needs some work.

In the vuetify component:

const canvas = document.querySelector("canvas”)!;
new myScene(canvas, “all my values from vuetify components”

In the main babylon scene that intializes the scene and engine and has the cameras and all that. It is also importing the “MeshGenerator” file

MeshGenerator.GetMeshes(scene, "all values to generate meshes”);

In the mesh generator code, this is how it is set up to create the meshes:

import {
} from "@babylonjs/core”;

export class MeshGenerator
constructor(private scene: Scene) { }

public static GetSpineRoofs(scene: Scene | undefined, "all values to create meshes"): Mesh[] 
    let meshes: Mesh[] = [];
    //     meshes

const mesh = MeshBuilder.CreateBox(‘mesh’, { width: meshLength + 1, height: .5, depth: meshWidth + 1, updatable: true }, scene);
mesh.position = new Vector3(meshlength / 2 - someValue - meshLength / 2,
meshElev + 1,


    return meshes;


I would much rather just send the values from vuetify to the mesh generator file, but nothing I tried would work. This is the only way it would work. By calling the mesh generator from the babylon scene file.

Now that I am doing a couple other classes….this doesn’t seem like too bad of a solution.

I would like it if some of you pros would let me know if this is a good practice though….just to make sure I am doing this accurately.

Decoupling is usually good idea. So if you can split the code into smaller parts just do it.
From what you wrote already it seems to me that you should be able to pass the scene instance. Why you can’t do that I don’t know. Looks like vuetify issue, and I don’t know vuetify.
If you could provide repo or minimal repro repo would help a lot as it is guessing game without the actual code.

No, I do have it working….but I’m not sending the data to each babylon file as needed….that seems to a wasted effort because I need the scene from the main babylon scene anyway…so sending the data from there will work.

So if you have it solved please mark the most suiting post as “Solved” so the BabylonJS team (and others) know that you don’t need more help in this thread.

1 Like