Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Editor/Scripts/GLTFExportMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,14 @@ private static bool Export(ExportBatch batch, bool binary, bool askForLocation)
{
var sceneName = batch.sceneName;
var ext = binary ? ".glb" : ".gltf";
bool allowExporting64BitGLB = settings.AllowExporting64BitGLB;
var resultFile = GLTFSceneExporter.GetFileName(path, sceneName, ext);
settings.SaveFolderPath = path;
// Prefer saving as GLB version 2 for compatibility.
int glbVersion = allowExporting64BitGLB ? -1 : 2; // -1 means "auto".

if (binary)
exporter.SaveGLB(path, sceneName);
exporter.SaveGLB(path, sceneName, glbVersion);
else
exporter.SaveGLTFandBin(path, sceneName);

Expand Down
4 changes: 2 additions & 2 deletions Editor/Scripts/GLTFImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public class AnimationClipImportInfo
// public float endTime;
}

#if !UNIYT_2020_2_OR_NEWER
#if !UNITY_2020_2_OR_NEWER
private class NonReorderableAttribute : Attribute {}
#endif

Expand Down Expand Up @@ -761,7 +761,7 @@ string GetUniqueName(string desiredName)
foreach (var mat in materials)
{
if (!mat) continue;
// ensure materials that are overriden aren't shown in the hierarchy.
// ensure materials that are overridden aren't shown in the hierarchy.
var si = new SourceAssetIdentifier(mat);
if (map.TryGetValue(si, out var remappedMaterial) && remappedMaterial)
mat.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Plugins/GLTFSerialization/AttributeAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AttributeAccessor
public NumericArray AccessorContent { get; set; }

public NativeArray<byte> bufferData { get; set; }
public uint Offset { get; set; }
public long Offset { get; set; }

public AttributeAccessor()
{
Expand Down
213 changes: 117 additions & 96 deletions Runtime/Plugins/GLTFSerialization/GLBBuilder.cs

Large diffs are not rendered by default.

50 changes: 43 additions & 7 deletions Runtime/Plugins/GLTFSerialization/GLBObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@

namespace GLTF
{
public enum GLBChunkFormat : uint
{
JSON = 0x4e4f534a, // ASCII string "JSON" in little-endian order.
BIN = 0x004e4942 // ASCII string "BIN\0" in little-endian order.
}

/// <summary>
/// Information containing parsed GLB Header
/// </summary>
public struct GLBHeader
{
public uint Version { get; set; }
public long FileLength { get; set; }

public long GetFileHeaderSize() => Version == 2 ? 12 : 16;
public long GetChunkHeaderSize() => Version == 2 ? 8 : 16;
public long GetAlignment() => Version == 2 ? 4 : 8;
public long GetAlignmentBitmask() => Version == 2 ? 3 : 7;

/// <summary>
/// ASCII string "glTF" in little-endian order.
/// </summary>
public static readonly uint GLTF_MAGIC_NUMBER = 0x46546C67;
}

/// <summary>
/// Information that contains parsed chunk
/// </summary>
public struct GLBChunkInfo
{
public long StartPosition;
public long Length;
public GLBChunkFormat Type;
public uint Encoding;
}

/// <summary>
/// Objects containing GLB data and associated parsing information
/// </summary>
Expand Down Expand Up @@ -41,22 +77,22 @@ public GLBObject(GLBObject other)
/// <summary>
/// Information on JSON chunk
/// </summary>
public ChunkInfo JsonChunkInfo { get { return _jsonChunkInfo; } internal set { _jsonChunkInfo = value; } }
public GLBChunkInfo JsonChunkInfo { get { return _jsonChunkInfo; } internal set { _jsonChunkInfo = value; } }

/// <summary>
/// Information on Binary chunk
/// </summary>
public ChunkInfo BinaryChunkInfo { get { return _binaryChunkInfo; } internal set { _binaryChunkInfo = value; } }
public GLBChunkInfo BinaryChunkInfo { get { return _binaryChunkInfo; } internal set { _binaryChunkInfo = value; } }

private GLBHeader _glbHeader;
private ChunkInfo _jsonChunkInfo;
private ChunkInfo _binaryChunkInfo;
private GLBChunkInfo _jsonChunkInfo;
private GLBChunkInfo _binaryChunkInfo;

internal GLBObject()
{
}

internal void SetFileLength(uint newHeaderLength)
internal void SetFileLength(long newHeaderLength)
{
_glbHeader.FileLength = newHeaderLength;
}
Expand All @@ -66,7 +102,7 @@ internal void SetJsonChunkStartPosition(long startPosition)
_jsonChunkInfo.StartPosition = startPosition;
}

internal void SetJsonChunkLength(uint jsonChunkLength)
internal void SetJsonChunkLength(long jsonChunkLength)
{
_jsonChunkInfo.Length = jsonChunkLength;
}
Expand All @@ -76,7 +112,7 @@ internal void SetBinaryChunkStartPosition(long startPosition)
_binaryChunkInfo.StartPosition = startPosition;
}

internal void SetBinaryChunkLength(uint binaryChunkLength)
internal void SetBinaryChunkLength(long binaryChunkLength)
{
_binaryChunkInfo.Length = binaryChunkLength;
if (Root.Buffers == null)
Expand Down
10 changes: 5 additions & 5 deletions Runtime/Plugins/GLTFSerialization/GLTFHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using GLTF.Schema;
Expand Down Expand Up @@ -442,7 +442,7 @@ public static void BuildAnimationSamplers(ref Dictionary<string, List<AttributeA

/// <summary>
/// Merges the right root into the left root
/// This function combines all of the lists of objects on each glTF root together and updates the relative indicies
/// This function combines all of the lists of objects on each glTF root together and updates the relative indices
/// All properties all merged except Asset and Default, which will stay "mergeToRoot"'s value
/// </summary>
/// <param name="mergeToRoot">The node to merge into</param>
Expand Down Expand Up @@ -475,7 +475,7 @@ public static void MergeGLTF(GLTFRoot mergeToRoot, GLTFRoot mergeFromRoot)
// merge extensions
MergeExtensions(mergeToRoot, mergeFromRootCopy);

// merge accessors, buffers, and bufferviews
// merge accessors, buffers, and buffer views
MergeAccessorsBufferViewsAndBuffers(mergeToRoot, mergeFromRootCopy, previousGLTFSize);

// merge materials, samplers, images, and textures
Expand Down Expand Up @@ -522,7 +522,7 @@ private static void LoadBufferView(AttributeAccessor attributeAccessor, out Nati
LoadBufferView(attributeAccessor.AccessorId.Value.BufferView?.Value, attributeAccessor.Offset, attributeAccessor.bufferData, out bufferViewCache);
}

internal static void LoadBufferView(BufferView bufferView, uint Offset, NativeArray<byte> nativeBuffer, out NativeArray<byte> bufferViewCache)
internal static void LoadBufferView(BufferView bufferView, long Offset, NativeArray<byte> nativeBuffer, out NativeArray<byte> bufferViewCache)
{
// The bufferView can be null for sparse buffers with just a count.
// In that case, this is a buffer padded with zeros, so we can just return the nativeBuffer.
Expand All @@ -532,7 +532,7 @@ internal static void LoadBufferView(BufferView bufferView, uint Offset, NativeAr
return;
}

uint totalOffset = bufferView.ByteOffset + Offset;
long totalOffset = bufferView.ByteOffset + Offset;
bufferViewCache = nativeBuffer.GetSubArray((int)totalOffset, (int)bufferView.ByteLength);
}

Expand Down
Loading