// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit.Utilities.Gltf.Schema
{
///
/// A view into a buffer generally representing a subset of the buffer.
/// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/schema/bufferView.schema.json
///
[Serializable]
public class GltfBufferView : GltfChildOfRootProperty, ISerializationCallbackReceiver
{
///
/// The index of the buffer.
///
public int buffer = -1;
///
/// The offset into the buffer in bytes.
/// 0
///
public int byteOffset = 0;
///
/// The length of the bufferView in bytes.
/// 0
///
public int byteLength = 0;
///
/// The stride, in bytes, between vertex attributes or other interleavable data.
/// When this is zero, data is tightly packed.
/// 0
/// 255
///
public int byteStride = 0;
///
/// The target that the WebGL buffer should be bound to.
/// All valid values correspond to WebGL enums.
/// When this is not provided, the bufferView contains animation or skin data.
///
public GltfBufferViewTarget Target { get; set; }
[SerializeField]
private string target = null;
///
/// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/schema/buffer.schema.json
///
public GltfBuffer Buffer { get; internal set; }
void ISerializationCallbackReceiver.OnAfterDeserialize()
{
if (Enum.TryParse(target, out GltfBufferViewTarget result))
{
Target = result;
}
else
{
Target = GltfBufferViewTarget.None;
}
}
void ISerializationCallbackReceiver.OnBeforeSerialize()
{
target = Target.ToString();
}
}
}