瀏覽代碼

Reorganized Punctual Lights code

Vicente Penades 4 年之前
父節點
當前提交
13db0e3c63

+ 1 - 1
src/SharpGLTF.Core/Schema2/Generated/ext.ModelLightsPunctual.g.cs

@@ -106,7 +106,7 @@ namespace SharpGLTF.Schema2
 	
 	}
 
-	partial class KHR_lights_punctualglTFextension : ExtraProperties
+	partial class _ModelPunctualLights : ExtraProperties
 	{
 	
 		private const int _lightsMinItems = 1;

+ 1 - 1
src/SharpGLTF.Core/Schema2/Generated/ext.NodeLightsPunctual.g.cs

@@ -27,7 +27,7 @@ namespace SharpGLTF.Schema2
 {
 	using Collections;
 
-	partial class KHR_lights_punctualnodeextension : ExtraProperties
+	partial class _NodePunctualLight : ExtraProperties
 	{
 	
 		private Int32 _light;

+ 52 - 0
src/SharpGLTF.Core/Schema2/gltf.Node.PunctualLight.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SharpGLTF.Schema2
+{
+    partial class _NodePunctualLight
+    {
+        #pragma warning disable CA1801 // Review unused parameters
+        internal _NodePunctualLight(Node node) { }
+        #pragma warning restore CA1801 // Review unused parameters
+
+        public int LightIndex
+        {
+            get => _light;
+            set => _light = value;
+        }
+    }
+
+    partial class Node
+    {
+        /// <summary>
+        /// Gets or sets the <see cref="Schema2.PunctualLight"/> of this <see cref="Node"/>.
+        /// </summary>
+        /// <remarks>
+        /// This is part of <see href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual"/> extension.
+        /// </remarks>
+        public PunctualLight PunctualLight
+        {
+            get
+            {
+                var ext = this.GetExtension<_NodePunctualLight>();
+                if (ext == null) return null;
+
+                return this.LogicalParent.LogicalPunctualLights[ext.LightIndex];
+            }
+            set
+            {
+                if (value == null) { this.RemoveExtensions<_NodePunctualLight>(); return; }
+
+                Guard.MustShareLogicalParent(this, value, nameof(value));
+
+                // this.UsingExtension(typeof(_NodePunctualLight));
+
+                var ext = new _NodePunctualLight(this);
+                ext.LightIndex = value.LogicalIndex;
+
+                this.SetExtension(ext);
+            }
+        }
+    }
+}

+ 2 - 126
src/SharpGLTF.Core/Schema2/khr.lights.cs → src/SharpGLTF.Core/Schema2/gltf.PunctualLight.cs

@@ -1,37 +1,11 @@
 using System;
 using System.Collections.Generic;
-using System.Numerics;
 using System.Linq;
-
-using SharpGLTF.Collections;
+using System.Numerics;
+using System.Text;
 
 namespace SharpGLTF.Schema2
 {
-    partial class KHR_lights_punctualglTFextension
-    {
-        internal KHR_lights_punctualglTFextension(ModelRoot root)
-        {
-            _lights = new ChildrenCollection<PunctualLight, ModelRoot>(root);
-        }
-
-        protected override IEnumerable<ExtraProperties> GetLogicalChildren()
-        {
-            return base.GetLogicalChildren().Concat(_lights);
-        }
-
-        public IReadOnlyList<PunctualLight> Lights => _lights;
-
-        public PunctualLight CreateLight(string name, PunctualLightType ltype)
-        {
-            var light = new PunctualLight(ltype);
-            light.Name = name;
-
-            _lights.Add(light);
-
-            return light;
-        }
-    }
-
     /// <summary>
     /// Defines all the types of <see cref="PunctualLight"/> types.
     /// </summary>
@@ -233,102 +207,4 @@ namespace SharpGLTF.Schema2
             base.OnValidateContent(validate);
         }
     }
-
-    partial class KHR_lights_punctualnodeextension
-    {
-        #pragma warning disable CA1801 // Review unused parameters
-        internal KHR_lights_punctualnodeextension(Node node) { }
-        #pragma warning restore CA1801 // Review unused parameters
-
-        public int LightIndex
-        {
-            get => _light;
-            set => _light = value;
-        }
-    }
-
-    partial class Node
-    {
-        /// <summary>
-        /// Gets or sets the <see cref="Schema2.PunctualLight"/> of this <see cref="Node"/>.
-        /// </summary>
-        /// <remarks>
-        /// This is part of <see href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual"/> extension.
-        /// </remarks>
-        public PunctualLight PunctualLight
-        {
-            get
-            {
-                var ext = this.GetExtension<KHR_lights_punctualnodeextension>();
-                if (ext == null) return null;
-
-                return this.LogicalParent.LogicalPunctualLights[ext.LightIndex];
-            }
-            set
-            {
-                if (value == null) { this.RemoveExtensions<KHR_lights_punctualnodeextension>(); return; }
-
-                Guard.MustShareLogicalParent(this, value, nameof(value));
-
-                this.UsingExtension(typeof(KHR_lights_punctualnodeextension));
-
-                var ext = new KHR_lights_punctualnodeextension(this);
-                ext.LightIndex = value.LogicalIndex;
-
-                this.SetExtension(ext);
-            }
-        }
-    }
-
-    partial class ModelRoot
-    {
-        /// <summary>
-        /// Gets A collection of <see cref="PunctualLight"/> instances.
-        /// </summary>
-        /// <remarks>
-        /// This is part of <see href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual">KHR_lights_punctual</see> extension.
-        /// </remarks>
-        public IReadOnlyList<PunctualLight> LogicalPunctualLights
-        {
-            get
-            {
-                var ext = this.GetExtension<KHR_lights_punctualglTFextension>();
-                if (ext == null) return Array.Empty<PunctualLight>();
-
-                return ext.Lights;
-            }
-        }
-
-        /// <summary>
-        /// Creates a new <see cref="PunctualLight"/> instance and
-        /// adds it to <see cref="ModelRoot.LogicalPunctualLights"/>.
-        /// </summary>
-        /// <param name="lightType">A value of <see cref="PunctualLightType"/> describing the type of light to create.</param>
-        /// <returns>A <see cref="PunctualLight"/> instance.</returns>
-        public PunctualLight CreatePunctualLight(PunctualLightType lightType)
-        {
-            return CreatePunctualLight(null, lightType);
-        }
-
-        /// <summary>
-        /// Creates a new <see cref="PunctualLight"/> instance.
-        /// and adds it to <see cref="ModelRoot.LogicalPunctualLights"/>.
-        /// </summary>
-        /// <param name="name">The name of the instance.</param>
-        /// <param name="lightType">A value of <see cref="PunctualLightType"/> describing the type of light to create.</param>
-        /// <returns>A <see cref="PunctualLight"/> instance.</returns>
-        public PunctualLight CreatePunctualLight(string name, PunctualLightType lightType)
-        {
-            var ext = this.GetExtension<KHR_lights_punctualglTFextension>();
-            if (ext == null)
-            {
-                this.UsingExtension(typeof(ModelRoot), typeof(KHR_lights_punctualglTFextension));
-
-                ext = new KHR_lights_punctualglTFextension(this);
-                this.SetExtension(ext);
-            }
-
-            return ext.CreateLight(name, lightType);
-        }
-    }
 }

+ 86 - 0
src/SharpGLTF.Core/Schema2/gltf.Root.PunctualLights.cs

@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Numerics;
+using System.Linq;
+
+using SharpGLTF.Collections;
+
+namespace SharpGLTF.Schema2
+{
+    partial class _ModelPunctualLights
+    {
+        internal _ModelPunctualLights(ModelRoot root)
+        {
+            _lights = new ChildrenCollection<PunctualLight, ModelRoot>(root);
+        }
+
+        protected override IEnumerable<ExtraProperties> GetLogicalChildren()
+        {
+            return base.GetLogicalChildren().Concat(_lights);
+        }
+
+        public IReadOnlyList<PunctualLight> Lights => _lights;
+
+        public PunctualLight CreateLight(string name, PunctualLightType ltype)
+        {
+            var light = new PunctualLight(ltype);
+            light.Name = name;
+
+            _lights.Add(light);
+
+            return light;
+        }
+    }
+
+    partial class ModelRoot
+    {
+        /// <summary>
+        /// Gets A collection of <see cref="PunctualLight"/> instances.
+        /// </summary>
+        /// <remarks>
+        /// This is part of <see href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual">KHR_lights_punctual</see> extension.
+        /// </remarks>
+        public IReadOnlyList<PunctualLight> LogicalPunctualLights
+        {
+            get
+            {
+                var ext = this.GetExtension<_ModelPunctualLights>();
+                if (ext == null) return Array.Empty<PunctualLight>();
+
+                return ext.Lights;
+            }
+        }
+
+        /// <summary>
+        /// Creates a new <see cref="PunctualLight"/> instance and
+        /// adds it to <see cref="ModelRoot.LogicalPunctualLights"/>.
+        /// </summary>
+        /// <param name="lightType">A value of <see cref="PunctualLightType"/> describing the type of light to create.</param>
+        /// <returns>A <see cref="PunctualLight"/> instance.</returns>
+        public PunctualLight CreatePunctualLight(PunctualLightType lightType)
+        {
+            return CreatePunctualLight(null, lightType);
+        }
+
+        /// <summary>
+        /// Creates a new <see cref="PunctualLight"/> instance.
+        /// and adds it to <see cref="ModelRoot.LogicalPunctualLights"/>.
+        /// </summary>
+        /// <param name="name">The name of the instance.</param>
+        /// <param name="lightType">A value of <see cref="PunctualLightType"/> describing the type of light to create.</param>
+        /// <returns>A <see cref="PunctualLight"/> instance.</returns>
+        public PunctualLight CreatePunctualLight(string name, PunctualLightType lightType)
+        {
+            var ext = this.GetExtension<_ModelPunctualLights>();
+            if (ext == null)
+            {
+                this.UsingExtension(typeof(ModelRoot), typeof(_ModelPunctualLights));
+
+                ext = new _ModelPunctualLights(this);
+                this.SetExtension(ext);
+            }
+
+            return ext.CreateLight(name, lightType);
+        }
+    }
+}