Browse Source

some more API changes
improving aPI dump

Vicente Penades 6 years ago
parent
commit
7ce61a5c23

+ 0 - 1
src/SharpGLTF.Core/IO/Unknown.cs

@@ -6,7 +6,6 @@ using Newtonsoft.Json;
 
 namespace SharpGLTF.IO
 {
-
     [System.Diagnostics.DebuggerDisplay("Unknown {_Name}")]
     class UnknownNode : JsonSerializable
     {

+ 1 - 1
src/SharpGLTF.Core/Memory/SparseArrays.cs

@@ -9,7 +9,7 @@ namespace SharpGLTF.Memory
     /// <summary>
     /// Special accessor to wrap over a base accessor and a sparse accessor
     /// </summary>
-    /// <typeparam name="T"></typeparam>
+    /// <typeparam name="T">An unmanage structure type.</typeparam>
     [System.Diagnostics.DebuggerDisplay("Sparse {typeof(T).Name} Accessor {Count}")]
     public struct SparseArray<T> : IList<T>, IReadOnlyList<T>
         where T : unmanaged

+ 0 - 11
src/SharpGLTF.Core/Schema2/gltf.Accessors.cs

@@ -87,17 +87,6 @@ namespace SharpGLTF.Schema2
         /// </summary>
         public int ItemByteSize                 => Encoding.ByteLength() * Dimensions.DimCount();
 
-        public Transforms.BoundingBox3? LocalBounds3
-        {
-            get
-            {
-                if (this._min.Count != 3) return null;
-                if (this._max.Count != 3) return null;
-
-                return new Transforms.BoundingBox3(this._min, this._max);
-            }
-        }
-
         #endregion
 
         #region API

+ 1 - 1
src/SharpGLTF.Core/Schema2/gltf.MaterialChannel.cs

@@ -229,7 +229,7 @@ namespace SharpGLTF.Schema2
 
             if (_Material == null) throw new InvalidOperationException();
 
-            var sampler = _Material.LogicalParent.UseSampler(min, mag, ws, wt);
+            var sampler = _Material.LogicalParent.UseTextureSampler(min, mag, ws, wt);
             var texture = _Material.LogicalParent.UseTexture(texImg, sampler);
 
             SetTexture(texCoord, texture);

+ 0 - 2
src/SharpGLTF.Core/Schema2/gltf.Mesh.cs

@@ -34,8 +34,6 @@ namespace SharpGLTF.Schema2
 
         public IReadOnlyList<Single> MorphWeights => _weights.Select(item => (Single)item).ToArray();
 
-        public Transforms.BoundingBox3? LocalBounds3 => Transforms.BoundingBox3.UnionOf(Primitives.Select(item => item.LocalBounds3));
-
         #endregion
 
         #region API

+ 0 - 2
src/SharpGLTF.Core/Schema2/gltf.MeshPrimitive.cs

@@ -69,8 +69,6 @@ namespace SharpGLTF.Schema2
 
         public int MorphTargetsCount => _targets.Count;
 
-        public Transforms.BoundingBox3? LocalBounds3 => VertexAccessors["POSITION"]?.LocalBounds3;
-
         public IReadOnlyDictionary<String, Accessor> VertexAccessors => new ReadOnlyLinqDictionary<String, int, Accessor>(_attributes, alidx => this.LogicalParent.LogicalParent.LogicalAccessors[alidx]);
 
         public Accessor IndexAccessor { get => GetIndexAccessor(); set => SetIndexAccessor(value); }

+ 1 - 5
src/SharpGLTF.Core/Schema2/gltf.Scene.cs

@@ -161,8 +161,6 @@ namespace SharpGLTF.Schema2
             }
         }
 
-        public Transforms.BoundingBox3? WorldBounds3 => Transforms.BoundingBox3.Create(this);
-
         #endregion
 
         #region API
@@ -313,12 +311,10 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<Node> VisualChildren => _nodes.Select(idx => LogicalParent.LogicalNodes[idx]);
 
-        public Transforms.BoundingBox3? WorldBounds3 => Transforms.BoundingBox3.Create(this);
-
         #endregion
 
         #region API
-        
+
         /// <summary>
         /// Creates a new <see cref="Node"/> instance,
         /// adds it to <see cref="ModelRoot.LogicalNodes"/>

+ 1 - 1
src/SharpGLTF.Core/Schema2/gltf.Textures.cs

@@ -108,7 +108,7 @@ namespace SharpGLTF.Schema2
         /// <param name="ws">The <see cref="TEXWRAP"/> in the S axis.</param>
         /// <param name="wt">The <see cref="TEXWRAP"/> in the T axis.</param>
         /// <returns>A <see cref="TextureSampler"/> instance, or null if all the arguments are default values.</returns>
