Skip to content

Commit

Permalink
com.rest.blockadelabs 1.0.0-preview.2 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Jun 11, 2023
1 parent b9a100f commit 3e6a444
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ BlockadeLabs/Assets/Resources
BlockadeLabs/Assets/Resources.meta
BlockadeLabs/Assets/Plugins
BlockadeLabs/Assets/Plugins.meta
BlockadeLabs/ProjectSettings/SceneTemplateSettings.json
10 changes: 5 additions & 5 deletions BlockadeLabs/Assets/Demo/SkyboxDemo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ MonoBehaviour:
m_VerticalScrollbarEventHandler: {fileID: 0}
m_LayoutGroup: {fileID: 0}
m_ScrollSensitivity: 1
m_ContentType: 4
m_ContentType: 0
m_InputType: 0
m_AsteriskChar: 42
m_KeyboardType: 1
m_LineType: 0
m_KeyboardType: 0
m_LineType: 1
m_HideMobileInput: 0
m_HideSoftKeyboard: 0
m_CharacterValidation: 4
m_CharacterValidation: 0
m_RegexValue:
m_GlobalPointSize: 24
m_CharacterLimit: 0
Expand Down Expand Up @@ -2137,7 +2137,7 @@ MonoBehaviour:
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
Expand Down
117 changes: 113 additions & 4 deletions BlockadeLabs/Packages/com.rest.blockadelabs/Documentation~/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

