Search Unity

The terrain can draw on sphere

Discussion in 'Wish List' started by noolza, Mar 6, 2009.

  1. noolza

    noolza

    Joined:
    Mar 6, 2009
    Posts:
    27
    I want Terrain contain a sphere not only a plane
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Perhaps a derivative class of the Terrain could do this, but practically it would render a lot of members of the Terrain class nonfunctional or nonsensical. If you're trying to make a planet, you're probably better off writing a custom class from scratch IMO.
     
  3. joe gamble

    joe gamble

    Joined:
    Jan 3, 2007
    Posts:
    85
    I have developed code that can build terrain on a sphere. It doesn't use the built in terrain classes. It's all custom code. Not exactly sure what you are looking for, but maybe my code would work for you.
     
  4. joe gamble

    joe gamble

    Joined:
    Jan 3, 2007
    Posts:
    85
    I'll try to post some images later if you are interested.
     
  5. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    I'm interested!

    Just because it's interesting, not for any practical use, however.
     
  6. joe gamble

    joe gamble

    Joined:
    Jan 3, 2007
    Posts:
    85
    Still a work in progress. I haven't put a lot of energy into textures yet.
    The terrain is all procedural. These are NOT imported models.
    The number of verts can be modified for more/less resolution of the mesh.
    I'll probably add fbx exporter so I can save these off.

    The number and size of the islands can be controlled.

    The heights of the terrains can also be modified or constrained. I could also add creation from a height map with little trouble.

    Clouds work off a different set of verts with particles applied.
    The ocean is a separate mesh of lower vertex resolution.

    Let me know what you think.
     

    Attached Files:

  7. fursund

    fursund

    Joined:
    Dec 2, 2008
    Posts:
    30
    This is cool, and looks good, though it seems you have some problems with the seam. A small editor tool for editing the heightmap could be even cooler. That way you could make a small distributable package called PlanetCreator (reminds me of Hitchhikers Guide to the Galaxy. Go make some fjords in Norway!).
     
  8. fursund

    fursund

    Joined:
    Dec 2, 2008
    Posts:
    30
  9. joe gamble

    joe gamble

    Joined:
    Jan 3, 2007
    Posts:
    85
    Thanks for the feedback.

    I already saw the problem with the seam. It just hasn't been a priority yet. I'll get that fixed soon.

    I had a former incarnation of this code already working with the FBX exporter but I recently overhauled the way I'm creating the mesh so I'll have to revisit that code, make some tweaks and make sure it still works.

    I'd like to eventually create a nice little app with sliders and such to make planet editing easier.

    Also better texturing is on my list. Vegetation is also a possibility. I experimented with that recently and had decent results.
     
  10. eric77

    eric77

    Joined:
    Apr 8, 2009
    Posts:
    19
    Good job Joe !

    Happy to hear about planet rendering her... I'm looking for a solution in Unity to draw a planet, maybe without elevation at start, but using paged textures system, to be able to have hi-def earth working, using very big Nasa Blue Marble maps...

    For the moment I'm using Openscenegraph to draw the Earth, using paged textures system, works well, but I want to go to unity for now due to lots of reasons.

    Did someone ever heard about such a solution ? For example, the Moquette plugin in Ogre3D (http://moquette.hybird.org/trac) (look the video!) is exactly what I would like to obtain in Unity.

    Hope I need'nt write it using c++ from scratch :eek:

    I don't find lot of things of paging in forum threads, maybe need to search more...

    Joe, how do you manage the terrain resolution on your planet ? Something fixed or using CLOD for example ?
     
  11. joe gamble

    joe gamble

    Joined:
    Jan 3, 2007
    Posts:
    85
    For now the mesh resolution is fixed. But I'll be looking into other methods of managing that in the future.

    For the project I wrote this for a fixed resolution was all that I needed. But I'm slowly fleshing out the code for future uses.

    That Ogre3D plugin looks impressive. Overkill for what I need but I can see many uses for something like that.
     
  12. joe gamble

    joe gamble

    Joined:
    Jan 3, 2007
    Posts:
    85
    For now the mesh resolution is fixed. But I'll be looking into other methods of managing that in the future.

    For the project I wrote this for a fixed resolution was all that I needed. But I'm slowly fleshing out the code for future uses.

    That Ogre3D plugin looks impressive. Overkill for what I need but I can see many uses for something like that.
     
  13. CosmoKing

    CosmoKing

    Joined:
    Feb 23, 2009
    Posts:
    111
    The next thing you would need would be gravity. I tried podperson's faux gravity scripts, and they freaked out when I tried to make a car go over a hill.
     
  14. Cosmas

    Cosmas

    Joined:
    Jan 9, 2010
    Posts:
    133
    Is this still in development or is it released somewhere?

    Very interested in a script like this.
     
  15. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    I second this. :)
     
  16. Rskennan

    Rskennan

    Joined:
    Nov 18, 2009
    Posts:
    17
    One thing that's working well for me is Blender World Forge. Ironically I posted just the other day somewhere else about how it wasn't working for me, but I got it going.

    Once you get the hang of it, you can create planets made of smaller meshes, layer terrain, and do things like have a hills and valleys layer, a mountain layer, and a canyon/badlands layer... the options go on. Basically, you just create a world for each type of terrain on top of each other, make sure to keep the meshes separate for importing, then import and texture.

    I was actually able to do a prehistoric hollow world type setting with this. The only problems I'm working on are gravity, which I can probably do with an unrendered cage of gravity bodies using the gravity script on the wiki, and getting some foliage. Obviously, I can't just paint it, and the scene is huge.
     
  17. Cosmas

    Cosmas

    Joined:
    Jan 9, 2010
    Posts:
    133
    Well thats sounds great, but the advantage of joe's system would be that you can dynamically generate the terrain.

    I'm trying to do a hybrid RTS so this would be perfect for me rather than having to create several dozen world mesh models. For me it also doubles in many ways as a crucial design mechanic.
     
  18. Rskennan

    Rskennan

    Joined:
    Nov 18, 2009
    Posts:
    17
    Of course. I'd prefer to be able to do it dynamically, too. I'm very much waiting for spherical or voxel terrain. I guess I was just trying to share an option I found in the meantime.
     
  19. Cosmas

    Cosmas

    Joined:
    Jan 9, 2010
    Posts:
    133
    I can see lots of reasons to use modeled terrain in conjunction with dynamic terrain. I'm guessing this effort is dead however. I'd try to code it myself but school is underway now and I'm a mediocre coder at best. I wouldn't know where to begin understanding the 3D concepts. :wink:

    I have done a little research on the topic however, I've read Hugo Elias' logic of the idea, and found a partial python implementation by Shea Koffman. Maybe someone can retrofit it to C#.

    Or really.. easier than that, just rework Andrew's terrain generation code.
     
  20. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    Just covered Spherical coordinates in math class today. Perhaps someone with more scripting knowlege than I can convert Unity's native Cartesian Coordinates to Spherical Coordinates? From a Math standpoint its not too difficult. http://www.equationsheet.com/eqninfo/Equation-0348.html
     
  21. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    It would seem to me that you could defeat the gravity isssue of being -y by always keeping the player on top of the world and rotating the world instead of them walking "across" it. Even with multiplayer.. Just transfer the transform rotations to the other players on top of their worlds to be at the respective spherical coordinates of the other players..

    HTH
    Bluster T
     
  22. joe gamble

    joe gamble

    Joined:
    Jan 3, 2007
    Posts:
    85
    I don't presently have this released for anyone to use. I'm still working although rather slowly due to time constraints. My code is designed mainly for a game that I am working on so I haven't given a lot of thought to building a general purpose tool. Although if there is interest I could change my mind. Sorry I haven't updated this thread but I wasn't aware anyone was still posting to it.
     
  23. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Without proper centralized gravity, surely objects would fall off the planet?

    I notice that Unity's terrains are a plane, and upon this plane the heightmap is turned into terrain. I wonder if it is at all possible to access the plane's vertices and warm them into a section of a spherical surface - ie would the heightmap become warped as well? If so that could work.
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The terrain doesn't exist as a persistent mesh, it's generated dynamically at runtime from the heightmap, with the more distant parts being drawn using less detail.

    --Eric
     
  25. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hmm yah I thought you might say that.

    Oh well. Maybe someone can come up with factal planets like Terragen 2 or that Infinity game. You need some kind of level of detail system.
     
  26. Slem

    Slem

    Joined:
    Jan 28, 2009
    Posts:
    191
    I just did this for a personal project. I havent tested the CartesianToSpherical method thouroughly, but I think it should work.
    Note that this expect the "planet" to be at (0,0,0).

    NOTE: These methods are here displayed as extension methods and are in C#:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public static class Extensions {
    6.  
    7.     public static Vector3 ToCartesian(this Coordinate coordinate, float radius)
    8.     {
    9.         float latitude = coordinate.Latitude * Mathf.Deg2Rad;
    10.         float lon = coordinate.Longitude * Mathf.Deg2Rad;
    11.         float x = radius * Mathf.Cos(latitude) * Mathf.Cos(lon);
    12.         float y = radius * Mathf.Cos(latitude) * Mathf.Sin(lon);
    13.         var z = radius * Mathf.Sin(latitude);
    14.         return new Vector3(x, z, y);
    15.     }
    16.  
    17.     public static Coordinate ToSpherical(this Vector3 worldPosition)
    18.     {
    19.         float r = Mathf.Sqrt(worldPosition.x * worldPosition.x + worldPosition.y * worldPosition.y + worldPosition.z * worldPosition.z);
    20.         float lat = Mathf.Asin(worldPosition.y / r) * Mathf.Rad2Deg;
    21.         float lng = Mathf.Atan2(worldPosition.z, worldPosition.x) * Mathf.Rad2Deg;
    22.         return new Coordinate()
    23.         {
    24.             Latitude = lat,
    25.             Longitude = lng
    26.         };
    27.     }
    28. }
    29.  
    You need the very simple Coordinate class:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System;
    4.  
    5. [Serializable]
    6. public class Coordinate  {
    7.  
    8.     public float Latitude;
    9.     public float Longitude;
    10. }
    Since I'm no math wiz (and have to do extensive googling to do this) there might errors in there. Please let me know if there are.