Add support for importing and exporting GLB version 3 files#905
Open
aaronfranke wants to merge 6 commits into
Open
Add support for importing and exporting GLB version 3 files#905aaronfranke wants to merge 6 commits into
aaronfranke wants to merge 6 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the ability for UnityGLTF to import and export 64-bit glTF binary format version 3 files. This GLB version 3 format is being defined as part of glTF 2.1, but the format itself is not tied to glTF 2.1: you can use a version 2 file to hold glTF 2.1 data, or use a version 3 file to hold glTF 2.0 data. It's this latter case which this PR supports. KhronosGroup/glTF#2594
This is not all of the changes to the
.glbformat that will be required for glTF 2.1. There will also be a more flexible chunk layout and support for multiple binary chunks. However, that will require changes to the parsing of the actual glTF JSON data as well, and that part has not yet been standardized, and I want to try and avoid sending in a massive unreviewable blob of all the changes all at once (this PR is already super big as it is), so I am submitting this PR to just add support for GLB version 3 with the same layout.For easy reviewability, I split this PR into 6 commits. Let me know if you'd like me to open separate PRs for these:
Noisy whitespace-only changes
Fix a lot of typos
var vec in arrfollowed byvect.x, fixed tovec.x).childs->children,remaks->remarks,desintation->destination,UNIYT->UNITY.Rename and relocate several things for clarity
ChunkOffsettoChunkDataOffsetto clarify that this points to the chunk's data, not the chunk header.ChunkFormattoGLBChunkFormatto clarify it's about GLB specifically.ChunkInfotoGLBChunkInfoto clarify it's about GLB specifically.GLBChunkFormat,GLBHeader, andGLBChunkInfotoGLBObject.csinstead ofGLBParser.cs.HEADER_SIZEtoGLB2_FILE_HEADER_SIZEand move toGLBHeader.CHUNK_HEADER_SIZEtoGLB2_CHUNK_HEADER_SIZEand move toGLBHeader.MAGIC_NUMBERtoGLTF_MAGIC_NUMBERand move toGLBHeaderand deduplicate with other cases of this magic number in 2 other places.headervariables toglbHeaderto avoid confusion with the chunk header.ParseJsonChunktoParseJsonChunkAndFileHeaderbecause it does both of those things.SeekToBinaryChunktoSeekToBinaryChunkDatabecause it seeks past the header.Upgrade data type for sizes, lengths, offsets, set to 64-bit
long.gltffiles even with glTF 2.0, we need to use 64-bit values for sizes.longtype is preferred over the unsigned variant for general use for several reasons: alignment with C# Stream API, alignment with GLB version 3 having the most-significant bit of the size always zero, avoiding underflow with negative numbers and subtraction, and ability to use -1 as a sentinel value.ReadDoubleAsUInt64, addsGetUInt64, and adds a check toGetUInt32.AlignToBoundary.Support importing GLB version 3 files
GLBHeaderto allow the version to be taken into consideration.int binaryChunkIndexparameter inSeekToBinaryChunkDatato actually use binary chunk indices, not buffer indices under the wrong name. Removed the TODO comment.Support exporting GLB version 3 files
GLBHeaderand use its functions instead of constants.I tested both the import and export code with Unity 6000.5.0f1 on macOS. I tested importing test files generated by UnityGLTF, glTFast, and Godot Engine, and all work.
I made a similar PR to glTFast: Unity-Technologies/com.unity.cloud.gltfast#51