-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Change Log | ||
|
||
## [1.0.0] - 2020-08-07 | ||
Initial release. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Izayoi Jiichan | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# VgoGltf | ||
|
||
VgoGltf is the basic and common definition of glTF. | ||
|
||
___ | ||
## Storage | ||
|
||
- GltfHeader | ||
- GltfChunk | ||
|
||
## Buffers | ||
|
||
- IByteBuffer | ||
- ArraySegmentByteBuffer | ||
- ReadOnlyArraySegmentByteBuffer | ||
|
||
## Enums | ||
|
||
- WebGL | ||
- GltfBufferViewTarget | ||
- GltfComponentType | ||
- GltfCullFaceMode | ||
- GltfMeshPrimitiveMode | ||
- GltfTextureMagFilterMode | ||
- GltfTextureMinFilterMode | ||
- GltfTextureTarget | ||
- GltfTextureWrapMode | ||
- EnumString | ||
- GltfAccessorType | ||
- GltfAlphaMode | ||
- GltfAnimationChannelPath | ||
- GltfAnimationInterpolationType | ||
- GltfCameraProjectionType | ||
|
||
## Structs | ||
|
||
- Color3 | ||
- Color4 | ||
- Matrix2 | ||
- Matrix3 | ||
- Vector4Uint | ||
- Vector4Ushort | ||
|
||
## Framework | ||
|
||
- .NET Standard 2.0 | ||
- .NET Framework 4.7 | ||
|
||
___ | ||
Last updated: 7 August, 2020 | ||
Editor: Izayoi Jiichan | ||
|
||
*Copyright (C) 2020 Izayoi Jiichan. All Rights Reserved.* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
// ---------------------------------------------------------------------- | ||
// @Namespace : VgoGltf.Buffers | ||
// @Class : ArraySegmentByteBuffer | ||
// ---------------------------------------------------------------------- | ||
namespace VgoGltf.Buffers | ||
{ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
/// <summary> | ||
/// Array Segment Byte Buffer | ||
/// </summary> | ||
public class ArraySegmentByteBuffer : IByteBuffer | ||
{ | ||
#region Fields | ||
|
||
/// <summary>The bytes in the buffer.</summary> | ||
protected byte[] _Bytes; | ||
|
||
/// <summary>The default byte size to extend when the buffer runs out of size.</summary> | ||
protected readonly int _DefaultExtendSize = 10 * 1024; | ||
|
||
#endregion | ||
|
||
#region Properties | ||
|
||
/// <summary>Gets or sets the number of bytes allocated for this buffer.</summary> | ||
public int Capacity { get; private set; } | ||
|
||
/// <summary>Gets or sets the current length of the buffer in bytes.</summary> | ||
public int Length { get; private set; } | ||
|
||
/// <summary>Gets the maximum capacity of this instance.</summary> | ||
public int MaxCapacity { get; } = 2 * 1024 * 1024; | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
||
/// <summary> | ||
/// Create a new instance of ArraySegmentByteBuffer with capacity. | ||
/// </summary> | ||
/// <param name="capacity">Specifies the initial size of the buffer.</param> | ||
public ArraySegmentByteBuffer(int capacity) | ||
{ | ||
if (capacity <= 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(capacity)); | ||
} | ||
|
||
_Bytes = new byte[capacity]; | ||
|
||
Length = _Bytes.Length; | ||
|
||
Capacity = capacity; | ||
} | ||
|
||
#endregion | ||
|
||
#region Public Methods | ||
|
||
/// <summary> | ||
/// Appends data to the buffer. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="data"></param> | ||
/// <param name="stride"></param> | ||
/// <returns>Returns the size of the appended data.</returns> | ||
public int Append<T>(ArraySegment<T> data, int stride = 0) where T : struct | ||
{ | ||
if (data == null) | ||
{ | ||
throw new ArgumentNullException(nameof(data)); | ||
} | ||
|
||
if (data.Count == 0) | ||
{ | ||
throw new ArgumentException(nameof(data)); | ||
} | ||
|
||
int perDataSize = Marshal.SizeOf(typeof(T)); | ||
|
||
if (stride == 0) | ||
{ | ||
stride = perDataSize; | ||
} | ||
else if (stride < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(stride)); | ||
} | ||
else if (stride < perDataSize) | ||
{ | ||
throw new InvalidOperationException(); | ||
} | ||
|
||
int dataCount = data.Count; | ||
|
||
int dataSize = stride * dataCount; | ||
|
||
ExtendBufferIfNecessary(dataSize); | ||
|
||
if (stride == perDataSize) | ||
{ | ||
using (Pin<T> pin = Pin.Create(data)) | ||
{ | ||
Marshal.Copy(pin.Ptr, _Bytes, Length, dataSize); | ||
} | ||
|
||
Length += dataSize; | ||
|
||
return dataSize; | ||
} | ||
else | ||
{ | ||
int start = Length; | ||
|
||
for (int index = 0; index < dataCount; index++) | ||
{ | ||
ArraySegment<T> src = new ArraySegment<T>(data.Array, data.Offset + index, perDataSize); | ||
|
||
using (Pin<T> pin = Pin.Create(src)) | ||
{ | ||
Marshal.Copy(pin.Ptr, _Bytes, start + index * stride, perDataSize); | ||
} | ||
} | ||
|
||
Length += dataSize; | ||
|
||
return dataSize; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get the used byte data in the buffer. | ||
/// </summary> | ||
/// <returns>Returns the used byte data.</returns> | ||
public ArraySegment<byte> GetBytes() | ||
{ | ||
//if (m_bytes == null) | ||
//{ | ||
// return new ArraySegment<byte>(); | ||
//} | ||
return new ArraySegment<byte>(_Bytes, 0, Length); | ||
} | ||
|
||
/// <summary> | ||
/// Writes the buffer data to a byte array. | ||
/// </summary> | ||
/// <returns>A new byte array.</returns> | ||
public byte[] ToArray() | ||
{ | ||
byte[] destinationArray = new byte[Length]; | ||
|
||
Array.Copy(sourceArray: _Bytes, destinationArray, Length); | ||
|
||
return destinationArray; | ||
} | ||
|
||
#endregion | ||
|
||
#region Private Methods | ||
|
||
/// <summary> | ||
/// Extend the buffer if necessary. | ||
/// </summary> | ||
/// <param name="dataSizeToWrite">The data size to be written.</param> | ||
private void ExtendBufferIfNecessary(int dataSizeToWrite) | ||
{ | ||
if (Length + dataSizeToWrite > Capacity) | ||
{ | ||
int extendSize = (dataSizeToWrite > _DefaultExtendSize) ? dataSizeToWrite : _DefaultExtendSize; | ||
|
||
ExtendBuffer(extendSize); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Extend the buffer. | ||
/// </summary> | ||
/// <param name="extendSize">The size to extend.</param> | ||
private void ExtendBuffer(int extendSize) | ||
{ | ||
int newCapacity = Length + extendSize; | ||
|
||
byte[] newBuffer = new byte[newCapacity]; | ||
|
||
Buffer.BlockCopy(_Bytes, 0, newBuffer, 0, Length); | ||
|
||
_Bytes = newBuffer; | ||
|
||
Capacity = newCapacity; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// ---------------------------------------------------------------------- | ||
// @Namespace : VgoGltf.Buffers | ||
// @Class : IByteBuffer | ||
// ---------------------------------------------------------------------- | ||
namespace VgoGltf.Buffers | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// ByteBuffer Interface | ||
/// </summary> | ||
public interface IByteBuffer | ||
{ | ||
#region Properties | ||
|
||
/// <summary>Gets or sets the number of bytes allocated for this buffer.</summary> | ||
int Capacity { get; } | ||
|
||
/// <summary>Gets or sets the current length of the buffer in bytes.</summary> | ||
int Length { get; } | ||
|
||
#endregion | ||
|
||
#region Public Methods | ||
|
||
/// <summary> | ||
/// Appends data to the buffer. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="data"></param> | ||
/// <param name="stride"></param> | ||
/// <returns>Returns the size of the appended data.</returns> | ||
int Append<T>(ArraySegment<T> data, int stride = 0) where T : struct; | ||
|
||
/// <summary> | ||
/// Get the used byte data in the buffer. | ||
/// </summary> | ||
/// <returns>Returns the used byte data.</returns> | ||
ArraySegment<byte> GetBytes(); | ||
|
||
/// <summary> | ||
/// Writes the buffer data to a byte array. | ||
/// </summary> | ||
/// <returns>A new byte array.</returns> | ||
byte[] ToArray(); | ||
|
||
#endregion | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.