Skip to content

Commit 2369c09

Browse files
committed
Fixes errors and warns about build settings
Moves menu item to Window
1 parent b322a3e commit 2369c09

File tree

9 files changed

+154
-53
lines changed

9 files changed

+154
-53
lines changed

Assets/Ionic.Zip.dll renamed to Assets/External Tools/SketchfabExporter/Ionic.Zip.dll

File renamed without changes.

Assets/External Tools/SketchfabExporter/Ionic.Zip.dll.meta

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Sketchfab unity exporter
2+
========================
3+
4+
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.
5+
6+
Release date: Nov 22, 2013
7+
Last update: Aug 12, 2015
8+
Unity version: 5.1.1f1
9+
Author: Sketchfab, Clément Léger, Bryan Thatcher
10+
11+
Installation
12+
------------
13+
Download the unitypackage file and install it from *Assets → Import Package → Custom Package...*
14+
15+
Or download this repository and copy assets and its content into the root of your Unity project.
16+
17+
You should have the files :
18+
- Assets/External Tools/SketchfabExporter/SketchfabExporterWindow.cs
19+
- Assets/External Tools/SketchfabExporter/SimpleJSON.cs
20+
- Assets/External Tools/SketchfabExporter/Ionic.Zip.dll
21+
22+
The Unity project is automatically updated and a new menu item will appear: *Window → Export Selection to Sketchfab...*
23+
24+
Usage
25+
-----
26+
You must save your scene before using the exporter.
27+
28+
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.
29+
30+
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.
31+
32+
Open the *Export Selection to Sketchfab...* window, add model metadata and your API token ( https://sketchfab.com/settings/password )
33+
34+
- Title
35+
- Description
36+
- Tags (space-sparated)
37+
- Private (PRO and Business accounts only)
38+
- Password (Optional for private models)
39+
40+
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.
41+
42+
Contact
43+
-------
44+
Please send your questions or feedback to [email protected]

Assets/External Tools/SketchfabExporter/README.md.meta

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/External Tools/Exporter/SimpleJSON.cs renamed to Assets/External Tools/SketchfabExporter/SimpleJSON.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ public string SaveToCompressedBase64()
432432
throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
433433
}
434434
#endif
435-
435+
436+
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX // edit: added Platform Dependent Compilation - win or osx standalone - will not get called anyway if false
436437
public void SaveToFile(string aFileName)
437438
{
438439
System.IO.Directory.CreateDirectory((new System.IO.FileInfo(aFileName)).Directory.FullName);
@@ -441,6 +442,8 @@ public void SaveToFile(string aFileName)
441442
SaveToStream(F);
442443
}
443444
}
445+
#endif
446+
444447
public string SaveToBase64()
445448
{
446449
using (var stream = new System.IO.MemoryStream())

Assets/External Tools/SketchfabExporter/SimpleJSON.cs.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/External Tools/Exporter/SketchfabExporterWindow.cs renamed to Assets/External Tools/SketchfabExporter/SketchfabExporterWindow.cs

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ public class SketchfabExporterWww : MonoBehaviour {
1919
private string api_url = "https://api.sketchfab.com/v1/models";
2020
private WWW www = null;
2121

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

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

4144
www = new WWW(api_url, postForm);
4245

43-
yield return www;
44-
}
46+
#endif
47+
yield return www;
48+
49+
}
4550