-        public TextureSampler UseSampler(TEXMIPMAP min, TEXLERP mag, TEXWRAP ws, TEXWRAP wt)
+        public TextureSampler UseTextureSampler(TEXMIPMAP min, TEXLERP mag, TEXWRAP ws, TEXWRAP wt)
         {
             if (TextureSampler.IsDefault(min, mag, ws, wt)) return null;
 

+ 6 - 15
src/SharpGLTF.Core/Transforms/AffineTransform.cs

@@ -5,11 +5,13 @@ using System.Text;
 
 namespace SharpGLTF.Transforms
 {
-    // https://github.com/KhronosGroup/glTF-Validator/issues/33
-
     /// <summary>
-    /// Represents an affine transform in 3D space, defined by a <see cref="Quaternion"/> rotation, a <see cref="Vector3"/> scale and a <see cref="Vector3"/> translation.
+    /// Represents an affine transform in 3D space,
+    /// defined by a <see cref="Quaternion"/> rotation,
+    /// a <see cref="Vector3"/> scale
+    /// and a <see cref="Vector3"/> translation.
     /// </summary>
+    /// <see href="https://github.com/KhronosGroup/glTF-Validator/issues/33"/>
     public struct AffineTransform
     {
         #region lifecycle
@@ -52,7 +54,7 @@ namespace SharpGLTF.Transforms
         #region properties
 
         /// <summary>
-        /// Gets the <see cref="Matrix"/> transform of the current <see cref="AffineTransform"/>
+        /// Gets the <see cref="Matrix4x4"/> transform of the current <see cref="AffineTransform"/>
         /// </summary>
         public Matrix4x4 Matrix
         {
@@ -98,17 +100,6 @@ namespace SharpGLTF.Transforms
             return childWorld * invWorld;
         }
 
-        public static Matrix4x4 CreateFromRows(Vector4 x, Vector4 y, Vector4 z, Vector4 w)
-        {
-            return new Matrix4x4
-                (
-                x.X, x.Y, x.Z, x.W,
-                y.X, y.Y, y.Z, y.W,
-                z.X, z.Y, z.Z, z.W,
-                w.X, w.Y, w.Z, w.W
-                );
-        }
-
         #endregion
     }
 }

+ 0 - 131
src/SharpGLTF.Core/Transforms/BoundingBox.cs

@@ -1,131 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Numerics;
-using System.Text;
-
-namespace SharpGLTF.Transforms
-{
-    public struct BoundingBox3
-    {
-        #region constructors
-
-        public static BoundingBox3? UnionOf(IEnumerable<BoundingBox3?> bounds)
-        {
-            var final = Empty;
-
-            foreach (var b in bounds.Where(item => item.HasValue))
-            {
-                final = final.IsEmpty ? b.Value : new BoundingBox3(final, b.Value);
-            }
-
-            return final.IsEmpty ? (BoundingBox3?)null : final;
-        }
-
-        public static BoundingBox3? FromPoints(IEnumerable<Vector3> points)
-        {
-            var final = Empty;
-
-            foreach (var p in points)
-            {
-                final = final.IsEmpty ? new BoundingBox3(p) : new BoundingBox3(final, new BoundingBox3(p));
-            }
-
-            return final.IsEmpty ? (BoundingBox3?)null : final;
-        }
-
-        internal static BoundingBox3? Create(Schema2.IVisualNodeContainer container)
-        {
-            var nodes = Schema2.Node
-                .Flatten(container)
-                .Where(item => item.Mesh != null);
-
-            var final = Empty;
-
-            var points = new List<Vector3>();
-
-            foreach (var n in nodes)
-            {
-                var bounds = n.Mesh.LocalBounds3;
-
-                if (!bounds.HasValue) continue;
-
-                var xform = n.WorldMatrix;
-
-                var xppp = n.Mesh.LocalBounds3.Value.Points.Select(p => Vector3.Transform(p, xform));
-
-                points.AddRange(xppp);
-            }
-
-            return BoundingBox3.FromPoints(points);
-        }
-
-        internal BoundingBox3(IReadOnlyList<Double> a, IReadOnlyList<Double> b)
-        {
-            var va = new Vector3((float)a[0], (float)a[1], (float)a[2]);
-            var vb = new Vector3((float)b[0], (float)b[1], (float)b[2]);
-
-            Min = Vector3.Min(va, vb);
-            Max = Vector3.Max(va, vb);
-        }
-
-        public BoundingBox3(BoundingBox3 a, BoundingBox3 b)
-        {
-            Min = Vector3.Min(a.Min, b.Min);
-            Max = Vector3.Max(a.Max, b.Max);
-        }
-
-        public BoundingBox3(Vector3 a)
-        {
-            Min = a;
-            Max = a;
-        }
-
-        public BoundingBox3(Vector3 a, Vector3 b)
-        {
-            Min = Vector3.Min(a, b);
-            Max = Vector3.Max(a, b);
-        }
-
-        #endregion
-
-        #region data
-
-        public Vector3 Min;
-        public Vector3 Max;
-
-        #endregion
-
-        #region properties
-
-        public static readonly BoundingBox3 Empty = new BoundingBox3()
-        {
-            Min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue),
-            Max = new Vector3(float.MinValue, float.MinValue, float.MinValue)
-        };
-
-        public Vector3 Center => (Min + Max) * 0.5f;
-
-        public Vector3 Size => IsEmpty ? Vector3.Zero : Max - Min;
-
-        public bool IsEmpty => (Min.X > Max.X) | (Min.Y > Max.Y) | (Min.Z > Max.Z);
-
-        public IEnumerable<Vector3> Points
-        {
-            get
-            {
-                yield return new Vector3(Min.X, Min.Y, Min.Z);
-                yield return new Vector3(Max.X, Min.Y, Min.Z);
-                yield return new Vector3(Min.X, Max.Y, Min.Z);
-                yield return new Vector3(Max.X, Max.Y, Min.Z);
-
-                yield return new Vector3(Min.X, Min.Y, Max.Z);
-                yield return new Vector3(Max.X, Min.Y, Max.Z);
-                yield return new Vector3(Min.X, Max.Y, Max.Z);
-                yield return new Vector3(Max.X, Max.Y, Max.Z);
-            }
-        }
-
-        #endregion
-    }
-}

+ 22 - 2
tests/SharpGLTF.Tests/AssemblyAPITests.cs

@@ -11,17 +11,37 @@ namespace SharpGLTF
     public class AssemblyAPITests
     {
         [Test]
-        public void DumpCurrentAPI()
+        public void DumpCoreAPI()
         {
+            TestContext.CurrentContext.AttachShowDirLink();
+
             var assembly = typeof(Schema2.ModelRoot).Assembly;
 
-            var API = DumpAssemblyAPI.GetAssemblySignature(assembly).OrderBy(item => item).ToList();
+            var API = DumpAssemblyAPI.GetAssemblySignature(assembly).OrderBy(item => item).ToArray();
+
+            TestContext.CurrentContext.AttachText("CoreAPI.txt", API);
 
             foreach(var l in API)
             {
                 TestContext.WriteLine(l);
             }
+        }
+
+        [Test]
+        public void DumpToolkitAPI()
+        {
+            TestContext.CurrentContext.AttachShowDirLink();
 
+            var assembly = typeof(Schema2.Schema2Toolkit).Assembly;
+
+            var API = DumpAssemblyAPI.GetAssemblySignature(assembly).OrderBy(item => item).ToArray();
+
+            TestContext.CurrentContext.AttachText("ToolkitAPI.txt", API);
+
+            foreach (var l in API)
+            {
+                TestContext.WriteLine(l);
+            }
         }
     }
 }

+ 46 - 19
tests/SharpGLTF.Tests/DumpAssemblyAPI.cs

@@ -59,7 +59,26 @@ namespace SharpGLTF
                 baseName += "CLASS";
             }
 
-            baseName += " " + tinfo.GetFriendlyName();
+            baseName += " " + tinfo.GetQualifiedName();
+
+            if (tinfo.IsClass)
+            {
+                // base classes
+                var baseType = tinfo.BaseType;
+                while (baseType != null && baseType != typeof(object))
+                {
+                    yield return baseName + " { USING " + baseType.GetQualifiedName() + " } ";
+                    baseType = baseType.BaseType;
+                }
+            }
+
+            foreach(var ifaceType in tinfo.GetInterfaces())
+            {
+                if (ifaceType.IsNotPublic) continue;
+
+                yield return baseName + " { USING " + ifaceType.GetQualifiedName() + " } ";
+            }
+
 
             Object instance = null;
 
@@ -101,7 +120,7 @@ namespace SharpGLTF
             if (finfo.IsLiteral) name += "CONST";
             else name += "FIELD";
 
-            name += $" {finfo.Name} {finfo.FieldType.GetFriendlyName()}";
+            name += $" {finfo.Name} {finfo.FieldType.GetQualifiedName()}";
 
             if (finfo.IsStatic)
             {
@@ -121,7 +140,7 @@ namespace SharpGLTF
 
         public static IEnumerable<string> GetPropertySignature(Object instance, PropertyInfo pinfo)
         {
-            var pname = $"{pinfo.Name} {pinfo.PropertyType.GetFriendlyName()}";
+            var pname = $"{pinfo.Name} {pinfo.PropertyType.GetQualifiedName()}";
 
             var getter = pinfo.GetGetMethod();
             if (IsVisible(getter,true)) yield return GetMethodModifiers(getter)+ "PROPERTYGET " + pname;
@@ -132,16 +151,14 @@ namespace SharpGLTF
 
         public static IEnumerable<string> GetMethodSignature(Object instance, MethodBase minfo)
         {
-            // TODO: if parameters have default values, dump the same method multiple times with one parameter less each time.
-
-            
+            // TODO: if parameters have default values, dump the same method multiple times with one parameter less each time.            
 
             var mname = GetMethodModifiers(minfo);
 
             if (minfo is MethodInfo mminfo)
             {
                 if (!IsVisible(minfo)) yield break;
-                mname += "METHOD " + mminfo.Name + $" {mminfo.ReturnType.GetFriendlyName()} ";
+                mname += "METHOD " + mminfo.Name + $" {mminfo.ReturnType.GetQualifiedName()} ";
             }
 
             if (minfo is ConstructorInfo cinfo)
@@ -151,12 +168,19 @@ namespace SharpGLTF
             }             
 
             var mparams = minfo.GetParameters()
-                .Select(item => item.ParameterType.GetFriendlyName())
-                .ToList();
+                .Select(item => GetParameterSignature(item))
+                .ToList();            
 
             yield return mname + "(" + string.Join(", ", mparams) + ")";
         }
 
+        public static string GetParameterSignature(ParameterInfo pinfo)
+        {
+            var isParams = pinfo.GetCustomAttribute(typeof(ParamArrayAttribute)) != null;
+
+            return (isParams ? "params " : "") + pinfo.ParameterType.GetQualifiedName();
+        }
+
         public static bool IsVisible(FieldInfo finfo)
         {
             if (finfo == null) return false;
@@ -196,22 +220,24 @@ namespace SharpGLTF
             return mod;
         }
 
-        public static string GetFriendlyName(this Type tinfo)
+        public static string GetQualifiedName(this Type tinfo)
         {
-            return tinfo.GetTypeInfo().GetFriendlyName();
+            return tinfo.GetTypeInfo().GetQualifiedName();
         }
 
-        public static string GetFriendlyName(this TypeInfo tinfo)
+        public static string GetQualifiedName(this System.Reflection.TypeInfo tinfo)
         {
-            if (!tinfo.IsGenericType) return tinfo.Name;
-
             var name = tinfo.Name;
 
-            /*
-            if (tinfo.Name == "System.Nullable`1")
+            if (tinfo.IsArray)
             {
-                return tinfo.GenericTypeParameters.First().Name + "?";
-            }*/           
+                var fname = tinfo.GetElementType().GetQualifiedName();
+                fname += "[" + string.Join("", Enumerable.Repeat(",", tinfo.GetArrayRank() - 1)) + "]";                
+
+                return fname; 
+            }
+
+            if (!tinfo.IsGenericType && !tinfo.IsGenericTypeDefinition) return tinfo.Name;            
 
             name = name.Replace("`1","");
             name = name.Replace("`2", "");
@@ -224,7 +250,8 @@ namespace SharpGLTF
 
             var gpm = tinfo
                 .GenericTypeArguments
-                .Select(item => GetFriendlyName(item.GetTypeInfo()))
+                .Concat(tinfo.GenericTypeParameters)
+                .Select(item => GetQualifiedName(item.GetTypeInfo()))
                 .ToList();
 
             if (gpm.Count > 0) name += "<" + string.Join(", ", gpm) + ">";

+ 1 - 0
tests/SharpGLTF.Tests/SharpGLTF.Tests.csproj

@@ -10,6 +10,7 @@
 
   <ItemGroup>
     <PackageReference Include="LibGit2Sharp" Version="0.26.0" />
+    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0-beta4-final" />
     <PackageReference Include="nunit" Version="3.11.0" />
     <PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />    

+ 10 - 0
tests/SharpGLTF.Tests/TestUtils.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Text;
 
 namespace SharpGLTF
@@ -61,6 +62,15 @@ namespace SharpGLTF
             NUnit.Framework.TestContext.AddTestAttachment(fileName);
         }
 
+        public static void AttachText(this NUnit.Framework.TestContext context, string fileName, string[] lines)
+        {
+            fileName = context.GetAttachmentPath(fileName, true);
+
+            System.IO.File.WriteAllLines(fileName, lines.ToArray());
+
+            NUnit.Framework.TestContext.AddTestAttachment(fileName);
+        }
+
         public static void AttachShowDirLink(this NUnit.Framework.TestContext context)
         {
             context.AttachFileLink("📂 Show Directory", context.GetAttachmentPath(string.Empty));