Просмотр исходного кода

Added public constructors for LightBuilder. Fixes #161

Vicente Penades 3 лет назад
Родитель
Сommit
9be252325c

+ 2 - 2
src/SharpGLTF.Core/Schema2/gltf.PunctualLight.cs

@@ -105,13 +105,13 @@ namespace SharpGLTF.Schema2
         /// Gets the Angle, in radians, from centre of spotlight where falloff begins.
         /// Must be greater than or equal to 0 and less than outerConeAngle.
         /// </summary>
-        public Single InnerConeAngle => this._spot == null ? 0 : (Single)this._spot.InnerConeAngle;
+        public Single InnerConeAngle => this._spot?.InnerConeAngle ?? 0;
 
         /// <summary>
         /// Gets Angle, in radians, from centre of spotlight where falloff ends.
         /// Must be greater than innerConeAngle and less than or equal to PI / 2.0.
         /// </summary>
-        public Single OuterConeAngle => this._spot == null ? 0 : (Single)this._spot.OuterConeAngle;
+        public Single OuterConeAngle => this._spot?.OuterConeAngle ?? 0;
 
         /// <summary>
         /// Gets or sets the RGB value for light's color in linear space.

+ 31 - 2
src/SharpGLTF.Toolkit/Scenes/LightBuilder.cs

@@ -10,7 +10,12 @@ namespace SharpGLTF.Scenes
     /// </summary>
     public abstract class LightBuilder : BaseBuilder
     {
-        #region lifecycle
+        #region lifecycle        
+        protected LightBuilder()
+        {
+            this.Color = Vector3.One;
+            this.Intensity = 1f;
+        }
 
         protected LightBuilder(Schema2.PunctualLight light)
         {
@@ -61,8 +66,16 @@ namespace SharpGLTF.Scenes
         public sealed class Directional : LightBuilder
         {
             #region lifecycle
+
+            public Directional()
+                : base()
+            { }
+
             internal Directional(Schema2.PunctualLight light)
-                : base(light) { }
+                : base(light)
+            {
+                System.Diagnostics.Debug.Assert(light.LightType == Schema2.PunctualLightType.Directional);
+            }
 
             public override LightBuilder Clone()
             {
@@ -81,9 +94,16 @@ namespace SharpGLTF.Scenes
         {
             #region lifecycle
 
+            public Point()
+                : base()
+            {
+                this.Range = float.PositiveInfinity;
+            }
+
             internal Point(Schema2.PunctualLight light)
                 : base(light)
             {
+                System.Diagnostics.Debug.Assert(light.LightType == Schema2.PunctualLightType.Point);
                 this.Range = light.Range;
             }
 
@@ -119,9 +139,18 @@ namespace SharpGLTF.Scenes
         {
             #region lifecycle
 
+            public Spot()
+                : base()
+            {
+                this.Range = float.PositiveInfinity;
+                this.InnerConeAngle = 0;
+                this.OuterConeAngle = 0.7853981633974483f;
+            }
+
             internal Spot(Schema2.PunctualLight light)
                 : base(light)
             {
+                System.Diagnostics.Debug.Assert(light.LightType == Schema2.PunctualLightType.Spot);
                 this.Range = light.Range;
                 this.InnerConeAngle = light.InnerConeAngle;
                 this.OuterConeAngle = light.OuterConeAngle;