User extensions: empty collections and null
See original GitHub issueAny key-value pair whose value is {}
, []
, or None
gets scrubbed out of the glTF data when exporting. That means a user-extension can’t do things like this:
"extensions": { "KHR_materials_unlit": {} }
// gets turned into "extensions": {}
"extensions": { "my_ext": { "foo": [] } }
// gets turned into "extensions": { "my_ext": {} }
The way the in-tree code works around this is to use a hard-coded whitelist of key-names that shouldn’t be scrubbed.
That’s not very flexible and it doesn’t help user extensions anyway. Here’s my proposed fix:
-
Add some new objects you should use wherever you want an empty collection/null
EmptyDict = object() # use this where you want an empty dict EmptyList = object() # use this where you want an empty list Null = object() # use this where you want a null
-
Make
from_extension
believe thatEmptyDict
is a dict so it will allow it in the"extensions"
object. -
Change
__fix_json
to convertEmptyDict
into{}
etc. Get rid of the whitelist. -
Wherever you want to put an empty dict, just use
EmptyDict
instead. Example:extensions['KHR_materials_unlit'] = Extension( 'KHR_materials_unlit', EmptyDict, required=False, )
What’s everyone think?
cc @jjcasmar
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Ways of handling null collections and AddRange
I could use Enumerable.Empty() which will only allocate a new array the first time around, but that just isn't as neat and tidy....
Read more >How to create an Extension method for a list to return null if ...
I have multiple lists of different objects. for all objects I want to return null if it's an empty list or ...
Read more >How to Implement Lazy Default-If-Empty Functionality on ...
Solution to the problem is to provide custom implementation for the DefaultIfEmpty extension method, which receives a lambda instead of actual ...
Read more >Empty arrays and collections should be returned instead of ...
In-IDE. Code Quality and Security in your IDE with SonarLint. IDE extension that lets you fix coding issues before they exist! Discover SonarLint ......
Read more >null - JavaScript - MDN Web Docs - Mozilla
The null value represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
They just do it the same way they import everything else
I agree. I have the same doubts when I first looks at the __fix_json. I think your solution is a good one.