Browse Source

WriteSettings constructor is now public.
reversed c# 8 feature.
split runtime files.

Vicente Penades 6 years ago
parent
commit
c6d3aea57b

+ 132 - 0
src/SharpGLTF.Core/Runtime/Drawables.cs

@@ -0,0 +1,132 @@
+using System;
+using System.Collections.Generic;
+using System.Numerics;
+using System.Text;
+
+namespace SharpGLTF.Runtime
+{
+    /// <summary>
+    /// Defines a reference to a drawable mesh
+    /// </summary>
+    abstract class DrawableReference
+    {
+        #region lifecycle
+
+        protected DrawableReference(Schema2.Node node)
+        {
+            _LogicalMeshIndex = node.Mesh.LogicalIndex;
+        }
+
+        #endregion
+
+        #region data
+
+        private readonly int _LogicalMeshIndex;
+
+        #endregion
+
+        #region properties
+
+        /// <summary>
+        /// Gets the index of a <see cref="Schema2.Mesh"/> in <see cref="Schema2.ModelRoot.LogicalMeshes"/>
+        /// </summary>
+        public int LogicalMeshIndex => _LogicalMeshIndex;
+
+        #endregion
+
+        #region API
+
+        public abstract Transforms.IGeometryTransform CreateGeometryTransform();
+
+        public abstract void UpdateGeometryTransform(Transforms.IGeometryTransform geoxform, IReadOnlyList<NodeInstance> instances);
+
+        #endregion
+    }
+
+    /// <summary>
+    /// Defines a reference to a drawable rigid mesh
+    /// </summary>
+    sealed class RigidDrawableReference : DrawableReference
+    {
+        #region lifecycle
+
+        internal RigidDrawableReference(Schema2.Node node, Func<Schema2.Node, int> indexFunc)
+            : base(node)
+        {
+            _NodeIndex = indexFunc(node);
+        }
+
+        #endregion
+
+        #region data
+
+        private readonly int _NodeIndex;
+
+        #endregion
+
+        #region API
+
+        public override Transforms.IGeometryTransform CreateGeometryTransform() { return new Transforms.RigidTransform(); }
+
+        public override void UpdateGeometryTransform(Transforms.IGeometryTransform rigidTransform, IReadOnlyList<NodeInstance> instances)
+        {
+            var node = instances[_NodeIndex];
+
+            var statxform = (Transforms.RigidTransform)rigidTransform;
+            statxform.Update(node.WorldMatrix);
+            statxform.Update(node.MorphWeights, false);
+        }
+
+        #endregion
+    }
+
+    /// <summary>
+    /// Defines a reference to a drawable skinned mesh
+    /// </summary>
+    sealed class SkinnedDrawableReference : DrawableReference
+    {
+        #region lifecycle
+
+        internal SkinnedDrawableReference(Schema2.Node node, Func<Schema2.Node, int> indexFunc)
+            : base(node)
+        {
+            var skin = node.Skin;
+
+            _MorphNodeIndex = indexFunc(node);
+
+            _JointsNodeIndices = new int[skin.JointsCount];
+            _BindMatrices = new Matrix4x4[skin.JointsCount];
+
+            for (int i = 0; i < _JointsNodeIndices.Length; ++i)
+            {
+                var (j, ibm) = skin.GetJoint(i);
+
+                _JointsNodeIndices[i] = indexFunc(j);
+                _BindMatrices[i] = ibm;
+            }
+        }
+
+        #endregion
+
+        #region data
+
+        private readonly int _MorphNodeIndex;
+        private readonly int[] _JointsNodeIndices;
+        private readonly Matrix4x4[] _BindMatrices;
+
+        #endregion
+
+        #region API
+
+        public override Transforms.IGeometryTransform CreateGeometryTransform() { return new Transforms.SkinnedTransform(); }
+
+        public override void UpdateGeometryTransform(Transforms.IGeometryTransform skinnedTransform, IReadOnlyList<NodeInstance> instances)
+        {
+            var skinxform = (Transforms.SkinnedTransform)skinnedTransform;
+            skinxform.Update(_JointsNodeIndices.Length, idx => _BindMatrices[idx], idx => instances[_JointsNodeIndices[idx]].WorldMatrix);
+            skinxform.Update(instances[_MorphNodeIndex].MorphWeights, false);
+        }
+
+        #endregion
+    }
+}

+ 118 - 0
src/SharpGLTF.Core/Runtime/NodeInstance.cs

