vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
457 stars 72 forks source link

Extras Encoding #100

Closed Zhuangkh closed 3 years ago

Zhuangkh commented 3 years ago

I use string dictionary (like {"Hello":"你好"}) to construct JsonContent, and try to skip escaping by setting the Encoder property of JsonSerializerOptions to JavaScriptEncoder.UnsafeRelaxedJsonEscaping.

But when I finally generated the Gltf file, it was still escaped as {"Hello":"\u4f60\u597d"}.

Is there any setting available to solve this problem?😭

vpenades commented 3 years ago

Hmmm.... the Extras uses its own encoder so you can interact with the extras at many levels.... BUT.... the glTF writer uses its own encoder.... and right now I haven't exposed any json options other than indenting, so right now I don't think it's possible to fix this on your own.

So it's probably a bug on my side; certainly you have to be able to write non ascii characters, so I'll look into it.

Zhuangkh commented 3 years ago

Maybe add an Encoder property to WriteSettings?

vpenades commented 3 years ago

Maybe add an Encoder property to WriteSettings?

It's not that easy: the json settings cannot be applied selectively, so a setting that would fix your issue, maybe it could break the texture URIs.

I've forwarded this issue to the khronos gltf board to ask which is the expected behaviour on this issue.

vpenades commented 3 years ago

@Zhuangkh It took a while, but I finally got an answer. It was also specified in the schema, but for some reason I missed it:

https://github.com/KhronosGroup/glTF/issues/1978#issuecomment-831624406

Still checking whether it's allowed...

vpenades commented 3 years ago

@Zhuangkh Okey, after talking with people from glTF board, I understand writing chinese characters to the json file would be allowed, except for URIs, which would still require escaped characters.

You can find the changes in this commit.

Also, there's a unit test showcasing how to configure the write settings to allow extended characters here.

Zhuangkh commented 3 years ago

I have seen the relevant issues discussed.

Thank you for your work!