4 public class Model : IDisposable {
21 if (bone.
Name == name) {
25 return throwIfNotFound ?
throw new InvalidOperationException(
"ModelBone not found.") :
null;
30 if (mesh.
Name == name) {
34 return throwIfNotFound ?
throw new InvalidOperationException(
"ModelMesh not found.") :
null;
38 ArgumentNullException.ThrowIfNull(name);
39 if (parentBone ==
null
41 throw new InvalidOperationException(
"There can be only one root bone.");
43 if (parentBone !=
null
44 && parentBone.
Model !=
this) {
45 throw new InvalidOperationException(
"Parent bone must belong to the same model.");
47 ModelBone modelBone =
new() {
Model =
this, Index = m_bones.Count };
49 modelBone.Name = name;
50 modelBone.Transform = transform;
51 if (parentBone !=
null) {
52 modelBone.ParentBone = parentBone;
66 ArgumentNullException.ThrowIfNull(name);
67 ArgumentNullException.ThrowIfNull(parentBone);
68 return parentBone.Model !=
this
69 ?
throw new InvalidOperationException(
"Parent bone must belong to the same model.")
74 ArgumentNullException.ThrowIfNull(absoluteTransforms);
75 if (absoluteTransforms.Length <
m_bones.Count) {
76 throw new ArgumentOutOfRangeException(nameof(absoluteTransforms));
78 for (
int i = 0; i <
m_bones.Count; i++) {
81 absoluteTransforms[i] = modelBone.
Transform;
87 out absoluteTransforms[i]
94 if (absoluteTransforms ==
null) {
95 throw new ArgumentNullException(nameof(absoluteTransforms));
97 if (absoluteTransforms.Length <
m_bones.Count) {
98 throw new ArgumentOutOfRangeException(nameof(absoluteTransforms));
100 for (
int i = 0; i <
m_bones.Count; i++) {
109 out absoluteTransforms[i]
116 ArgumentNullException.ThrowIfNull(absoluteTransforms);
117 if (absoluteTransforms.Length <
m_bones.Count) {
118 throw new ArgumentOutOfRangeException(nameof(absoluteTransforms));
141 model.
Initialize(modelData, keepSourceVertexDataInTags);
145 public static Model Load(Stream stream,
bool keepSourceVertexDataInTags =
false) =>
Load(
ModelData.Load(stream), keepSourceVertexDataInTags);
147 public static Model Load(
string fileName,
bool keepSourceVertexDataInTags =
false) =>
152 ArgumentNullException.ThrowIfNull(modelData);
156 for (
int i = 0; i < modelData.
Buffers.Count; i++) {
162 array[i].SetData(modelBuffersData.
Vertices, 0, modelBuffersData.
Vertices.Length);
164 array2[i].SetData(modelBuffersData.
Indices, 0, modelBuffersData.
Indices.Length);
165 if (keepSourceVertexDataInTags) {
177 modelMesh.NewMeshPart(
List< ModelBone > m_childBones
BoundingBox CalculateAbsoluteBoundingBox(Matrix[] absoluteTransforms)
static Model Load(string fileName, bool keepSourceVertexDataInTags=false)
ModelBone NewBone(string name, Matrix transform, ModelBone parentBone)
static Model Load(Stream stream, bool keepSourceVertexDataInTags=false)
ModelMesh FindMesh(string name, bool throwIfNotFound=true)
List< ModelMesh > m_meshes
ModelMesh NewMesh(string name, ModelBone parentBone, BoundingBox boundingBox)
ReadOnlyList< ModelBone > Bones
void AddMesh(ModelMesh mesh)
List< ModelBone > m_bones
ModelBone FindBone(string name, bool throwIfNotFound=true)
void Initialize(ModelData modelData, bool keepSourceVertexDataInTags)
static Model Load(ModelData modelData, bool keepSourceVertexDataInTags=false)
void CopyAbsoluteBoneTransformsTo(Matrix[] absoluteTransforms, Matrix matrix)
void CopyAbsoluteBoneTransformsTo(Matrix[] absoluteTransforms)
ReadOnlyList< ModelMesh > Meshes
BoundingBox m_boundingBox
static BoundingBox Transform(BoundingBox b, Matrix m)
static BoundingBox Union(BoundingBox b1, BoundingBox b2)
static void MultiplyRestricted(ref Matrix m1, ref Matrix m2, out Matrix result)