void ISerializationCallbackReceiver.OnAfterDeserialize()
 {
     if (Enum.TryParse(componentType, out GltfComponentType result))
     {
         ComponentType = result;
     }
     else
     {
         ComponentType = default;
     }
 }
示例#2
0
        public static int ByteSize(this GltfComponentType t)
        {
            switch (t)
            {
            case GltfComponentType.BYTE: return(1);

            case GltfComponentType.UNSIGNED_BYTE: return(4);

            case GltfComponentType.SHORT: return(2);

            case GltfComponentType.UNSIGNED_SHORT: return(2);

            case GltfComponentType.UNSIGNED_INT: return(4);

            case GltfComponentType.FLOAT: return(4);

            default: throw new ArgumentException();
            }
        }
        private static void GetTypeDetails(GltfComponentType type, out int componentSize, out float maxValue)
        {
            componentSize = 1;
            maxValue      = byte.MaxValue;

            switch (type)
            {
            case GltfComponentType.Byte:
                componentSize = sizeof(sbyte);
                maxValue      = sbyte.MaxValue;
                break;

            case GltfComponentType.UnsignedByte:
                componentSize = sizeof(byte);
                maxValue      = byte.MaxValue;
                break;

            case GltfComponentType.Short:
                componentSize = sizeof(short);
                maxValue      = short.MaxValue;
                break;

            case GltfComponentType.UnsignedShort:
                componentSize = sizeof(ushort);
                maxValue      = ushort.MaxValue;
                break;

            case GltfComponentType.UnsignedInt:
                componentSize = sizeof(uint);
                maxValue      = uint.MaxValue;
                break;

            case GltfComponentType.Float:
                componentSize = sizeof(float);
                maxValue      = float.MaxValue;
                break;

            default:
                throw new Exception("Unsupported component type.");
            }
        }
        /// <summary>
        /// Gets the byte size of the component type.
        /// </summary>
        /// <param name="componentType">The component type.</param>
        /// <returns>The byte size of the component type.</returns>
        public static int ByteSize(this GltfComponentType componentType)
        {
            switch (componentType)
            {
            case GltfComponentType.BYTE:
            case GltfComponentType.UNSIGNED_BYTE:
                return(1);

            case GltfComponentType.SHORT:
            case GltfComponentType.UNSIGNED_SHORT:
                return(2);

            case GltfComponentType.INT:
            case GltfComponentType.UNSIGNED_INT:
            case GltfComponentType.FLOAT:
                return(4);

            default:
                throw new NotImplementedException();
            }
        }
        private static uint GetDiscreteUnsignedElement(byte[] data, int offset, GltfComponentType type)
        {
            switch (type)
            {
            case GltfComponentType.Byte:
                return((uint)Convert.ToSByte(data[offset]));

            case GltfComponentType.UnsignedByte:
                return(data[offset]);

            case GltfComponentType.Short:
                return((uint)BitConverter.ToInt16(data, offset));

            case GltfComponentType.UnsignedShort:
                return(BitConverter.ToUInt16(data, offset));

            case GltfComponentType.UnsignedInt:
                return(BitConverter.ToUInt32(data, offset));

            default:
                throw new Exception($"Unsupported type passed in: {type}");
            }
        }