Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit c3ba39a

Browse files
com.rest.blockadelabs 1.0.0-preview.2 (#2)
1 parent 50f9926 commit c3ba39a

File tree

5 files changed

+129
-28
lines changed

5 files changed

+129
-28
lines changed

Documentation~/README.md

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22

33
[![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/)
44

5-
A BlockadeLabs package for the [Unity](https://unity.com/) Game Engine.
5+
A non-official [BlockadeLabs](https://www.blockadelabs.com/) Skybox AI RESTful client for the [Unity](https://unity.com/) Game Engine.
6+
7+
I am not affiliated with BlockadeLabs and an account with api access is required.
8+
9+
***All copyrights, trademarks, logos, and assets are the property of their respective owners.***
610

711
## Installing
812

13+
Requires Unity 2021.3 LTS or higher.
14+
15+
The recommended installation method is though the unity package manager and [OpenUPM](https://openupm.com/packages/com.openai.unity).
16+
917
### Via Unity Package Manager and OpenUPM
1018

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

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

2940
## Documentation
3041

31-
### Project Setup
42+
### Table of Contents
43+
44+
- [Authentication](#authentication)
45+
- [Skyboxes](#skyboxes)
46+
- [Get Skybox Styles](#get-skybox-styles)
47+
- [Generate Skybox](#generate-skybox)
48+
- [Get Skybox by Id](get-skybox)
49+
50+
### Authentication
51+
52+
There are 4 ways to provide your API keys, in order of precedence:
53+
54+
1. [Pass keys directly with constructor](#pass-keys-directly-with-constructor)
55+
2. [Unity Scriptable Object](#unity-scriptable-object)
56+
3. [Load key from configuration file](#load-key-from-configuration-file)
57+
4. [Use System Environment Variables](#use-system-environment-variables)
58+
59+
#### Pass keys directly with constructor
60+
61+
```csharp
62+
var api = new BlockadeLabsClient("yourApiKey");
63+
```
64+
65+
Or create a `BlockadeLabsAuthentication` object manually
66+
67+
```csharp
68+
var api = new BlockadeLabsClient(new BlockadeLabsAuthentication("yourApiKey"));
69+
```
70+
71+
#### Unity Scriptable Object
72+
73+
You can save the key directly into a scriptable object that is located in the `Assets/Resources` folder.
74+
75+
You can create a new one by using the context menu of the project pane and creating a new `BlockadeLabsConfiguration` scriptable object.
76+
77+
![Create new BlockadeLabsConfiguration](images/create-scriptable-object.png)
78+
79+
#### Load key from configuration file
80+
81+
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.
82+
83+
To create a configuration file, create a new text file named `.blockadelabs` and containing the line:
84+
85+
##### Json format
86+
87+
```json
88+
{
89+
"apiKey": "yourApiKey",
90+
}
91+
```
92+
93+
You can also load the file directly with known path by calling a static method in Authentication:
94+
95+
```csharp
96+
var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromDirectory("your/path/to/.blockadelabs"));;
97+
```
98+
99+
#### Use System Environment Variables
100+
101+
Use your system's environment variables specify an api key to use.
102+
103+
- Use `BLOCKADE_LABS_API_KEY` for your api key.
104+
105+
```csharp
106+
var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment());
107+
```
108+
109+
### Skyboxes
110+
111+
#### [Get Skybox Styles](https://blockade.cloudshell.run/redoc#tag/skybox/operation/Get_Skybox_Styles_api_v1_skybox_styles_get)
112+
113+
Returns the list of predefined styles that can influence the overall aesthetic of your skybox generation.
114+
115+
```csharp
116+
var api = new BlockadeLabsClient();
117+
var skyboxStyles = await api.SkyboxEndpoint.GetSkyboxStylesAsync();
118+
119+
foreach (var skyboxStyle in skyboxStyles)
120+
{
121+
Debug.Log($"{skyboxStyle.Name}");
122+
}
123+
```
124+
125+
#### [Generate Skybox](https://blockade.cloudshell.run/redoc#tag/skybox/operation/Generate_Skybox_api_v1_skybox_generate_post)
126+
127+
Generate a skybox image
128+
129+
```csharp
130+
var api = new BlockadeLabsClient();
131+
var request = new SkyboxRequest("underwater", depth: true);
132+
var skyboxInfo = await api.SkyboxEndpoint.GenerateSkyboxAsync(request);
133+
skyboxMaterial.mainTexture = skyboxInfo.MainTexture;
134+
skyboxMaterial.depthTexture = skyboxInfo.DepthTexture;
135+
```
136+
137+
#### [Get Skybox](https://blockade.cloudshell.run/redoc#tag/skybox/operation/Get_Skybox_By_Id_api_v1_skybox_info__id__get)
138+
139+
Returns the skybox metadata for the given skybox id.
32140

33141
```csharp
34-
// TODO
142+
var skyboxInfo = await api.SkyboxEndpoint.GetSkyboxInfoAsync("skybox-id");
143+
Debug.Log($"Skybox: {result.Id} | {result.MainTextureUrl}");
35144
```
42.1 KB
Loading

Runtime/Skyboxes/SkyboxEndpoint.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,12 @@
44
using System.Collections.Generic;
55
using System.Threading;
66
using System.Threading.Tasks;
7-
using UnityEngine.Scripting;
87
using Utilities.WebRequestRest;
98

109
namespace BlockadeLabs.Skyboxes
1110
{
1211
public sealed class SkyboxEndpoint : BlockadeLabsBaseEndpoint
1312
{
14-
[Preserve]
15-
private class SkyboxMetadata
16-
{
17-
[Preserve]
18-
public SkyboxMetadata([JsonProperty("request")] SkyboxInfo request)
19-
{
20-
Request = request;
21-
}
22-
23-
[Preserve]
24-
[JsonProperty("request")]
25-
public SkyboxInfo Request { get; }
26-
}
27-
2813
public SkyboxEndpoint(BlockadeLabsClient client) : base(client) { }
2914

3015
protected override string Root => "skybox";
@@ -84,7 +69,7 @@ public async Task<SkyboxInfo> GetSkyboxInfoAsync(int id, CancellationToken cance
8469
{
8570
var response = await Rest.GetAsync(GetUrl($"/info/{id}"), parameters: new RestParameters(client.DefaultRequestHeaders), cancellationToken);
8671
response.Validate();
87-
return JsonConvert.DeserializeObject<SkyboxMetadata>(response.Body, client.JsonSerializationOptions).Request;
72+
return JsonConvert.DeserializeObject<SkyboxInfo>(response.Body, client.JsonSerializationOptions);
8873
}
8974
}
9075
}

Tests/TestFixture_00_Skyboxes.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public async Task Test_01_GetSkyboxStyles()
1212
{
1313
var api = new BlockadeLabsClient();
1414
Assert.IsNotNull(api.SkyboxEndpoint);
15-
var result = await api.SkyboxEndpoint.GetSkyboxStylesAsync();
16-
Assert.IsNotNull(result);
15+
var skyboxStyles = await api.SkyboxEndpoint.GetSkyboxStylesAsync();
16+
Assert.IsNotNull(skyboxStyles);
1717

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

30-
var request = new SkyboxRequest("underwater"/*, depth: true*/);
30+
var request = new SkyboxRequest("underwater", depth: true);
3131
var skyboxInfo = await api.SkyboxEndpoint.GenerateSkyboxAsync(request);
3232
Assert.IsNotNull(skyboxInfo);
33+
Debug.Log($"Successfully created skybox: {skyboxInfo.Id}");
3334
Debug.Log(skyboxInfo.MainTextureUrl);
3435
Assert.IsNotNull(skyboxInfo.MainTexture);
3536
Debug.Log(skyboxInfo.DepthTextureUrl);
36-
//Assert.IsNotNull(skyboxInfo.DepthTexture);
37+
Assert.IsNotNull(skyboxInfo.DepthTexture);
38+
}
39+
40+
[Test]
41+
public async Task Test_03_GetSkyboxInfo()
42+
{
43+
var api = new BlockadeLabsClient();
44+
Assert.IsNotNull(api.SkyboxEndpoint);
3745

38-
var result = await api.SkyboxEndpoint.GetSkyboxInfoAsync(skyboxInfo.Id);
46+
var result = await api.SkyboxEndpoint.GetSkyboxInfoAsync(5719637);
3947
Assert.IsNotNull(result);
4048
Debug.Log($"Skybox: {result.Id} | {result.MainTextureUrl}");
41-
Assert.IsTrue(skyboxInfo.Id == result.Id);
4249
}
4350
}
4451
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "BlockadeLabs",
44
"description": "A Non-Official Blockade Labs Rest Client for Unity (UPM)",
55
"keywords": [],
6-
"version": "1.0.0-preview.1",
6+
"version": "1.0.0-preview.2",
77
"unity": "2021.3",
88
"documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.blockadelabs#documentation",
99
"changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.blockadelabs/releases",

0 commit comments

Comments
 (0)