@@ -0,0 +1,118 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using SharpGLTF.Transforms;
+
+using XFORM = System.Numerics.Matrix4x4;
+
+namespace SharpGLTF.Runtime
+{
+    /// <summary>
+    /// Defines a node of a scene graph in <see cref="SceneInstance"/>
+    /// </summary>
+    [System.Diagnostics.DebuggerDisplay("{Name}")]
+    public sealed class NodeInstance
+    {
+        #region lifecycle
+
+        internal NodeInstance(NodeTemplate template, NodeInstance parent)
+        {
+            _Template = template;
+            _Parent = parent;
+        }
+
+        #endregion
+
+        #region data
+
+        private readonly NodeTemplate _Template;
+        private readonly NodeInstance _Parent;
+
+        private XFORM _LocalMatrix;
+        private XFORM? _WorldMatrix;
+
+        private SparseWeight8 _MorphWeights;
+
+        #endregion
+
+        #region properties
+
+        public String Name => _Template.Name;
+
+        public NodeInstance VisualParent => _Parent;
+
+        public SparseWeight8 MorphWeights
+        {
+            get => _MorphWeights;
+            set => _MorphWeights = value;
+        }
+
+        public XFORM LocalMatrix
+        {
+            get => _LocalMatrix;
+            set
+            {
+                _LocalMatrix = value;
+                _WorldMatrix = null;
+            }
+        }
+
+        public XFORM WorldMatrix
+        {
+            get => _GetWorldMatrix();
+            set => _SetWorldMatrix(value);
+        }
+
+        /// <summary>
+        /// Gets a value indicating whether any of the transforms down the scene tree has been modified.
+        /// </summary>
+        private bool TransformChainIsDirty
+        {
+            get
+            {
+                if (!_WorldMatrix.HasValue) return true;
+
+                return _Parent == null ? false : _Parent.TransformChainIsDirty;
+            }
+        }
+
+        #endregion
+
+        #region API
+
+        private XFORM _GetWorldMatrix()
+        {
+            if (!TransformChainIsDirty) return _WorldMatrix.Value;
+
+            _WorldMatrix = _Parent == null ? _LocalMatrix : XFORM.Multiply(_LocalMatrix, _Parent.WorldMatrix);
+
+            return _WorldMatrix.Value;
+        }
+
+        private void _SetWorldMatrix(XFORM xform)
+        {
+            if (_Parent == null) { LocalMatrix = xform; return; }
+
+            XFORM.Invert(_Parent._GetWorldMatrix(), out XFORM ipwm);
+
+            LocalMatrix = XFORM.Multiply(xform, ipwm);
+        }
+
+        public void SetPoseTransform() { SetAnimationFrame(-1, 0); }
+
+        public void SetAnimationFrame(int trackLogicalIndex, float time)
+        {
+            this.MorphWeights = _Template.GetMorphWeights(trackLogicalIndex, time);
+            this.LocalMatrix = _Template.GetLocalMatrix(trackLogicalIndex, time);
+        }
+
+        public void SetAnimationFrame(ReadOnlySpan<int> track, ReadOnlySpan<float> time, ReadOnlySpan<float> weight)
+        {
+            this.MorphWeights = _Template.GetMorphWeights(track, time, weight);
+            this.LocalMatrix = _Template.GetLocalMatrix(track, time, weight);
+        }
+
+        #endregion
+    }
+}

+ 170 - 0
src/SharpGLTF.Core/Runtime/NodeTemplate.cs

