Merge Ground with Height Map and other meshes

There is no problem to merge box and sphere, but they don’t want to merge with ground… with Height Map.
Seems I miss some operation which is necessary to perform before merging.
https://playground.babylonjs.com/#CQNGRK#432

Hi Labris! Actually, that looks like a perfect merge. What do you see wrong with that? Keep in mind that the box and the sphere are likely low-vertex-count, while the heightMap is higher-rez.

https://playground.babylonjs.com/#CQNGRK#434

I tried some things, here. First, see the function(){ at the end of line 18? That is a “callback function” (onLoaded…DO)… that makes sure we wait for the heightMap texture to finish loading… before we do ANYTHING else. That function ends at line 49, so almost all code below the heightMap creation line… is within that function. Safer… esp for big un-cached heightmap-displacement files.

I also added some subdivs/tessellation (segments) to the sphere… to try to make it match the heightmap, resolution-wise. If you activate line 47, you can see that the sphere and heightMap “resolution”… match fairly-closely.

A new merge line was added, too… line 44… merging all three mesh. AND, notice I didn’t add a material to ANYTHING… until AFTER mesh4 was created. Then I set material on IT, only.

Is it the “sharp” and/or “abrupt” edges around the sphere and along the edge where heightMap and box1 meet… that makes it seem like a bad merge (to you)?

Keep it mind that a merge is not an “averaging”. You can’t expect BJS mergeMeshes to soften/smooth those abrupt edges for you. It ONLY merges. There MAY BE some Catmull/Rom functions nearby… that COULD smooth those abrupt edges, but that’s some pretty fancy stuff. :slight_smile:

https://playground.babylonjs.com/#CQNGRK#435

Here… I pulled the sphere away from the heightMap, a bit, and you can see that you sort-of positioned the sphere… at a “unique” place of the heightmap… where a fun “bulge” is happening. Is THAT causing some of your questioning? Did it look like the sphere… actually deformed the heightmap at their intersection point? It didn’t, I dont think.

BECAUSE I waited until after the merge… to add the material, I was hoping that the material would sort of “continue its pattern” at the “seams”, but it doesn’t. There might be some kind of computeNewUVs() or similar… that would make the texture more continuous/fluid as it crosses mesh-seams. I’m not sure how to do that, if possible.

In #435, lines 47-49, I also disabled the three original mesh used in the merge… so we don’t have sparkles when the camera pans. :slight_smile:

Thoughts?

1 Like

Thanks, this is the perfect solution!
I had errors when tried to merge ground, maybe because of preliminary material definition.
And, also, now I know the mystery of sparkles (couldn’t understand their origin in some other scenes) !

1 Like

Thanks, Labris, good to hear.

Let’s continue to listen for comments about that, (if it is ok with you… to extend your topic-thread, Labris.)

MergeMeshes source: https://github.com/BabylonJS/Babylon.js/blob/master/src/Meshes/mesh.ts#L3953

There’s some “extended parameters” on the MergeMeshes() method:

MergeMeshes(meshes: Array, disposeSource = true, allow32BitsIndices?: boolean, meshSubclass?: Mesh, subdivideWithSubMeshes?: boolean, multiMultiMaterials?: boolean

I’m not sure if any of those… apply to this.

Yeah, our new combo-mesh is a rather oddly-shaped critter, but… one would think… that we could set its UVs in such a way… that the grid texture maps across all of it. (no pattern disruption at the seams)

Maybe… we would REMOVE all the UVs from mesh4 (if there’s some ON it or its component mesh)… and after that, the texture would map across it “whole”. It would likely be severely stretched in various places… but still… it would fun to see, just once. UVs are optional… for mesh/vertexData… ya know? We could send-in the Roto-Rooter folks to suck-out all the UVs from mesh4. :slight_smile:

Thoughts, anyone? I’m certainly no UV wizard. But DocsMaster @JohnK published some fine info, and a demo … about calculating UVs for custom mesh. Thx JK!

As soon as I get enough coffee into me… to bring my vision into focus once again, I might do some reading in that area. C’mon along, friends. :slight_smile: Thwock me if I doze-off, eh?

1 Like