NeoLightMapExport

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
Line 37: Line 37:
 
EditorUtility.DisplayDialog("Texture Duplicated", "Selected Texture2D saved in Assets/ as: " + filename, "See You Again!");
 
EditorUtility.DisplayDialog("Texture Duplicated", "Selected Texture2D saved in Assets/ as: " + filename, "See You Again!");
 
}
 
}
}</javascript>
+
}</syntaxhighlight>

Latest revision as of 20:52, 10 January 2012

Author: Neodrop

[edit] Description

This is editor script for export lightmap from selected terrain and save it as image in Asset folder. Based on LightmapExport.cs from Island Demo.

[edit] Usage

Place this script in YourProject/Assets/Editor and the "Export LightMap" menu items will appear in the NeoTools/Terrain menu once it is compiled.

[edit] Javascript - NeoLightmapExport.js

import System.IO;
class NeoLightmapExport extends ScriptableWizard
{
	var terrain : Terrain;
	private var terrainData : TerrainData;
 
	@MenuItem("NeoTools/Terrain/Export Lightmap...")
	static function CreateWizard ()
	{
		ScriptableWizard.DisplayWizard("Export Lightmap", NeoLightmapExport, "Export"); 
	}
 
	function OnWizardUpdate ()
	{
		helpString = "Well, let's go Rock!";
		if(!terrain) {
            helpString = "I need a terrain!";
        } else {
            terrainData = terrain.terrainData;
        }
	}
 
	function OnWizardCreate ()
    {
		var lightmapTexture : Texture2D = terrainData.lightmap;
		var myBytes : byte[] = lightmapTexture.EncodeToPNG();
		var filename : String = terrain.name + "Duplicate.png";
		File.WriteAllBytes(Application.dataPath + "/"+filename, myBytes);
		EditorUtility.DisplayDialog("Texture Duplicated", "Selected Texture2D saved in Assets/ as: " + filename, "See You Again!");
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox