How can I batch everything that there are in the scene and have a single big mesh?

how can I batch everything that there are in the scene and have a single big mesh?
they must keep position and scale and rotation. they are just some separate buildings and a road and landscape…
I want to merge or join or batch them to a single mesh to use it for navmesh and pathfinding. I need to export it to the object format to import and edit in the blender too.
can you please help me to do it?

best regards.

Hi.

In first approximation, to get united mesh of whole scene, you may just recursively iterate scene objects and fetch geometrical data by Mesh.getBuffer, aggregating it applying ttransformation parent transformations.

Then you may use resulting structure as graph for A* implementation or anyhow else.

Could you tell more about context of your problem? It will make your intentions more clear and allow people make more useful hints and directions.

Also, you need to export scene to blender? That’s a bit strange. Why don’t open in blender the original model, which was used to load the scene?

i understand its not about TextureAtlas.makeAtlasBatch since you only need mesh for pathfinding.

so you can do something like:

        Mesh mesh = new Mesh();        
        List<Geometry> geoms = findGeometries();
        if(geoms != null && !geoms.isEmpty()){
            GeometryBatchFactory.mergeGeometries(geoms, mesh);
            //then just use **mesh** to get vertex and indices and whatever you need for Navmesh
        }

where in findGeometries, just find geoms what you need for pathfind generate (have them cloned in list).

Please note if you want make “tile navmesh building” then take only geoms that are on/near this tile for generate purpose. (myself im using Recast4Java configured thanks to Mitm, and use tile based generation, so can re-generate only part of navmesh)

About exporting it to Blender, you can just use this “mesh” param to generate Geometry and then export as some format to load in Blender.

just to wonder, do you generate Navmesh in blender? you no need do that there.

2 Likes

thanks for code pointer, I didn’t know about this untility class.

I’m looking to the couple of methods GeometryBatchFactory.mergeGeometries and GeometryBatchFactory.gatherGeoms, that are used in conjunction, and wonder how it handle node transformations.

mergeGeometries takes flat list of geometries, where each element may come from the different branches of scene graph with different transformations. But mergeGeometries just fetch vertexes and material data without any care transformations. gatherGeoms doesn’t deal with transformation too.

What’s the trick?

2 Likes

idk.

hmm i thought it take transforms for verts,

but if it dont, could just “apply transforms” before passing geom to geoms list i belive.

like using:

Transform transform = new Transform();
transform.setTranslation(x, y, z);

and

transform.combineWithParent(getNode().getWorldTransform());

and

transform.getTranslation().x;

i belive?

1 Like

I just looked bad. It handles transform, so everything is clear.

// GeometryBatchFactory.java:192
            geom.computeWorldMatrix();
            Matrix4f worldMatrix = geom.getWorldMatrix();
2 Likes

ah, then its all fine.

didnt even remember there is “geom.computeWorldMatrix();”

1 Like

I need to edit some parts of the navmesh, so it must be editable in the blender, and also position and scale and rotation of buildings are set in the runtime and I cant use to separate model that I used to make j3o file…

the scene is so big and spends a lot of time to generate navmesh in JME. and also I need to edit it before using it as navmesh in pathfinding.

Looks like transforms (position+scale+rotation) of your buildings are static, so why do not place them in blender too? You can define positions of buildings using special markers.

For example, I use brightly-colored cubes with special naming to define spawn points of player and monsters. And then, in runtime right after scene loading just replace them with in-game objects.

It might significantly simplify your pipeline (edit all geomtry, including navmesh, level geometry and building transforms in blender).

1 Like