This repository has no description
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 MizunagiKB <mizukb@live.jp>
3using System;
4using Godot;
5using Godot.NativeInterop;
6
7
8#pragma warning disable CA1050
9
10
11public partial class GDCubismUserModelCS : GodotObject
12{
13 public enum Moc3FileFormatVersionEnum : long
14 {
15 /// <summary>Unknown or failed to load.</summary>
16 CSM_MOC_VERSION_UNKNOWN = 0,
17 /// <summary>moc3 file version 3.0.00 - 3.2.07</summary>
18 CSM_MOC_VERSION_30 = 1,
19 /// <summary>moc3 file version 3.3.00 - 3.3.03</summary>
20 CSM_MOC_VERSION_33 = 2,
21 /// <summary>moc3 file version 4.0.00 - 4.1.05</summary>
22 CSM_MOC_VERSION_40 = 3,
23 /// <summary>moc3 file version 4.2.00 - 4.2.02</summary>
24 CSM_MOC_VERSION_42 = 4,
25 /// <summary>moc3 file version 5.0.00 -</summary>
26 CSM_MOC_VERSION_50 = 5
27 }
28
29 public enum PriorityEnum : long
30 {
31 PriorityNone = 0,
32 PriorityIdle = 1,
33 PriorityNormal = 2,
34 PriorityForce = 3
35 }
36
37 public enum ParameterModeEnum : long
38 {
39 FullParameter = 0,
40 NoneParameter = 1
41 }
42
43 public enum MotionProcessCallbackEnum : long
44 {
45 /// <summary>
46 /// The animation update process is performed within the <c>_physics_process</c> function.
47 /// This is used when you want to interact with physical simulations.
48 /// </summary>
49 Physics = 0,
50 /// <summary>
51 /// The animation update process is performed within the _process function.
52 /// </summary>
53 Idle = 1,
54 /// <summary>
55 /// No animation update process is performed. Use the <c>advance</c> function to process the animation.
56 /// </summary>
57 Manual = 2
58 }
59
60 private static readonly StringName NativeName = "GDCubismUserModel";
61 public static readonly StringName MotionEventName = "motion_event";
62 public static readonly StringName MotionFinishedName = "motion_finished";
63
64 protected Node2D InternalObject = null;
65
66 public GDCubismUserModelCS()
67 {
68 this.InternalObject = (Node2D)Godot.ClassDB.Instantiate(NativeName);
69 }
70
71 public GDCubismUserModelCS(Node2D o)
72 {
73 this.InternalObject = o;
74 }
75
76 public Node2D GetInternalObject()
77 {
78 return this.InternalObject;
79 }
80
81 public void Attach(Node2D o)
82 {
83 this.InternalObject = o;
84 }
85
86 public Node2D Detach()
87 {
88 Node2D o = this.InternalObject;
89 this.InternalObject = null;
90 return o;
91 }
92
93 // ------------------------------------------------------------ Property(s)
94
95 /// <value>
96 /// Property <c>Assets</c>
97 /// <br />
98 /// You can load a Live2D model by specifying a file with the *.model3.json extension.
99 /// The file is loaded immediately upon specification.
100 /// <br />
101 /// if you want to switch the Live2D model, you can do so simply by specifying a new file.
102 /// </value>
103 public String Assets
104 {
105 set { this.InternalObject.Call("set_assets", value); }
106 get { return (String)this.InternalObject.Call("get_assets"); }
107 }
108
109 /// <value>
110 /// Property <c>LoadExpressions</c>
111 /// <br />
112 /// If set to <c>false</c>, it will not load _Expressions_ when loading the Live2D Model.
113 /// </value>
114 public bool LoadExpressions
115 {
116 set { this.InternalObject.Call("set_load_expressions", value); }
117 get { return (bool)this.InternalObject.Call("get_load_expressions"); }
118 }
119
120 /// <value>
121 /// Property <c>LoadMotions</c>
122 /// <br />
123 /// If set to <c>false</c>, it will not load _Motions_ when loading the Live2D Model.
124 /// </value>
125 public bool LoadMotions
126 {
127 set { this.InternalObject.Call("set_load_motions", value); }
128 get { return (bool)this.InternalObject.Call("get_load_motions"); }
129 }
130
131 /// <value>
132 /// Property <c>MaskViewportSize</c>
133 /// <br />
134 /// Specify the maximum resolution for any individual mask required for the Live2D model.
135 /// <br />
136 /// If set to 0, size of the mask will be relative to the source pixel resolution of the model's canvas.
137 /// <br />
138 /// Mask resolution is also dynamically resized relative to the model's scale within its viewport.
139 /// <br />
140 /// <br />
141 /// Reducing the resolution can help conserve GPU memory, however reducing resolution too far can cause visual issues where masks are applied.
142 /// <br />
143 /// For many, it's best to leave this at default and rely solely on the automatic scaling.
144 /// </value>
145 public int MaskViewportSize
146 {
147 set { this.InternalObject.Call("set_mask_viewport_size", value); }
148 get { return (int)this.InternalObject.Call("get_mask_viewport_size"); }
149 }
150
151 /// <value>
152 /// Property <c>ParameterMode</c>
153 /// <br />
154 /// Specifies the control method for the currently held Live2D model.
155 /// </value>
156 public ParameterModeEnum ParameterMode
157 {
158 set { this.InternalObject.Call("set_parameter_mode", (int)value); }
159 get
160 {
161 int value = (int)this.InternalObject.Call("get_parameter_mode");
162 return (ParameterModeEnum)Enum.ToObject(typeof(ParameterModeEnum), value);
163 }
164 }
165
166 /// <value>
167 /// Property <c>PhysicsEvaluate</c>
168 /// <br />
169 /// Setting this parameter to `false` disables physical calculations.
170 /// </value>
171 public bool PhysicsEvaluate
172 {
173 set { this.InternalObject.Call("set_physics_evaluate", value); }
174 get { return (bool)this.InternalObject.Call("get_physics_evaluate"); }
175 }
176
177 /// <value>
178 /// Property <c>PlaybackProcessMode</c>
179 /// <br />
180 /// Specifies the playback method for the currently held Live2D model.
181 /// </value>
182 public MotionProcessCallbackEnum PlaybackProcessMode
183 {
184 set { this.InternalObject.Call("set_process_callback", (int)value); }
185 get
186 {
187 int value = (int)this.InternalObject.Call("get_process_callback");
188 return (MotionProcessCallbackEnum)Enum.ToObject(typeof(MotionProcessCallbackEnum), value);
189 }
190 }
191
192 /// <value>
193 /// Property <c>PoseUpdate</c>
194 /// <br />
195 /// Setting this parameter to `false` disables transparency calculations between drawing parts specified in the pose group.
196 /// If you want to manually handle all transparency calculations, set this parameter to `false`.
197 /// </value>
198 public bool PoseUpdate
199 {
200 set { this.InternalObject.Call("set_pose_update", value); }
201 get { return (bool)this.InternalObject.Call("get_pose_update"); }
202 }
203
204 public Shader ShaderAdd
205 {
206 set { this.InternalObject.Call("set_shader_add", (Shader)value); }
207 get { return (Shader)this.InternalObject.Call("get_shader_add"); }
208 }
209
210 public Shader ShaderMix
211 {
212 set { this.InternalObject.Call("set_shader_mix", (Shader)value); }
213 get { return (Shader)this.InternalObject.Call("get_shader_mix"); }
214 }
215
216 public Shader ShaderMul
217 {
218 set { this.InternalObject.Call("set_shader_mul", (Shader)value); }
219 get { return (Shader)this.InternalObject.Call("get_shader_mul"); }
220 }
221
222 public Shader ShaderMask
223 {
224 set { this.InternalObject.Call("set_shader_mask", (Shader)value); }
225 get { return (Shader)this.InternalObject.Call("get_shader_mask"); }
226 }
227
228 public Shader ShaderMaskAdd
229 {
230 set { this.InternalObject.Call("set_shader_mask_add", (Shader)value); }
231 get { return (Shader)this.InternalObject.Call("get_shader_mask_add"); }
232 }
233
234 public Shader ShaderMaskAddInv
235 {
236 set { this.InternalObject.Call("set_shader_mask_add_inv", (Shader)value); }
237 get { return (Shader)this.InternalObject.Call("get_shader_mask_add_inv"); }
238 }
239
240 public Shader ShaderMaskMix
241 {
242 set { this.InternalObject.Call("set_shader_mask_mix", (Shader)value); }
243 get { return (Shader)this.InternalObject.Call("get_shader_mask_mix"); }
244 }
245
246 public Shader ShaderMaskMixInv
247 {
248 set { this.InternalObject.Call("set_shader_mask_mix_inv", (Shader)value); }
249 get { return (Shader)this.InternalObject.Call("get_shader_mask_mix_inv"); }
250 }
251
252 public Shader ShaderMaskMul
253 {
254 set { this.InternalObject.Call("set_shader_mask_mul", (Shader)value); }
255 get { return (Shader)this.InternalObject.Call("get_shader_mask_mul"); }
256 }
257
258 public Shader ShaderMaskMulInv
259 {
260 set { this.InternalObject.Call("set_shader_mask_mul_inv", (Shader)value); }
261 get { return (Shader)this.InternalObject.Call("get_shader_mask_mul_inv"); }
262 }
263
264 /// <value>
265 /// Property <c>SpeedScale</c>
266 /// <br />
267 /// Specifies the playback speed for the currently held Live2D model.
268 /// </value>
269 public float SpeedScale
270 {
271 set { this.InternalObject.Call("set_speed_scale", (float)value); }
272 get { return (float)this.InternalObject.Call("get_speed_scale"); }
273 }
274
275 // -------------------------------------------------------------- Method(s)
276
277 /// <summary>
278 /// Advances the animation by the specified <paramref name="delta">delta</paramref> time (in seconds).
279 /// Please specify a value of 0.0 or more for delta.
280 /// </summary>
281 /// <param name="delta">The time to progress the animation.</param>
282 public void Advance(double delta)
283 {
284 this.InternalObject.Call("advance", delta);
285 }
286
287 /// <summary>
288 /// Returns the latest file version that GDCubismUserModel can load.
289 /// </summary>
290 /// <returns>Moc3FileFormatVersionEnum</returns>
291 public Moc3FileFormatVersionEnum CsmGetLatestMocVersion()
292 {
293 long value = (long)this.InternalObject.Call("csm_get_latest_moc_version");
294 return (Moc3FileFormatVersionEnum)Enum.ToObject(typeof(Moc3FileFormatVersionEnum), value);
295 }
296
297 /// <summary>
298 /// Returns the version of the loaded moc3 file.
299 /// </summary>
300 /// <returns>Moc3FileFormatVersionEnum</returns>
301 public Moc3FileFormatVersionEnum CsmGetMocVersion()
302 {
303 long value = (long)this.InternalObject.Call("csm_get_moc_version");
304 return (Moc3FileFormatVersionEnum)Enum.ToObject(typeof(Moc3FileFormatVersionEnum), value);
305 }
306
307 /// <summary>
308 /// Returns the version number of the Cubism Native SDK Core used by GDCubism in <c>Dictionary</c> format
309 /// <list type="bullet">
310 /// <item>
311 /// <term>version</term>
312 /// <description>int: The value returned by the csmVersion function is stored as is.</description>
313 /// </item>
314 /// <item>
315 /// <term>major</term>
316 /// <description>int: Only the major version is extracted from the version and stored.</description>
317 /// </item>
318 /// <item>
319 /// <term>minor</term>
320 /// <description>int: Only the minor version is extracted from the version and stored.</description>
321 /// </item>
322 /// <item>
323 /// <term>patch</term>
324 /// <description>int: Only the patch number is extracted from the version and stored.</description>
325 /// </item>
326 /// </list>
327 /// </summary>
328 /// <returns>Godot.Collections.Dictionary</returns>
329 public Godot.Collections.Dictionary CsmGetVersion()
330 {
331 return (Godot.Collections.Dictionary)this.InternalObject.Call("csm_get_version");
332 }
333
334 /// <summary>
335 /// Returns the following information in <c>Dictionary</c> format.
336 /// <list type="bullet">
337 /// <item>
338 /// <term>size_in_pixels</term>
339 /// <description>Vector2: Returns the width and height of the canvas of the loaded Live2D model in pixels.</description>
340 /// </item>
341 /// <item>
342 /// <term>origin_in_pixels</term>
343 /// <description>Vector2: Returns the center position of the loaded Live2D model in pixels.</description>
344 /// </item>
345 /// <item>
346 /// <term>ixels_per_unit</term>
347 /// <description>float: Returns the pixelsPerUnit of the loaded Live2D model.</description>
348 /// </item>
349 /// </list>
350 /// </summary>
351 /// <returns>Godot.Collections.Dictionary</returns>
352 public Godot.Collections.Dictionary GetCanvasInfo()
353 {
354 return (Godot.Collections.Dictionary)this.InternalObject.Call("get_canvas_info");
355 }
356
357 /// <summary>
358 /// Returns the information of the <c>Motion</c> currently being played.
359 /// </summary>
360 /// <returns>Godot.Collections.Array</returns>
361 public Godot.Collections.Array GetCubismMotionQueueEntries()
362 {
363 return (Godot.Collections.Array)this.InternalObject.Call("get_cubism_motion_queue_entries");
364 }
365
366 /// <summary>
367 /// Returns a list of Expressions from the currently held Live2D model.
368 /// The information obtained can be used as an argument for the <c>start_expression</c> function.
369 /// </summary>
370 /// <returns>Godot.Collections.Array</returns>
371 public Godot.Collections.Array<String> GetExpressions()
372 {
373 return (Godot.Collections.Array<String>)this.InternalObject.Call("get_expressions");
374 }
375
376 public Godot.Collections.Array GetHitAreas()
377 {
378 return (Godot.Collections.Array)this.InternalObject.Call("get_hit_areas");
379 }
380
381 /// <summary>
382 /// Retrieves the <c>ArrayMesh</c> information of the <c>MeshInstance</c> used in the current Motion state.
383 /// The keys held by this <c>Dictionary</c> are identical to the names of the <c>MeshInstance</c> generated by <c>GDCubismUserModel</c>.
384 /// <br />
385 /// The information that can be obtained is the <c>ArrayMesh</c> used internally.
386 /// <br />
387 /// CAUTION<br />
388 /// get_meshes is an experimental function added in v0.1. Please be aware that the specifications may change or be removed in the future.
389 /// </summary>
390 /// <returns>Godot.Collections.Dictionary</returns>
391 public Godot.Collections.Dictionary GetMeshes()
392 {
393 return (Godot.Collections.Dictionary)this.InternalObject.Call("get_meshes");
394 }
395
396 /// <summary>
397 /// Returns a list of <c>Motions</c> from the currently held Live2D model.
398 /// The returned <c>Dictionary</c> is the <c>group</c> and the number of motions it contains.
399 /// </summary>
400 /// <returns>Godot.Collections.Dictionary</returns>
401 public Godot.Collections.Dictionary<String, int> GetMotions()
402 {
403 return (Godot.Collections.Dictionary<String, int>)this.InternalObject.Call("get_motions");
404 }
405
406 /// <summary>
407 /// Retrieves the controller class for operating the currently held Live2D model.
408 /// </summary>
409 /// <returns>Godot.Collections.Array</returns>
410 public Godot.Collections.Array<GDCubismParameterCS> GetParameters()
411 {
412 Godot.Collections.Array<GodotObject> ary = (Godot.Collections.Array<GodotObject>)this.InternalObject.Call("get_parameters");
413 Godot.Collections.Array<GDCubismParameterCS> ary_result = new();
414 foreach (GodotObject o in ary)
415 {
416 ary_result.Add(new GDCubismParameterCS(o));
417 }
418
419 return ary_result;
420 }
421
422 /// <summary>
423 /// Retrieves the controller class for operating the transparency of the parts of the currently held Live2D model.
424 /// </summary>
425 /// <returns>Godot.Collections.Array</returns>
426 public Godot.Collections.Array<GDCubismPartOpacityCS> GetPartOpacities()
427 {
428 Godot.Collections.Array<GodotObject> ary = (Godot.Collections.Array<GodotObject>)this.InternalObject.Call("get_part_opacities");
429 Godot.Collections.Array<GDCubismPartOpacityCS> ary_result = new();
430 foreach (GodotObject o in ary)
431 {
432 ary_result.Add(new GDCubismPartOpacityCS(o));
433 }
434
435 return ary_result;
436 }
437
438 /// <summary>
439 /// Plays the specified <paramref name="expression_id">expression_id</paramref>.
440 /// </summary>
441 /// <param name="expression_id"></param>
442 public void StartExpression(String expression_id)
443 {
444 this.InternalObject.Call("start_expression", expression_id);
445 }
446
447 /// <summary>
448 /// Plays the specified <paramref name="grp_name">group</paramref> and <paramref name="no">no</paramref>.
449 /// </summary>
450 /// <param name="grp_name"></param>
451 /// <param name="no"></param>
452 /// <param name="priority"></param>
453 public void StartMotion(String grp_name, int no, PriorityEnum priority)
454 {
455 this.InternalObject.Call("start_motion", grp_name, no, (int)priority);
456 }
457
458 /// <summary>
459 /// Plays the specified <paramref name="grp_name">group</paramref> and <paramref name="no">no</paramref>.
460 /// If you want to play it repeatedly, specify it.
461 /// If the loop argument is <c>false</c>, it will behave the same as the <c>start_motion</c> function.
462 /// </summary>
463 /// <param name="grp_name"></param>
464 /// <param name="no"></param>
465 /// <param name="priority"></param>
466 /// <param name="loop"></param>
467 /// <param name="loop_in_fade"></param>
468 public void StartMotionLoop(String grp_name, int no, PriorityEnum priority, bool loop, bool loop_in_fade)
469 {
470 this.InternalObject.Call("start_motion_loop", grp_name, no, (int)priority, loop, loop_in_fade);
471 }
472
473 /// <summary>
474 /// It stops the currently playing <c>Expression</c>.
475 /// </summary>
476 public void StopExpression()
477 {
478 this.InternalObject.Call("stop_expression");
479 }
480
481 /// <summary>
482 /// It stops the currently playing <c>Motion</c>.
483 /// </summary>
484 public void StopMotion()
485 {
486 this.InternalObject.Call("stop_motion");
487 }
488
489 // -------------------------------------------------------------- Signal(s)
490
491 public delegate void MotionEventEventHandler(string value);
492
493 private static void MotionEventTrampoline(object delegateObj, NativeVariantPtrArgs args, out godot_variant ret)
494 {
495 ((MotionEventEventHandler)delegateObj)(VariantUtils.ConvertTo<string>(args[0]));
496 ret = default;
497 }
498
499 public unsafe event MotionEventEventHandler MotionEvent
500 {
501 add => this.InternalObject.Connect(MotionEventName, Callable.CreateWithUnsafeTrampoline(value, &MotionEventTrampoline));
502 remove => this.InternalObject.Disconnect(MotionEventName, Callable.CreateWithUnsafeTrampoline(value, &MotionEventTrampoline));
503 }
504
505 public event Action MotionFinished
506 {
507 add => this.InternalObject.Connect(MotionFinishedName, Callable.From(value));
508 remove => this.InternalObject.Disconnect(MotionFinishedName, Callable.From(value));
509 }
510}