ai.muna.muna 0.0.44 → 0.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/MunaMenu.cs +17 -7
- package/Plugins/Android/Muna.aar +0 -0
- package/Plugins/macOS/Function.dylib.meta +26 -25
- package/README.md +1 -1
- package/Runtime/API/DotNetClient.cs +0 -3
- package/Runtime/Beta/BetaClient.cs +14 -1
- package/Runtime/Beta/OpenAI/AudioService.cs +38 -0
- package/Runtime/Beta/OpenAI/AudioService.cs.meta +11 -0
- package/Runtime/Beta/OpenAI/ChatService.cs +38 -0
- package/Runtime/Beta/OpenAI/ChatService.cs.meta +11 -0
- package/Runtime/Beta/OpenAI/CompletionService.cs +117 -0
- package/Runtime/Beta/OpenAI/CompletionService.cs.meta +11 -0
- package/Runtime/Beta/OpenAI/EmbeddingService.cs +252 -0
- package/Runtime/Beta/OpenAI/EmbeddingService.cs.meta +11 -0
- package/Runtime/Beta/OpenAI/OpenAIClient.cs +50 -0
- package/Runtime/Beta/OpenAI/OpenAIClient.cs.meta +11 -0
- package/Runtime/Beta/OpenAI/SpeechService.cs +256 -0
- package/Runtime/Beta/OpenAI/SpeechService.cs.meta +11 -0
- package/Runtime/Beta/OpenAI/Types.cs +364 -0
- package/Runtime/Beta/OpenAI/Types.cs.meta +11 -0
- package/Runtime/Beta/OpenAI.meta +8 -0
- package/Runtime/Beta/Remote/RemotePredictionService.cs +50 -70
- package/Runtime/Beta/{Value.cs → Types/Value.cs} +3 -4
- package/Runtime/Beta/Types.meta +8 -0
- package/Runtime/C/Configuration.cs +1 -1
- package/Runtime/C/Function.cs +1 -1
- package/Runtime/C/Prediction.cs +1 -1
- package/Runtime/C/PredictionStream.cs +1 -1
- package/Runtime/C/Predictor.cs +1 -1
- package/Runtime/C/Value.cs +3 -2
- package/Runtime/C/ValueMap.cs +1 -1
- package/Runtime/Muna.cs +2 -2
- package/Runtime/Types/Parameter.cs +75 -0
- package/Runtime/Types/Parameter.cs.meta +11 -0
- package/Runtime/Types/Predictor.cs +0 -53
- package/Unity/API/PredictionCacheClient.cs +1 -1
- package/Unity/Converters/Color.cs +46 -0
- package/Unity/Converters/Color.cs.meta +2 -0
- package/Unity/Converters/Rect.cs +230 -0
- package/Unity/Converters/Rect.cs.meta +2 -0
- package/Unity/Converters/Vector2.cs +44 -0
- package/Unity/Converters/Vector2.cs.meta +2 -0
- package/Unity/Converters/Vector3.cs +45 -0
- package/Unity/Converters/Vector3.cs.meta +2 -0
- package/Unity/Converters/Vector4.cs +46 -0
- package/Unity/Converters/Vector4.cs.meta +2 -0
- package/Unity/Converters.meta +8 -0
- package/Unity/MunaUnity.cs +67 -19
- package/package.json +1 -1
- /package/Runtime/Beta/{Value.cs.meta → Types/Value.cs.meta} +0 -0
package/Runtime/C/ValueMap.cs
CHANGED
package/Runtime/Muna.cs
CHANGED
|
@@ -87,14 +87,14 @@ namespace Muna {
|
|
|
87
87
|
this.Users = new UserService(client);
|
|
88
88
|
this.Predictors = new PredictorService(client);
|
|
89
89
|
this.Predictions = new PredictionService(client);
|
|
90
|
-
this.Beta = new BetaClient(client);
|
|
90
|
+
this.Beta = new BetaClient(client, this.Predictors, this.Predictions);
|
|
91
91
|
}
|
|
92
92
|
#endregion
|
|
93
93
|
|
|
94
94
|
|
|
95
95
|
#region --Operations--
|
|
96
96
|
public readonly MunaClient client;
|
|
97
|
-
public const string Version = @"0.0.
|
|
97
|
+
public const string Version = @"0.0.46";
|
|
98
98
|
internal const string URL = @"https://api.muna.ai/v1";
|
|
99
99
|
#endregion
|
|
100
100
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
#pragma warning disable 8618
|
|
8
|
+
|
|
9
|
+
namespace Muna {
|
|
10
|
+
|
|
11
|
+
using System;
|
|
12
|
+
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// Predictor parameter.
|
|
15
|
+
/// </summary>
|
|
16
|
+
[Preserve, Serializable]
|
|
17
|
+
public class Parameter {
|
|
18
|
+
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Parameter name.
|
|
21
|
+
/// </summary>
|
|
22
|
+
public string name;
|
|
23
|
+
|
|
24
|
+
/// <summary>
|
|
25
|
+
/// Parameter type.
|
|
26
|
+
/// </summary>
|
|
27
|
+
public Dtype type;
|
|
28
|
+
|
|
29
|
+
/// <summary>
|
|
30
|
+
/// Parameter description.
|
|
31
|
+
/// </summary>
|
|
32
|
+
public string? description;
|
|
33
|
+
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Parameter denotation.
|
|
36
|
+
/// </summary>
|
|
37
|
+
public string? denotation;
|
|
38
|
+
|
|
39
|
+
/// <summary>
|
|
40
|
+
/// Parameter is optional.
|
|
41
|
+
/// </summary>
|
|
42
|
+
public bool? optional;
|
|
43
|
+
|
|
44
|
+
/// <summary>
|
|
45
|
+
/// Parameter value range for numeric parameters.
|
|
46
|
+
/// </summary>
|
|
47
|
+
public float[]? range;
|
|
48
|
+
|
|
49
|
+
/// <summary>
|
|
50
|
+
/// Parameter value choices for enumeration parameters.
|
|
51
|
+
/// </summary>
|
|
52
|
+
public EnumerationMember[]? enumeration;
|
|
53
|
+
|
|
54
|
+
/// <summary>
|
|
55
|
+
/// Parameter audio sample rate.
|
|
56
|
+
/// </summary>
|
|
57
|
+
public int? sampleRate;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// <summary>
|
|
61
|
+
/// Prediction parameter enumeration member.
|
|
62
|
+
/// </summary>
|
|
63
|
+
[Preserve, Serializable]
|
|
64
|
+
public class EnumerationMember {
|
|
65
|
+
/// <summary>
|
|
66
|
+
/// Enumeration member name.
|
|
67
|
+
/// </summary>
|
|
68
|
+
public string name;
|
|
69
|
+
/// <summary>
|
|
70
|
+
/// Enumeration member value.
|
|
71
|
+
/// This is usually a `string` or `int`.
|
|
72
|
+
/// </summary>
|
|
73
|
+
public object value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -94,59 +94,6 @@ namespace Muna {
|
|
|
94
94
|
public Parameter[] outputs;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
/// <summary>
|
|
98
|
-
/// Predictor parameter.
|
|
99
|
-
/// </summary>
|
|
100
|
-
[Preserve, Serializable]
|
|
101
|
-
public class Parameter {
|
|
102
|
-
|
|
103
|
-
/// <summary>
|
|
104
|
-
/// Parameter name.
|
|
105
|
-
/// </summary>
|
|
106
|
-
public string? name;
|
|
107
|
-
|
|
108
|
-
/// <summary>
|
|
109
|
-
/// Parameter type.
|
|
110
|
-
/// </summary>
|
|
111
|
-
public Dtype? type;
|
|
112
|
-
|
|
113
|
-
/// <summary>
|
|
114
|
-
/// Parameter description.
|
|
115
|
-
/// </summary>
|
|
116
|
-
public string? description;
|
|
117
|
-
|
|
118
|
-
/// <summary>
|
|
119
|
-
/// Parameter is optional.
|
|
120
|
-
/// </summary>
|
|
121
|
-
public bool? optional;
|
|
122
|
-
|
|
123
|
-
/// <summary>
|
|
124
|
-
/// Parameter value range for numeric parameters.
|
|
125
|
-
/// </summary>
|
|
126
|
-
public float[]? range;
|
|
127
|
-
|
|
128
|
-
/// <summary>
|
|
129
|
-
/// Parameter value choices for enumeration parameters.
|
|
130
|
-
/// </summary>
|
|
131
|
-
public EnumerationMember[]? enumeration;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/// <summary>
|
|
135
|
-
/// Prediction parameter enumeration member.
|
|
136
|
-
/// </summary>
|
|
137
|
-
[Preserve, Serializable]
|
|
138
|
-
public class EnumerationMember {
|
|
139
|
-
/// <summary>
|
|
140
|
-
/// Enumeration member name.
|
|
141
|
-
/// </summary>
|
|
142
|
-
public string name;
|
|
143
|
-
/// <summary>
|
|
144
|
-
/// Enumeration member value.
|
|
145
|
-
/// This is usually a `string` or `int`.
|
|
146
|
-
/// </summary>
|
|
147
|
-
public object value;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
97
|
/// <summary>
|
|
151
98
|
/// Predictor access mode.
|
|
152
99
|
/// </summary>
|
|
@@ -109,7 +109,7 @@ namespace Muna.API {
|
|
|
109
109
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".fxn") :
|
|
110
110
|
Path.Combine(Application.persistentDataPath, @"fxn");
|
|
111
111
|
private static string ResourceCachePath => Path.Combine(CacheRoot, @"cache");
|
|
112
|
-
|
|
112
|
+
internal static string PredictorCachePath => Path.Combine(CacheRoot, @"predictors");
|
|
113
113
|
|
|
114
114
|
private async Task<PredictionResource> GetCachedResource(PredictionResource resource) {
|
|
115
115
|
var path = PredictionService.GetResourcePath(resource, ResourceCachePath);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.Converters {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using UnityEngine;
|
|
12
|
+
using Newtonsoft.Json;
|
|
13
|
+
using Newtonsoft.Json.Linq;
|
|
14
|
+
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// Convert an array field to a `Color`.
|
|
17
|
+
/// The array MUST contain three or four numbers.
|
|
18
|
+
/// </summary>
|
|
19
|
+
public sealed class ArrayToColorConverter : JsonConverter<Color> {
|
|
20
|
+
|
|
21
|
+
public override void WriteJson(
|
|
22
|
+
JsonWriter writer,
|
|
23
|
+
Color value,
|
|
24
|
+
JsonSerializer serializer
|
|
25
|
+
) {
|
|
26
|
+
var obj = new JArray { value.r, value.g, value.b, value.a };
|
|
27
|
+
obj.WriteTo(writer);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public override Color ReadJson(
|
|
31
|
+
JsonReader reader,
|
|
32
|
+
Type type,
|
|
33
|
+
Color existing,
|
|
34
|
+
bool hasExisting,
|
|
35
|
+
JsonSerializer s
|
|
36
|
+
) {
|
|
37
|
+
var arr = JArray.Load(reader);
|
|
38
|
+
return new Color(
|
|
39
|
+
r: (float)arr[0],
|
|
40
|
+
g: (float)arr[1],
|
|
41
|
+
b: (float)arr[2],
|
|
42
|
+
a: arr.Count > 3 ? (float)arr[3] : 1f
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.Converters {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using System.Runtime.Serialization;
|
|
12
|
+
using UnityEngine;
|
|
13
|
+
using Newtonsoft.Json;
|
|
14
|
+
using Newtonsoft.Json.Converters;
|
|
15
|
+
using Newtonsoft.Json.Linq;
|
|
16
|
+
|
|
17
|
+
/// <summary>
|
|
18
|
+
/// Box format.
|
|
19
|
+
/// </summary>
|
|
20
|
+
[JsonConverter(typeof(StringEnumConverter))]
|
|
21
|
+
public enum BoxFormat : int {
|
|
22
|
+
/// <summary>
|
|
23
|
+
/// Boxes are represented via corners: x1, y1 being top left and x2, y2 being bottom right.
|
|
24
|
+
/// </summary>
|
|
25
|
+
[EnumMember(Value = @"xyxy")]
|
|
26
|
+
XYXY = 1,
|
|
27
|
+
/// <summary>
|
|
28
|
+
/// Boxes are represented via corner, width and height: x1, y2 being top left.
|
|
29
|
+
/// </summary>
|
|
30
|
+
[EnumMember(Value = @"xywh")]
|
|
31
|
+
XYWH = 2,
|
|
32
|
+
/// <summary>
|
|
33
|
+
/// Boxes are represented via center, width, and height.
|
|
34
|
+
/// </summary>
|
|
35
|
+
[EnumMember(Value = @"cxcywh")]
|
|
36
|
+
CxCyWH = 3,
|
|
37
|
+
/// <summary>
|
|
38
|
+
/// Boxes are represented via corners:
|
|
39
|
+
/// - x1, y1 being top left
|
|
40
|
+
/// - x2, y2 top right
|
|
41
|
+
/// - x3, y3 bottom right
|
|
42
|
+
/// - x4, y4 bottom left
|
|
43
|
+
/// </summary>
|
|
44
|
+
[EnumMember(Value = @"xyxyxyxy")]
|
|
45
|
+
XYXYXYXY = 4,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// <summary>
|
|
49
|
+
/// Convert an object field to a `Rect`.
|
|
50
|
+
/// </summary>
|
|
51
|
+
public sealed class ObjectToRectConverter : JsonConverter<Rect> {
|
|
52
|
+
|
|
53
|
+
private readonly BoxFormat format;
|
|
54
|
+
private readonly string[] fieldNames;
|
|
55
|
+
|
|
56
|
+
/// <summary>
|
|
57
|
+
/// Create a converter with the provided box format.
|
|
58
|
+
/// </summary>
|
|
59
|
+
/// <param name="format">Box format to parse.</param>
|
|
60
|
+
public ObjectToRectConverter(BoxFormat format): this(
|
|
61
|
+
format,
|
|
62
|
+
GetReferenceFieldNames(format)
|
|
63
|
+
) { }
|
|
64
|
+
|
|
65
|
+
/// <summary>
|
|
66
|
+
/// Create a converter with the provided box format and corresponding field names.
|
|
67
|
+
/// </summary>
|
|
68
|
+
/// <param name="format">Box format to parse.</param>
|
|
69
|
+
/// <param name="fieldNames">Field names that correspond to the chosen format.</param>
|
|
70
|
+
public ObjectToRectConverter(BoxFormat format, string[] fieldNames) {
|
|
71
|
+
this.format = format;
|
|
72
|
+
this.fieldNames = fieldNames;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public override void WriteJson(
|
|
76
|
+
JsonWriter writer,
|
|
77
|
+
Rect value,
|
|
78
|
+
JsonSerializer serializer
|
|
79
|
+
) {
|
|
80
|
+
var values = GetRectValues(value, format);
|
|
81
|
+
var obj = new JObject();
|
|
82
|
+
for (var i = 0; i < fieldNames.Length; ++i)
|
|
83
|
+
obj[fieldNames[i]] = values[i];
|
|
84
|
+
obj.WriteTo(writer);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public override Rect ReadJson(
|
|
88
|
+
JsonReader reader,
|
|
89
|
+
Type type,
|
|
90
|
+
Rect existing,
|
|
91
|
+
bool hasExisting,
|
|
92
|
+
JsonSerializer s
|
|
93
|
+
) {
|
|
94
|
+
var obj = JObject.Load(reader);
|
|
95
|
+
return format switch {
|
|
96
|
+
BoxFormat.XYXY => Rect.MinMaxRect(
|
|
97
|
+
xmin: GetFieldValue(obj, fieldNames[0]),
|
|
98
|
+
ymin: GetFieldValue(obj, fieldNames[1]),
|
|
99
|
+
xmax: GetFieldValue(obj, fieldNames[2]),
|
|
100
|
+
ymax: GetFieldValue(obj, fieldNames[3])
|
|
101
|
+
),
|
|
102
|
+
BoxFormat.XYWH => new Rect(
|
|
103
|
+
x: GetFieldValue(obj, fieldNames[0]),
|
|
104
|
+
y: GetFieldValue(obj, fieldNames[1]),
|
|
105
|
+
width: GetFieldValue(obj, fieldNames[2]),
|
|
106
|
+
height: GetFieldValue(obj, fieldNames[3])
|
|
107
|
+
),
|
|
108
|
+
BoxFormat.CxCyWH => GetCenterRect(obj),
|
|
109
|
+
BoxFormat.XYXYXYXY => Rect.MinMaxRect(
|
|
110
|
+
xmin: GetFieldValue(obj, fieldNames[0]), // left
|
|
111
|
+
ymin: GetFieldValue(obj, fieldNames[1]), // top
|
|
112
|
+
xmax: GetFieldValue(obj, fieldNames[4]), // right
|
|
113
|
+
ymax: GetFieldValue(obj, fieldNames[5]) // bottom
|
|
114
|
+
),
|
|
115
|
+
_ => throw new JsonSerializationException($"Failed to read `Rect` from JSON object because of unsupported format: {format}")
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private Rect GetCenterRect(JObject obj) {
|
|
120
|
+
var cx = GetFieldValue(obj, fieldNames[0]);
|
|
121
|
+
var cy = GetFieldValue(obj, fieldNames[1]);
|
|
122
|
+
var w = GetFieldValue(obj, fieldNames[2]);
|
|
123
|
+
var h = GetFieldValue(obj, fieldNames[3]);
|
|
124
|
+
var center = new Vector2(cx, cy);
|
|
125
|
+
var size = new Vector2(w, h);
|
|
126
|
+
return new Rect(center - 0.5f * size, size);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private float GetFieldValue(
|
|
130
|
+
JObject obj,
|
|
131
|
+
string name
|
|
132
|
+
) {
|
|
133
|
+
if (!obj.TryGetValue(name, StringComparison.InvariantCulture, out var value))
|
|
134
|
+
throw new JsonSerializationException($"Missing '{name}' field for {format} box.");
|
|
135
|
+
return (float)value;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
internal static float[] GetRectValues(
|
|
139
|
+
in Rect rect,
|
|
140
|
+
BoxFormat format
|
|
141
|
+
) => format switch {
|
|
142
|
+
BoxFormat.XYXY => new[] { rect.xMin, rect.yMin, rect.xMax, rect.yMax },
|
|
143
|
+
BoxFormat.XYWH => new[] { rect.xMin, rect.yMin, rect.width, rect.height },
|
|
144
|
+
BoxFormat.CxCyWH => new[] { rect.center.x, rect.center.y, rect.width, rect.height },
|
|
145
|
+
BoxFormat.XYXYXYXY => new[] {
|
|
146
|
+
rect.xMin, rect.yMin, // top-left
|
|
147
|
+
rect.xMax, rect.yMin, // top-right
|
|
148
|
+
rect.xMax, rect.yMax, // bottom-right
|
|
149
|
+
rect.xMin, rect.yMax // bottom-left
|
|
150
|
+
},
|
|
151
|
+
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
private static string[] GetReferenceFieldNames(BoxFormat format) => format switch {
|
|
155
|
+
BoxFormat.XYXY => new[] { @"x_min", @"y_min", @"x_max", @"y_max" },
|
|
156
|
+
BoxFormat.XYWH => new[] { @"x", @"y", @"width", @"height" },
|
|
157
|
+
BoxFormat.CxCyWH => new[] { @"x_center", @"y_center", @"width", @"height" },
|
|
158
|
+
BoxFormat.XYXYXYXY => new[] { @"x1", @"y1", @"x2", @"y2", @"x3", @"y3", @"x4", @"y4" },
|
|
159
|
+
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/// <summary>
|
|
164
|
+
/// Convert an array field to a `Rect`.
|
|
165
|
+
/// The array MUST contain numbers, and have the required count depending on the box format.
|
|
166
|
+
/// </summary>
|
|
167
|
+
public sealed class ArrayToRectConverter : JsonConverter<Rect> {
|
|
168
|
+
|
|
169
|
+
private readonly BoxFormat format;
|
|
170
|
+
|
|
171
|
+
/// <summary>
|
|
172
|
+
/// Create a converter for the provided box format.
|
|
173
|
+
/// </summary>
|
|
174
|
+
/// <param name="format">Box format to parse.</param>
|
|
175
|
+
public ArrayToRectConverter(BoxFormat format) => this.format = format;
|
|
176
|
+
|
|
177
|
+
public override void WriteJson(
|
|
178
|
+
JsonWriter writer,
|
|
179
|
+
Rect value,
|
|
180
|
+
JsonSerializer serializer
|
|
181
|
+
) {
|
|
182
|
+
var values = ObjectToRectConverter.GetRectValues(value, format);
|
|
183
|
+
var arr = new JArray(values);
|
|
184
|
+
arr.WriteTo(writer);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public override Rect ReadJson(
|
|
188
|
+
JsonReader reader,
|
|
189
|
+
Type type,
|
|
190
|
+
Rect existing,
|
|
191
|
+
bool hasExisting,
|
|
192
|
+
JsonSerializer s
|
|
193
|
+
) {
|
|
194
|
+
var arr = JArray.Load(reader);
|
|
195
|
+
var expected = ExpectedCount(format);
|
|
196
|
+
if (arr.Count != expected)
|
|
197
|
+
throw new JsonSerializationException($"Expected {expected} numbers for {format} box but got {arr.Count}.");
|
|
198
|
+
var data = arr.ToObject<float[]>()!;
|
|
199
|
+
return format switch {
|
|
200
|
+
BoxFormat.XYXY => Rect.MinMaxRect(
|
|
201
|
+
xmin: data[0],
|
|
202
|
+
ymin: data[1],
|
|
203
|
+
xmax: data[2],
|
|
204
|
+
ymax: data[3]
|
|
205
|
+
),
|
|
206
|
+
BoxFormat.XYWH => new Rect(
|
|
207
|
+
x: data[0],
|
|
208
|
+
y: data[1],
|
|
209
|
+
width: data[2],
|
|
210
|
+
height: data[3]
|
|
211
|
+
),
|
|
212
|
+
BoxFormat.CxCyWH => new Rect(
|
|
213
|
+
x: data[0] - 0.5f * data[2],
|
|
214
|
+
y: data[1] * 0.5f - data[3],
|
|
215
|
+
width: data[2],
|
|
216
|
+
height: data[3]
|
|
217
|
+
),
|
|
218
|
+
_ => throw new JsonSerializationException($"Failed to read `Rect` from JSON array because of unsupported format: {format}")
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private static int ExpectedCount(BoxFormat format) => format switch {
|
|
223
|
+
BoxFormat.XYXY => 4,
|
|
224
|
+
BoxFormat.XYWH => 4,
|
|
225
|
+
BoxFormat.CxCyWH => 4,
|
|
226
|
+
BoxFormat.XYXYXYXY => 8,
|
|
227
|
+
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.Converters {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using UnityEngine;
|
|
12
|
+
using Newtonsoft.Json;
|
|
13
|
+
using Newtonsoft.Json.Linq;
|
|
14
|
+
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// Convert an array field to a `Vector2`.
|
|
17
|
+
/// The array MUST contain exactly two numbers.
|
|
18
|
+
/// </summary>
|
|
19
|
+
public sealed class ArrayToVector2Converter : JsonConverter<Vector2> {
|
|
20
|
+
|
|
21
|
+
public override void WriteJson(
|
|
22
|
+
JsonWriter writer,
|
|
23
|
+
Vector2 value,
|
|
24
|
+
JsonSerializer serializer
|
|
25
|
+
) {
|
|
26
|
+
var obj = new JArray { value.x, value.y };
|
|
27
|
+
obj.WriteTo(writer);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public override Vector2 ReadJson(
|
|
31
|
+
JsonReader reader,
|
|
32
|
+
Type type,
|
|
33
|
+
Vector2 existing,
|
|
34
|
+
bool hasExisting,
|
|
35
|
+
JsonSerializer s
|
|
36
|
+
) {
|
|
37
|
+
var arr = JArray.Load(reader);
|
|
38
|
+
return new Vector2(
|
|
39
|
+
x: (float)arr[0],
|
|
40
|
+
y: (float)arr[1]
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.Converters {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using UnityEngine;
|
|
12
|
+
using Newtonsoft.Json;
|
|
13
|
+
using Newtonsoft.Json.Linq;
|
|
14
|
+
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// Convert an array field to a `Vector3`.
|
|
17
|
+
/// The array MUST contain exactly three numbers.
|
|
18
|
+
/// </summary>
|
|
19
|
+
public sealed class ArrayToVector3Converter : JsonConverter<Vector3> {
|
|
20
|
+
|
|
21
|
+
public override void WriteJson(
|
|
22
|
+
JsonWriter writer,
|
|
23
|
+
Vector3 value,
|
|
24
|
+
JsonSerializer serializer
|
|
25
|
+
) {
|
|
26
|
+
var obj = new JArray { value.x, value.y, value.z };
|
|
27
|
+
obj.WriteTo(writer);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public override Vector3 ReadJson(
|
|
31
|
+
JsonReader reader,
|
|
32
|
+
Type type,
|
|
33
|
+
Vector3 existing,
|
|
34
|
+
bool hasExisting,
|
|
35
|
+
JsonSerializer s
|
|
36
|
+
) {
|
|
37
|
+
var arr = JArray.Load(reader);
|
|
38
|
+
return new Vector3(
|
|
39
|
+
x: (float)arr[0],
|
|
40
|
+
y: (float)arr[1],
|
|
41
|
+
z: (float)arr[2]
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Muna
|
|
3
|
+
* Copyright © 2025 NatML Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#nullable enable
|
|
7
|
+
|
|
8
|
+
namespace Muna.Converters {
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using UnityEngine;
|
|
12
|
+
using Newtonsoft.Json;
|
|
13
|
+
using Newtonsoft.Json.Linq;
|
|
14
|
+
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// Convert an array field to a `Vector4`.
|
|
17
|
+
/// The array MUST contain exactly four numbers.
|
|
18
|
+
/// </summary>
|
|
19
|
+
public sealed class ArrayToVector4Converter : JsonConverter<Vector4> {
|
|
20
|
+
|
|
21
|
+
public override void WriteJson(
|
|
22
|
+
JsonWriter writer,
|
|
23
|
+
Vector4 value,
|
|
24
|
+
JsonSerializer serializer
|
|
25
|
+
) {
|
|
26
|
+
var obj = new JArray { value.x, value.y, value.z, value.w };
|
|
27
|
+
obj.WriteTo(writer);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public override Vector4 ReadJson(
|
|
31
|
+
JsonReader reader,
|
|
32
|
+
Type type,
|
|
33
|
+
Vector4 existing,
|
|
34
|
+
bool hasExisting,
|
|
35
|
+
JsonSerializer s
|
|
36
|
+
) {
|
|
37
|
+
var arr = JArray.Load(reader);
|
|
38
|
+
return new Vector4(
|
|
39
|
+
x: (float)arr[0],
|
|
40
|
+
y: (float)arr[1],
|
|
41
|
+
z: (float)arr[2],
|
|
42
|
+
w: (float)arr[3]
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|