@@ -0,0 +1,170 @@
+using System;
+using System.Collections.Generic;
+using System.Numerics;
+using System.Text;
+
+namespace SharpGLTF.Runtime
+{
+    /// <summary>
+    /// Defines a hierarchical transform node of a scene graph tree.
+    /// </summary>
+    [System.Diagnostics.DebuggerDisplay("[{LogicalNodeIndex}] {Name}")]
+    class NodeTemplate
+    {
+        #region lifecycle
+
+        internal NodeTemplate(Schema2.Node srcNode, int parentIdx, int[] childIndices, bool isolateMemory)
+        {
+            _LogicalSourceIndex = srcNode.LogicalIndex;
+
+            _ParentIndex = parentIdx;
+            _ChildIndices = childIndices;
+
+            Name = srcNode.Name;
+
+            _LocalMatrix = srcNode.LocalMatrix;
+            _LocalTransform = srcNode.LocalTransform;
+
+            _Scale = new AnimatableProperty<Vector3>(_LocalTransform.Scale);
+            _Rotation = new AnimatableProperty<Quaternion>(_LocalTransform.Rotation);
+            _Translation = new AnimatableProperty<Vector3>(_LocalTransform.Translation);
+
+            var mw = Transforms.SparseWeight8.Create(srcNode.MorphWeights);
+            _Morphing = new AnimatableProperty<Transforms.SparseWeight8>(mw);
+
+            foreach (var anim in srcNode.LogicalParent.LogicalAnimations)
+            {
+                var index = anim.LogicalIndex;
+                var name = anim.Name;
+
+                var scaAnim = anim.FindScaleSampler(srcNode)?.CreateCurveSampler(isolateMemory);
+                if (scaAnim != null) _Scale.AddCurve(index, name, scaAnim);
+
+                var rotAnim = anim.FindRotationSampler(srcNode)?.CreateCurveSampler(isolateMemory);
+                if (rotAnim != null) _Rotation.AddCurve(index, name, rotAnim);
+
+                var traAnim = anim.FindTranslationSampler(srcNode)?.CreateCurveSampler(isolateMemory);
+                if (traAnim != null) _Translation.AddCurve(index, name, traAnim);
+
+                var mrpAnim = anim.FindSparseMorphSampler(srcNode)?.CreateCurveSampler(isolateMemory);
+                if (mrpAnim != null) _Morphing.AddCurve(index, name, mrpAnim);
+            }
+
+            _UsePrecomputed = !(_Scale.IsAnimated | _Rotation.IsAnimated | _Translation.IsAnimated);
+
+            if (_UsePrecomputed)
+            {
+                _Scale = null;
+                _Rotation = null;
+                _Translation = null;
+            }
+        }
+
+        #endregion
+
+        #region data
+
+        private readonly int _LogicalSourceIndex;
+
+        private readonly int _ParentIndex;
+        private readonly int[] _ChildIndices;
+
+        private readonly bool _UsePrecomputed;
+        private readonly Matrix4x4 _LocalMatrix;
+        private readonly Transforms.AffineTransform _LocalTransform;
+
+        private readonly AnimatableProperty<Vector3> _Scale;
+        private readonly AnimatableProperty<Quaternion> _Rotation;
+        private readonly AnimatableProperty<Vector3> _Translation;
+        private readonly AnimatableProperty<Transforms.SparseWeight8> _Morphing;
+
+        #endregion
+
+        #region properties
+
+        public string Name { get; set; }
+
+        /// <summary>
+        /// Gets the index of the source <see cref="Schema2.Node"/> in <see cref="Schema2.ModelRoot.LogicalNodes"/>
+        /// </summary>
+        public int LogicalNodeIndex => _LogicalSourceIndex;
+
+        /// <summary>
+        /// Gets the index of the parent <see cref="NodeTemplate"/> in <see cref="SceneTemplate._NodeTemplates"/>
+        /// </summary>
+        public int ParentIndex => _ParentIndex;
+
+        /// <summary>
+        /// Gets the list of indices of the children <see cref="NodeTemplate"/> in <see cref="SceneTemplate._NodeTemplates"/>
+        /// </summary>
+        public IReadOnlyList<int> ChildIndices => _ChildIndices;
+
+        public Matrix4x4 LocalMatrix => _LocalMatrix;
+
+        #endregion
+
+        #region API
+
+        public Transforms.SparseWeight8 GetMorphWeights(int trackLogicalIndex, float time)
+        {
+            if (trackLogicalIndex < 0) return _Morphing.Value;
+
+            return _Morphing.GetValueAt(trackLogicalIndex, time);
+        }
+
+        public Transforms.SparseWeight8 GetMorphWeights(ReadOnlySpan<int> track, ReadOnlySpan<float> time, ReadOnlySpan<float> weight)
+        {
+            if (!_Morphing.IsAnimated) return _Morphing.Value;
+
+            Span<Transforms.SparseWeight8> xforms = stackalloc Transforms.SparseWeight8[track.Length];
+
+            for (int i = 0; i < xforms.Length; ++i)
+            {
+                xforms[i] = GetMorphWeights(track[i], time[i]);
+            }
+
+            return Transforms.SparseWeight8.Blend(xforms, weight);
+        }
+
+        public Transforms.AffineTransform GetLocalTransform(int trackLogicalIndex, float time)
+        {
+            if (_UsePrecomputed || trackLogicalIndex < 0) return _LocalTransform;
+
+            var s = _Scale?.GetValueAt(trackLogicalIndex, time);
+            var r = _Rotation?.GetValueAt(trackLogicalIndex, time);
+            var t = _Translation?.GetValueAt(trackLogicalIndex, time);
+
+            return Transforms.AffineTransform.Create(s, r, t);
+        }
+
+        public Transforms.AffineTransform GetLocalTransform(ReadOnlySpan<int> track, ReadOnlySpan<float> time, ReadOnlySpan<float> weight)
+        {
+            if (_UsePrecomputed) return _LocalTransform;
+
+            Span<Transforms.AffineTransform> xforms = stackalloc Transforms.AffineTransform[track.Length];
+
+            for (int i = 0; i < xforms.Length; ++i)
+            {
+                xforms[i] = GetLocalTransform(track[i], time[i]);
+            }
+
+            return Transforms.AffineTransform.Blend(xforms, weight);
+        }
+
+        public Matrix4x4 GetLocalMatrix(int trackLogicalIndex, float time)
+        {
+            if (_UsePrecomputed || trackLogicalIndex < 0) return _LocalMatrix;
+
+            return GetLocalTransform(trackLogicalIndex, time).Matrix;
+        }
+
+        public Matrix4x4 GetLocalMatrix(ReadOnlySpan<int> track, ReadOnlySpan<float> time, ReadOnlySpan<float> weight)
+        {
+            if (_UsePrecomputed) return _LocalMatrix;
+
+            return GetLocalTransform(track, time, weight).Matrix;
+        }
+
+        #endregion
+    }
+}

