ExportLightMapFromTerrain

From Unify Community Wiki
Jump to: navigation, search

Description

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

Usage

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

Java - NeoLightMapExport.js

import System.IO;
class NeoLightmapExport extends ScriptableWizard
{
	var terrain : Terrain;
	private var terrainData : TerrainData;
 
	@MenuItem("Terrain/ExportLightmap...")
	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 myBytes : byte[];
		var lightmapTexture : Texture2D = terrainData.lightmap;
		myBytes = 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