ExportOBJ

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "</csharp>" to "</syntaxhighlight>")
(Updated the page with the referenced .obj exporter script. Added a more confident description of the script's behavior. See the discussion page for more details.)
Line 2: Line 2:
  
 
==Description==
 
==Description==
Allows you to export the currently selected mesh(es) to OBJ format. Simply wraps the Utility script(s) ObjExporter.cs (required). NOTE: For some reason only exports one selected object, although many may be selected. A little help here?
+
Allows you to export the currently selected mesh(es) to OBJ format. Simply wraps the Utility script(s) [[ObjExporterColorUvs|ObjExporter.cs]].  
 +
 
 +
'''NOTE''': This will write mesh data for a single GameObject. It will not write mesh data for its children. If you happen to have several GameObjects selected at once, whatever GameObject is considered to have been selected last will be exported. See the [[Talk:ExportOBJ|discussion]] page for more information.
  
 
==Usage==
 
==Usage==

Revision as of 04:01, 13 January 2013

Author: DaveA

Description

Allows you to export the currently selected mesh(es) to OBJ format. Simply wraps the Utility script(s) ObjExporter.cs.

NOTE: This will write mesh data for a single GameObject. It will not write mesh data for its children. If you happen to have several GameObjects selected at once, whatever GameObject is considered to have been selected last will be exported. See the discussion page for more information.

Usage

You must place the script in a folder named Editor in your project's Assets folder for it to work properly.

Select an object in the scene heirarchy, then choose File -> Export -> Wavefront OBJ. The default name will be of the object selected (or first selected), but you can change it.

C# - ExportOBJ.cs

using UnityEngine;
using UnityEditor;
using System.Collections;
 
public class ObjExporter : ScriptableObject
{
    [MenuItem ("File/Export/Wavefront OBJ")]
    static void DoExport()
    {
		string meshName = Selection.gameObjects[0].name;
        string fileName = EditorUtility.SaveFilePanel("Export .obj file", "", meshName, "obj");
		foreach  (GameObject o in Selection.gameObjects)
		{
			MeshFilter mf = o.GetComponent(typeof(MeshFilter)) as MeshFilter;
			ObjExporterScript.MeshToFile(mf, fileName, false); 
		}
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox