Browse Source

small code cleanup.
fixed missing name and extras when adding rigid mesh to SceneBuilder.

Vicente Penades 3 years ago
parent
commit
a166ca17e4

+ 4 - 0
src/Shared/_Extensions.cs

@@ -46,7 +46,11 @@ namespace SharpGLTF
 
 
         internal static bool _IsFinite(this float value)
         internal static bool _IsFinite(this float value)
         {
         {
+            #if NETSTANDARD2_1_OR_GREATER
+            return float.IsFinite(value);
+            #else
             return !(float.IsNaN(value) || float.IsInfinity(value));
             return !(float.IsNaN(value) || float.IsInfinity(value));
+            #endif
         }
         }
 
 
         internal static bool _IsFinite(this Vector2 v)
         internal static bool _IsFinite(this Vector2 v)

+ 3 - 3
src/SharpGLTF.Core/IO/JsonSerializable.cs

@@ -413,7 +413,7 @@ namespace SharpGLTF.IO
                 // System.Diagnostics.Debug.Assert(reader.TokenType != JsonToken.StartConstructor);
                 // System.Diagnostics.Debug.Assert(reader.TokenType != JsonToken.StartConstructor);
             }
             }
 
 
-            if (list.Count == 0) throw new JsonException("Empty array found.");
+            if (list.Count == 0) throw new JSONEXCEPTION("Empty array found.");
 
 
             System.Diagnostics.Debug.Assert(reader.TokenType == JSONTOKEN.EndArray);
             System.Diagnostics.Debug.Assert(reader.TokenType == JSONTOKEN.EndArray);
         }
         }
@@ -445,7 +445,7 @@ namespace SharpGLTF.IO
                 }
                 }
             }
             }
 
 
-            if (dict.Count == 0) throw new JsonException("Empty dictionary found.");
+            if (dict.Count == 0) throw new JSONEXCEPTION("Empty dictionary found.");
         }
         }
 
 
         private static bool _TryCastValue(ref Utf8JsonReader reader, Type vtype, out Object value)
         private static bool _TryCastValue(ref Utf8JsonReader reader, Type vtype, out Object value)
@@ -505,7 +505,7 @@ namespace SharpGLTF.IO
             {
             {
                 var l = new List<float>(4);
                 var l = new List<float>(4);
                 DeserializePropertyList<float>(ref reader, l);
                 DeserializePropertyList<float>(ref reader, l);
-                value = new System.Numerics.Quaternion(l[0], l[1], l[2], l[3]);
+                value = new Quaternion(l[0], l[1], l[2], l[3]);
                 return true;
                 return true;
             }
             }
 
 

+ 4 - 1
src/SharpGLTF.Toolkit/Scenes/Transformers.Schema2.cs

@@ -18,7 +18,7 @@ namespace SharpGLTF.Scenes
         #region debug
         #region debug
 
 
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
-        private string _DebugName => string.IsNullOrWhiteSpace(_ParentNode.Name) ? "*" : _ParentNode.Name;
+        private string _DebugName => _ParentNode?.Name ?? "*";
 
 
         #endregion
         #endregion
 
 