+ 0 - 108
src/SharpGLTF.Core/Runtime/SceneInstance.cs

@@ -10,114 +10,6 @@ using XFORM = System.Numerics.Matrix4x4;
 
 
 namespace SharpGLTF.Runtime
 namespace SharpGLTF.Runtime
 {
 {
-    /// <summary>
-    /// Defines a node of a scene graph in <see cref="SceneInstance"/>
-    /// </summary>
-    [System.Diagnostics.DebuggerDisplay("{Name}")]
-    public sealed class NodeInstance
-    {
-        #region lifecycle
-
-        internal NodeInstance(NodeTemplate template, NodeInstance parent)
-        {
-            _Template = template;
-            _Parent = parent;
-        }
-
-        #endregion
-
-        #region data
-
-        private readonly NodeTemplate _Template;
-        private readonly NodeInstance _Parent;
-
-        private XFORM _LocalMatrix;
-        private XFORM? _WorldMatrix;
-
-        private SparseWeight8 _MorphWeights;
-
-        #endregion
-
-        #region properties
-
-        public String Name => _Template.Name;
-
-        public NodeInstance VisualParent => _Parent;
-
-        public SparseWeight8 MorphWeights
-        {
-            get => _MorphWeights;
-            set => _MorphWeights = value;
-        }
-
-        public XFORM LocalMatrix
-        {
-            get => _LocalMatrix;
-            set
-            {
-                _LocalMatrix = value;
-                _WorldMatrix = null;
-            }
-        }
-
-        public XFORM WorldMatrix
-        {
-            get => _GetWorldMatrix();
-            set => _SetWorldMatrix(value);
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether any of the transforms down the scene tree has been modified.
-        /// </summary>
-        private bool TransformChainIsDirty
-        {
-            get
-            {
-                if (!_WorldMatrix.HasValue) return true;
-
-                return _Parent == null ? false : _Parent.TransformChainIsDirty;
-            }
-        }
-
-        #endregion
-
-        #region API
-
-        private XFORM _GetWorldMatrix()
-        {
-            if (!TransformChainIsDirty) return _WorldMatrix.Value;
-
-            _WorldMatrix = _Parent == null ? _LocalMatrix : XFORM.Multiply(_LocalMatrix, _Parent.WorldMatrix);
-
-            return _WorldMatrix.Value;
-        }
-
-        private void _SetWorldMatrix(XFORM xform)
-        {
-            if (_Parent == null) { LocalMatrix = xform; return; }
-
-            XFORM.Invert(_Parent._GetWorldMatrix(), out XFORM ipwm);
-
-            LocalMatrix = XFORM.Multiply(xform, ipwm);
-        }
-
-        public void SetPoseTransform() { SetAnimationFrame(-1, 0); }
-
-        public void SetAnimationFrame(int trackLogicalIndex, float time)
-        {
-            this.MorphWeights = _Template.GetMorphWeights(trackLogicalIndex, time);
-            this.LocalMatrix = _Template.GetLocalMatrix(trackLogicalIndex, time);
-        }
-
-        public void SetAnimationFrame(ReadOnlySpan<int> track, ReadOnlySpan<float> time, ReadOnlySpan<float> weight)
-        {
-            this.MorphWeights = _Template.GetMorphWeights(track, time, weight);
-            this.LocalMatrix = _Template.GetLocalMatrix(track, time, weight);
-        }
-
-        #endregion
-    }
-
     /// <summary>
     /// <summary>
     /// Represents a specific and independent state of a <see cref="SceneTemplate"/>.
     /// Represents a specific and independent state of a <see cref="SceneTemplate"/>.
     /// </summary>
     /// </summary>

+ 0 - 288
src/SharpGLTF.Core/Runtime/SceneTemplate.cs

@@ -7,294 +7,6 @@ using System.Threading.Tasks;
 
 
 namespace SharpGLTF.Runtime
 namespace SharpGLTF.Runtime
 {
 {
-    /// <summary>
-    /// Defines a hierarchical transform node of a scene graph tree.
-    /// </summary>
-    [System.Diagnostics.DebuggerDisplay("[{LogicalNodeIndex}] {Name}")]
-    class NodeTemplate
-    {
-        #region lifecycle
-
-        internal NodeTemplate(Schema2.Node srcNode, int parentIdx, int[] childIndices, bool isolateMemory)
-        {
-            _LogicalSourceIndex = srcNode.LogicalIndex;
-
-            _ParentIndex = parentIdx;
-            _ChildIndices = childIndices;
-
-            Name = srcNode.Name;
-
-            _LocalMatrix = srcNode.LocalMatrix;
-            _LocalTransform = srcNode.LocalTransform;
-
-            _Scale = new AnimatableProperty<Vector3>(_LocalTransform.Scale);
-            _Rotation = new AnimatableProperty<Quaternion>(_LocalTransform.Rotation);
-            _Translation = new AnimatableProperty<Vector3>(_LocalTransform.Translation);
-
-            var mw = Transforms.SparseWeight8.Create(srcNode.MorphWeights);
-            _Morphing = new AnimatableProperty<Transforms.SparseWeight8>(mw);
-
-            foreach (var anim in srcNode.LogicalParent.LogicalAnimations)
-            {
-                var index = anim.LogicalIndex;
-                var name = anim.Name;
-
-                var scaAnim = anim.FindScaleSampler(srcNode)?.CreateCurveSampler(isolateMemory);
-                if (scaAnim != null) _Scale.AddCurve(index, name, scaAnim);
-
-                var rotAnim = anim.FindRotationSampler(srcNode)?.CreateCurveSampler(isolateMemory);
-                if (rotAnim != null) _Rotation.AddCurve(index, name, rotAnim);
-
-                var traAnim = anim.FindTranslationSampler(srcNode)?.CreateCurveSampler(isolateMemory);
-                if (traAnim != null) _Translation.AddCurve(index, name, traAnim);
-
-                var mrpAnim = anim.FindSparseMorphSampler(srcNode)?.CreateCurveSampler(isolateMemory);
-                if (mrpAnim != null) _Morphing.AddCurve(index, name, mrpAnim);
-            }
-
-            _UsePrecomputed = !(_Scale.IsAnimated | _Rotation.IsAnimated | _Translation.IsAnimated);
-
-            if (_UsePrecomputed)
-            {
-                _Scale = null;
-                _Rotation = null;
-                _Translation = null;
-            }
-        }
-
-        #endregion
-
-        #region data
-
-        private readonly int _LogicalSourceIndex;
-
-        private readonly int _ParentIndex;
-        private readonly int[] _ChildIndices;
-
-        private readonly bool _UsePrecomputed;
-        private readonly Matrix4x4 _LocalMatrix;
-        private readonly Transforms.AffineTransform _LocalTransform;
-
-        private readonly AnimatableProperty<Vector3> _Scale;
-        private readonly AnimatableProperty<Quaternion> _Rotation;
-        private readonly AnimatableProperty<Vector3> _Translation;
-        private readonly AnimatableProperty<Transforms.SparseWeight8> _Morphing;
-
-        #endregion
-
-        #region properties
-
-        public string Name { get; set; }
-
-        /// <summary>
-        /// Gets the index of the source <see cref="Schema2.Node"/> in <see cref="Schema2.ModelRoot.LogicalNodes"/>
-        /// </summary>
-        public int LogicalNodeIndex => _LogicalSourceIndex;
-
-        /// <summary>
-        /// Gets the index of the parent <see cref="NodeTemplate"/> in <see cref="SceneTemplate._NodeTemplates"/>
-        /// </summary>
-        public int ParentIndex => _ParentIndex;
-
-        /// <summary>
-        /// Gets the list of indices of the children <see cref="NodeTemplate"/> in <see cref="SceneTemplate._NodeTemplates"/>
-        /// </summary>
-        public IReadOnlyList<int> ChildIndices => _ChildIndices;
-
-        public Matrix4x4 LocalMatrix => _LocalMatrix;
-
-        #endregion
-
-        #region API
-
-        public Transforms.SparseWeight8 GetMorphWeights(int trackLogicalIndex, float time)
-        {
-            if (trackLogicalIndex < 0) return _Morphing.Value;
-
-            return _Morphing.GetValueAt(trackLogicalIndex, time);
-        }
-
-        public Transforms.SparseWeight8 GetMorphWeights(ReadOnlySpan<int> track, ReadOnlySpan<float> time, ReadOnlySpan<float> weight)
-        {
-            if (!_Morphing.IsAnimated) return _Morphing.Value;
-
-            Span<Transforms.SparseWeight8> xforms = stackalloc Transforms.SparseWeight8[track.Length];
-
-            for (int i = 0; i < xforms.Length; ++i)
-            {
-                xforms[i] = GetMorphWeights(track[i], time[i]);
-            }
-
-            return Transforms.SparseWeight8.Blend(xforms, weight);
-        }
-
-        public Transforms.AffineTransform GetLocalTransform(int trackLogicalIndex, float time)
-        {
-            if (_UsePrecomputed || trackLogicalIndex < 0) return _LocalTransform;
-
-            var s = _Scale?.GetValueAt(trackLogicalIndex, time);
-            var r = _Rotation?.GetValueAt(trackLogicalIndex, time);
-            var t = _Translation?.GetValueAt(trackLogicalIndex, time);
-
-            return Transforms.AffineTransform.Create(s, r, t);
-        }
-
-        public Transforms.AffineTransform GetLocalTransform(ReadOnlySpan<int> track, ReadOnlySpan<float> time, ReadOnlySpan<float> weight)
-        {
-            if (_UsePrecomputed) return _LocalTransform;
-
-            Span<Transforms.AffineTransform> xforms = stackalloc Transforms.AffineTransform[track.Length];
-
-            for (int i = 0; i < xforms.Length; ++i)
-            {
-                xforms[i] = GetLocalTransform(track[i], time[i]);
-            }
-
-            return Transforms.AffineTransform.Blend(xforms, weight);
-        }
-
-        public Matrix4x4 GetLocalMatrix(int trackLogicalIndex, float time)
-        {
-            if (_UsePrecomputed || trackLogicalIndex < 0) return _LocalMatrix;
-
-            return GetLocalTransform(trackLogicalIndex, time).Matrix;
-        }
-
-        public Matrix4x4 GetLocalMatrix(ReadOnlySpan<int> track, ReadOnlySpan<float> time, ReadOnlySpan<float> weight)
-        {
-            if (_UsePrecomputed) return _LocalMatrix;
-
-            return GetLocalTransform(track, time, weight).Matrix;
-        }
-
-        #endregion
-    }
-
-    /// <summary>
-    /// Defines a reference to a drawable mesh
-    /// </summary>
-    abstract class DrawableReference
-    {
-        #region lifecycle
-
-        protected DrawableReference(Schema2.Node node)
-        {
-            _LogicalMeshIndex = node.Mesh.LogicalIndex;
-        }
-
-        #endregion
-
-        #region data
-
-        private readonly int _LogicalMeshIndex;
-
-        #endregion
-
-        #region properties
-
-        /// <summary>
-        /// Gets the index of a <see cref="Schema2.Mesh"/> in <see cref="Schema2.ModelRoot.LogicalMeshes"/>
-        /// </summary>
-        public int LogicalMeshIndex => _LogicalMeshIndex;
-
-        #endregion
-
-        #region API
-
-        public abstract Transforms.IGeometryTransform CreateGeometryTransform();
-
-        public abstract void UpdateGeometryTransform(Transforms.IGeometryTransform geoxform, IReadOnlyList<NodeInstance> instances);
-
-        #endregion
-    }
-
-    /// <summary>
-    /// Defines a reference to a drawable rigid mesh
-    /// </summary>
-    sealed class RigidDrawableReference : DrawableReference
-    {
-        #region lifecycle
-
-        internal RigidDrawableReference(Schema2.Node node, Func<Schema2.Node, int> indexFunc)
-            : base(node)
-        {
-            _NodeIndex = indexFunc(node);
-        }
-
-        #endregion
-
-        #region data
-
-        private readonly int _NodeIndex;
-
-        #endregion
-
-        #region API
-
-        public override Transforms.IGeometryTransform CreateGeometryTransform() { return new Transforms.RigidTransform(); }
-
-        public override void UpdateGeometryTransform(Transforms.IGeometryTransform rigidTransform, IReadOnlyList<NodeInstance> instances)
-        {
-            var node = instances[_NodeIndex];
-
-            var statxform = (Transforms.RigidTransform)rigidTransform;
-            statxform.Update(node.WorldMatrix);
-            statxform.Update(node.MorphWeights, false);
-        }
-
-        #endregion
-    }
-
-    /// <summary>
-    /// Defines a reference to a drawable skinned mesh
-    /// </summary>
-    sealed class SkinnedDrawableReference : DrawableReference
-    {
-        #region lifecycle
-
-        internal SkinnedDrawableReference(Schema2.Node node, Func<Schema2.Node, int> indexFunc)
-            : base(node)
-        {
-            var skin = node.Skin;
-
-            _MorphNodeIndex = indexFunc(node);
-
-            _JointsNodeIndices = new int[skin.JointsCount];
-            _BindMatrices = new Matrix4x4[skin.JointsCount];
-
-            for (int i = 0; i < _JointsNodeIndices.Length; ++i)
-            {
-                var (j, ibm) = skin.GetJoint(i);
-
-                _JointsNodeIndices[i] = indexFunc(j);
-                _BindMatrices[i] = ibm;
-            }
-        }
-
-        #endregion
-
-        #region data
-
-        private readonly int _MorphNodeIndex;
-        private readonly int[] _JointsNodeIndices;
-        private readonly Matrix4x4[] _BindMatrices;
-
-        #endregion
-
-        #region API
-
-        public override Transforms.IGeometryTransform CreateGeometryTransform() { return new Transforms.SkinnedTransform(); }
-
-        public override void UpdateGeometryTransform(Transforms.IGeometryTransform skinnedTransform, IReadOnlyList<NodeInstance> instances)
-        {
-            var skinxform = (Transforms.SkinnedTransform)skinnedTransform;
-            skinxform.Update(_JointsNodeIndices.Length, idx => _BindMatrices[idx], idx => instances[_JointsNodeIndices[idx]].WorldMatrix);
-            skinxform.Update(instances[_MorphNodeIndex].MorphWeights, false);
-        }
-
-        #endregion
-    }
-
     /// <summary>
     /// <summary>
     /// Defines a templatized representation of a <see cref="Schema2.Scene"/> that can be used
     /// Defines a templatized representation of a <see cref="Schema2.Scene"/> that can be used
     /// to create <see cref="SceneInstance"/>, which can help render a scene on a client application.
     /// to create <see cref="SceneInstance"/>, which can help render a scene on a client application.

+ 17 - 19
src/SharpGLTF.Core/Schema2/gltf.Serialization.Write.cs

@@ -13,24 +13,24 @@ namespace SharpGLTF.Schema2
     using MODEL = ModelRoot;
     using MODEL = ModelRoot;
 
 
     /// <summary>
     /// <summary>
-    /// Determines the way in which <see cref="Image"/> instances are stored.
+    /// Determines how resources are written.
     /// </summary>
     /// </summary>
-    public enum ImageWriteMode
+    public enum ResourceWriteMode
     {
     {
         /// <summary>
         /// <summary>
-        /// Images will be stored as external satellite files.
+        /// Resources will be stored as external satellite files.
         /// </summary>
         /// </summary>
         SatelliteFile,
         SatelliteFile,
 
 
         /// <summary>
         /// <summary>
-        /// Images will be stored as internal binary buffers.
+        /// Resources will be embedded into the JSON encoded in MIME64.
         /// </summary>
         /// </summary>
-        BufferView,
+        Embedded,
 
 
         /// <summary>
         /// <summary>
-        /// Images will be embedded into the JSON encoded in MIME64.
+        /// Resources will be stored as internal binary buffers. Valid only for <see cref="Image"/>
         /// </summary>
         /// </summary>
-        Embedded
+        BufferView
     }
     }
 
 
     /// <summary>
     /// <summary>
@@ -57,7 +57,7 @@ namespace SharpGLTF.Schema2
             var settings = new WriteSettings()
             var settings = new WriteSettings()
             {
             {
                 BinaryMode = false,
                 BinaryMode = false,
-                ImageWriting = ImageWriteMode.SatelliteFile,
+                ImageWriting = ResourceWriteMode.SatelliteFile,
                 MergeBuffers = false,
                 MergeBuffers = false,
                 JsonFormatting = Formatting.None,
                 JsonFormatting = Formatting.None,
                 _UpdateSupportedExtensions = false,
                 _UpdateSupportedExtensions = false,
@@ -78,7 +78,7 @@ namespace SharpGLTF.Schema2
             var settings = new WriteSettings
             var settings = new WriteSettings
             {
             {
                 BinaryMode = false,
                 BinaryMode = false,
-                ImageWriting = ImageWriteMode.SatelliteFile,
+                ImageWriting = ResourceWriteMode.SatelliteFile,
                 MergeBuffers = true,
                 MergeBuffers = true,
                 JsonFormatting = Formatting.Indented,
                 JsonFormatting = Formatting.Indented,
                 _UpdateSupportedExtensions = true,
                 _UpdateSupportedExtensions = true,
@@ -94,7 +94,7 @@ namespace SharpGLTF.Schema2
             var settings = new WriteSettings()
             var settings = new WriteSettings()
             {
             {
                 BinaryMode = false,
                 BinaryMode = false,
-                ImageWriting = ImageWriteMode.SatelliteFile,
+                ImageWriting = ResourceWriteMode.SatelliteFile,
                 MergeBuffers = false,
                 MergeBuffers = false,
                 JsonFormatting = Formatting.None,
                 JsonFormatting = Formatting.None,
                 _UpdateSupportedExtensions = true,
                 _UpdateSupportedExtensions = true,
@@ -114,7 +114,7 @@ namespace SharpGLTF.Schema2
             var settings = new WriteSettings
             var settings = new WriteSettings
             {
             {
                 BinaryMode = true,
                 BinaryMode = true,
-                ImageWriting = ImageWriteMode.BufferView,
+                ImageWriting = ResourceWriteMode.BufferView,
                 MergeBuffers = true,
                 MergeBuffers = true,
                 JsonFormatting = Formatting.None,
                 JsonFormatting = Formatting.None,
                 _UpdateSupportedExtensions = true,
                 _UpdateSupportedExtensions = true,
@@ -133,7 +133,7 @@ namespace SharpGLTF.Schema2
             var settings = new WriteSettings
             var settings = new WriteSettings
             {
             {
                 BinaryMode = true,
                 BinaryMode = true,
-                ImageWriting = ImageWriteMode.BufferView,
+                ImageWriting = ResourceWriteMode.BufferView,
                 MergeBuffers = true,
                 MergeBuffers = true,
                 JsonFormatting = Formatting.None,
                 JsonFormatting = Formatting.None,
                 _UpdateSupportedExtensions = true,
                 _UpdateSupportedExtensions = true,
@@ -143,9 +143,7 @@ namespace SharpGLTF.Schema2
 
 
             return settings;
             return settings;
         }
         }
-
-        private WriteSettings() { }
-
+        
         #endregion
         #endregion
 
 
         #region data
         #region data
@@ -158,7 +156,7 @@ namespace SharpGLTF.Schema2
         /// <summary>
         /// <summary>
         /// Gets or sets a value indicating how to write the images of the model.
         /// Gets or sets a value indicating how to write the images of the model.
         /// </summary>
         /// </summary>
-        public ImageWriteMode ImageWriting { get; set; }
+        public ResourceWriteMode ImageWriting { get; set; }
 
 
         /// <summary>
         /// <summary>
         /// Gets or sets a value indicating whether to merge all the buffers in <see cref="MODEL.LogicalBuffers"/> into a single buffer.
         /// Gets or sets a value indicating whether to merge all the buffers in <see cref="MODEL.LogicalBuffers"/> into a single buffer.
@@ -203,7 +201,7 @@ namespace SharpGLTF.Schema2
 
 
             var needsMergeBuffers = (this.MergeBuffers | this.BinaryMode) && model.LogicalBuffers.Count > 1;
             var needsMergeBuffers = (this.MergeBuffers | this.BinaryMode) && model.LogicalBuffers.Count > 1;
 
 
-            var imagesAsBufferViews = model.LogicalImages.Count > 0 && this.ImageWriting == ImageWriteMode.BufferView;
+            var imagesAsBufferViews = model.LogicalImages.Count > 0 && this.ImageWriting == ResourceWriteMode.BufferView;
 
 
             if (needsMergeBuffers | imagesAsBufferViews)
             if (needsMergeBuffers | imagesAsBufferViews)
             {
             {
@@ -211,7 +209,7 @@ namespace SharpGLTF.Schema2
                 model = model.DeepClone();
                 model = model.DeepClone();
             }
             }
 
 
-            if (ImageWriting == ImageWriteMode.BufferView)
+            if (ImageWriting == ResourceWriteMode.BufferView)
             {
             {
                 model.MergeImages();
                 model.MergeImages();
                 needsMergeBuffers |= this.MergeBuffers | this.BinaryMode;
                 needsMergeBuffers |= this.MergeBuffers | this.BinaryMode;
@@ -399,7 +397,7 @@ namespace SharpGLTF.Schema2
             {
             {
                 var image = model._images[i];
                 var image = model._images[i];
                 var iname = model._images.Count != 1 ? $"{baseName}_{i}" : $"{baseName}";
                 var iname = model._images.Count != 1 ? $"{baseName}_{i}" : $"{baseName}";
-                if (settings.ImageWriting != ImageWriteMode.SatelliteFile) image._WriteToInternal();
+                if (settings.ImageWriting != ResourceWriteMode.SatelliteFile) image._WriteToInternal();
                 else image._WriteToSatellite(settings.FileWriter, iname);
                 else image._WriteToSatellite(settings.FileWriter, iname);
             }
             }
 
 

+ 1 - 1
src/SharpGLTF.Toolkit/Geometry/MeshBuilderToolkit.cs

@@ -86,7 +86,7 @@ namespace SharpGLTF.Geometry
         {
         {
             var posnrm = new Dictionary<Vector3, Vector3>();
             var posnrm = new Dictionary<Vector3, Vector3>();
 
 
-            static void addDirection(Dictionary<Vector3, Vector3> dict, Vector3 pos, Vector3 dir)
+            void addDirection(Dictionary<Vector3, Vector3> dict, Vector3 pos, Vector3 dir)
             {
             {
                 if (!dir._IsFinite()) return;
                 if (!dir._IsFinite()) return;
                 if (!dict.TryGetValue(pos, out Vector3 n)) n = Vector3.Zero;
                 if (!dict.TryGetValue(pos, out Vector3 n)) n = Vector3.Zero;