Skip to content

Commit

Permalink
Fixes errors and warns about build settings
Browse files Browse the repository at this point in the history
Moves menu item to Window
  • Loading branch information
PadreZippo committed Aug 12, 2015
1 parent b322a3e commit 2369c09
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 53 deletions.
File renamed without changes.
14 changes: 14 additions & 0 deletions Assets/External Tools/SketchfabExporter/Ionic.Zip.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions Assets/External Tools/SketchfabExporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Sketchfab unity exporter
========================

The Sketchfab exporter for Unity is a script that helps uploading models from a Unity project to a Sketchfab model in just a few clicks.

Release date: Nov 22, 2013
Last update: Aug 12, 2015
Unity version: 5.1.1f1
Author: Sketchfab, Clément Léger, Bryan Thatcher

Installation
------------
Download the unitypackage file and install it from *Assets → Import Package → Custom Package...*

Or download this repository and copy assets and its content into the root of your Unity project.

You should have the files :
- Assets/External Tools/SketchfabExporter/SketchfabExporterWindow.cs
- Assets/External Tools/SketchfabExporter/SimpleJSON.cs
- Assets/External Tools/SketchfabExporter/Ionic.Zip.dll

The Unity project is automatically updated and a new menu item will appear: *Window → Export Selection to Sketchfab...*

Usage
-----
You must save your scene before using the exporter.

Your project build settings shoud be set to *PC, Mac & Linux Standalone*. It won't work with Web Player, for example, because it does not allow manipulation of OBJ/ZIP files.

Select the objects you want to export - static geometry and skinned meshes. Basically, MeshFilter objects SkinnedMeshRenderer are exported which covers most static geometry and characters in T-pose.

Open the *Export Selection to Sketchfab...* window, add model metadata and your API token ( https://sketchfab.com/settings/password )

- Title
- Description
- Tags (space-sparated)
- Private (PRO and Business accounts only)
- Password (Optional for private models)

When the fields are set just press *Upload to Sketchfab* and wait, depending on the textures and your connection speed it could take some time until a message box appears informing you of the upload result.

Contact
-------
Please send your questions or feedback to support@sketchfab.com
6 changes: 6 additions & 0 deletions Assets/External Tools/SketchfabExporter/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ public string SaveToCompressedBase64()
throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
}
#endif


#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX // edit: added Platform Dependent Compilation - win or osx standalone - will not get called anyway if false
public void SaveToFile(string aFileName)
{
System.IO.Directory.CreateDirectory((new System.IO.FileInfo(aFileName)).Directory.FullName);
Expand All @@ -441,6 +442,8 @@ public void SaveToFile(string aFileName)
SaveToStream(F);
}
}
#endif

