ExportLightMapFromTerrain

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
 
m
Line 1: Line 1:
#REDIRECT [[ExportLightMapFromTerrain (wrong page, must be deleted)]]
+
==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==
 +
<javascript>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!");
 +
}
 +
}</javascript>

Revision as of 10:20, 10 October 2011

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

<javascript>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!"); } }</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox