Skip to content
0.2.0-dev Download ZIP
221 lines ·6.1 KB Raw
1using System.Numerics;
2using EvilEngine.Formats.Humanoids;
3
4namespace EvilEngine.Formats.Models;
5
6public sealed record Model(
7 IReadOnlyList<ModelNode> Nodes,
8 IReadOnlyList<int> Roots,
9 IReadOnlyList<ModelMesh> Meshes,
10 IReadOnlyList<ModelSkin> Skins,
11 IReadOnlyList<ModelMaterial> Materials,
12 IReadOnlyList<ModelTexture> Textures,
13 IReadOnlyList<ModelImage> Images,
14 IReadOnlyList<ModelAnimation> Animations,
15 IReadOnlyList<string> Variants,
16 ModelExtras Extras);
17
18public sealed record ModelNode(
19 string? Name,
20 IReadOnlyList<int> Children,
21 Vector3 Translation,
22 Quaternion Rotation,
23 Vector3 Scale,
24 int? Mesh = null,
25 int? Skin = null,
26 IReadOnlyList<float>? Weights = null,
27 IReadOnlyList<ModelLod>? Lods = null)
28{
29 public static ModelNode Named(string? name, params int[] children)
30 {
31 return new ModelNode(name, children, Vector3.Zero, Quaternion.Identity, Vector3.One);
32 }
33}
34
35public sealed record ModelLod(int Mesh, float Distance);
36
37public sealed record ModelMesh(
38 string? Name,
39 IReadOnlyList<ModelPrimitive> Primitives,
40 IReadOnlyList<string> MorphNames,
41 IReadOnlyList<float> MorphWeights);
42
43public sealed record ModelPrimitive(
44 int? Material,
45 uint[] Indices,
46 ModelVertices Vertices,
47 IReadOnlyList<ModelMorphTarget> Targets,
48 IReadOnlyList<ModelVariantMapping> VariantMappings);
49
50public sealed record ModelVertices(
51 Vector3[] Positions,
52 Vector3[]? Normals = null,
53 Vector4[]? Tangents = null,
54 Vector2[]? Uv0 = null,
55 Vector2[]? Uv1 = null,
56 Vector4[]? Colors = null,
57 IReadOnlyList<ModelJointSet>? Joints = null,
58 IReadOnlyList<ModelAttribute>? Custom = null)
59{
60 public IReadOnlyList<ModelJointSet> JointSets => Joints ?? [];
61
62 public IReadOnlyList<ModelAttribute> CustomAttributes => Custom ?? [];
63}
64
65public sealed record ModelJointSet(ushort[] Joints, float[] Weights);
66
67public sealed record ModelAttribute(string Name, int Components, float[] Values);
68
69public sealed record ModelMorphTarget(Vector3[]? Positions, Vector3[]? Normals, Vector3[]? Tangents);
70
71public sealed record ModelVariantMapping(int Material, IReadOnlyList<int> Variants);
72
73public sealed record ModelSkin(string? Name, IReadOnlyList<int> Joints, Matrix4x4[] InverseBindMatrices, int? Skeleton);
74
75public sealed record ModelMaterial(string? Name, ContentId? Id, ModelPbr Pbr);
76
77public enum ModelAlphaMode
78{
79 Opaque,
80 Mask,
81 Blend
82}
83
84public sealed record ModelPbr(
85 Vector4 BaseColor,
86 ModelTextureRef? BaseColorTexture,
87 float Metallic,
88 float Roughness,
89 ModelTextureRef? MetallicRoughnessTexture,
90 ModelTextureRef? NormalTexture,
91 float NormalScale,
92 ModelTextureRef? OcclusionTexture,
93 float OcclusionStrength,
94 Vector3 Emissive,
95 ModelTextureRef? EmissiveTexture,
96 ModelAlphaMode AlphaMode,
97 float AlphaCutoff,
98 bool DoubleSided)
99{
100 public static readonly ModelPbr Default = new(Vector4.One, null, 1, 1, null, null, 1, null, 1, Vector3.Zero, null,
101 ModelAlphaMode.Opaque, 0.5f, false);
102}
103
104public sealed record ModelTextureRef(int Texture, int TexCoord = 0);
105
106public sealed record ModelTexture(int? Image, ModelSampler Sampler);
107
108public sealed record ModelSampler(
109 int? MagFilter = null,
110 int? MinFilter = null,
111 int WrapS = ModelSampler.Repeat,
112 int WrapT = ModelSampler.Repeat)
113{
114 public const int Repeat = 10497;
115
116 public static readonly ModelSampler Default = new();
117}
118
119public sealed record ModelImage(string? Name, string MimeType, byte[] Bytes);
120
121public enum ModelChannelPath
122{
123 Translation,
124 Rotation,
125 Scale,
126 Weights
127}
128
129public enum ModelInterpolation
130{
131 Linear,
132 Step,
133 CubicSpline
134}
135
136public sealed record ModelAnimation(string? Name, IReadOnlyList<ModelChannel> Channels)
137{
138 public ModelAnimationInfo? Info { get; init; }
139}
140
141public sealed record ModelAnimationInfo(ContentId? Model, float Rate, bool Loop)
142{
143 public Vector3? Move { get; init; }
144
145 public IReadOnlyList<string> Parameters { get; init; } = [];
146
147 public IReadOnlyList<float> At { get; init; } = [];
148
149 public Vector2? Fade { get; init; }
150
151 public string? Blend { get; init; }
152
153 public bool Delta { get; init; }
154
155 public bool Realtime { get; init; }
156
157 public IReadOnlyList<float>? Weights { get; init; }
158
159 public IReadOnlyList<ModelAnimationLayer> Layers { get; init; } = [];
160}
161
162public sealed record ModelAnimationLayer(ContentId Animation, bool Always);
163
164public sealed record ModelChannel(
165 int Node,
166 ModelChannelPath Path,
167 ModelInterpolation Interpolation,
168 float[] Times,
169 float[] Values);
170
171public sealed record ModelExtras(
172 IReadOnlyList<ModelBodyGroup> BodyGroups,
173 IReadOnlyList<int> Attachments,
174 IReadOnlyList<ModelHitbox> Hitboxes,
175 IReadOnlyDictionary<string, string> Attributes,
176 IReadOnlyDictionary<string, string> Games)
177{
178 public static readonly ModelExtras Empty = new([], [], [], new Dictionary<string, string>(),
179 new Dictionary<string, string>());
180
181 public HumanoidBinding? Humanoid { get; init; }
182
183 public IReadOnlyList<ModelEyeball> Eyeballs { get; init; } = [];
184
185 public IReadOnlyList<ModelMouth> Mouths { get; init; } = [];
186
187 public IReadOnlyList<ModelConstraint> Constraints { get; init; } = [];
188}
189
190public sealed record ModelBodyGroup(string Name, IReadOnlyList<ModelBodyChoice> Choices);
191
192public sealed record ModelBodyChoice(string Name, IReadOnlyList<int> Nodes);
193
194public sealed record ModelEyeball(
195 int Node,
196 Vector3 Origin,
197 Vector3 Up,
198 Vector3 Forward,
199 float Radius,
200 float Iris,
201 float Turn,
202 Vector3 Look,
203 float Limit,
204 IReadOnlyList<ModelPrimitiveRef> Primitives);
205
206public sealed record ModelMouth(int Node, Vector3 Forward);
207
208public abstract record ModelConstraint(int Node);
209
210public sealed record ModelPoseInterp(int Node, int Driver, IReadOnlyList<ModelInterpTrigger> Triggers)
211 : ModelConstraint(Node);
212
213public readonly record struct ModelInterpTrigger(
214 float Tolerance,
215 Quaternion Trigger,
216 Vector3 Position,
217 Quaternion Rotation);
218
219public readonly record struct ModelPrimitiveRef(int Mesh, int Primitive);
220
221public sealed record ModelHitbox(string? Name, int Group, int Node, Vector3 Min, Vector3 Max);