@@ -130,7 +130,10 @@ namespace SharpGLTF.Scenes
                     if (srcChild.Content is SCHEMA2NODE srcOperator)
                     if (srcChild.Content is SCHEMA2NODE srcOperator)
                     {
                     {
                         var dstNode = dst.CreateNode();
                         var dstNode = dst.CreateNode();
+                        dstNode.Name = srcChild.Name;
+                        dstNode.Extras = srcChild.Extras.DeepClone();
                         dstNode.LocalTransform = srcChild.ChildTransform;
                         dstNode.LocalTransform = srcChild.ChildTransform;
+
                         srcOperator.ApplyTo(dstNode, context);
                         srcOperator.ApplyTo(dstNode, context);
 
 
                         System.Diagnostics.Debug.Assert(dstNode.WorldMatrix == srcChild.GetPoseWorldMatrix(), "Transform mismatch!");
                         System.Diagnostics.Debug.Assert(dstNode.WorldMatrix == srcChild.GetPoseWorldMatrix(), "Transform mismatch!");

+ 12 - 15
src/SharpGLTF.Toolkit/Scenes/Transformers.cs

@@ -12,7 +12,7 @@ using TRANSFORM = SharpGLTF.Transforms.AffineTransform;
 namespace SharpGLTF.Scenes
 namespace SharpGLTF.Scenes
 {
 {
     /// <summary>
     /// <summary>
-    /// Represents the content of <see cref="InstanceBuilder.Content"/>.<br/>
+    /// Represents the transform of a <see cref="InstanceBuilder.Content"/>.<br/>
     /// Applies a transform to the underlaying content object (usually a Mesh, a Camera or a light)
     /// Applies a transform to the underlaying content object (usually a Mesh, a Camera or a light)
     /// </summary>
     /// </summary>
     public abstract class ContentTransformer
     public abstract class ContentTransformer
@@ -41,14 +41,9 @@ namespace SharpGLTF.Scenes
         {
         {
             Guard.NotNull(other, nameof(other));
             Guard.NotNull(other, nameof(other));
 
 
-            if (other._Content is ICloneable cloneable)
-            {
-                this._Content = cloneable.Clone();
-            }
-            else
-            {
-                this._Content = other._Content;
-            }
+            this._Content = other._Content is ICloneable cloneable
+                ? cloneable.Clone()
+                : other._Content;
 
 
             this._Morphings = other._Morphings?.Clone();
             this._Morphings = other._Morphings?.Clone();
         }
         }
@@ -166,7 +161,7 @@ namespace SharpGLTF.Scenes
     }
     }
 
 
     /// <summary>
     /// <summary>
-    /// Represents the content of <see cref="InstanceBuilder.Content"/>.<br/>
+    /// Represents the transform of a <see cref="InstanceBuilder.Content"/>.<br/>
     /// Applies a fixed <see cref="Matrix4x4"/> transform to the underlaying content.
     /// Applies a fixed <see cref="Matrix4x4"/> transform to the underlaying content.
     /// </summary>
     /// </summary>
     [System.Diagnostics.DebuggerDisplay("Fixed Node[{_DebugName,nq}] = {Content}")]
     [System.Diagnostics.DebuggerDisplay("Fixed Node[{_DebugName,nq}] = {Content}")]
@@ -217,7 +212,7 @@ namespace SharpGLTF.Scenes
         private NodeBuilder _ParentNode;
         private NodeBuilder _ParentNode;
 
 
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
-        private Transforms.AffineTransform _ChildTransform;
+        private TRANSFORM _ChildTransform;
 
 
         #endregion
         #endregion
 
 
@@ -239,7 +234,7 @@ namespace SharpGLTF.Scenes
 
 
         public NodeBuilder ParentNode => _ParentNode;
         public NodeBuilder ParentNode => _ParentNode;
 
 
-        public Transforms.AffineTransform ChildTransform => _ChildTransform;
+        public TRANSFORM ChildTransform => _ChildTransform;
 
 
         #endregion
         #endregion
 
 
@@ -249,7 +244,9 @@ namespace SharpGLTF.Scenes
 
 
         public override Matrix4x4 GetPoseWorldMatrix()
         public override Matrix4x4 GetPoseWorldMatrix()
         {
         {
-            return _ParentNode == null ? _ChildTransform.Matrix : _ChildTransform.Matrix * _ParentNode.WorldMatrix;
+            return _ParentNode == null
+                ? _ChildTransform.Matrix
+                : _ChildTransform.Matrix * _ParentNode.WorldMatrix;
         }
         }
 
 
         #endregion
         #endregion
@@ -257,7 +254,7 @@ namespace SharpGLTF.Scenes
     }
     }
 
 
     /// <summary>
     /// <summary>
-    /// Represents the content of <see cref="InstanceBuilder.Content"/>.<br/>
+    /// Represents the transform of a <see cref="InstanceBuilder.Content"/>.<br/>
     /// Applies the transform of a single <see cref="NodeBuilder"/> to the underlaying content.
     /// Applies the transform of a single <see cref="NodeBuilder"/> to the underlaying content.
     /// </summary>
     /// </summary>
     [System.Diagnostics.DebuggerDisplay("Rigid Node[{_DebugName,nq}] = {Content}")]
     [System.Diagnostics.DebuggerDisplay("Rigid Node[{_DebugName,nq}] = {Content}")]
@@ -327,7 +324,7 @@ namespace SharpGLTF.Scenes
     }
     }
 
 
     /// <summary>
     /// <summary>
-    /// Represents the content of <see cref="InstanceBuilder.Content"/>.<br/>
+    /// Represents the transform of a <see cref="InstanceBuilder.Content"/>.<br/>
     /// Applies the transforms of many <see cref="NodeBuilder"/> to the underlaying content.
     /// Applies the transforms of many <see cref="NodeBuilder"/> to the underlaying content.
     /// </summary>
     /// </summary>
     [System.Diagnostics.DebuggerDisplay("Skinned Node[{_DebugName,nq}] = {Content}")]
     [System.Diagnostics.DebuggerDisplay("Skinned Node[{_DebugName,nq}] = {Content}")]