public string SaveToBase64()
{
using (var stream = new System.IO.MemoryStream())
Expand Down
10 changes: 10 additions & 0 deletions Assets/External Tools/SketchfabExporter/SimpleJSON.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 43 additions & 34 deletions ...Tools/Exporter/SketchfabExporterWindow.cs → ...tchfabExporter/SketchfabExporterWindow.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ public class SketchfabExporterWww : MonoBehaviour {
private string api_url = "https://api.sketchfab.com/v1/models";
private WWW www = null;

public IEnumerator UploadFileCo(string localFileName, string token, bool model_private, string title, string description, string tags) {
byte[] data = File.ReadAllBytes(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + localFileName);
public IEnumerator UploadFileCo(string localFileName, string token, bool model_private, string title, string description, string tags)
{
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX // edit: added Platform Dependent Compilation - win or osx standalone - will not get called anyway if false
byte[] data = File.ReadAllBytes(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + localFileName);
if (data.Length > 0) {
Debug.Log("Loaded file successfully : " + data.Length + " bytes");
} else {
Debug.Log("Open file error");
yield break;
}


WWWForm postForm = new WWWForm();
postForm.AddBinaryData("fileModel",data,localFileName, "application/zip");
Expand All @@ -40,8 +43,10 @@ public IEnumerator UploadFileCo(string localFileName, string token, bool model_p

www = new WWW(api_url, postForm);

yield return www;
}
#endif
yield return www;

}

public string getUrlID() {
if (www.error == null) {
Expand Down Expand Up @@ -112,11 +117,13 @@ public SketchfabExporter(string token, ArrayList m, string title, string descrip
param_password = password;
}

public void export(string filename) {
public void export() {
exportDirectory = Application.temporaryCachePath + Path.DirectorySeparatorChar + "SketchfabExport";
clean();
zip = new ZipFile();

FileInfo fi = new FileInfo(EditorApplication.currentScene);
string filename = fi.Name + "_" + meshList.Count;
MeshesToFile(meshList, exportDirectory, filename);
System.IO.Directory.CreateDirectory(exportDirectory);

Expand All @@ -134,7 +141,7 @@ public void export(string filename) {
private static string SkinnedMeshRendererFilterToString(SkinnedMeshRenderer mf, Dictionary<string, ObjMaterial> materialList)
{
Mesh m = mf.sharedMesh;
Material[] mats = mf.renderer.sharedMaterials;
Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;

StringBuilder sb = new StringBuilder();

Expand Down Expand Up @@ -165,7 +172,7 @@ private static string SkinnedMeshRendererFilterToString(SkinnedMeshRenderer mf,
private static string MeshFilterToString(MeshFilter mf, Dictionary<string, ObjMaterial> materialList)
{
Mesh m = mf.sharedMesh;
Material[] mats = mf.renderer.sharedMaterials;
Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;

StringBuilder sb = new StringBuilder();

Expand Down Expand Up @@ -387,39 +394,38 @@ public class SketchfabExporterWindow : EditorWindow
private string param_password = "";
private string param_token = "";

private static string apitoken_url = "https://sketchfab.com/settings/password";
private static string dashboard_url = "https://sketchfab.com/dashboard";
private SketchfabExporter exporter;
private bool finished = false;

[MenuItem ("GameObject/Export selection to Sketchfab...")]
static void Init() {
SketchfabExporterWindow window = (SketchfabExporterWindow)EditorWindow.GetWindow (typeof(SketchfabExporterWindow));
private bool finished = false;

[MenuItem("Window/Export selection to Sketchfab...")]
static void Init()
{
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX // edit: added Platform Dependent Compilation - win or osx standalone
SketchfabExporterWindow window = (SketchfabExporterWindow)EditorWindow.GetWindow (typeof(SketchfabExporterWindow));
window.initialize();
}
#else // and error dialog if not standalone
EditorUtility.DisplayDialog("Error", "Your build target must be set to standalone", "Okay");
#endif
}

void initialize() {
param_title = getSceneName();
}

private string getSceneName() {
if(EditorApplication.currentScene.Length > 0) {
FileInfo fi = new FileInfo(EditorApplication.currentScene);
return fi.Name;
} else {
return "UnsavedScene";
}

void initialize() {
FileInfo fi = new FileInfo(EditorApplication.currentScene);
param_title = fi.Name;
}

void export() {
finished = false;
Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab);
if (selection.Length == 0) {
EditorUtility.DisplayDialog("No source object selected!", "Please select one or more target objects", "");
EditorUtility.DisplayDialog("No source object selected!", "Please select one or more target objects", "Okay :(");
return;
}

if (param_token.Trim().Length == 0) {
EditorUtility.DisplayDialog("Invalid token!", "Your Sketchfab API Token identifies yourself to Sketchfab. You can get this token at https://sketchfab.com/settings/password.", "");
EditorUtility.DisplayDialog("Invalid token!", "Your Sketchfab API Token identifies yourself to Sketchfab. You can get this token at https://sketchfab.com/dashboard.", "");
return;
}

Expand All @@ -438,26 +444,29 @@ void export() {

if (meshList.Count > 0) {
exporter = new SketchfabExporter(param_token, meshList, param_title, param_description, param_tags, param_private, param_password);
exporter.export(getSceneName() + "_" + meshList.Count);
exporter.export();
} else {
EditorUtility.DisplayDialog("Objects not exported", "Make sure at least some of your selected objects have mesh filters!", "");
EditorUtility.DisplayDialog("Objects not exported", "Make sure at least some of your selected objects have mesh filters!", "Okay :(");
}
}

void OnGUI() {
GUILayout.Label("Model settings", EditorStyles.boldLabel);
param_title = EditorGUILayout.TextField("Title*", param_title);
param_title = EditorGUILayout.TextField("Title (Scene name)", param_title); //edit: added name source
param_description = EditorGUILayout.TextField("Description", param_description);
param_tags = EditorGUILayout.TextField("Tags", param_tags);
param_private = EditorGUILayout.Toggle("Private", param_private);
param_password = EditorGUILayout.PasswordField("Password", param_password);

// edit: contained the password field in a toggle group
param_private = EditorGUILayout.BeginToggleGroup("Private", param_private);
param_password = EditorGUILayout.PasswordField("Password", param_password);
EditorGUILayout.EndToggleGroup();

GUILayout.Label("Sketchfab settings", EditorStyles.boldLabel);
param_token = EditorGUILayout.TextField("API Token", param_token);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("find your API token");
if(GUILayout.Button("my profile"))
Application.OpenURL(apitoken_url);
EditorGUILayout.PrefixLabel("find your token");
if(GUILayout.Button("open dashboard"))
Application.OpenURL(dashboard_url);
EditorGUILayout.EndHorizontal();

EditorGUILayout.Space();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 23 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,40 @@ Sketchfab unity exporter
The Sketchfab exporter for Unity is a script that helps uploading models from a Unity project to a Sketchfab model in just a few clicks.

Release date: Nov 22, 2013
Last update: Apr 23, 2014
Unity version: 4.3.4f1
Author: Clément Léger (clement@sketchfab.com), Sketchfab (support@sketchfab.com)
Last update: Aug 12, 2015
Unity version: 5.1.1f1
Author: Sketchfab, Clément Léger, Bryan Thatcher

Installation
------------
Just copy the folder Assets and its content into the root of your Unity project.
You should have the files :
- Assets/External Tools/Exporter/EditorObjExporter.cs
- Assets/External Tools/Exporter/SimpleJSON.cs
- Assets/Ionic.Zip.dll
Download the unitypackage file and install it from *Assets → Import Package → Custom Package...*

Or download this repository and copy assets and its content into the root of your Unity project.

The Unity project is automatically updated so the installation is done when a menu "Custom" should appear and reveal a "Export to Sketchfab" option.
You should have the files :
- Assets/External Tools/SketchfabExporter/SketchfabExporterWindow.cs
- Assets/External Tools/SketchfabExporter/SimpleJSON.cs
- Assets/External Tools/SketchfabExporter/Ionic.Zip.dll

Your project must not build for the Web Player as it disallows the manipulation of obj/zip files.
To switch the build, go to File menu, and click on the Build Settings... entry. Then select a different platform than Web Player, for instance PC, Mac & Linux Standalone.
The Unity project is automatically updated and a new menu item will appear: *Window → Export Selection to Sketchfab...*

Usage
-----
Select in your scene the objects you want to export. Are exported static geometry but also skinned meshes.
Basically, MeshFilter objects SkinnedMeshRenderer are exported which covers most static geometry and characters in T-pose.
You must save your scene before using the exporter.

Your project build settings shoud be set to *PC, Mac & Linux Standalone*. It won't work with Web Player, for example, because it does not allow manipulation of OBJ/ZIP files.

Select the objects you want to export - static geometry and skinned meshes. Basically, MeshFilter objects SkinnedMeshRenderer are exported which covers most static geometry and characters in T-pose.

Then open the Custom menu, then Export and finally click on "Export to Sketchfab".
A window will open and some parameters are required in order to upload your model.
Open the *Export Selection to Sketchfab...* window, add model metadata and your API token ( https://sketchfab.com/settings/password )

The token field matches the api key token you can find on your dashboard : http://sketchfab.com/dashboard and is required so the exporter links the model to your account.
Following options are basic models properties : private if your account allows it, the model title, its description and a list of space separated tags.
- Title
- Description
- Tags (space-sparated)
- Private (PRO and Business accounts only)
- Password (Optional for private models)

When the fields are set just press the Upload button and wait, depending on the textures and your speed connection it could take some time until a message box appears informing you of the upload result.
When the fields are set just press *Upload to Sketchfab* and wait, depending on the textures and your connection speed it could take some time until a message box appears informing you of the upload result.

Contact
-------
Expand Down

0 comments on commit 2369c09

Please sign in to comment.