Author Topic: Align hexagrid to underlying terrain  (Read 171 times)

Doxs_Roxs

  • Newbie
  • *
  • Posts: 4
    • View Profile
Align hexagrid to underlying terrain
« on: August 28, 2020, 06:45:00 PM »
Hi

Im pretty new but Ill try to explain what Im trying to do.

I got a custom mesh under the hexasphere.
Is there a way to have the hexasphere conform to the underlying mesh?

I hope the picture can make it easier to see what I am trying to do.
Currently it is intersecting mountains while hovering over the sea and flat areas.
« Last Edit: August 30, 2020, 01:08:14 PM by Kronnect »

Doxs_Roxs

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Align hexagrid to underlying terrain
« Reply #1 on: August 29, 2020, 01:57:15 PM »
I think it should be possible to use the wire shader to project straight down on the planet instead of having it in a sphere, but I am not quite sure how.
I do not care if the cells are distorted with one side of a hex on land and the other going off a cliff. I plan to go through and mark what cells can be accessible by land, sea, air etc. later.
I do not plan to use the hex grid for graphics except as a positional grid for units and buildings.

If this is outside the scope of Hexasphere Im ok with that too, but even as a complete noob and no real understanding of the underlaying system I have the feeling that it could be doable with a few mouse clicks.
If I find an easy way to do it Ill post it here, any help is appreciated. If not Ill have to try and make my own solution :)

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6214
    • View Profile
Re: Align hexagrid to underlying terrain
« Reply #2 on: August 30, 2020, 12:48:39 PM »
Although there's no way to provide a heightmap in inspector (and it should be an option, noted for next update), you can call:

Code
hexa.ApplyHeightMap (heightMap);

where heightMap is a texture where the red channel contains the elevation. You need to have the extrusion option enabled first.

Note that this option will make the entire cell pop according to the elevation at the center of the tile. It won't lay the vertices on top of the terrain individually. This won't be complicated, though. I think we can add this option as well as this seems an interesting and useful use case.

Doxs_Roxs

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Align hexagrid to underlying terrain
« Reply #3 on: August 30, 2020, 10:09:56 PM »
Although there's no way to provide a heightmap in inspector (and it should be an option, noted for next update), you can call:

Code
hexa.ApplyHeightMap (heightMap);

where heightMap is a texture where the red channel contains the elevation. You need to have the extrusion option enabled first.

Note that this option will make the entire cell pop according to the elevation at the center of the tile. It won't lay the vertices on top of the terrain individually. This won't be complicated, though. I think we can add this option as well as this seems an interesting and useful use case.

Thank you, I had already checked out the extrusion as a plan b just to get started until I can get my own solution fixed.

If you can implement vertices on top of the terrain as part of Hexasphere it would be awesome!
I'm also pretty sure your solution will be way better then mine :p

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6214
    • View Profile
Re: Align hexagrid to underlying terrain
« Reply #4 on: August 31, 2020, 01:42:28 PM »
Do you have a sample scene including a heighmap texture used to extrude the vertices of your planet? I'd like to have a reference for testing purposes during dev.

Doxs_Roxs

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Align hexagrid to underlying terrain
« Reply #5 on: August 31, 2020, 09:24:43 PM »
Do you have a sample scene including a heighmap texture used to extrude the vertices of your planet? I'd like to have a reference for testing purposes during dev.

Of course, but I am worried it might be a bit to large to send you my entire project, also I'm not quite sure exactly what files to send you since the planets are generated using code that is not mine.

Just to mock up a prototype I used the following planet generator and inserted a Hexasphere, perhaps you can use it directly as a reference?
https://github.com/SebLague/Solar-System/tree/Episode_02

The only thing I did was to adjust the size so that it fits the planet and fiddle around a bit with the planet generator settings.

If that does not work I can try and make a lightweight version and send it to you, but I'm not sure I can pull it off without breaking things ;D