• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MeltyPlayer / MeltyTool / 27799056011

19 Jun 2026 01:05AM UTC coverage: 41.112% (-0.5%) from 41.598%
27799056011

push

github

MeltyPlayer
Updated goldens.

7325 of 19738 branches covered (37.11%)

Branch coverage included in aggregate %.

30549 of 72385 relevant lines covered (42.2%)

60321.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/FinModelUtility/Fin/Fin/src/math/TextureTransformManager.cs
1
using System.Collections.Generic;
2
using System.Numerics;
3

4
using fin.data.indexable;
5
using fin.math.matrix.four;
6
using fin.math.matrix.three;
7
using fin.math.rotations;
8
using fin.model;
9
using fin.util.time;
10

11
namespace fin.math;
12

13
public interface IReadOnlyTextureTransformManager {
14
  (bool is2d, Matrix3x2 twoDMatrix, Matrix4x4 threeDMatrix)? GetMatrix(
15
      IReadOnlyTexture texture);
16
}
17

18
public interface ITextureTransformManager : IReadOnlyTextureTransformManager {
19
  void Clear();
20

21
  void CalculateMatrices(
22
      IReadOnlyList<IReadOnlyTexture> textures,
23
      (IReadOnlyModelAnimation, float)? animationAndFrame
24
  );
25
}
26

