/
CubismRenderer.cs
1110 lines (862 loc) · 28.4 KB
/
CubismRenderer.cs
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/
using Live2D.Cubism.Core;
using Live2D.Cubism.Rendering.Masking;
using System;
using UnityEngine;
using UnityEngine.Rendering;
namespace Live2D.Cubism.Rendering
{
/// <summary>
/// Wrapper for drawing <see cref="CubismDrawable"/>s.
/// </summary>
[ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public sealed class CubismRenderer : MonoBehaviour
{
/// <summary>
/// <see cref="LocalSortingOrder"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private int _localSortingOrder;
/// <summary>
/// Local sorting order.
/// </summary>
public int LocalSortingOrder
{
get
{
return _localSortingOrder;
}
set
{
// Return early if same value given.
if (value == _localSortingOrder)
{
return;
}
// Store value.
_localSortingOrder = value;
// Apply it.
ApplySorting();
}
}
/// <summary>
/// <see cref="Color"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private Color _color = Color.white;
/// <summary>
/// Color.
/// </summary>
public Color Color
{
get { return _color; }
set
{
// Return early if same value given.
if (value == _color)
{
return;
}
// Store value.
_color = value;
// Apply color.
ApplyVertexColors();
}
}
/// <summary>
/// <see cref="OverwriteFlagForDrawableMultiplyColors"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private bool _isOverwrittenDrawableMultiplyColors;
/// <summary>
/// Whether to overwrite with multiply color from the model.
/// </summary>
public bool OverwriteFlagForDrawableMultiplyColors
{
get { return _isOverwrittenDrawableMultiplyColors; }
set { _isOverwrittenDrawableMultiplyColors = value; }
}
/// <summary>
/// Last <see cref="OverwriteFlagForDrawableMultiplyColors"/>.
/// </summary>
public bool LastIsUseUserMultiplyColor { get; set; }
/// <summary>
/// <see cref="OverwriteFlagForDrawableScreenColors"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private bool _isOverwrittenDrawableScreenColors;
/// <summary>
/// Whether to overwrite with screen color from the model.
/// </summary>
public bool OverwriteFlagForDrawableScreenColors
{
get { return _isOverwrittenDrawableScreenColors; }
set { _isOverwrittenDrawableScreenColors = value; }
}
/// <summary>
/// Last <see cref="OverwriteFlagForDrawableScreenColors"/>.
/// </summary>
public bool LastIsUseUserScreenColors { get; set; }
/// <summary>
/// <see cref="MultiplyColor"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private Color _multiplyColor = Color.white;
/// <summary>
/// Drawable Multiply Color.
/// </summary>
public Color MultiplyColor
{
get
{
if (OverwriteFlagForDrawableMultiplyColors || RenderController.OverwriteFlagForModelMultiplyColors)
{
return _multiplyColor;
}
return Drawable.MultiplyColor;
}
set
{
// Return early if same value given.
if (value == _multiplyColor)
{
return;
}
// Store value.
_multiplyColor = (value != null)
? value
: Color.white;
}
}
/// <summary>
/// Last Drawable Multiply Color.
/// </summary>
public Color LastMultiplyColor { get; set; }
/// <summary>
/// <see cref="ScreenColor"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private Color _screenColor = Color.clear;
/// <summary>
/// Drawable Screen Color.
/// </summary>
public Color ScreenColor
{
get
{
if (OverwriteFlagForDrawableScreenColors || RenderController.OverwriteFlagForModelScreenColors)
{
return _screenColor;
}
return Drawable.ScreenColor;
}
set
{
// Return early if same value given.
if (value == _screenColor)
{
return;
}
// Store value.
_screenColor = (value != null)
? value
: Color.black;
}
}
/// <summary>
/// Last Drawable Screen Color.
/// </summary>
public Color LastScreenColor { get; set; }
/// <summary>
/// <see cref="UnityEngine.Material"/>.
/// </summary>
public Material Material
{
get
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
return MeshRenderer.sharedMaterial;
}
#endif
return MeshRenderer.material;
}
set
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
MeshRenderer.sharedMaterial = value;
return;
}
#endif
MeshRenderer.material = value;
}
}
/// <summary>
/// <see cref="MainTexture"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private Texture2D _mainTexture;
/// <summary>
/// <see cref="MeshRenderer"/>'s main texture.
/// </summary>
public Texture2D MainTexture
{
get { return _mainTexture; }
set
{
// Return early if same value given and main texture is valid.
if (value == _mainTexture && _mainTexture != null)
{
return;
}
// Store value.
_mainTexture = (value != null)
? value
: Texture2D.whiteTexture;
// Apply it.
ApplyMainTexture();
}
}
/// <summary>
/// Meshes.
/// </summary>
/// <remarks>
/// Double buffering dynamic meshes increases performance on mobile, so we double-buffer them here.
/// </remarks>
private Mesh[] Meshes { get; set; }
/// <summary>
/// Index of front buffer mesh.
/// </summary>
private int FrontMesh { get; set; }
/// <summary>
/// Index of back buffer mesh..
/// </summary>
private int BackMesh { get; set; }
/// <summary>
/// <see cref="UnityEngine.Mesh"/>.
/// </summary>
public Mesh Mesh
{
get { return Meshes[FrontMesh]; }
}
/// <summary>
/// <see cref="MeshFilter"/> backing field.
/// </summary>
[NonSerialized]
private MeshFilter _meshFilter;
/// <summary>
/// <see cref="UnityEngine.MeshFilter"/>.
/// </summary>
public MeshFilter MeshFilter
{
get
{
return _meshFilter;
}
}
/// <summary>
/// <see cref="MeshRenderer"/> backing field.
/// </summary>
[NonSerialized]
private MeshRenderer _meshRenderer;
/// <summary>
/// <see cref="UnityEngine.MeshRenderer"/>.
/// </summary>
public MeshRenderer MeshRenderer
{
get
{
TryInitializeMeshRenderer();
return _meshRenderer;
}
}
/// <summary>
/// <see cref="CubismDrawable"/>.
/// </summary>
private CubismDrawable Drawable { get; set; }
/// <summary>
/// <see cref="CubismRenderController"/>.
/// </summary>
private CubismRenderController RenderController { get; set; }
#region Interface For CubismRenderController
/// <summary>
/// <see cref="SortingMode"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private CubismSortingMode _sortingMode;
/// <summary>
/// Sorting mode.
/// </summary>
private CubismSortingMode SortingMode
{
get { return _sortingMode; }
set { _sortingMode = value; }
}
/// <summary>
/// <see cref="SortingOrder"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private int _sortingOrder;
/// <summary>
/// Sorting mode.
/// </summary>
private int SortingOrder
{
get { return _sortingOrder; }
set { _sortingOrder = value; }
}
/// <summary>
/// <see cref="RenderOrder"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private int _renderOrder;
/// <summary>
/// Sorting mode.
/// </summary>
private int RenderOrder
{
get { return _renderOrder; }
set { _renderOrder = value; }
}
/// <summary>
/// <see cref="DepthOffset"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private float _depthOffset = 0.00001f;
/// <summary>
/// Offset to apply in case of depth sorting.
/// </summary>
private float DepthOffset
{
get { return _depthOffset; }
set { _depthOffset = value; }
}
/// <summary>
/// <see cref="Opacity"/> backing field.
/// </summary>
[SerializeField, HideInInspector]
private float _opacity;
/// <summary>
/// Opacity.
/// </summary>
private float Opacity
{
get { return _opacity; }
set { _opacity = value; }
}
/// <summary>
/// Buffer for vertex colors.
/// </summary>
private Color[] VertexColors { get; set; }
/// <summary>
/// Allows tracking of what vertex data was updated last swap.
/// </summary>
private SwapInfo LastSwap { get; set; }
/// <summary>
/// Allows tracking of what vertex data will be swapped.
/// </summary>
private SwapInfo ThisSwap { get; set; }
/// <summary>
/// Swaps mesh buffers.
/// </summary>
/// <remarks>
/// Make sure to manually call this method in case you changed the <see cref="Color"/>.
/// </remarks>
public void SwapMeshes()
{
// Perform internal swap.
BackMesh = FrontMesh;
FrontMesh = (FrontMesh == 0) ? 1 : 0;
var mesh = Meshes[FrontMesh];
// Update colors.
Meshes[BackMesh].colors = VertexColors;
// Update swap info.
LastSwap = ThisSwap;
ResetSwapInfoFlags();
// Apply swap.
#if UNITY_EDITOR
if (!Application.isPlaying)
{
MeshFilter.mesh = mesh;
return;
}
#endif
MeshFilter.mesh = mesh;
}
/// <summary>
/// Updates visibility.
/// </summary>
public void UpdateVisibility()
{
if (LastSwap.DidBecomeVisible)
{
MeshRenderer.enabled = true;
}
else if (LastSwap.DidBecomeInvisible)
{
MeshRenderer.enabled = false;
}
ResetVisibilityFlags();
}
/// <summary>
/// Updates render order.
/// </summary>
public void UpdateRenderOrder()
{
if (LastSwap.NewRenderOrder)
{
ApplySorting();
}
ResetRenderOrderFlag();
}
/// <summary>
/// Updates sorting layer.
/// </summary>
/// <param name="newSortingLayer">New sorting layer.</param>
internal void OnControllerSortingLayerDidChange(int newSortingLayer)
{
MeshRenderer.sortingLayerID = newSortingLayer;
}
/// <summary>
/// Updates sorting mode.
/// </summary>
/// <param name="newSortingMode">New sorting mode.</param>
internal void OnControllerSortingModeDidChange(CubismSortingMode newSortingMode)
{
SortingMode = newSortingMode;
ApplySorting();
}
/// <summary>
/// Updates sorting order.
/// </summary>
/// <param name="newSortingOrder">New sorting order.</param>
internal void OnControllerSortingOrderDidChange(int newSortingOrder)
{
SortingOrder = newSortingOrder;
ApplySorting();
}
/// <summary>
/// Updates depth offset.
/// </summary>
/// <param name="newDepthOffset"></param>
internal void OnControllerDepthOffsetDidChange(float newDepthOffset)
{
DepthOffset = newDepthOffset;
ApplySorting();
}
/// <summary>
/// Sets the opacity.
/// </summary>
/// <param name="newOpacity">New opacity.</param>
internal void OnDrawableOpacityDidChange(float newOpacity)
{
Opacity = newOpacity;
ApplyVertexColors();
}
/// <summary>
/// Updates render order.
/// </summary>
/// <param name="newRenderOrder">New render order.</param>
internal void OnDrawableRenderOrderDidChange(int newRenderOrder)
{
if (RenderOrder == newRenderOrder) return;
RenderOrder = newRenderOrder;
SetNewRenderOrder();
}
/// <summary>
/// Sets the <see cref="UnityEngine.Mesh.vertices"/>.
/// </summary>
/// <param name="newVertexPositions">Vertex positions to set.</param>
internal void OnDrawableVertexPositionsDidChange(Vector3[] newVertexPositions)
{
var mesh = Mesh;
// Apply positions and update bounds.
mesh.vertices = newVertexPositions;
mesh.RecalculateBounds();
// Set swap flag.
SetNewVertexPositions();
}
/// <summary>
/// Sets visibility.
/// </summary>
/// <param name="newVisibility">New visibility.</param>
internal void OnDrawableVisiblityDidChange(bool newVisibility)
{
// Set swap flag if visible.
if (newVisibility)
{
BecomeVisible();
}
else
{
BecomeInvisible();
}
}
/// <summary>
/// Sets mask properties.
/// </summary>
/// <param name="newMaskProperties">Value to set.</param>
internal void OnMaskPropertiesDidChange(CubismMaskProperties newMaskProperties)
{
MeshRenderer.GetPropertyBlock(SharedPropertyBlock);
var renderTextureIndex = newMaskProperties.Tile.RenderTextureIndex;
if (newMaskProperties.Texture.RenderTextureCount > 0 && !(renderTextureIndex < newMaskProperties.Texture.RenderTextures.Length))
{
Debug.LogError("An invalid value has been entered for `newMaskProperties.Tile.RenderTextureIndex`.\n" +
$"[Details] newMaskProperties.Tile.RenderTextureIndex: {renderTextureIndex}, newMaskProperties.Texture.RenderTextureCount: {newMaskProperties.Texture.RenderTextureCount}");
return;
}
var texture = newMaskProperties.Texture.RenderTextureCount > 0
? newMaskProperties.Texture.RenderTextures[renderTextureIndex]
: (Texture)newMaskProperties.Texture;
// Write properties.
SharedPropertyBlock.SetTexture(CubismShaderVariables.MaskTexture, texture);
SharedPropertyBlock.SetVector(CubismShaderVariables.MaskTile, newMaskProperties.Tile);
SharedPropertyBlock.SetVector(CubismShaderVariables.MaskTransform, newMaskProperties.Transform);
MeshRenderer.SetPropertyBlock(SharedPropertyBlock);
}
/// <summary>
/// Sets model opacity.
/// </summary>
/// <param name="newModelOpacity">Opacity to set.</param>
internal void OnModelOpacityDidChange(float newModelOpacity)
{
_meshRenderer.GetPropertyBlock(SharedPropertyBlock);
// Write property.
SharedPropertyBlock.SetFloat(CubismShaderVariables.ModelOpacity, newModelOpacity);
MeshRenderer.SetPropertyBlock(SharedPropertyBlock);
}
#endregion
/// <summary>
/// <see cref="SharedPropertyBlock"/> backing field.
/// </summary>
private static MaterialPropertyBlock _sharedPropertyBlock;
/// <summary>
/// <see cref="MaterialPropertyBlock"/> that can be shared on the main script thread.
/// </summary>
private static MaterialPropertyBlock SharedPropertyBlock
{
get
{
// Lazily initialize.
if (_sharedPropertyBlock == null)
{
_sharedPropertyBlock = new MaterialPropertyBlock();
}
return _sharedPropertyBlock;
}
}
/// <summary>
/// Applies main texture for rendering.
/// </summary>
private void ApplyMainTexture()
{
MeshRenderer.GetPropertyBlock(SharedPropertyBlock);
// Write property.
SharedPropertyBlock.SetTexture(CubismShaderVariables.MainTexture, MainTexture);
MeshRenderer.SetPropertyBlock(SharedPropertyBlock);
}
/// <summary>
/// Applies sorting.
/// </summary>
private void ApplySorting()
{
// Sort by order.
if (SortingMode.SortByOrder())
{
MeshRenderer.sortingOrder = SortingOrder + ((SortingMode == CubismSortingMode.BackToFrontOrder)
? (RenderOrder + LocalSortingOrder)
: -(RenderOrder + LocalSortingOrder));
transform.localPosition = Vector3.zero;
return;
}
// Sort by depth.
var offset = (SortingMode == CubismSortingMode.BackToFrontZ)
? -DepthOffset
: DepthOffset;
MeshRenderer.sortingOrder = SortingOrder + LocalSortingOrder;
transform.localPosition = new Vector3(0f, 0f, RenderOrder * offset);
}
/// <summary>
/// Uploads mesh vertex colors.
/// </summary>
public void ApplyVertexColors()
{
var vertexColors = VertexColors;
var color = Color;
color.a *= Opacity;
for (var i = 0; i < vertexColors.Length; ++i)
{
vertexColors[i] = color;
}
// Set swap flag.
SetNewVertexColors();
}
/// <summary>
/// Uploads diffuse colors.
/// </summary>
public void ApplyMultiplyColor()
{
MeshRenderer.GetPropertyBlock(SharedPropertyBlock);
// Write property.
SharedPropertyBlock.SetColor(CubismShaderVariables.MultiplyColor, MultiplyColor);
MeshRenderer.SetPropertyBlock(SharedPropertyBlock);
}
/// <summary>
/// Initializes the main texture if possible.
/// </summary>
private void TryInitializeMultiplyColor()
{
LastIsUseUserMultiplyColor = false;
LastMultiplyColor = MultiplyColor;
ApplyMultiplyColor();
}
/// <summary>
/// Uploads tint colors.
/// </summary>
public void ApplyScreenColor()
{
MeshRenderer.GetPropertyBlock(SharedPropertyBlock);
// Write property.
SharedPropertyBlock.SetColor(CubismShaderVariables.ScreenColor, ScreenColor);
MeshRenderer.SetPropertyBlock(SharedPropertyBlock);
}
/// <summary>
/// Initializes the main texture if possible.
/// </summary>
private void TryInitializeScreenColor()
{
LastIsUseUserScreenColors = false;
LastScreenColor = ScreenColor;
ApplyScreenColor();
}
/// <summary>
/// Initializes the mesh renderer.
/// </summary>
private void TryInitializeMeshRenderer()
{
if (_meshRenderer == null)
{
_meshRenderer = GetComponent<MeshRenderer>();
// Lazily add component.
if (_meshRenderer == null)
{
_meshRenderer = gameObject.AddComponent<MeshRenderer>();
_meshRenderer.hideFlags = HideFlags.HideInInspector;
_meshRenderer.receiveShadows = false;
_meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
_meshRenderer.lightProbeUsage = LightProbeUsage.BlendProbes;
}
}
}
/// <summary>
/// Initializes the mesh filter.
/// </summary>
private void TryInitializeMeshFilter()
{
if (_meshFilter == null)
{
_meshFilter = GetComponent<MeshFilter>();
// Lazily add component.
if (_meshFilter == null)
{
_meshFilter = gameObject.AddComponent<MeshFilter>();
_meshFilter.hideFlags = HideFlags.HideInInspector;
}
}
}
/// <summary>
/// Initializes the mesh if necessary.
/// </summary>
private void TryInitializeMesh()
{
// Only create mesh if necessary.
// HACK 'Mesh.vertex > 0' makes sure mesh is recreated in case of runtime instantiation.
if (Meshes != null && Mesh.vertexCount > 0)
{
return;
}
if (Meshes == null)
{
Meshes = new Mesh[2];
}
for (var i = 0; i < 2; ++i)
{
var mesh = new Mesh
{
name = Drawable.name,
vertices = Drawable.VertexPositions,
uv = Drawable.VertexUvs,
triangles = Drawable.Indices
};
mesh.MarkDynamic();
mesh.RecalculateBounds();
// Store mesh.
Meshes[i] = mesh;
}
}
/// <summary>
/// Initializes vertex colors.
/// </summary>
private void TryInitializeVertexColor()
{
var mesh = Mesh;
VertexColors = new Color[mesh.vertexCount];
for (var i = 0; i < VertexColors.Length; ++i)
{
VertexColors[i] = Color;
VertexColors[i].a *= Opacity;
}
}
/// <summary>
/// Initializes the main texture if possible.
/// </summary>
private void TryInitializeMainTexture()
{
if (MainTexture == null)
{
MainTexture = null;
}
ApplyMainTexture();
}
/// <summary>
/// Initializes components if possible.
/// </summary>
public void TryInitialize(CubismRenderController renderController)
{
Drawable = GetComponent<CubismDrawable>();
RenderController = renderController;
TryInitializeMeshRenderer();
TryInitializeMeshFilter();
TryInitializeMesh();
TryInitializeVertexColor();
TryInitializeMainTexture();
TryInitializeMultiplyColor();
TryInitializeScreenColor();
ApplySorting();
}
#region Swap Info
/// <summary>
/// Sets <see cref="NewVertexPositions"/>.
/// </summary>
private void SetNewVertexPositions()
{
var swapInfo = ThisSwap;
swapInfo.NewVertexPositions = true;
ThisSwap = swapInfo;
}
/// <summary>
/// Sets <see cref="NewVertexColors"/>.
/// </summary>
private void SetNewVertexColors()
{
var swapInfo = ThisSwap;
swapInfo.NewVertexColors = true;
ThisSwap = swapInfo;
}
/// <summary>
/// Sets <see cref="DidBecomeVisible"/> on visible.
/// </summary>
private void BecomeVisible()
{
var swapInfo = ThisSwap;
swapInfo.DidBecomeVisible = true;
ThisSwap = swapInfo;
}
/// <summary>