[![openupm](https://img.shields.io/npm/v/com.rest.blockadelabs?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.rest.blockadelabs/)

A BlockadeLabs package for the [Unity](https://unity.com/) Game Engine.
A non-official [BlockadeLabs](https://www.blockadelabs.com/) Skybox AI RESTful client for the [Unity](https://unity.com/) Game Engine.

I am not affiliated with BlockadeLabs and an account with api access is required.

***All copyrights, trademarks, logos, and assets are the property of their respective owners.***

## Installing

Requires Unity 2021.3 LTS or higher.

The recommended installation method is though the unity package manager and [OpenUPM](https://openupm.com/packages/com.openai.unity).

### Via Unity Package Manager and OpenUPM

- Open your Unity project settings
Expand All @@ -15,7 +23,7 @@ A BlockadeLabs package for the [Unity](https://unity.com/) Game Engine.
- Name: `OpenUPM`
- URL: `https://package.openupm.com`
- Scope(s):
- `com.rest`
- `com.rest.blockadelabs`
- `com.utilities`
- Open the Unity Package Manager window
- Change the Registry from Unity to `My Registries`
Expand All @@ -25,11 +33,112 @@ A BlockadeLabs package for the [Unity](https://unity.com/) Game Engine.

- Open your Unity Package Manager
- Add package from git url: `https://github.com/RageAgainstThePixel/com.rest.blockadelabs.git#upm`
> Note: this repo has dependencies on other repositories! You are responsible for adding these on your own.
- [com.utilities.async](https://github.com/RageAgainstThePixel/com.utilities.async)
- [com.utilities.rest](https://github.com/RageAgainstThePixel/com.utilities.rest)

## Documentation

### Project Setup
### Table of Contents

- [Authentication](#authentication)
- [Skyboxes](#skyboxes)
- [Get Skybox Styles](#get-skybox-styles)
- [Generate Skybox](#generate-skybox)
- [Get Skybox by Id](get-skybox)

### Authentication

There are 4 ways to provide your API keys, in order of precedence:

1. [Pass keys directly with constructor](#pass-keys-directly-with-constructor)
2. [Unity Scriptable Object](#unity-scriptable-object)
3. [Load key from configuration file](#load-key-from-configuration-file)
4. [Use System Environment Variables](#use-system-environment-variables)

#### Pass keys directly with constructor

```csharp
var api = new BlockadeLabsClient("yourApiKey");
```

Or create a `BlockadeLabsAuthentication` object manually

```csharp
var api = new BlockadeLabsClient(new BlockadeLabsAuthentication("yourApiKey"));
```

#### Unity Scriptable Object

You can save the key directly into a scriptable object that is located in the `Assets/Resources` folder.

You can create a new one by using the context menu of the project pane and creating a new `BlockadeLabsConfiguration` scriptable object.

![Create new BlockadeLabsConfiguration](images/create-scriptable-object.png)

#### Load key from configuration file

Attempts to load api keys from a configuration file, by default `.blockadelabs` in the current directory, optionally traversing up the directory tree or in the user's home directory.

To create a configuration file, create a new text file named `.blockadelabs` and containing the line:

##### Json format

```json
{
"apiKey": "yourApiKey",
}
```

You can also load the file directly with known path by calling a static method in Authentication:

```csharp
var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromDirectory("your/path/to/.blockadelabs"));;
```

#### Use System Environment Variables

Use your system's environment variables specify an api key to use.

- Use `BLOCKADE_LABS_API_KEY` for your api key.

```csharp
var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment());
```

### Skyboxes

#### [Get Skybox Styles](https://blockade.cloudshell.run/redoc#tag/skybox/operation/Get_Skybox_Styles_api_v1_skybox_styles_get)

Returns the list of predefined styles that can influence the overall aesthetic of your skybox generation.

```csharp
var api = new BlockadeLabsClient();
var skyboxStyles = await api.SkyboxEndpoint.GetSkyboxStylesAsync();

foreach (var skyboxStyle in skyboxStyles)
{
Debug.Log($"{skyboxStyle.Name}");
}
```

#### [Generate Skybox](https://blockade.cloudshell.run/redoc#tag/skybox/operation/Generate_Skybox_api_v1_skybox_generate_post)

Generate a skybox image

```csharp
var api = new BlockadeLabsClient();
var request = new SkyboxRequest("underwater", depth: true);
var skyboxInfo = await api.SkyboxEndpoint.GenerateSkyboxAsync(request);
skyboxMaterial.mainTexture = skyboxInfo.MainTexture;
skyboxMaterial.depthTexture = skyboxInfo.DepthTexture;
```

#### [Get Skybox](https://blockade.cloudshell.run/redoc#tag/skybox/operation/Get_Skybox_By_Id_api_v1_skybox_info__id__get)

Returns the skybox metadata for the given skybox id.

```csharp
// TODO
var skyboxInfo = await api.SkyboxEndpoint.GetSkyboxInfoAsync("skybox-id");
Debug.Log($"Skybox: {result.Id} | {result.MainTextureUrl}");
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,12 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine.Scripting;
using Utilities.WebRequestRest;

namespace BlockadeLabs.Skyboxes
{
public sealed class SkyboxEndpoint : BlockadeLabsBaseEndpoint
{
[Preserve]
private class SkyboxMetadata
{
[Preserve]
public SkyboxMetadata([JsonProperty("request")] SkyboxInfo request)
{
Request = request;
}

[Preserve]
[JsonProperty("request")]
public SkyboxInfo Request { get; }
}

public SkyboxEndpoint(BlockadeLabsClient client) : base(client) { }

protected override string Root => "skybox";
Expand Down Expand Up @@ -84,7 +69,7 @@ public async Task<SkyboxInfo> GetSkyboxInfoAsync(int id, CancellationToken cance
{
var response = await Rest.GetAsync(GetUrl($"/info/{id}"), parameters: new RestParameters(client.DefaultRequestHeaders), cancellationToken);
response.Validate();
return JsonConvert.DeserializeObject<SkyboxMetadata>(response.Body, client.JsonSerializationOptions).Request;
return JsonConvert.DeserializeObject<SkyboxInfo>(response.Body, client.JsonSerializationOptions);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public async Task Test_01_GetSkyboxStyles()
{
var api = new BlockadeLabsClient();
Assert.IsNotNull(api.SkyboxEndpoint);
var result = await api.SkyboxEndpoint.GetSkyboxStylesAsync();
Assert.IsNotNull(result);
var skyboxStyles = await api.SkyboxEndpoint.GetSkyboxStylesAsync();
Assert.IsNotNull(skyboxStyles);

foreach (var skyboxStyle in result)
foreach (var skyboxStyle in skyboxStyles)
{
Debug.Log($"{skyboxStyle.Name}");
}
Expand All @@ -27,18 +27,25 @@ public async Task Test_02_GenerateSkybox()
var api = new BlockadeLabsClient();
Assert.IsNotNull(api.SkyboxEndpoint);

var request = new SkyboxRequest("underwater"/*, depth: true*/);
var request = new SkyboxRequest("underwater", depth: true);
var skyboxInfo = await api.SkyboxEndpoint.GenerateSkyboxAsync(request);
Assert.IsNotNull(skyboxInfo);
Debug.Log($"Successfully created skybox: {skyboxInfo.Id}");
Debug.Log(skyboxInfo.MainTextureUrl);
Assert.IsNotNull(skyboxInfo.MainTexture);
Debug.Log(skyboxInfo.DepthTextureUrl);
//Assert.IsNotNull(skyboxInfo.DepthTexture);
Assert.IsNotNull(skyboxInfo.DepthTexture);
}

[Test]
public async Task Test_03_GetSkyboxInfo()
{
var api = new BlockadeLabsClient();
Assert.IsNotNull(api.SkyboxEndpoint);

var result = await api.SkyboxEndpoint.GetSkyboxInfoAsync(skyboxInfo.Id);
var result = await api.SkyboxEndpoint.GetSkyboxInfoAsync(5719637);
Assert.IsNotNull(result);
Debug.Log($"Skybox: {result.Id} | {result.MainTextureUrl}");
Assert.IsTrue(skyboxInfo.Id == result.Id);
}
}
}
2 changes: 1 addition & 1 deletion BlockadeLabs/Packages/com.rest.blockadelabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "BlockadeLabs",
"description": "A Non-Official Blockade Labs Rest Client for Unity (UPM)",
"keywords": [],
"version": "1.0.0-preview.1",
"version": "1.0.0-preview.2",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.blockadelabs#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.blockadelabs/releases",
Expand Down
Loading

0 comments on commit 3e6a444

Please sign in to comment.