Skip to content

Commit

Permalink
Merge pull request #5 from sketchfab/feature/adds-banner_D3D-4591
Browse files Browse the repository at this point in the history
[#D3D-4591] Adds store banner in plugin
  • Loading branch information
cedricpinson authored Oct 29, 2018
2 parents c95ce11 + 55a23b1 commit b4380a6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 22 deletions.
48 changes: 28 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,67 @@
# Sketchfab Plugin for Unity

Unity plugin to browse, import and export asset between Unity and Sketchfab.
*Based on khronos' [UnityGLTF plugin](https://github.com/KhronosGroup/UnityGLTF)*
*Browse, import and export assets between Unity and Sketchfab*

A Sketchfab account is required for most of this plugin features (you can [create one here](https://sketchfab.com/signup))


*Based on Khronos' [UnityGLTF plugin](https://github.com/KhronosGroup/UnityGLTF)*

*Supported versions: Unity 5.6.4 or later*

## Installation

Download attached `SketchfabForUnity-vx.x.x.unitypackage` from the [latest release](https://github.com/sketchfab/UnityGLTF/releases/latest) and double click on it to import the plugin into your current Unity project.

## Report an issue
If you have any issue, please use the [Report an issue](https://help.sketchfab.com/hc/en-us/requests/new?type=exporters&subject=Unity+Exporter) link to be redirected to the support form.

## Sketchfab Asset Browser
*Available in menu: Sketchfab/Browse Sketchfab*

Browse more than [nb] free downloadable models from Sketchfab and import them into your Unity project.
#### Authentication
Browse more than [150k free downloadable models from Sketchfab](https://sketchfab.com/models?features=downloadable&sort_by=-likeCount&type=models) and import them into your Unity project.

*You need a Sketchfab account to download and import assets from Sketchfab*
(browser image)

Click on a thubnail to show the corresponding model page with a button to download and import the asset
(model page)
#### Asset Browser UI
![unity2](https://user-images.githubusercontent.com/4066133/37648425-37afe732-2c2f-11e8-9ba1-9f82eeccae06.JPG)

Click on a thumbnail to show the corresponding model page with a button to download and import the asset
![unity3](https://user-images.githubusercontent.com/4066133/37648438-3ded2682-2c2f-11e8-83f3-96087d1b26df.JPG)

You can specify a path **in your project directory** to import the asset into, set a name for the prefab that will contain the model and also choose to import it into your current scene.

You can specify a directory in your project to import the asset into, and also choose to add the model to your current scene.
Click the "Download model" button to download to proceed.


## Sketchfab Exporter
*Available in menu: Sketchfab/Publish to Sketchfab*

Export and share your current Unity scene on Sketchfab.

*You need a Sketchfab account to download and import assets from Sketchfab*

Important note: glTF file format is used as transport between Unity and Sketchfab.
**Important note:** glTF file format is used as transport between Unity and Sketchfab.
Because of this, a few features will not be supported and will be missing on the Sketchfab result.

The plugin will not export:
* animations or object handled by custom scripts
* custom materials/shaders

Only Standard materials (including Specular setup) are supported.

For animation, only Generic or Legacy animation type are exported.

This support will be improved in the future.

(exporter image)
![unity4](https://user-images.githubusercontent.com/4066133/37648662-e1612fa2-2c2f-11e8-8f7b-9658970da423.JPG)



## glTF Importer (editor)

Import glTF asset into Unity
*Available in menu: Sketchfab/Import glTF*

(import image)


## Installation

Download the Unity package of the [latest release](https://github.com/sketchfab/UnityGLTF/releases) and double click on it to import the plugin into your current Unity project.


## Report an issue
If you have any issue, please use the [Report an issue](https://help.sketchfab.com/hc/en-us/requests/new?type=exporters&subject=Unity+Exporter) link to be redirected to the support form.
Drag and drop glTF asset on the importer window, set the import options and click import.
![unity5](https://user-images.githubusercontent.com/4066133/37648668-e72c98fe-2c2f-11e8-8e80-b228b2df82dd.JPG)
1 change: 1 addition & 0 deletions UnityGLTF/Assets/UnityGLTF/Scripts/GLTFEditorExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ private MaterialId ExportMaterial(UnityEngine.Material materialObj)
switch (materialObj.shader.name)
{
case "Standard":
case "Standard (Roughness setup)":
case "GLTF/GLTFStandard":
material.PbrMetallicRoughness = ExportPBRMetallicRoughness(materialObj);
if (materialObj.HasProperty("_OcclusionMap"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void displayImportDirectory()
GUILayout.FlexibleSpace();
if (GUILayout.Button("Change destination", GUILayout.Height(UI_SIZE.y), GUILayout.Width(minWidthButton)))
{
string newImportDir = EditorUtility.OpenFolderPanel("Choose import directory", GLTFUtils.getPathAbsoluteFromProject(_importDirectory), GLTFUtils.getPathAbsoluteFromProject(_importDirectory));
string newImportDir = EditorUtility.OpenFolderPanel("Choose import directory", _importDirectory, "");
if (GLTFUtils.isFolderInProjectDirectory(newImportDir))
{
_importDirectory = newImportDir;
Expand Down
38 changes: 37 additions & 1 deletion UnityGLTF/Assets/UnityGLTF/Scripts/Sketchfab/SketchfabPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using UnityEngine.Networking;
using SimpleJSON;

// Static data and assets related to the plugin
Expand All @@ -27,6 +27,8 @@ public struct Urls
public static string draftInfo = "https://help.sketchfab.com/hc/en-us/articles/115000472906-Draft-Mode";
public static string latestReleaseCheck = "https://api.github.com/repos/sketchfab/UnityGLTF/releases";
public static string plans = "https://sketchfab.com/plans";
public static string bannerUrl = "https://static.sketchfab.com/plugins/unity/banner.jpg";
public static string storeUrl = "https://sketchfab.com/store?utm_source=plugin&utm_medium=banner&utm_campaign=unity-plugin";
public static string categories = server + "/v3/categories";
private static string dummyClientId = "IUO8d5VVOIUCzWQArQ3VuXfbwx5QekZfLeDlpOmW";
public static string oauth = server + "/oauth2/token/?grant_type=password&client_id=" + dummyClientId;
Expand All @@ -52,6 +54,7 @@ public struct Urls

// UI ELEMENTS
public static Texture2D DEFAULT_AVATAR;
public static Texture2D bannerTexture;

// Plugin elements
static SketchfabUI _ui;
Expand All @@ -68,9 +71,27 @@ public static void Initialize()
_api = new SketchfabAPI();
_logger = new SketchfabLogger();
checkUpdates();
retrieveBannerImage();
DEFAULT_AVATAR = Resources.Load("defaultAvatar") as Texture2D;
}

public static void retrieveBannerImage()
{
SketchfabRequest request = new SketchfabRequest(Urls.bannerUrl);
request.setCallback(onBannerRetrieved);
getAPI().registerRequest(request);
}

public static void onBannerRetrieved(UnityWebRequest request)
{
bool sRGBBackup = GL.sRGBWrite;
GL.sRGBWrite = true;
byte[] data = request.downloadHandler.data;

bannerTexture = new Texture2D(2, 2);
bannerTexture.LoadImage(data);
}

public static void checkValidity()
{
if(_ui == null || _logger == null || _api == null || DEFAULT_AVATAR == null)
Expand Down Expand Up @@ -138,6 +159,21 @@ public static void displayHeader()

GUILayout.BeginHorizontal(whiteGround, GUILayout.Height(75));
_logger.showLoginUi();
GUILayout.FlexibleSpace();

// If banner available, display it
if (bannerTexture != null)
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
if(GUILayout.Button(bannerTexture, _ui.SketchfabLabel))
{
Application.OpenURL(Urls.storeUrl);
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}

GUILayout.FlexibleSpace();
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
Expand Down

0 comments on commit b4380a6

Please sign in to comment.