Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement gltf loading #3

Merged
merged 27 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2d5cf14
Create Gltf format projects
B3zaleel May 21, 2024
8fa7e6a
Create Gltf elements
B3zaleel May 21, 2024
627bd2e
Create Gltf root element
B3zaleel May 21, 2024
4a0e60c
Create a class that stores Gltf default values
B3zaleel May 21, 2024
50a1630
Create element reader representations and a GltfReader context to pro…
B3zaleel May 21, 2024
182b05a
Create Utf8JsonReader helpers for reading Gltf content
B3zaleel May 21, 2024
d2cff84
Create a Gltf extension handler representation
B3zaleel May 21, 2024
e3ba684
Implement the extensions' serialization reader
B3zaleel May 21, 2024
107de9f
Create an unimplemented extras' serialization reader
B3zaleel May 21, 2024
c5f0567
Implement an integer map's serialization reader
B3zaleel May 21, 2024
e6478b9
Implement an image's serialization reader
B3zaleel May 21, 2024
1e08660
Implement a material's serialization reader
B3zaleel May 21, 2024
771956e
Implement a node's serialization reader
B3zaleel May 21, 2024
82be48d
Implement a sampler's serialization reader
B3zaleel May 21, 2024
d3c8d13
Implement a scene's serialization reader
B3zaleel May 21, 2024
cc960af
Implement a skin's serialization reader
B3zaleel May 21, 2024
c52c645
Implement a texture's serialization reader
B3zaleel May 21, 2024
8eb0b12
Implement a camera's serialization reader
B3zaleel May 21, 2024
eddeeac
Implement a buffer's serialization reader
B3zaleel May 21, 2024
cabd7cd
Implement an asset's serialization reader
B3zaleel May 21, 2024
f0a1d66
Implement an animation's serialization reader
B3zaleel May 21, 2024
93dc764
Implement an accessor's serialization reader
B3zaleel May 21, 2024
980b88f
Implement a buffer view's serialization reader
B3zaleel May 21, 2024
338afe1
Implement a mesh's serialization reader
B3zaleel May 21, 2024
f286754
Add additional chunks to Gltf container
B3zaleel May 21, 2024
d81de4e
Create a class that stores Gltf-related constant values
B3zaleel May 21, 2024
3eb3592
Implement a glTF reader
B3zaleel May 21, 2024
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
14 changes: 14 additions & 0 deletions ThreeDModels.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThreeDModels.Format.Ctm", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThreeDModels.Format.Ctm.UnitTests", "tests\ThreeDModels\Format\Ctm.UnitTests\ThreeDModels.Format.Ctm.UnitTests.csproj", "{0C3E07D5-30ED-4B46-94D0-DF39D4101D95}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThreeDModels.Format.Gltf", "src\ThreeDModels\Format\Gltf\ThreeDModels.Format.Gltf.csproj", "{568C50F8-4085-4806-B293-30C06AD8D959}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThreeDModels.Format.Gltf.UnitTests", "tests\ThreeDModels\Format\Gltf.UnitTests\ThreeDModels.Format.Gltf.UnitTests.csproj", "{E74FFBE6-091C-4D82-8E5C-895F72A740A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -48,6 +52,14 @@ Global
{0C3E07D5-30ED-4B46-94D0-DF39D4101D95}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C3E07D5-30ED-4B46-94D0-DF39D4101D95}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C3E07D5-30ED-4B46-94D0-DF39D4101D95}.Release|Any CPU.Build.0 = Release|Any CPU
{568C50F8-4085-4806-B293-30C06AD8D959}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{568C50F8-4085-4806-B293-30C06AD8D959}.Debug|Any CPU.Build.0 = Debug|Any CPU
{568C50F8-4085-4806-B293-30C06AD8D959}.Release|Any CPU.ActiveCfg = Release|Any CPU
{568C50F8-4085-4806-B293-30C06AD8D959}.Release|Any CPU.Build.0 = Release|Any CPU
{E74FFBE6-091C-4D82-8E5C-895F72A740A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E74FFBE6-091C-4D82-8E5C-895F72A740A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E74FFBE6-091C-4D82-8E5C-895F72A740A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E74FFBE6-091C-4D82-8E5C-895F72A740A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A75E239E-4BB5-423D-B7E9-D60E96855389} = {7D388FB1-4C7A-410B-B186-92D5CD8819E9}
Expand All @@ -58,5 +70,7 @@ Global
{272082CD-8882-40F1-A232-E64F43156B1F} = {2E7AAD7B-6592-4BCD-9766-CBD16C6553BF}
{6F517121-325F-410D-B7B3-7B1D2FC1E420} = {9352709B-38FB-4B82-BB5B-740A7746887C}
{0C3E07D5-30ED-4B46-94D0-DF39D4101D95} = {2E7AAD7B-6592-4BCD-9766-CBD16C6553BF}
{568C50F8-4085-4806-B293-30C06AD8D959} = {9352709B-38FB-4B82-BB5B-740A7746887C}
{E74FFBE6-091C-4D82-8E5C-895F72A740A0} = {2E7AAD7B-6592-4BCD-9766-CBD16C6553BF}
EndGlobalSection
EndGlobal
47 changes: 47 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/Accessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents a typed view into a buffer view that contains raw binary data.
/// </summary>
public class Accessor : IGltfRootProperty
{
/// <summary>
/// The index of the bufferView.
/// </summary>
public int? BufferView { get; set; }
/// <summary>
/// The offset relative to the start of the buffer view in bytes.
/// </summary>
public int? ByteOffset { get; set; }
/// <summary>
/// The datatype of the accessor's components.
/// </summary>
public required int ComponentType { get; set; }
/// <summary>
/// Specifies whether integer data values are normalized before usage.
/// </summary>
public bool Normalized { get; set; }
/// <summary>
/// The number of elements referenced by this accessor.
/// </summary>
public required int Count { get; set; }
/// <summary>
/// Specifies if the accessor's elements are scalars, vectors, or matrices.
/// </summary>
public required string Type { get; set; } = string.Empty;
/// <summary>
/// Maximum value of each component in this accessor.
/// </summary>
public List<float> Max { get; set; } = [];
/// <summary>
/// Minimum value of each component in this accessor.
/// </summary>
public List<float> Min { get; set; } = [];
/// <summary>
/// Sparse storage of elements that deviate from their initialization value.
/// </summary>
public AccessorSparse? Sparse { get; set; }
public string? Name { get; set; } = string.Empty;
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
22 changes: 22 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/AccessorSparse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents a sparse storage of accessor values that deviate from their initialization value.
/// </summary>
public class AccessorSparse : IGltfProperty
{
/// <summary>
/// Number of deviating accessor values stored in the sparse array.
/// </summary>
public required int Count { get; set; }
/// <summary>
/// An object pointing to a buffer view containing the indices of deviating accessor values.
/// </summary>
public required AccessorSparseIndices Indices { get; set; }
/// <summary>
/// An object pointing to a buffer view containing the deviating accessor values.
/// </summary>
public required AccessorSparseValues Values { get; set; }
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
22 changes: 22 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/AccessorSparseIndices..cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents an object pointing to a buffer view containing the indices of deviating accessor values.
/// </summary>
public class AccessorSparseIndices : IGltfProperty
{
/// <summary>
/// The index of the buffer view with sparse indices.
/// </summary>
public required int BufferView { get; set; }
/// <summary>
/// The offset relative to the start of the buffer view in bytes.
/// </summary>
public int ByteOffset { get; set; } = 0;
/// <summary>
/// The indices data type.
/// </summary>
public required int ComponentType { get; set; }
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
18 changes: 18 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/AccessorSparseValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents an object pointing to a buffer view containing the deviating accessor values.
/// </summary>
public class AccessorSparseValues : IGltfProperty
{
/// <summary>
/// The index of the bufferView with sparse values.
/// </summary>
public required int BufferView { get; set; }
/// <summary>
/// The offset relative to the start of the bufferView in bytes.
/// </summary>
public int ByteOffset { get; set; } = 0;
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
19 changes: 19 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/Animation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents a keyframe animation.
/// </summary>
public class Animation : IGltfRootProperty
{
/// <summary>
/// An array of animation channels.
/// </summary>
public required List<AnimationChannel> Channels { get; set; } = [];
/// <summary>
/// An array of animation samplers.
/// </summary>
public required List<AnimationSampler> Samplers { get; set; } = [];
public string? Name { get; set; } = string.Empty;
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
18 changes: 18 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/AnimationChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents a combination of an animation sampler with a target property being animated.
/// </summary>
public class AnimationChannel : IGltfProperty
{
/// <summary>
/// The index of a sampler in this animation used to compute the value for the target.
/// </summary>
public required int Sampler { get; set; }
/// <summary>
/// The descriptor of the animated property.
/// </summary>
public required AnimationChannelTarget Target { get; set; }
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
24 changes: 24 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/AnimationChannelTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents the descriptor of the animated property.
/// </summary>
public class AnimationChannelTarget : IGltfProperty
{
/// <summary>
/// The index of the node to animate.
/// </summary>
public int? Node { get; set; }
/// <summary>
/// The name of the node's TRS property to animate, or the `weights` of the Morph Targets it instantiates.
/// <para/>
/// For the `translation` property, the values that are provided by the sampler are the translation along the X, Y, and Z axes.
/// <para/>
/// For the `rotation` property, the values are a quaternion in the order (x, y, z, w), where w is the scalar.
/// <para/>
/// For the `scale` property, the values are the scaling factors along the X, Y, and Z axes.
/// </summary>
public required string Path { get; set; }
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
24 changes: 24 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/AnimationSampler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ThreeDModels.Format.Gltf.IO;

namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents a combination of timestamps with a sequence of output values and defines an interpolation algorithm.
/// </summary>
public class AnimationSampler : IGltfProperty
{
/// <summary>
/// The index of an accessor containing keyframe timestamps.
/// </summary>
public required int Input { get; set; }
/// <summary>
/// Interpolation algorithm.
/// </summary>
public string Interpolation { get; set; } = Default.InterpolationAlgorithm;
/// <summary>
/// The index of an accessor, containing keyframe output values.
/// </summary>
public required int Output { get; set; }
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
26 changes: 26 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/Asset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents an object that contains metadata about the glTF asset.
/// </summary>
public class Asset : IGltfProperty
{
/// <summary>
/// A copyright message suitable for display to credit the content creator.
/// </summary>
public string? Copyright { get; set; } = string.Empty;
/// <summary>
/// Tool that generated this glTF model. Useful for debugging.
/// </summary>
public string? Generator { get; set; } = string.Empty;
/// <summary>
/// The glTF version in the form of `<major>.<minor>` that this asset targets.
/// </summary>
public required string Version { get; set; }
/// <summary>
/// The minimum glTF version in the form of `<major>.<minor>` that this asset targets.
/// </summary>
public string? MinVersion { get; set; } = string.Empty;
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
19 changes: 19 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/Buffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents data that points to binary geometry, animation, or skins.
/// </summary>
public class Buffer : IGltfRootProperty
{
/// <summary>
/// The URI (or IRI) of the buffer.
/// </summary>
public string? Uri { get; set; } = string.Empty;
/// <summary>
/// The length of the buffer in bytes.
/// </summary>
public required int ByteLength { get; set; }
public string? Name { get; set; } = string.Empty;
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
33 changes: 33 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/BufferView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using ThreeDModels.Format.Gltf.IO;

namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents a subset of a buffer.
/// </summary>
public class BufferView : IGltfRootProperty
{
/// <summary>
/// The index of the buffer.
/// </summary>
public required int Buffer { get; set; }
/// <summary>
/// The offset into the buffer in bytes.
/// </summary>
public int ByteOffset { get; set; } = Default.ByteOffset;
/// <summary>
/// The length of the bufferView in bytes.
/// </summary>
public required int ByteLength { get; set; }
/// <summary>
/// The stride, in bytes.
/// </summary>
public int? ByteStride { get; set; }
/// <summary>
/// The hint representing the intended GPU buffer type to use with this buffer view.
/// </summary>
public int? Target { get; set; }
public string? Name { get; set; } = string.Empty;
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
23 changes: 23 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/Camera.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents a camera's projection.
/// </summary>
public class Camera : IGltfRootProperty
{
/// <summary>
/// An orthographic camera containing properties to create an orthographic projection matrix.
/// </summary>
public CameraOrthographic? Orthographic { get; set; }
/// <summary>
/// A perspective camera containing properties to create a perspective projection matrix.
/// </summary>
public CameraPerspective? Perspective { get; set; }
/// <summary>
/// Specifies if the camera uses a perspective or orthographic projection.
/// </summary>
public required string Type { get; set; }
public string? Name { get; set; } = string.Empty;
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
26 changes: 26 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/CameraOrthographic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// An orthographic camera containing properties to create an orthographic projection matrix.
/// </summary>
public class CameraOrthographic : IGltfProperty
{
/// <summary>
/// The floating-point horizontal magnification of the view.
/// </summary>
public required float XMag { get; set; }
/// <summary>
/// The floating-point vertical magnification of the view.
/// </summary>
public required float YMag { get; set; }
/// <summary>
/// The floating-point distance to the far clipping plane.
/// </summary>
public required float ZFar { get; set; }
/// <summary>
/// The floating-point distance to the near clipping plane.
/// </summary>
public required float ZNear { get; set; }
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
26 changes: 26 additions & 0 deletions src/ThreeDModels/Format/Gltf/Elements/CameraPerspective.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace ThreeDModels.Format.Gltf.Elements;

/// <summary>
/// Represents a perspective camera containing properties to create a perspective projection matrix.
/// </summary>
public class CameraPerspective : IGltfProperty
{
/// <summary>
/// The floating-point aspect ratio of the field of view.
/// </summary>
public float? AspectRatio { get; set; }
/// <summary>
/// The floating-point vertical field of view in radians.
/// </summary>
public required float YFov { get; set; }
/// <summary>
/// The floating-point distance to the far clipping plane.
/// </summary>
public float? ZFar { get; set; }
/// <summary>
/// The floating-point distance to the near clipping plane.
/// </summary>
public required float ZNear { get; set; }
public Dictionary<string, object?>? Extensions { get; set; }
public object? Extras { get; set; }
}
Loading
Loading