# Subdivide mesh as grid

**URL:** <https://forum.babylonjs.com/t/subdivide-mesh-as-grid/32198>\
**Category:** Questions\
**Created:** [July 15, 2022, 6:49am UTC](https://forum.babylonjs.com/t/subdivide-mesh-as-grid/32198 "2022-07-15T06:49:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![arcman7](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/arcman7/32/20249_2.png) [@arcman7](https://forum.babylonjs.com/u/arcman7)\
**Post date:** [July 15, 2022, 6:49am UTC](https://forum.babylonjs.com/t/subdivide-mesh-as-grid/32198/1 "2022-07-15T06:49:58Z")

</div>

I made a go at writing a script to subdivide an arbitrary landscape mesh into a grid in the playground below. Some problems I encountered:

- stitching artifacts that show the borders of each grid piece
- malformed geometry **[Update: fixed]**

Please note that the original model uses a normal map file that’s 300+ MB; it will take a few minutes to load.

1st attempt: [https://playground.babylonjs.com/#HQBU7K#164](https://playground.babylonjs.com/#HQBU7K#164)  
2nd (fixed geometry): [https://playground.babylonjs.com/#HQBU7K#168](https://playground.babylonjs.com/#HQBU7K#168)  
3rd better UV mapping: [https://playground.babylonjs.com/#HQBU7K#172](https://playground.babylonjs.com/#HQBU7K#172)  
(also less visible seams)

I was wondering if this has already been solved by one or some combination of the methods babylon js already provides. If not, any tips?

Update/Conclusion:  
I think most people will be able to directly make use of this script -  
[https://playground.babylonjs.com/#HQBU7K#172](https://playground.babylonjs.com/#HQBU7K#172)

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [July 15, 2022, 6:59pm UTC](https://forum.babylonjs.com/t/subdivide-mesh-as-grid/32198/2 "2022-07-15T18:59:47Z")

</div>

Would [Grid Material | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/toolsAndResources/assetLibraries/materialsLibrary/gridMat) work?

---

<div class="post-metadata">

**Author:** ![arcman7](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/arcman7/32/20249_2.png) [@arcman7](https://forum.babylonjs.com/u/arcman7)\
**Post date:** [July 15, 2022, 7:56pm UTC](https://forum.babylonjs.com/t/subdivide-mesh-as-grid/32198/3 "2022-07-15T19:56:04Z")

</div>

This looks extremely promising; gonna play around with that and see if I can cook up the result I’m going for. Thank you!

---

<div class="post-metadata">

**Author:** ![arcman7](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/arcman7/32/20249_2.png) [@arcman7](https://forum.babylonjs.com/u/arcman7)\
**Post date:** [July 15, 2022, 8:21pm UTC](https://forum.babylonjs.com/t/subdivide-mesh-as-grid/32198/4 "2022-07-15T20:21:30Z")

</div>

So how would one go about generating height maps for each logical grid partition? I have a script that kind of works towards that end, but is very time intensive for detailed large maps.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [July 18, 2022, 11:14am UTC](https://forum.babylonjs.com/t/subdivide-mesh-as-grid/32198/5 "2022-07-18T11:14:24Z")

</div>

Hmmm Grid Material is mostly for display, so you’d have to roll your own thing 🤔 @Evgeni_Popov any tips for that?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [July 18, 2022, 1:00pm UTC](https://forum.babylonjs.com/t/subdivide-mesh-as-grid/32198/6 "2022-07-18T13:00:40Z")

</div>

I don’t know if it’s relevant but we have the dynamic terrain extension: [Dynamic Terrain | Babylon.js Documentation](https://doc.babylonjs.com/extensions/dynamicTerrains) ?

---

<div class="post-metadata">

**Author:** ![arcman7](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/arcman7/32/20249_2.png) [@arcman7](https://forum.babylonjs.com/u/arcman7)\
**Post date:** [July 19, 2022, 3:47am UTC](https://forum.babylonjs.com/t/subdivide-mesh-as-grid/32198/7 "2022-07-19T03:47:25Z")

</div>

This also looks super promising. And pretty interesting too. I’ll be trying this one out too, thanks!
