Search Unity

ProWorld - Procedural World Generation

Discussion in 'Assets and Asset Store' started by tertle, Oct 4, 2012.

  1. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    audio is fine, but the screen goes black intermittently through the video. Still helpful, though - thanks for a great tool!
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Hmm that's unusual, I'll look at fixing it.
     
  3. Whistle

    Whistle

    Joined:
    Feb 23, 2013
    Posts:
    8
    Oh, for next update, could we have a GUI implentation of seperating the Entities and texture generators? For example, when generating a map of 10x10km with a height map of 4096 (yes, this takes FOREVER!), I sometimes want to change only the entities and texture placements.

    And yes, I'm a bug hunter!
    "Come on you apes, you wanna live forever?" -Starship Troopers
     
  4. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Will you be adding support for the terrain Detail Map? For waving grass, etc. It could be tied to the texture for a given layer.

    Also, when using the realtime generated terrains, the stitching between chunks is very noticable. Maybe it broke between 1.2 and 2.0?
     
  5. Whistle

    Whistle

    Joined:
    Feb 23, 2013
    Posts:
    8
    I can also verify the stitching being weird. For some reason textures aren't matching up, which... is odd, because this occurs even when the heights are flat/the same occasionally. And even when only using one texture.
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Yeah I am aware of a texture stitching between terrain being off in certain cases looking into it.

    As for grass, I'm looking at implementing that pretty soon. It'll probably work very similar/exactly the same as entities so I'm hoping it doesn't take much effort to implement. Though it'll still probably be a few weeks off as I'm quite busy at the moment.

    Hopefully the next build is live on monday with bug fixes + a couple of changes to real-time terrain for Whistle!
     
  7. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I've messed with Unity's terrain detail maps a bit and they're kind of wonky. If I recall, the x and y coordinates are switched, so [x, y] on the height map is actually [y, x] on the splat map. Just something to look into if you start implementing and see results that make no sense. ;)
     
  8. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I've added ability to add your own custom workers. This is something I think Whistle was looking at doing and is pretty important for real time (let's you generate/destroy npcs or whatever in a specific terrain etc)

    It's not the nicest implementation as you need to do a couple of specific things but I've included a template.
    Here's a copy

    Code (csharp):
    1. using System;
    2. using System.ComponentModel;
    3. using System.Runtime.Serialization;
    4. using ProWorldSDK;
    5.  
    6. [Serializable]
    7. public class MyCustomWorker : Worker
    8. {
    9.     private bool _isDone;
    10.    
    11.     // Constructor
    12.     public MyCustomWorker()
    13.     {
    14.         // Workers do work in order of the priority. Low value is run first, same value can run simultaneously.
    15.         // ProWorld workers have values of TerrainWorker = 0; TextureWorker = 4; EntityWorker = 8;
    16.         // Default priority of CustomWorker is 20.
    17.         // Priority = 20;
    18.     }
    19.  
    20.     public override void Generate(object sender, DoWorkEventArgs e)
    21.     {
    22.         // Generate runs in a seperate thread. You can not run any unity functions in here.
    23.         // This let's you calculate position of objects, run complex algorithms without affect the FPS.
    24.  
    25.         // e contains WorldData which is a copy of important terrain data generated by ProWorld.
    26.         var data = (WorldData)e.Argument;
    27.  
    28.         // DOYOURWORK
    29.        
    30.         // Unlock Apply when completed calculations
    31.         _isDone = true;
    32.     }
    33.  
    34.     public override bool Apply(WorldData data, DateTime startTime, double duration)
    35.     {
    36.         // Runs in primary thread. This is where you can create gameobjects, apply to terrain etc.
    37.         // Returning false tells ProWorld that the work hasn't been completed and to call this function again next frame
    38.         // Return true when work is completed.
    39.  
    40.         // You need some type of lock to stop Apply running before Generate is finished.
    41.         if (!_isDone) return false;
    42.  
    43.         // DOYOURWORK
    44.  
    45.         // If your work is going to take too much time you can split it over frames using the provided time data.
    46.         // By default duration is equivelant to 60fps but this doesn't include user logic.
    47.         // If you have a lot of your own calculations you might want to reduce how much ProWorld can do per frame
    48.         // This is declared at the top of Manager.cs
    49.        
    50.         if ((DateTime.Now - startTime).TotalMilliseconds > duration)
    51.         {
    52.             return false;
    53.         }
    54.  
    55.         // An example of how you might implement this.
    56.         // For example if you wanted to create lots of npcs but can only do say 15 per frame
    57.         /* while (_npcs.Count > 0)
    58.         {
    59.             var npc = _npcs.Dequeue();
    60.  
    61.             var npcCopy = UnityEngine.Object.Instantiate(npc.Model, npc.Position, npc.Rotation);
    62.             _npcsToClean.Add(npcCopy); // List of npcs created so we can remove them later in Clean();
    63.  
    64.             if ((DateTime.Now - startTime).TotalMilliseconds > duration)
    65.             {
    66.                 return false;
    67.             }
    68.         }*/
    69.  
    70.         return true;
    71.     }
    72.  
    73.  
    74.     // Optional
    75.     public override void Clean()
    76.     {
    77.         // Runs when a terrain is destroyed. Used to remove your own custom assets if they aren't attached to the terrain
    78.         // You should probably only remove Unity related stuff created in Apply.
    79.         // In theory this function could run before Generate finishes which the garbage collector should clean up.
    80.     }
    81.  
    82.     // Worker implements the ISerializable allowing you control your own serialization and deserialization
    83.     // This is important as your worker is cloned for each terrain.
    84.     // You need to serialize any value that is set by default or in the constructor.
    85.     // DO NOT serialize any containers used to pass data between between Generate/Apply/Clean.
    86.     // Just set this manually in their respective functions.
    87.     // You must call the base virtual function of GetObjectData
    88.    
    89.     // If you have nothing to serialize, you must still implement this Constructor
    90.     // In this case though you can leave out the GetObjectData as the virtual function will still be called.
    91.     #region ISerializable
    92.     public MyCustomWorker(SerializationInfo info, StreamingContext context)
    93.         : base(info, context)
    94.     {
    95.         //_health = (float) info.GetValue("Health", typeof (float));
    96.     }
    97.  
    98.     public override void GetObjectData(SerializationInfo info, StreamingContext context)
    99.     {
    100.         //info.AddValue("Health", _health);
    101.  
    102.         base.GetObjectData(info, context);
    103.     }
    104.     #endregion
    105. }
    Hopefully it makes sense. Is there any other functionality that you might need included that I haven't thought of?
    Instructions are included on how attach it.


    I also realized you probably could do with a GetHeightAt(x,y) function which'll be implemented in next version hopefully. At the moment you'll just have to interpolate yourself.


    One minor problem at the moment is you can't really pass data between customworkers unless you modifying my WorldData class (which is quite easy to do but not something you should be required to do). The other easy solution at the moment for you to just to use a static class to store the data but that's not great practice. I'll look at adding the option to add custom data values to WorldData.
     
    Last edited: Mar 4, 2013
  9. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I think i've identified the issue with textures blurring between layers. Unfortunately I already submitted the build so you'll need to wait till next build to implement it. You won't need to change anything for the fix.
     
    Last edited: Mar 4, 2013
  10. sacha

    sacha

    Joined:
    Oct 29, 2012
    Posts:
    22
    Hi guys,
    I'm struggling a bit with the nodes to create a nice looking big island with hills and coves and nice smooth transitions to the ocean.

    I really missed some "basic layout" to play with and see how the system reacts.

    I think it might be a good idea to post some of 'complex' nodes layout to help understanding how it works.

    Tertle, Could we have the "cicle" node back please ? Thanks


    Just my 0.1 euro..
     
    Last edited: Mar 4, 2013
  11. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Oh yeah that's what I forgot to re-add; Prefabs from 1.x. I'll add those as part of next version as well as well as bring back the circle (makes for good smooth water transitions).

    From memory when I was making islands one good way is to multiple a node multiple times. It gives some what of a parabola effect.
     
  12. sacha

    sacha

    Joined:
    Oct 29, 2012
    Posts:
    22
    Is the splitting the world into different terrain removed ?
     
  13. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Yeah, i missed that option too, also good that you will bring back the circle. One thing might be to replace the circle with an ellipse instead, that way you get some more freedom when making islands.
     
  14. sacha

    sacha

    Joined:
    Oct 29, 2012
    Posts:
    22
    Compiling for exe issue: (unity4)

    Assets/ProWorld/Scripts/World/WorldBuilder.cs(30,20): error CS0103: The name `Path' does not exist in the current context
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(33,14): error CS0103: The name `File' does not exist in the current context
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(40,32): error CS1502: The best overloaded method match for `ProWorldSDK.FileOperations.LoadFromFile(string)' has some invalid arguments
    Assets/ProWorld/Scripts/Util/FileOperations.cs(33,29): (Location of the symbol related to previous error)
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(40,32): error CS1503: Argument `#1' cannot convert `object' expression to type `string'
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(30,20): error CS0103: The name `Path' does not exist in the current context
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(33,14): error CS0103: The name `File' does not exist in the current context
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(40,32): error CS1502: The best overloaded method match for `ProWorldSDK.FileOperations.LoadFromFile(string)' has some invalid arguments
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(40,32): error CS1503: Argument `#1' cannot convert `object' expression to type `string'
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(30,20): error CS0103: The name `Path' does not exist in the current context
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(33,14): error CS0103: The name `File' does not exist in the current context
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(40,32): error CS1502: The best overloaded method match for `ProWorldSDK.FileOperations.LoadFromFile(string)' has some invalid arguments
    Assets/ProWorld/Scripts/Util/FileOperations.cs(33,29): (Location of the symbol related to previous error)
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(40,32): error CS1503: Argument `#1' cannot convert `object' expression to type `string'
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(30,20): error CS0103: The name `Path' does not exist in the current context
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(33,14): error CS0103: The name `File' does not exist in the current context
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(40,32): error CS1502: The best overloaded method match for `ProWorldSDK.FileOperations.LoadFromFile(string)' has some invalid arguments
    Assets/ProWorld/Scripts/World/WorldBuilder.cs(40,32): error CS1503: Argument `#1' cannot convert `object' expression to type `string'
     
  15. Whistle

    Whistle

    Joined:
    Feb 23, 2013
    Posts:
    8
    Sacha: Just type in "using System.IO;" at the beginning of WorldBuilder.cs. It's a known bug, will be fixed.
     
  16. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Yeah that bugs already been fixed. I submitted a new build 4 days ago which includes that fix and I'm still waiting for it to be approved. Just need to be patient unfortunately I can't do anything to speed it up.
     
  17. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    will you upload this tutorial again? is there any way to see these black parts?
     
  18. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Sorry I've been away, but the new build is finally up. Not sure why it took a week, usually only takes a day.
    Anyway I'll have a look at the tutorial and see what's wrong tomorrow.
     
  19. Mundal

    Mundal

    Joined:
    Mar 10, 2013
    Posts:
    7
    Hey, amazing package.. Although with the new build I get some errors when importing:

    Assets/ProWorld/Editor/Data/Entity/EntityEditorData.cs(46,41): error CS0117: `UnityEditor.EditorUtility' does not contain a definition for `GetAssetPreview'
    Assets/ProWorld/Editor/Data/Entity/EntityEditorData.cs(52,34): error CS1061: Type `object' does not contain a definition for `GetPixels' and no extension method `GetPixels' of type `object' could be found (are you missing a using directive or an assembly reference?)
    Assets/ProWorld/Editor/Data/Entity/EntityEditorData.cs(56,48): error CS1061: Type `object' does not contain a definition for `Length' and no extension method `Length' of type `object' could be found (are you missing a using directive or an assembly reference?)
    Assets/ProWorld/Editor/Data/Entity/EntityEditorData.cs(58,21): error CS0021: Cannot apply indexing with [] to an expression of type `object'
    Assets/ProWorld/Editor/Data/Entity/EntityEditorData.cs(60,21): error CS0021: Cannot apply indexing with [] to an expression of type `object'
    Assets/ProWorld/Editor/Data/Entity/EntityEditorData.cs(61,21): error CS0021: Cannot apply indexing with [] to an expression of type `object'
    Assets/ProWorld/Editor/Data/Entity/EntityEditorData.cs(65,29): error CS1502: The best overloaded method match for `UnityEngine.Texture2D.SetPixels(UnityEngine.Color[])' has some invalid arguments
    Assets/ProWorld/Editor/Data/Entity/EntityEditorData.cs(65,29): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.Color[]'

    I have upgraded to Unity 4.1 today - is that the issue?

    EDIT: I solved the problem by changing the #IF block from

    #IF UNITY_4_0
    to
    #IF UNITY_4_1

    So I guess this is an issue that will happen for those who upgrade to 4.1
     
    Last edited: Mar 14, 2013
  20. Mundal

    Mundal

    Joined:
    Mar 10, 2013
    Posts:
    7
    Is there any way to move the generation bit onto a server, and send the resulting terrain data to a client that draws the terrain?
     
  21. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Maybe you should use #if !UNITY_3_4 !UNITY_3_5 instead to be future proof or something similar.
     
    Last edited: Mar 15, 2013
  22. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Whoops that's a problem, I still develop in 3.6 so I haven't yet updated to 4.1 (didn't realize it was out). Really wish there was a UNITY_3_X option.

    I'll fix that up. Been studying for a test this Wednesday for some job. Next bug fix build will be submitted end of this week.

    It's possible but not pretty as it really wasn't designed for that, you'd have to write your server as a unity project which isn't a good solution. Servers shouldn't have any graphic output.
     
  23. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    The way to do it is probably that the server generates the random seed, sends that to the clients and then the clients have the responsibility for generating the terrain, you should always try to send as little data as you can across the network.
     
  24. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    Will the presets be coming back in the new version?
     
  25. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Sorry missed your post. I am looking at re-adding some presets now and still trying to fix another bug.

    Hopefully I can submit new build tomorrow, but the unity team is taking about a week to approve builds so may take a while to appear.

    -edit-

    I finally somewhat identified the issue with textures not blurring together. It was actually somewhat of a major bug with something and I'm working on a fix for the next build as well.

    -edit-

    In the end it was the most embarrassing of mistakes.

    Code (csharp):
    1. GenerateLayerTextures(index, map, resolution, offsetX, offsetX);
    Should be offsetY, not both X
    So anyway that'll finally fix that bug, I still want to improve blurring between terrain though. It's pretty good now but it is noticeable under certain circumstances.
     
    Last edited: Mar 25, 2013
  26. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Nice one : D
    Been there, done that! : p
     
  27. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Finally reuploaded tutorial, I have quite bad upload speeds and needed to find some time when I wouldn't destroy my network. All references in this thread have been updated.

    I still don't know why sections were black, I re-encoded using same settings and it seems fine.
     
  28. Daniko

    Daniko

    Joined:
    Mar 24, 2011
    Posts:
    16
    Hi, i really want to try your plugin for a project of mine, but i'm getting the following errors. This is using unity 4.1

    Assets/ProWorld/Editor/Windows/Entity/EntityLayerWindow.cs(132,56): error CS0117: `UnityEditor.EditorUtility' does not contain a definition for `GetAssetPreview'


    Assets/ProWorld/Editor/Windows/Entity/EntityLayerWindow.cs(136,27): error CS1502: The best overloaded method match for `UnityEngine.GUILayout.Box(UnityEngine.Texture, params UnityEngine.GUILayoutOption[])' has some invalid arguments


    Assets/ProWorld/Editor/Windows/Entity/EntityLayerWindow.cs(136,27): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.Texture'
     
    Last edited: Apr 7, 2013
  29. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I'm not sure why the bug fix version for 4.1 and texture matching hasn't appeared in unity store. It was submitted a while ago, I'm hoping it's up early next week. Unfortunately I'm in the process of looking at moving so I'm not sure when I'll be able to pump out another feature version.
     
  30. tylernocks

    tylernocks

    Joined:
    Sep 9, 2012
    Posts:
    256
    Sees title, thinks "Why would anybody buy this everybody knows everybody sells procedural world generators for like 5,000 dollars", clicks page, see price, throws money at screen and I beg for your forgiveness.
     
  31. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    Hello

    Have the next issue. Nodes such as Errosion, Smoth node can be connected by input to the output of Square or Perlin. But can't be connected to the output of Import or Stretch. I think there are more cases, but that is what i tested


    My system: OSX 1.8.3, Unity 4.1.0f4, latest ProWorld
     
  32. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    It's not an issue as such, it's intended due to how those nodes work.

    Those specific nodes used neighbours to generate their output so need to be hooked up directly to a noise function otherwise the results aren't deterministic. That's why they're grouped separately. Note you can string them together as well.

    In general it shouldn't matter as the same effect should be achievable just be reordering how you want to attach your nodes.
     
  33. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58

    Too bad. :(

    Is there any way to make my own custom nodes with C#?
     
    Last edited: Apr 17, 2013
  34. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Umm yes, but I haven't documented it anywhere. I actually have a few min now so might write a quick guide for you.

    It's not actually that hard.
     
  35. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    I do not need documentation. Could you give just example of the simple generator (like square) and simple filter (like blur)?
     
    Last edited: Apr 17, 2013
  36. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    That's what I meant by documentation. Just writing a simple basic example for you with a few comments of things to note.
     
  37. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    ok so here's a quick example of adding implement Add for 2 inputs, with option of adding a constant

    Code (csharp):
    1. // TestNodeGUI.cs
    2. // Needs to go in an editor folder
    3. // I store it in the Proworld/Editor/MapEditor/Nodes folder
    4. using System;
    5. using System.Runtime.Serialization;
    6. using ProWorldSDK;
    7. using UnityEngine;
    8.  
    9. namespace ProWorldEditor
    10. {
    11.     [Serializable]
    12.     public class TestNodeGUI : Node
    13.     {
    14.         // Bit of a hack. Name that appears in menu
    15.         public new static string Title = "Test";
    16.         // Type of node, used for the menu
    17.         public static NodeType Type = NodeType.Combine;
    18.  
    19.         public TestNodeGUI(MapEditor mapEditor)
    20.             : base(mapEditor, new TestNode(mapEditor.Data.Map), Title)
    21.         {
    22.         }
    23.  
    24.         // Place to put your custom controls
    25.         public override void Options()
    26.         {
    27.             var an = (TestNode)Data;
    28.  
    29.             GUILayout.BeginHorizontal();
    30.             GUILayout.Label("Constant:", GUILayout.Width(100));
    31.             an.Constant = GUILayout.HorizontalSlider(an.Constant, 0, 1, GUILayout.Width(100));
    32.             GUILayout.Label(an.Constant.ToString("0.00"), GUILayout.Width(80));
    33.             GUILayout.EndHorizontal();
    34.            
    35.             // Make sure you call the base after, otherwise theme won't fit
    36.             base.Options();
    37.         }
    38.  
    39.         // Can serialize any specific GUI based settings if you need. Usually not required though, but you still need the empty constructor.
    40.         #region ISerialize
    41.         protected TestNodeGUI(SerializationInfo info, StreamingContext context)
    42.             : base(info, context)
    43.         {
    44.         }
    45.         public override void GetObjectData(SerializationInfo info, StreamingContext context)
    46.         {
    47.             base.GetObjectData(info, context);
    48.         }
    49.         #endregion
    50.     }
    51. }
    Code (csharp):
    1. // TestNode.cs
    2. // Needs to go in a normal folder
    3. // I store it in the Proworld/Scripts/MapEditor/Nodes folder
    4. using System;
    5. using System.Runtime.Serialization;
    6.  
    7. namespace ProWorldSDK
    8. {
    9.     [Serializable]
    10.     public class TestNode : NodeData
    11.     {
    12.         public float Constant { get; set; }
    13.  
    14.         public TestNode(MapManager map)
    15.             : base(map)
    16.         {
    17.             Constant = 0f;
    18.  
    19.             // Number of inputs the node takes. Shouldn't use more than 4.
    20.             SetInput(2);
    21.         }
    22.  
    23.         protected override void Calculate(int resolution, float offsetX, float offsetY)
    24.         {
    25.             // Check the connections and assing them to the input
    26.             // Just use this chunk of code
    27.             for (var i = 0; i < InputConnections.Length; i++)
    28.             {
    29.                 if (!InputConnections[i])
    30.                 {
    31.                     InputData[i] = new float[resolution, resolution];
    32.                 }
    33.                 else
    34.                 {
    35.                     InputData[i] = InputConnections[i].From.OutputData;
    36.                 }
    37.             }
    38.  
    39.             // Do some work on InputData, run an algorithm etc
    40.             // Assign it to OutputData
    41.  
    42.             // Make sure you assign the output array
    43.             OutputData = new float[resolution,resolution];
    44.  
    45.             for (var y = 0; y < resolution; y++)
    46.             {
    47.                 for (var i = 0; i < resolution; i++)
    48.                 {
    49.                     OutputData[y, i] = InputData[0][y, i] + InputData[1][y, i] + Constant;
    50.                 }
    51.             }
    52.         }
    53.  
    54.         // Need to write your own custom serializer to save any custom fields
    55.         #region ISerializable
    56.         public TestNode(SerializationInfo info, StreamingContext context)
    57.             : base(info, context)
    58.         {
    59.             Constant = (float)info.GetValue("Constant", typeof(float));
    60.         }
    61.         public override void GetObjectData(SerializationInfo info, StreamingContext context)
    62.         {
    63.             // make sure you call the base
    64.             base.GetObjectData(info, context);
    65.  
    66.             info.AddValue("Constant", Constant);
    67.         }
    68.  
    69.         #endregion
    70.     }
    71. }
    72.  
    No need to tell the application that you've added a node, it should automatically add to the list.

    I'll give you a demonstration on generating from an algorithm next.
     
    Last edited: Apr 17, 2013
  38. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    Thanks allot. It works. Now i need to learn it and implement my nodes. Hope everything can be solved. Thanks again :D
     
  39. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Generate function works very similar. In general you don't need to change anything from the template except to assign your own Noise.

    Code (csharp):
    1. // TestGenerateNode.cs
    2. // Needs to go in a normal folder
    3. // I store it in the Proworld/Scripts/MapEditor/Nodes folder
    4. using System;
    5. using System.Runtime.Serialization;
    6.  
    7. namespace ProWorldSDK
    8. {
    9.     // Note for a generator node, you inherit from GeneratorNode not NodeData
    10.     [Serializable]
    11.     public class TestGenerateNode : GeneratorNode
    12.     {
    13.         public TestGenerateNode(MapManager map)
    14.             : base(map)
    15.         {
    16.             // Assign our noise function
    17.             // In general, this might be the only thing different you have to do in this class to make your own noise function
    18.             // Noise is an interface of INoise
    19.             // Has 1 member, Noise(float x, float y);
    20.             // Just implement your noise function using that
    21.             Noise = new Square();
    22.  
    23.             SetInput(0);
    24.         }
    25.  
    26.         // I should probably clean up this calculate function as there's a lot of stuff I could make hidden which is shared between other noise functions
    27.         protected override void Calculate(int resolution, float offsetX, float offsetY)
    28.         {
    29.             // Same as the other example, need to setup the output array. Then we start doing some work
    30.             OutputData = new float[resolution, resolution];
    31.  
    32.             // We calc 1 extra position for stitching
    33.             // This means we don't need to stitch between terrain as it's automatically done for us!
    34.             var nFactor = (resolution + 1) / (float)resolution;
    35.  
    36.             // We modify range by global range.
    37.             // Global range is used to zoom
    38.             var combinedRange = Range * GlobalRange;
    39.  
    40.             // Confusing naming
    41.             // offset is based off position in world
    42.             // Offset is just a local modifier to noise function to shift it left/right, up/down
    43.             // We just combining these offset values
    44.             var oX = (OffsetX + offsetX) * combinedRange;
    45.             var oY = (OffsetY + offsetY) * combinedRange;
    46.  
    47.             for (var y = 0; y < resolution; y++)
    48.             {
    49.                 for (var x = 0; x < resolution; x++)
    50.                 {
    51.                     // This doesn't make much sense just looking at it, but it's just calculating the correct x/y positions in the world
    52.                     // Just assume it's right
    53.                     OutputData[y, x] = Noise.Noise((x / (float)resolution * combinedRange) * nFactor + oX, (y / (float)resolution * combinedRange) * nFactor + oY);
    54.                 }
    55.             }
    56.         }
    57.  
    58.         // Again custom serializer if you need it
    59.         // Noise is automatically serialized though so you don't need to worry
    60.         #region ISerializable
    61.         public TestGenerateNode(SerializationInfo info, StreamingContext context)
    62.             : base(info, context)
    63.         {
    64.  
    65.         }
    66.         #endregion
    67.     }
    68. }
    Parts of that won't really make sense but just assume it works.
    You really just need set Noise to an implementation of INoise.

    Code (csharp):
    1.     public interface INoise
    2.     {
    3.         float Noise(float x, float y);
    4.     }
    The GUI part is exactly the same so I'm not going to post it again. The only thing you might need to change is to get a reference to your Noise.

    Code (csharp):
    1.         public override void Options()
    2.         {
    3.             var square = (SquareNode)Data;
    4.             var noise = (Square)square.Noise;
    5.  
     
    Last edited: Apr 17, 2013
  40. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    This code works too. Thank You :)
     
  41. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    One more question. When I use in the Node code the AnimationCurve, and then Load previously Saved ProWorld project, there is error message SerializationException: Type UnityEngine.AnimationCurve is not marked as Serializable at the last line of the next example.
    Code (csharp):
    1.  
    2.     public class FileOperations
    3.     {
    4.         public static void SaveToFile(string path, object data)
    5.         {
    6.             using (var zipFile = new ZipFile())
    7.             {
    8.                 zipFile.AlternateEncoding = Encoding.Unicode;
    9.  
    10.                 //serialize item to memorystream
    11.                 using (var m = new MemoryStream())
    12.                 {
    13.                     var formatter = new BinaryFormatter();
    14.                     formatter.Serialize(m, data);
    15.  
    Any ideas?

    P.S. For now i will use custom S-shape function instead of AnimationCurve
     
    Last edited: Apr 17, 2013
  42. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    There is another issue. For example I made my slope node which form the edges of the shape generators. But output of that node can't be used as input for the erosion. This limitations does not make any sense. Should i implement my erosion node also? What is your recommendation?
     
  43. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    There is another question. Look at this "steps" in the texture mapper. Can it be fixed?

    View attachment 50617

    Oh. I found that after when I used Apply dialog the steps are disappear. So problem is solved!
     
    Last edited: Apr 18, 2013
  44. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    I want share here few extra nodes. It is not perfect and very dirty but maybe someone will find it useful.

    $ProWorld.jpg

    Other improvement of the tool can be replacing the texture generator by node based version. Then I can have produce by nodes more complicated texturing. Where can be used not only layers (altitudes) but also slope angles, or other nodes result. Would be nice if i can do it with my custom code just right now. Any ideas?
     

    Attached Files:

  45. enjaysea

    enjaysea

    Joined:
    Apr 19, 2013
    Posts:
    3
    I have tried several times to get the run-time autogeneration of terrain to work, following your video tutorial exactly, and nothing ever displays. I put the camera exactly where you put it, select the main camera as the GameObject, select a world from your special save directory, click apply, choose 1 neighbor, and press Play.

    Nothing ever happens. The CPU spins up to some wild level, my computer fan is working overtime. There are terrains generated and displayed in the Hierarchy, but I can never actually see any terrain on screen. And if I run it too long the CPU usage brings my computer to its knees and I have to force quit Unity.

    Any ideas? I'm running Pro Unity 4.0.1 on a Mac 10.7.5. Is ProWorld supposed to work there?
     
  46. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    As I can see: when terrain is selected (in the scene) and ProWorld has eanbled button Preview (red color) the terrain will be updated automatically every time when you change parameters in the nodes. Also there are Apply button which bring you apply-dialog. At the top form (Single Terrain) click the button Selection while terrain in the scene is selected. Then click Apply. In some time (depends on your node tree) it will update the terrain in the scene.
     
  47. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Whoops got a notification of your post on my phone while driving the other day, was meant to reply with I got home and forgot so I shall do it all now.

    That's because you can't serialize any of Unity data types. If you have a look through my code, I wrote my own wrapper classes for everything, for example Vector2Serializable which I convert vector2 into before I serialize, then convert back to Vector2 when I deserialize.

    To make it so you can feed your node into erosion (and those other weird ones) , your node has to inherit from GeneratorNode. The reason for this restrictive implementation is neighbouring terrain for real time generation. If you're only generating 1 terrain then you'd have no issue running those filters from anything. I should probably add optional single terrain generation nodes.

    I was at one point writing a different way of generating my terrain so it wouldn't matter if the nodes came later, but it ended up being too CPU intensive so I settled on this for the moment sadly.

    Btw nice work on implementing your own nodes.

    My best guess without looking at anything is you've set a ridiculously large resolution which is taking way too long to compile. Alternatively you could be getting an error but I'm unaware of any known errors.
     
    Last edited: Apr 19, 2013
  48. hww

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    HiTertle

    Think about make scrollable and pannable are of node editor. It will be nicer to work with large project. See attachment. Also i recommend you add check box to disable texture processing on terain. As texture system of ProWorld is limited I just preffer to paint textures manually. So for this case APPLY must not override textures at the terrain.

    $ProWorldBigProject.jpg
     
  49. enjaysea

    enjaysea

    Joined:
    Apr 19, 2013
    Posts:
    3
    Isn't the resolution set by the world that I choose to autogenerate? I chose your world, called mountain.pw in the ProWorldSavedData folder that comes installed with the product. I haven't made any changes to the mountain.pw terrain. Using it right out of the box.

    Can you tell me which script does the generating so I can place a breakpoint there and see what's happening?
     
  50. MrFoamy

    MrFoamy

    Joined:
    Jan 7, 2013
    Posts:
    8
    Is there any way to have Proworld use the transform settings a prefab has? I've got a load of trees and other bits that need re-scaling/rotating to fit but proworld ignores the transform component settings.

    Also, do you plan on adding varying tree seeds at some point? Is it even possible?

    I also hit a couple of bugs: the first is where changing the entity density map nodes doesn't always update the output unless you save reload the file. It seems to be random for me, leaning heavily on the side of not updating.

    Second, the entity layer add asset window freaks out when I have more than a dozen or so assets in the project and only shows a few of the thumbnails at a time. The window is also titled 'Create Texture'

    I've only just started heavily playing with Proworld though so I could be missing a lot, you've done some fantastic work.