-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathmsNetworkAPI.cs
More file actions
320 lines (235 loc) · 9.9 KB
/
msNetworkAPI.cs
File metadata and controls
320 lines (235 loc) · 9.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Assertions;
#if AT_USE_SPLINES
using Unity.Mathematics;
#endif
namespace Unity.MeshSync {
#if UNITY_STANDALONE || UNITY_EDITOR
#region Server
internal struct ServerSettings {
public struct Flags {
public BitFlags flags;
}
public int maxQueue;
public int maxThreads;
public ushort port;
public Flags flags; // reserved
public uint meshSplitUnit;
public uint meshMaxBoneInfluence; // 4 or 255 (variable)
public static ServerSettings defaultValue {
get {
MeshSyncProjectSettings settings = MeshSyncProjectSettings.GetOrCreateInstance();
ServerSettings ret = new ServerSettings {
maxQueue = 512,
maxThreads = 8,
port = settings.GetDefaultServerPort(),
meshSplitUnit = Lib.maxVerticesPerMesh,
meshMaxBoneInfluence = Lib.maxBoneInfluence
};
return ret;
}
}
}
internal struct Server {
#region internal
public IntPtr self;
[DllImport(Lib.name)]
private static extern Server msServerIsStarted(int port);
[DllImport(Lib.name)]
private static extern Server msServerStart(ref ServerSettings settings);
[DllImport(Lib.name)]
private static extern void msServerStop(IntPtr self);
[DllImport(Lib.name)]
private static extern void msServerAbort(IntPtr self);
[DllImport(Lib.name)]
private static extern void msServerSetZUpCorrectionMode(IntPtr self, ZUpCorrectionMode v);
[DllImport(Lib.name)]
private static extern int msServerGetNumMessages(IntPtr self);
[DllImport(Lib.name)]
private static extern int msServerProcessMessages(IntPtr self, MessageHandler handler);
[DllImport(Lib.name)]
private static extern void msServerBeginServe(IntPtr self);
[DllImport(Lib.name)]
private static extern void msServerEndServe(IntPtr self);
[DllImport(Lib.name)]
private static extern void msServerServeTransform(IntPtr self, TransformData data);
[DllImport(Lib.name)]
private static extern void msServerServeCamera(IntPtr self, CameraData data);
[DllImport(Lib.name)]
private static extern void msServerServeLight(IntPtr self, LightData data);
[DllImport(Lib.name)]
private static extern void msServerServeMesh(IntPtr self, MeshData data);
[DllImport(Lib.name)]
private static extern void msServerServeTexture(IntPtr self, TextureData data);
[DllImport(Lib.name)]
private static extern void msServerServeMaterial(IntPtr self, MaterialData data);
[DllImport(Lib.name)]
private static extern void msServerAllowPublicAccess(IntPtr self, bool access);
[DllImport(Lib.name)]
private static extern bool msServerIsPublicAccessAllowed(IntPtr self);
[DllImport(Lib.name)]
private static extern void msServerSetFileRootPath(IntPtr self, string path);
[DllImport(Lib.name)]
private static extern void msServerSetScreenshotFilePath(IntPtr self, string path);
[DllImport(Lib.name)]
private static extern void msServerNotifyPoll(IntPtr self, PollMessage.PollType t);
[DllImport(Lib.name)]
private static extern void msServerSendPropertyInt(IntPtr self, int sourceType, string name, string path, string modifierName, string propertyName,
int newValue);
[DllImport(Lib.name)]
private static extern void msServerSendPropertyFloat(IntPtr self, int sourceType, string name, string path, string modifierName, string propertyName,
float newValue);
[DllImport(Lib.name)]
private static extern void msServerSendPropertyIntArray(IntPtr self, int sourceType, string name, string path, string modifierName, string propertyName,
int[] newValue, int arrayLength);
[DllImport(Lib.name)]
private static extern void msServerSendPropertyFloatArray(IntPtr self, int sourceType, string name, string path, string modifierName, string propertyName,
float[] newValue, int arrayLength);
[DllImport(Lib.name)]
private static extern void msServerSendPropertyString(IntPtr self, int sourceType, string name, string path, string modifierName, string propertyName,
string newValue, int length);
#if AT_USE_SPLINES
[DllImport(Lib.name)]
static extern void msServerSendTransform(IntPtr self, string path, float3 position, float3 scale, float3 rotation);
[DllImport(Lib.name)]
static extern void msServerSendCurve(IntPtr self, string path, int splineIndex, int knotCount, bool closed, float3[] cos, float3[] handlesLeft, float3[] handlesRight);
#endif
#if AT_USE_PROBUILDER
[DllImport(Lib.name)]
private static extern void msServerSendMesh(IntPtr self, MeshData data);
#endif
[DllImport(Lib.name)]
private static extern void msServerRequestFullSync(IntPtr self);
[DllImport(Lib.name)]
private static extern void msServerRequestUserScriptCallback(IntPtr self);
[DllImport(Lib.name)]
private static extern void msServerInitiatedResponseReady(IntPtr self);
[DllImport(Lib.name)]
private static extern bool msServerIsDCCLiveEditReady(IntPtr self);
[DllImport(Lib.name)]
private static extern void msServerNotifyEditorCommand(IntPtr self, string reply, int messageId, int sessionId);
#endregion
public delegate void MessageHandler(NetworkMessageType type, IntPtr data);
public static implicit operator bool(Server v) {
return v.self != IntPtr.Zero;
}
internal static bool IsStarted(int port) {
return msServerIsStarted(port);
}
public static bool Start(ref ServerSettings settings, out Server server) {
server = msServerStart(ref settings);
return server;
}
public void Stop() {
msServerStop(self);
}
public void Abort() {
msServerAbort(self);
}
internal void SetZUpCorrectionMode(ZUpCorrectionMode mode) {
msServerSetZUpCorrectionMode(self, mode);
}
public int numMessages {
get { return msServerGetNumMessages(self); }
}
public void ProcessMessages(MessageHandler handler) {
msServerProcessMessages(self, handler);
}
public string fileRootPath {
set { msServerSetFileRootPath(self, value); }
}
public void AllowPublicAccess(bool access) {
Assert.IsFalse(self == IntPtr.Zero);
msServerAllowPublicAccess(self, access);
}
public bool IsPublicAccessAllowed() {
Assert.IsFalse(self == IntPtr.Zero);
return msServerIsPublicAccessAllowed(self);
}
public string screenshotPath {
set { msServerSetScreenshotFilePath(self, value); }
}
#if AT_USE_SPLINES
public void SendCurve(string path, int splineIndex, int knotCount, bool closed, float3[] cos, float3[] handlesLeft, float3[] handlesRight)
{
msServerSendCurve(self, path, splineIndex, knotCount, closed, cos, handlesLeft, handlesRight);
}
#endif
#if AT_USE_PROBUILDER
public void SendMesh(MeshData data) {
msServerSendMesh(self, data);
}
#endif
public void SendProperty(PropertyInfoDataWrapper prop) {
switch (prop.type) {
case PropertyInfoDataType.Int:
msServerSendPropertyInt(self, (int)prop.sourceType, prop.name, prop.path, prop.modifierName, prop.propertyName, prop.GetValue<int>());
break;
case PropertyInfoDataType.Float:
msServerSendPropertyFloat(self, (int)prop.sourceType, prop.name, prop.path, prop.modifierName, prop.propertyName, prop.GetValue<float>());
break;
case PropertyInfoDataType.IntArray:
msServerSendPropertyIntArray(self, (int)prop.sourceType, prop.name, prop.path, prop.modifierName, prop.propertyName, prop.GetValue<int[]>(),
prop.arrayLength);
break;
case PropertyInfoDataType.FloatArray:
msServerSendPropertyFloatArray(self, (int)prop.sourceType, prop.name, prop.path, prop.modifierName, prop.propertyName, prop.GetValue<float[]>(),
prop.arrayLength);
break;
case PropertyInfoDataType.String:
string s = prop.GetValue<string>();
msServerSendPropertyString(self, (int)prop.sourceType, prop.name, prop.path, prop.modifierName, prop.propertyName, s, s.Length);
break;
default:
throw new NotImplementedException($"Type {prop.type} not implemented");
}
}
public void RequestClientSync() {
msServerRequestFullSync(self);
}
public void RequestUserScriptCallback() {
msServerRequestUserScriptCallback(self);
}
public void MarkServerInitiatedResponseReady() {
msServerInitiatedResponseReady(self);
}
public bool IsDCCLiveEditReady() {
return msServerIsDCCLiveEditReady(self);
}
public void BeginServe() {
msServerBeginServe(self);
}
public void EndServe() {
msServerEndServe(self);
}
public void ServeTransform(TransformData data) {
msServerServeTransform(self, data);
}
public void ServeCamera(CameraData data) {
msServerServeCamera(self, data);
}
public void ServeLight(LightData data) {
msServerServeLight(self, data);
}
public void ServeMesh(MeshData data) {
msServerServeMesh(self, data);
}
public void ServeTexture(TextureData data) {
msServerServeTexture(self, data);
}
public void ServeMaterial(MaterialData data) {
msServerServeMaterial(self, data);
}
public void NotifyPoll(PollMessage.PollType t) {
msServerNotifyPoll(self, t);
}
public void NotifyEditorCommand(string reply, EditorCommandMessage message) {
msServerNotifyEditorCommand(self, reply, message.id, message.session);
}
}
#endregion
#endif // UNITY_STANDALONE || UNITY_EDITOR
} //end namespace