@@ -80,38 +80,7 @@ static ExtensionsFactory()
8080
8181 public static IEnumerable < string > SupportedExtensions => _Extensions
8282 . Select ( item => item . Name )
83- . Concat ( new [ ] { "KHR_mesh_quantization" } ) ; // special case because it's a "typeless" extension.
84-
85- /// <summary>
86- /// Registers a new extensions to be used globally.
87- /// </summary>
88- /// <typeparam name="TParent">The parent type to which this extension is attached.</typeparam>
89- /// <typeparam name="TExtension">The extension type.</typeparam>
90- /// <param name="persistentName">The extension name.</param>
91- /// <remarks>
92- /// The <paramref name="persistentName"/> is the value used for serialization<br/>
93- /// and it must meet <see href="https://github.com/KhronosGroup/glTF/blob/master/extensions/Prefixes.md">extension naming constraints</see>.
94- /// </remarks>
95- [ Obsolete ( "Use RegisterExtension(name, factory) instead." ) ]
96- public static void RegisterExtension
97- < TParent ,
98- #if NET6_0_OR_GREATER
99- [ DYNAMICMEMBERS ( DYNAMICCONSTRUCTORS ) ]
100- #endif
101- TExtension >
102- ( string persistentName )
103- where TParent : JsonSerializable
104- where TExtension : JsonSerializable
105- {
106- Guard . NotNullOrEmpty ( persistentName , nameof ( persistentName ) ) ;
107- Guard . MustBeNull ( Identify ( typeof ( TParent ) , typeof ( TExtension ) ) , $ "{ nameof ( TExtension ) } already registered for { nameof ( TParent ) } ") ;
108-
109- // TODO: check that persistentName has a valid extension name.
110-
111- var ext = ExtensionEntry . Create < TParent , TExtension > ( persistentName ) ;
112-
113- _Extensions . Add ( ext ) ;
114- }
83+ . Concat ( new [ ] { "KHR_mesh_quantization" } ) ; // special case because it's a "typeless" extension.
11584
11685 /// <summary>
11786 /// Registers a new extensions to be used globally.
@@ -126,7 +95,7 @@ public static void RegisterExtension
12695 /// </remarks>
12796 public static void RegisterExtension < TParent , TExtension > ( string persistentName , Func < TParent , JsonSerializable > factory )
12897 where TParent : JsonSerializable
129- where TExtension : JsonSerializable
98+ where TExtension : ExtensionBase
13099 {
131100 Guard . NotNullOrEmpty ( persistentName , nameof ( persistentName ) ) ;
132101 Guard . MustBeNull ( Identify ( typeof ( TParent ) , typeof ( TExtension ) ) , $ "{ nameof ( TExtension ) } already registered for { nameof ( TParent ) } ") ;
@@ -299,13 +268,11 @@ internal void UpdateExtensionsSupport()
299268 if ( string . IsNullOrWhiteSpace ( id ) ) continue ;
300269
301270 bool isRequired = false ;
302-
303- #pragma warning disable GLTF1001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
304- if ( ext is IExtensionTypeInfo extInfo )
271+
272+ if ( ext is ExtensionBase extInfo )
305273 {
306274 isRequired = extInfo . CheckIsRequiredExtension ( c ) ;
307- }
308- #pragma warning restore GLTF1001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
275+ }
309276
310277 if ( exts . TryGetValue ( id , out var stored ) ) { isRequired |= stored ; }
311278
@@ -344,21 +311,15 @@ internal void _ValidateExtensions(Validation.ValidationContext validate)
344311 }
345312
346313 /// <summary>
347- /// Implemented by extensions
314+ /// Base class for extensions
348315 /// </summary>
349- #if NET8_0_OR_GREATER
350- [ Experimental ( "GLTF1001" ) ] // I might move this functionality to an "ExtensionBase" class
351- #endif
352- public interface IExtensionTypeInfo
316+ public abstract class ExtensionBase : ExtraProperties
353317 {
354- /// <summary>
355- /// Checks whether the extension instance implementing this interface should be tagged as required.
356- /// </summary>
357- /// <param name="extensionOwner">the owner of the extension</param>
358- /// <returns>true if the extension should be tagged as required</returns>
359- /// <remarks>
360- /// This is called just before saving the model.
361- /// </remarks>
362- public bool CheckIsRequiredExtension ( ExtraProperties extensionOwner ) ;
363- }
318+ protected ExtensionBase ( ) { }
319+
320+ public virtual bool CheckIsRequiredExtension ( ExtraProperties extensionOwner )
321+ {
322+ return false ;
323+ }
324+ }
364325}
0 commit comments