override public ModuleBase GetModule() { if (path == null) { return(null); } if (path == "") { return(null); } TerrainModule tm = TerrainModule.Load(path, false, 0, frequencyScale); if (tm != null) { this.module = tm.module; } else { Debug.LogError("MacroNode: Terrain module could not be loaded from " + path); this.module = new ModuleBase(); } SetOutputOptions(); return(this.module); }
public void Load(TextAsset ta, Planet livePreview) { if (ta == null) { return; } savepath = AssetDatabase.GetAssetPath(ta); windows.Clear(); settings = TerrainModule.LoadTextAsset(ta, true, 0, 1f); if (settings != null) { foreach (Node n in settings.nodes) { NodeWindow nw = new NodeWindow(n); if (n is OutputNode) { nw.livePreview = livePreview; } windows.Add(nw); } } }
/// <summary> /// Loads settings from the file /// </summary> public void LoadModule() { terrain = TerrainModule.LoadTextAsset(terrainAsset, randomizeSeeds, seed, frequencyScale); if (terrain == null) { Debug.Log("TerrainModule file not found."); return; } }
public void Load(string loadpath) { if(loadpath == "") return; savepath = loadpath; if(loadpath.Length != 0) { windows.Clear(); settings = TerrainModule.Load(loadpath, true, 0, 1f); if(settings != null) { foreach(Node n in settings.nodes) { windows.Add(new NodeWindow(n)); } } } }
/// <summary> /// Keeps connections to planet /// </summary> void OnEnable() { if (planet == null) { planet = GetComponent <Planet>(); } if (planet != null) { planet.SurfaceGenerated += OnSurfaceGenerated; } terrainModule = TerrainModule.LoadTextAsset(foliageModule, false, 0f, 1f); GenerateImpostors(); }
public void Load(TextAsset ta, Planet livePreview) { if(ta == null) return; savepath = AssetDatabase.GetAssetPath(ta); windows.Clear(); settings = TerrainModule.LoadTextAsset(ta, true, 0, 1f); if(settings != null) { foreach(Node n in settings.nodes) { NodeWindow nw = new NodeWindow(n); if(n is OutputNode) nw.livePreview = livePreview; windows.Add(nw); } } }
public void Load(string loadpath) { if (loadpath == "") { return; } savepath = loadpath; if (loadpath.Length != 0) { windows.Clear(); settings = TerrainModule.Load(loadpath, true, 0, 1f); if (settings != null) { foreach (Node n in settings.nodes) { windows.Add(new NodeWindow(n)); } } } }
/// <summary> /// Loads from text asset. /// </summary> public static TerrainModule LoadTextAsset(TextAsset ta, bool randomize, float seed, float frequencyScale) { TerrainModule ps = null; try { Stream s = new MemoryStream(ta.bytes); BinaryFormatter formatter = new BinaryFormatter(); ps = (TerrainModule)formatter.Deserialize(s); s.Close(); // retrieve node list ps.randomizeSeeds = randomize; ps.seed = seed; ps.frequencyScale = frequencyScale; ps.ReloadModules(); } catch (Exception e) { Debug.Log("Terrain Module file could not be loaded. " + e.Message); } return(ps); }
private void New() { // create starting nodes settings = new TerrainModule(); savepath = ""; GeneratorNode g1 = new GeneratorNode(100, 100); g1.seed = Random.Range(-100000, 100000); OutputNode output = new OutputNode(700, 100); output.Connect(g1, 0); settings.nodes.Add(g1); settings.nodes.Add(output); // create windows to represent nodes windows.Clear(); windows.Add(new NodeWindow(g1)); windows.Add(new NodeWindow(output)); }
/// <summary> /// Keeps connections to planet /// </summary> void OnEnable() { if(planet == null) planet = GetComponent<Planet>(); if(planet != null) planet.SurfaceGenerated += OnSurfaceGenerated; terrainModule = TerrainModule.LoadTextAsset(foliageModule, false, 0f, 1f); GenerateImpostors(); }
private void OutputGUI() { useLivePreview = EditorGUILayout.Foldout(useLivePreview, "Live preview"); if(useLivePreview) { livePreview = (Planet)EditorGUILayout.ObjectField("Live preview:", livePreview, typeof(Planet), true); if(livePreview != null) { if(GUILayout.Button("Update Mesh")) { TerrainModule tm = new TerrainModule(); tm.textureNodes = new List<TextureNode>(); tm.module = outputNode.GetModule(); livePreview.Terrain = tm; livePreview.Generate(null, false); } } EditorGUILayout.HelpBox("Drag a planet from scene to preview mesh while editing the module", MessageType.Info); node.rect.height += controlHeight * 2.5f; } node.rect.height += controlHeight * 1.5f; // export options showExport = EditorGUILayout.Foldout(showExport, "Export textures"); if(showExport) { // size EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Texture size:"); exportSize = EditorGUILayout.IntField(exportSize); EditorGUILayout.EndHorizontal(); if(GUILayout.Button("Save as PNG")) { string savepath = EditorUtility.SaveFilePanel("Export texture", Application.dataPath, "planet", ""); if(savepath.Length != 0) { float progress = 0; float total = 2; Texture2D temp; EditorUtility.DisplayProgressBar("Planet generator", "Generating texture...", progress / total); if(globalMapPreview) temp = GlobalMapUtility.Generate(exportSize, module); else temp = Generate(exportSize); progress++; EditorUtility.DisplayProgressBar("Planet generator", "Saving texture...", progress / total); File.WriteAllBytes(savepath + ".png", temp.EncodeToPNG()); EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); } } node.rect.height += controlHeight * 2f; } }
private void OutputGUI() { useLivePreview = EditorGUILayout.Foldout(useLivePreview, "Live preview"); if (useLivePreview) { livePreview = (Planet)EditorGUILayout.ObjectField("Live preview:", livePreview, typeof(Planet), true); if (livePreview != null) { if (GUILayout.Button("Update Mesh")) { TerrainModule tm = new TerrainModule(); tm.textureNodes = new List <TextureNode>(); tm.module = outputNode.GetModule(); livePreview.Terrain = tm; livePreview.Generate(null, false); } } EditorGUILayout.HelpBox("Drag a planet from scene to preview mesh while editing the module", MessageType.Info); node.rect.height += controlHeight * 2.5f; } node.rect.height += controlHeight * 1.5f; // export options showExport = EditorGUILayout.Foldout(showExport, "Export textures"); if (showExport) { // size EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Texture size:"); exportSize = EditorGUILayout.IntField(exportSize); EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Save as PNG")) { string savepath = EditorUtility.SaveFilePanel("Export texture", Application.dataPath, "planet", ""); if (savepath.Length != 0) { float progress = 0; float total = 2; Texture2D temp; EditorUtility.DisplayProgressBar("Planet generator", "Generating texture...", progress / total); if (globalMapPreview) { temp = GlobalMapUtility.Generate(exportSize, module); } else { temp = Generate(exportSize); } progress++; EditorUtility.DisplayProgressBar("Planet generator", "Saving texture...", progress / total); File.WriteAllBytes(savepath + ".png", temp.EncodeToPNG()); EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); } } node.rect.height += controlHeight * 2f; } }