4651
public string getUrlID() {
4752
if (www.error == null) {
@@ -112,11 +117,13 @@ public SketchfabExporter(string token, ArrayList m, string title, string descrip
112117
param_password = password;
113118
}
114119

115-
public void export(string filename) {
120+
public void export() {
116121
exportDirectory = Application.temporaryCachePath + Path.DirectorySeparatorChar + "SketchfabExport";
117122
clean();
118123
zip = new ZipFile();
119124

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

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

139146
StringBuilder sb = new StringBuilder();
140147

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

170177
StringBuilder sb = new StringBuilder();
171178

@@ -387,39 +394,38 @@ public class SketchfabExporterWindow : EditorWindow
387394
private string param_password = "";
388395
private string param_token = "";
389396

390-
private static string apitoken_url = "https://sketchfab.com/settings/password";
397+
private static string dashboard_url = "https://sketchfab.com/dashboard";
391398
private SketchfabExporter exporter;
392-
private bool finished = false;
393-
394-
[MenuItem ("GameObject/Export selection to Sketchfab...")]
395-
static void Init() {
396-
SketchfabExporterWindow window = (SketchfabExporterWindow)EditorWindow.GetWindow (typeof(SketchfabExporterWindow));
399+
private bool finished = false;
400+
401+
[MenuItem("Window/Export selection to Sketchfab...")]
402+
static void Init()
403+
{
404+
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX // edit: added Platform Dependent Compilation - win or osx standalone
405+
SketchfabExporterWindow window = (SketchfabExporterWindow)EditorWindow.GetWindow (typeof(SketchfabExporterWindow));
397406
window.initialize();
398-
}
407+
#else // and error dialog if not standalone
408+
EditorUtility.DisplayDialog("Error", "Your build target must be set to standalone", "Okay");
409+
#endif
410+
}
399411

400-
void initialize() {
401-
param_title = getSceneName();
402-
}
403412

404-
private string getSceneName() {
405-
if(EditorApplication.currentScene.Length > 0) {
406-
FileInfo fi = new FileInfo(EditorApplication.currentScene);
407-
return fi.Name;
408-
} else {
409-
return "UnsavedScene";
410-
}
413+
414+
void initialize() {
415+
FileInfo fi = new FileInfo(EditorApplication.currentScene);
416+
param_title = fi.Name;
411417
}
412418

413419
void export() {
414420
finished = false;
415421
Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab);
416422
if (selection.Length == 0) {
417-
EditorUtility.DisplayDialog("No source object selected!", "Please select one or more target objects", "");
423+
EditorUtility.DisplayDialog("No source object selected!", "Please select one or more target objects", "Okay :(");
418424
return;
419425
}
420426

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

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

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

447453
void OnGUI() {
448454
GUILayout.Label("Model settings", EditorStyles.boldLabel);
449-
param_title = EditorGUILayout.TextField("Title*", param_title);
455+
param_title = EditorGUILayout.TextField("Title (Scene name)", param_title); //edit: added name source
450456
param_description = EditorGUILayout.TextField("Description", param_description);
451457
param_tags = EditorGUILayout.TextField("Tags", param_tags);
452-
param_private = EditorGUILayout.Toggle("Private", param_private);
453-
param_password = EditorGUILayout.PasswordField("Password", param_password);
458+
459+
// edit: contained the password field in a toggle group
460+
param_private = EditorGUILayout.BeginToggleGroup("Private", param_private);
461+
param_password = EditorGUILayout.PasswordField("Password", param_password);
462+
EditorGUILayout.EndToggleGroup();
454463

455464
GUILayout.Label("Sketchfab settings", EditorStyles.boldLabel);
456465
param_token = EditorGUILayout.TextField("API Token", param_token);
457466
EditorGUILayout.BeginHorizontal();
458-
EditorGUILayout.PrefixLabel("find your API token");
459-
if(GUILayout.Button("my profile"))
460-
Application.OpenURL(apitoken_url);
467+
EditorGUILayout.PrefixLabel("find your token");
468+
if(GUILayout.Button("open dashboard"))
469+
Application.OpenURL(dashboard_url);
461470
EditorGUILayout.EndHorizontal();
462471

463472
EditorGUILayout.Space();

Assets/External Tools/SketchfabExporter/SketchfabExporterWindow.cs.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,40 @@ Sketchfab unity exporter
44
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.
55

66
Release date: Nov 22, 2013
7-
Last update: Apr 23, 2014
8-
Unity version: 4.3.4f1
9-
Author: Clément Léger ([email protected]), Sketchfab ([email protected])
7+
Last update: Aug 12, 2015
8+
Unity version: 5.1.1f1
9+
Author: Sketchfab, Clément Léger, Bryan Thatcher
1010

1111
Installation
1212
------------
13-
Just copy the folder Assets and its content into the root of your Unity project.
14-
You should have the files :
15-
- Assets/External Tools/Exporter/EditorObjExporter.cs
16-
- Assets/External Tools/Exporter/SimpleJSON.cs
17-
- Assets/Ionic.Zip.dll
13+
Download the unitypackage file and install it from *Assets → Import Package → Custom Package...*
14+
15+
Or download this repository and copy assets and its content into the root of your Unity project.
1816

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

21-
Your project must not build for the Web Player as it disallows the manipulation of obj/zip files.
22-
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.
22+
The Unity project is automatically updated and a new menu item will appear: *Window → Export Selection to Sketchfab...*
2323

2424
Usage
2525
-----
26-
Select in your scene the objects you want to export. Are exported static geometry but also skinned meshes.
27-
Basically, MeshFilter objects SkinnedMeshRenderer are exported which covers most static geometry and characters in T-pose.
26+
You must save your scene before using the exporter.
27+
28+
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.
29+
30+
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.
2831

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

32-
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.
33-
Following options are basic models properties : private if your account allows it, the model title, its description and a list of space separated tags.
34+
- Title
35+
- Description
36+
- Tags (space-sparated)
37+
- Private (PRO and Business accounts only)
38+
- Password (Optional for private models)
3439

35-
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.
40+
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.
3641

3742
Contact
3843
-------

0 commit comments

Comments
 (0)