27
public sealed class TextureTransformManager : ITextureTransformManager {
28
  private readonly IndexableDictionary<IReadOnlyTexture, (bool is2d, Matrix3x2
×
29
      twoDMatrix, Matrix4x4 threeDMatrix)> texturesToMatrices_ = new();
×
30

31
  private bool hasInit_;
32
  private (IReadOnlyModelAnimation, float)? previousAnimationAndFrame_;
33

34
  public void Clear() => this.texturesToMatrices_.Clear();
×
35

36
  public void CalculateMatrices(
37
      IReadOnlyList<IReadOnlyTexture> textures,
38
      (IReadOnlyModelAnimation, float)? animationAndFrame) {
×
39
    if (this.hasInit_ && this.previousAnimationAndFrame_ == animationAndFrame) {
×
40
      return;
×
41
    }
42

43
    this.hasInit_ = true;
×
44
    this.previousAnimationAndFrame_ = animationAndFrame;
×
45
    
46
    var animation = animationAndFrame?.Item1;
×
47
    var frame = animationAndFrame?.Item2;
×
48

49
    // Intentionally looping by index to avoid allocating an enumerator.
50
    for (var i = 0; i < textures.Count; ++i) {
×
51
      var texture = textures[i];
×
52
      Vector3? animationTranslation = null;
×
53
      Vector3? animationRotation = null;
×
54
      Vector3? animationScale = null;
×
55

56
      // The pose of the animation, if available.
57
      IReadOnlyTextureTracks? textureTracks = null;
×
58
      animation?.TextureTracks.TryGetValue(texture, out textureTracks);
×
59
      if (textureTracks != null) {
×
60
        // Only gets the values from the animation if the frame is at least partially defined.
61
        if (textureTracks.Translations?.HasAnyData ?? false) {
×
62
          if (textureTracks.Translations.TryGetAtFrame(
×
63
                  frame.Value,
×
64
                  out var outAnimationTranslation)) {
×
65
            animationTranslation = outAnimationTranslation;
×
66
          }
×
67
        }
×
68

69
        if (textureTracks.Rotations?.HasAnyData ?? false) {
×
70
          if (textureTracks.Rotations.TryGetAtFrame(
×
71
                  frame.Value,
×
72
                  out var outAnimationRotation)) {
×
73
            animationRotation = outAnimationRotation.ToEulerRadians();
×
74
          }
×
75
        }
×
76

77
        if (textureTracks.Scales?.HasAnyData ?? false) {
×
78
          if (textureTracks.Scales.TryGetAtFrame(
×
79
                  frame.Value,
×
80
                  out var outAnimationScale)) {
×
81
            animationScale = outAnimationScale;
×
82
          }
×
83
        }
×
84
      }
×
85

86
      // Uses the animation pose instead of the root pose when available.
87
      var transform = texture.TextureTransform;
×
88
      var center = transform.Center;
×
89
      var translation = animationTranslation ?? transform.Translation;
×
90
      var rotation = animationRotation ?? transform.RotationRadians;
×
91
      var scale = animationScale ?? transform.Scale;
×
92

93
      var isTransform3d = transform.IsTransform3d;
×
94

95
      if (isTransform3d) {
×
96
        this.texturesToMatrices_[texture] = (
×
97
            false,
×
98
            default,
×
99
            CalculateTextureTransform3d_(texture,
×
100
                                         center,
×
101
                                         translation,
×
102
                                         rotation,
×
103
                                         scale));
×
104
      } else {
×
105
        this.texturesToMatrices_[texture] = (
×
106
            true,
×
107
            CalculateTextureTransform2d_(texture,
×
108
                                         center,
×
109
                                         translation,
×
110
                                         rotation,
×
111
                                         scale),
×
112
            default);
×
113
      }
×
114
    }
×
115
  }
×
116

117
  private static Matrix3x2 CalculateTextureTransform2d_(
118
      IReadOnlyTexture texture,
119
      Vector3? textureCenter,
120
      Vector3? textureTranslation,
121
      Vector3? textureRotationRadians,
122
      Vector3? textureScale) {
×
123
    var scrollingTexture = texture as IScrollingTexture;
×
124

125
    if ((textureTranslation == null && scrollingTexture == null) &&
×
126
        textureScale == null &&
×
127
        textureRotationRadians == null) {
×
128
      return Matrix3x2.Identity;
×
129
    }
130

131
    var secondsSinceStart
×
132
        = (float) FrameTime.ElapsedTimeSinceApplicationOpened.TotalSeconds;
×
133

134
    Vector2? center = null;
×
135
    if (textureCenter != null) {
×
136
      center = textureCenter.Value.Xy();
×
137
    }
×
138

139
    Vector2? translation = null;
×
140
    if (textureTranslation != null || scrollingTexture != null) {
×
141
      translation = new Vector2((textureTranslation?.X ?? 0) +
×
142
                                secondsSinceStart *
×
143
                                (scrollingTexture?.ScrollSpeedX ?? 0),
×
144
                                (textureTranslation?.Y ?? 0) +
×
145
                                secondsSinceStart *
×
146
                                (scrollingTexture?.ScrollSpeedY ?? 0));
×
147
    }
×
148

149
    Vector2? scale = null;
×
150
    if (textureScale != null) {
×
151
      scale = textureScale.Value.Xy();
×
152
    }
×
153

154
    return SystemMatrix3x2Util.FromCtrss(center,
×
155
                                         translation,
×
156
                                         textureRotationRadians?.Z,
×
157
                                         scale,
×
158
                                         null);
×
159
  }
×
160

161
  private static Matrix4x4 CalculateTextureTransform3d_(
162
      IReadOnlyTexture texture,
163
      Vector3? textureCenter,
164
      Vector3? textureTranslation,
165
      Vector3? textureRotationRadians,
166
      Vector3? textureScale) {
×
167
    var scrollingTexture = texture as IScrollingTexture;
×
168

169
    if ((textureTranslation == null && scrollingTexture == null) &&
×
170
        textureScale == null &&
×
171
        textureRotationRadians == null) {
×
172
      return Matrix4x4.Identity;
×
173
    }
174

175
    var secondsSinceStart
×
176
        = (float) FrameTime.ElapsedTimeSinceApplicationOpened.TotalSeconds;
×
177

178
    Vector3? translation = null;
×
179
    if (textureTranslation != null || scrollingTexture != null) {
×
180
      translation = new Vector3((textureTranslation?.X ?? 0) +
×
181
                                secondsSinceStart *
×
182
                                (scrollingTexture?.ScrollSpeedX ?? 0),
×
183
                                (textureTranslation?.Y ?? 0) +
×
184
                                secondsSinceStart *
×
185
                                (scrollingTexture?.ScrollSpeedY ?? 0),
×
186
                                textureTranslation?.Z ?? 0);
×
187
    }
×
188

189
    Quaternion? rotation = null;
×
190
    if (textureRotationRadians != null) {
×
191
      rotation = QuaternionUtil.CreateZyxRadians(textureRotationRadians.Value.X,
×
192
                                          textureRotationRadians.Value.Y,
×
193
                                          textureRotationRadians.Value.Z);
×
194
    }
×
195

196
    return SystemMatrix4x4Util.FromCtrs(textureCenter, translation, rotation, textureScale);
×
197
  }
×
198

199
  public (bool is2d, Matrix3x2 twoDMatrix, Matrix4x4 threeDMatrix)? GetMatrix(
200
      IReadOnlyTexture texture) => this.texturesToMatrices_[texture];
×
201
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc