From 4ea3c3893f3f5f08e647cd56dbf5bc4b75ec1da0 Mon Sep 17 00:00:00 2001 From: "harry.cpp" Date: Fri, 20 Dec 2024 20:31:42 +0100 Subject: [PATCH] Fix compilation errors --- .../OpenAssetImporter.cs | 134 +++++------------- MonoGame.Framework/Color.cs | 14 +- 2 files changed, 46 insertions(+), 102 deletions(-) diff --git a/MonoGame.Framework.Content.Pipeline/OpenAssetImporter.cs b/MonoGame.Framework.Content.Pipeline/OpenAssetImporter.cs index 2879f4cc11f..8472740645f 100644 --- a/MonoGame.Framework.Content.Pipeline/OpenAssetImporter.cs +++ b/MonoGame.Framework.Content.Pipeline/OpenAssetImporter.cs @@ -1,10 +1,11 @@ -// MonoGame - Copyright (C) MonoGame Foundation, Inc +// MonoGame - Copyright (C) MonoGame Foundation, Inc // This file is subject to the terms and conditions defined in // file 'LICENSE.txt', which is part of this source code package. using System; using System.Collections.Generic; using System.Diagnostics; +using System.Numerics; using System.IO; using System.Linq; using System.Reflection; @@ -376,20 +377,20 @@ private void ImportXnaMaterials() material.Textures.Add("Bump", ImportTextureContentRef(aiMaterial.TextureHeight)); if (aiMaterial.HasColorDiffuse) - material.DiffuseColor = ToXna(aiMaterial.ColorDiffuse); + material.DiffuseColor = new Vector3(aiMaterial.ColorDiffuse.X, aiMaterial.ColorDiffuse.Y, aiMaterial.ColorDiffuse.Z); if (aiMaterial.HasColorEmissive) - material.EmissiveColor = ToXna(aiMaterial.ColorEmissive); + material.EmissiveColor = new Vector3(aiMaterial.ColorEmissive.X, aiMaterial.ColorEmissive.Y, aiMaterial.ColorEmissive.Z); if (aiMaterial.HasOpacity) material.Alpha = aiMaterial.Opacity; if (aiMaterial.HasColorSpecular) - material.SpecularColor = ToXna(aiMaterial.ColorSpecular); + material.SpecularColor = new Vector3(aiMaterial.ColorSpecular.X, aiMaterial.ColorSpecular.Y, aiMaterial.ColorSpecular.Z); if (aiMaterial.HasShininessStrength) material.SpecularPower = aiMaterial.Shininess; - + _materials.Add(material); } } @@ -452,17 +453,17 @@ private void ImportMaterials() if (aiMaterial.HasBumpScaling) material.OpaqueData.Add("BumpScaling", aiMaterial.BumpScaling); if (aiMaterial.HasColorAmbient) - material.OpaqueData.Add("AmbientColor", ToXna(aiMaterial.ColorAmbient)); + material.OpaqueData.Add("AmbientColor", aiMaterial.ColorAmbient); if (aiMaterial.HasColorDiffuse) - material.OpaqueData.Add("DiffuseColor", ToXna(aiMaterial.ColorDiffuse)); + material.OpaqueData.Add("DiffuseColor", aiMaterial.ColorDiffuse); if (aiMaterial.HasColorEmissive) - material.OpaqueData.Add("EmissiveColor", ToXna(aiMaterial.ColorEmissive)); + material.OpaqueData.Add("EmissiveColor", aiMaterial.ColorEmissive); if (aiMaterial.HasColorReflective) - material.OpaqueData.Add("ReflectiveColor", ToXna(aiMaterial.ColorReflective)); + material.OpaqueData.Add("ReflectiveColor", aiMaterial.ColorReflective); if (aiMaterial.HasColorSpecular) - material.OpaqueData.Add("SpecularColor", ToXna(aiMaterial.ColorSpecular)); + material.OpaqueData.Add("SpecularColor", aiMaterial.ColorSpecular); if (aiMaterial.HasColorTransparent) - material.OpaqueData.Add("TransparentColor", ToXna(aiMaterial.ColorTransparent)); + material.OpaqueData.Add("TransparentColor", aiMaterial.ColorTransparent); if (aiMaterial.HasOpacity) material.OpaqueData.Add("Opacity", aiMaterial.Opacity); if (aiMaterial.HasReflectivity) @@ -513,7 +514,7 @@ private NodeContent ImportNodes(Node aiNode, Node aiParent, NodeContent parent) { Name = aiNode.Name, Identity = _identity, - Transform = ToXna(GetRelativeTransform(aiNode, aiParent)) + Transform = GetRelativeTransform(aiNode, aiParent) }; foreach (var meshIndex in aiNode.MeshIndices) @@ -544,7 +545,7 @@ private NodeContent ImportNodes(Node aiNode, Node aiParent, NodeContent parent) _pivots.Add(originalName, pivot); } - Matrix transform = ToXna(aiNode.Transform); + Matrix transform = aiNode.Transform; if (aiNode.Name.EndsWith("_Translation")) pivot.Translation = transform; else if (aiNode.Name.EndsWith("_RotationOffset")) @@ -582,7 +583,7 @@ private NodeContent ImportNodes(Node aiNode, Node aiParent, NodeContent parent) { Name = aiNode.Name, Identity = _identity, - Transform = ToXna(GetRelativeTransform(aiNode, aiParent)) + Transform = GetRelativeTransform(aiNode, aiParent) }; } @@ -625,7 +626,7 @@ private GeometryContent CreateGeometry(MeshContent mesh, Mesh aiMesh) // Vertices var baseVertex = mesh.Positions.Count; foreach (var vert in aiMesh.Vertices) - mesh.Positions.Add(ToXna(vert)); + mesh.Positions.Add(vert); geom.Vertices.AddRange(Enumerable.Range(baseVertex, aiMesh.VertexCount)); geom.Indices.AddRange(aiMesh.GetIndices()); @@ -673,13 +674,13 @@ private GeometryContent CreateGeometry(MeshContent mesh, Mesh aiMesh) // Individual channels go here if (aiMesh.HasNormals) - geom.Vertices.Channels.Add(VertexChannelNames.Normal(), aiMesh.Normals.Select(ToXna)); + geom.Vertices.Channels.Add(VertexChannelNames.Normal(), aiMesh.Normals); for (var i = 0; i < aiMesh.TextureCoordinateChannelCount; i++) - geom.Vertices.Channels.Add(VertexChannelNames.TextureCoordinate(i), aiMesh.TextureCoordinateChannels[i].Select(ToXnaTexCoord)); + geom.Vertices.Channels.Add(VertexChannelNames.TextureCoordinate(i), aiMesh.TextureCoordinateChannels[i]); for (var i = 0; i < aiMesh.VertexColorChannelCount; i++) - geom.Vertices.Channels.Add(VertexChannelNames.Color(i), aiMesh.VertexColorChannels[i].Select(ToXnaColor)); + geom.Vertices.Channels.Add(VertexChannelNames.Color(i), aiMesh.VertexColorChannels[i]); return geom; } @@ -726,7 +727,7 @@ private static Dictionary FindDeformationBones(Scene scene) if (mesh.HasBones) foreach (var bone in mesh.Bones) if (!offsetMatrices.ContainsKey(bone.Name)) - offsetMatrices[bone.Name] = ToXna(bone.OffsetMatrix); + offsetMatrices[bone.Name] = bone.OffsetMatrix; return offsetMatrices; } @@ -808,7 +809,7 @@ private NodeContent ImportBones(Node aiNode, Node aiParent, NodeContent parent) { Name = aiNode.Name.Replace(mangling, string.Empty), Identity = _identity, - Transform = ToXna(GetRelativeTransform(aiNode, aiParent)) + Transform = GetRelativeTransform(aiNode, aiParent) }; } else if (_bones.Contains(aiNode)) @@ -876,7 +877,7 @@ private NodeContent ImportBones(Node aiNode, Node aiParent, NodeContent parent) // Offset matrices are not provided by Assimp. :( // Let's hope that the skeleton was exported in bind pose. // (Otherwise we are just importing garbage.) - node.Transform = ToXna(GetRelativeTransform(aiNode, aiParent)); + node.Transform = GetRelativeTransform(aiNode, aiParent); } } } @@ -951,24 +952,24 @@ private AnimationContent ImportAnimation(Animation aiAnimation, string nodeName scaleKeys = aiChannel.ScalingKeys; Debug.Assert(pivot.Scaling.HasValue); - Debug.Assert(!aiChannel.HasRotationKeys || (aiChannel.RotationKeyCount == 1 && (aiChannel.RotationKeys[0].Value == new Assimp.Quaternion(1, 0, 0, 0) || aiChannel.RotationKeys[0].Value == new Assimp.Quaternion(0, 0, 0, 0)))); - Debug.Assert(!aiChannel.HasPositionKeys || (aiChannel.PositionKeyCount == 1 && aiChannel.PositionKeys[0].Value == new Vector3D(0, 0, 0))); + Debug.Assert(!aiChannel.HasRotationKeys || (aiChannel.RotationKeyCount == 1 && (aiChannel.RotationKeys[0].Value == new Quaternion(1, 0, 0, 0) || aiChannel.RotationKeys[0].Value == new Quaternion(0, 0, 0, 0)))); + Debug.Assert(!aiChannel.HasPositionKeys || (aiChannel.PositionKeyCount == 1 && aiChannel.PositionKeys[0].Value == new Vector3(0, 0, 0))); } else if (aiChannel.NodeName.EndsWith("_$AssimpFbx$_Rotation")) { rotationKeys = aiChannel.RotationKeys; Debug.Assert(pivot.Rotation.HasValue); - Debug.Assert(!aiChannel.HasScalingKeys || (aiChannel.ScalingKeyCount == 1 && aiChannel.ScalingKeys[0].Value == new Vector3D(1, 1, 1))); - Debug.Assert(!aiChannel.HasPositionKeys || (aiChannel.PositionKeyCount == 1 && aiChannel.PositionKeys[0].Value == new Vector3D(0, 0, 0))); + Debug.Assert(!aiChannel.HasScalingKeys || (aiChannel.ScalingKeyCount == 1 && aiChannel.ScalingKeys[0].Value == new Vector3(1, 1, 1))); + Debug.Assert(!aiChannel.HasPositionKeys || (aiChannel.PositionKeyCount == 1 && aiChannel.PositionKeys[0].Value == new Vector3(0, 0, 0))); } else if (aiChannel.NodeName.EndsWith("_$AssimpFbx$_Translation")) { translationKeys = aiChannel.PositionKeys; Debug.Assert(pivot.Translation.HasValue); - Debug.Assert(!aiChannel.HasScalingKeys || (aiChannel.ScalingKeyCount == 1 && aiChannel.ScalingKeys[0].Value == new Vector3D(1, 1, 1))); - Debug.Assert(!aiChannel.HasRotationKeys || (aiChannel.RotationKeyCount == 1 && (aiChannel.RotationKeys[0].Value == new Assimp.Quaternion(1, 0, 0, 0) || aiChannel.RotationKeys[0].Value == new Assimp.Quaternion(0, 0, 0, 0)))); + Debug.Assert(!aiChannel.HasScalingKeys || (aiChannel.ScalingKeyCount == 1 && aiChannel.ScalingKeys[0].Value == new Vector3(1, 1, 1))); + Debug.Assert(!aiChannel.HasRotationKeys || (aiChannel.RotationKeyCount == 1 && (aiChannel.RotationKeys[0].Value == new Quaternion(1, 0, 0, 0) || aiChannel.RotationKeys[0].Value == new Quaternion(0, 0, 0, 0)))); } else { @@ -1006,7 +1007,7 @@ private AnimationContent ImportAnimation(Animation aiAnimation, string nodeName if (scaleIndex != -1) { // Scaling key found. - scale = ToXna(scaleKeys[scaleIndex].Value); + scale = scaleKeys[scaleIndex].Value; prevScaleIndex = scaleIndex; prevScaleTime = time; prevScale = scale; @@ -1019,7 +1020,7 @@ private AnimationContent ImportAnimation(Animation aiAnimation, string nodeName // Lerp between previous and next scaling key. var nextScaleKey = scaleKeys[prevScaleIndex + 1]; var nextScaleTime = nextScaleKey.Time; - var nextScale = ToXna(nextScaleKey.Value); + var nextScale = nextScaleKey.Value; var amount = (float)((time - prevScaleTime) / (nextScaleTime - prevScaleTime)); scale = Vector3.Lerp(prevScale.Value, nextScale, amount); } @@ -1036,7 +1037,7 @@ private AnimationContent ImportAnimation(Animation aiAnimation, string nodeName if (rotationIndex != -1) { // Rotation key found. - rotation = ToXna(rotationKeys[rotationIndex].Value); + rotation = rotationKeys[rotationIndex].Value; prevRotationIndex = rotationIndex; prevRotationTime = time; prevRotation = rotation; @@ -1049,7 +1050,7 @@ private AnimationContent ImportAnimation(Animation aiAnimation, string nodeName // Lerp between previous and next rotation key. var nextRotationKey = rotationKeys[prevRotationIndex + 1]; var nextRotationTime = nextRotationKey.Time; - var nextRotation = ToXna(nextRotationKey.Value); + var nextRotation = nextRotationKey.Value; var amount = (float)((time - prevRotationTime) / (nextRotationTime - prevRotationTime)); rotation = Quaternion.Slerp(prevRotation.Value, nextRotation, amount); } @@ -1066,7 +1067,7 @@ private AnimationContent ImportAnimation(Animation aiAnimation, string nodeName if (translationIndex != -1) { // Translation key found. - translation = ToXna(translationKeys[translationIndex].Value); + translation = translationKeys[translationIndex].Value; prevTranslationIndex = translationIndex; prevTranslationTime = time; prevTranslation = translation; @@ -1079,7 +1080,7 @@ private AnimationContent ImportAnimation(Animation aiAnimation, string nodeName // Lerp between previous and next translation key. var nextTranslationKey = translationKeys[prevTranslationIndex + 1]; var nextTranslationTime = nextTranslationKey.Time; - var nextTranslation = ToXna(nextTranslationKey.Value); + var nextTranslation = nextTranslationKey.Value; var amount = (float)((time - prevTranslationTime) / (nextTranslationTime - prevTranslationTime)); translation = Vector3.Lerp(prevTranslation.Value, nextTranslation, amount); } @@ -1166,72 +1167,5 @@ private static string GetNodeName(string name) int index = name.IndexOf("_$AssimpFbx$", StringComparison.Ordinal); return (index >= 0) ? name.Remove(index) : name; } - - #region Conversion Helpers - - [DebuggerStepThrough] - public static Matrix ToXna(Matrix4x4 matrix) - { - var result = Matrix.Identity; - - result.M11 = matrix.A1; - result.M12 = matrix.B1; - result.M13 = matrix.C1; - result.M14 = matrix.D1; - - result.M21 = matrix.A2; - result.M22 = matrix.B2; - result.M23 = matrix.C2; - result.M24 = matrix.D2; - - result.M31 = matrix.A3; - result.M32 = matrix.B3; - result.M33 = matrix.C3; - result.M34 = matrix.D3; - - result.M41 = matrix.A4; - result.M42 = matrix.B4; - result.M43 = matrix.C4; - result.M44 = matrix.D4; - - return result; - } - - [DebuggerStepThrough] - public static Vector2 ToXna(Vector2D vector) - { - return new Vector2(vector.X, vector.Y); - } - - [DebuggerStepThrough] - public static Vector3 ToXna(Vector3D vector) - { - return new Vector3(vector.X, vector.Y, vector.Z); - } - - [DebuggerStepThrough] - public static Quaternion ToXna(Assimp.Quaternion quaternion) - { - return new Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W); - } - - [DebuggerStepThrough] - public static Vector3 ToXna(Color4D color) - { - return new Vector3(color.R, color.G, color.B); - } - - [DebuggerStepThrough] - public static Vector2 ToXnaTexCoord(Vector3D vector) - { - return new Vector2(vector.X, vector.Y); - } - - [DebuggerStepThrough] - public static Color ToXnaColor(Color4D color) - { - return new Color(color.R, color.G, color.B, color.A); - } - #endregion } } diff --git a/MonoGame.Framework/Color.cs b/MonoGame.Framework/Color.cs index 37b4ce73c57..c20685497be 100644 --- a/MonoGame.Framework/Color.cs +++ b/MonoGame.Framework/Color.cs @@ -386,8 +386,18 @@ public byte A this._packedValue = (this._packedValue & 0x00ffffff) | ((uint)value << 24); } } - - /// + + /// + /// Converts a to a by mapping XYZW -> RGBA. + /// + /// The converted value. + /// + public static implicit operator Color(System.Numerics.Vector4 value) + { + return new Color(value.X, value.Y, value.Z, value.W); + } + + /// /// Compares whether two instances are equal. /// /// instance on the left of the equal sign.