private static uint DetermineNoOfComponents(Accessor.TypeEnum type) { switch (type) { case Accessor.TypeEnum.SCALAR: return(1U); case Accessor.TypeEnum.VEC2: return(2U); case Accessor.TypeEnum.VEC3: return(3U); case Accessor.TypeEnum.VEC4: return(4U); case Accessor.TypeEnum.MAT2: return(4U); case Accessor.TypeEnum.MAT3: return(9U); case Accessor.TypeEnum.MAT4: return(16U); default: throw new NotSupportedException(); } }
public static int GetTypeMultiplier(Accessor.TypeEnum accessorType) { var mult = 0; switch (accessorType) { case glTFLoader.Schema.Accessor.TypeEnum.SCALAR: mult = 1; break; case glTFLoader.Schema.Accessor.TypeEnum.VEC2: mult = 2; break; case glTFLoader.Schema.Accessor.TypeEnum.VEC3: mult = 3; break; case glTFLoader.Schema.Accessor.TypeEnum.VEC4: case glTFLoader.Schema.Accessor.TypeEnum.MAT2: mult = 4; break; case glTFLoader.Schema.Accessor.TypeEnum.MAT3: mult = 9; break; case glTFLoader.Schema.Accessor.TypeEnum.MAT4: mult = 16; break; } return(mult); }
private int GetTypeSize(Accessor.TypeEnum type) { switch (type) { case Accessor.TypeEnum.SCALAR: return(1); case Accessor.TypeEnum.VEC2: return(2); case Accessor.TypeEnum.VEC3: return(3); case Accessor.TypeEnum.VEC4: return(4); case Accessor.TypeEnum.MAT2: return(4); case Accessor.TypeEnum.MAT3: return(9); case Accessor.TypeEnum.MAT4: return(16); } throw new InvalidEnumArgumentException("Unknown type!"); }
public static int NumOfComponents(this Accessor.TypeEnum t) { switch (t) { case Accessor.TypeEnum.Scalar: return(1); case Accessor.TypeEnum.Vec2: return(2); case Accessor.TypeEnum.Vec3: return(3); case Accessor.TypeEnum.Vec4: return(4); case Accessor.TypeEnum.Mat2: return(4); case Accessor.TypeEnum.Mat3: return(9); case Accessor.TypeEnum.Mat4: return(16); default: throw new NotImplementedException(); } }
public static int GetComponentDimension(this Accessor.TypeEnum type) { switch (type) { case Accessor.TypeEnum.SCALAR: return(1); case Accessor.TypeEnum.VEC2: return(2); case Accessor.TypeEnum.VEC3: return(3); case Accessor.TypeEnum.VEC4: case Accessor.TypeEnum.MAT2: return(4); case Accessor.TypeEnum.MAT3: return(9); case Accessor.TypeEnum.MAT4: return(16); default: return(0); } }
private T[] ReadTypeArray <T>(System.Func <T> read, Accessor.TypeEnum expectedType) { if (m_accessor.Type != expectedType) { throw new System.TypeLoadException("Wrong expected type: " + expectedType + " got " + m_accessor.Type); } T[] res = new T[m_accessor.Count]; for (int i = 0; i < m_accessor.Count; ++i) { res[i] = read(); m_offset += m_skip; } return(res); }
private static int AddAccessor(this Gltf gltf, int bufferView, int byteOffset, Accessor.ComponentTypeEnum componentType, int count, float[] min, float[] max, Accessor.TypeEnum accessorType) { var a = new Accessor(); a.BufferView = bufferView; a.ByteOffset = byteOffset; a.ComponentType = componentType; a.Min = min; a.Max = max; a.Type = accessorType; a.Count = count; if (gltf.Accessors != null) { var accessors = gltf.Accessors.ToList(); accessors.Add(a); gltf.Accessors = accessors.ToArray(); } else { gltf.Accessors = new [] { a }; } return(gltf.Accessors.Length - 1); }
private static int AddAccessor(List <Accessor> accessors, int bufferView, int byteOffset, Accessor.ComponentTypeEnum componentType, int count, float[] min, float[] max, Accessor.TypeEnum accessorType) { var a = new Accessor(); a.BufferView = bufferView; a.ByteOffset = byteOffset; a.ComponentType = componentType; a.Min = min; a.Max = max; a.Type = accessorType; a.Count = count; accessors.Add(a); return(accessors.Count - 1); }
private static MgFormat DetermineFormat(Accessor.TypeEnum type, Accessor.ComponentTypeEnum componentType) { if (type == Accessor.TypeEnum.SCALAR) { switch (componentType) { case Accessor.ComponentTypeEnum.BYTE: return(MgFormat.R8_SINT); case Accessor.ComponentTypeEnum.UNSIGNED_BYTE: return(MgFormat.R8_UINT); case Accessor.ComponentTypeEnum.FLOAT: return(MgFormat.R32_SFLOAT); case Accessor.ComponentTypeEnum.SHORT: return(MgFormat.R16_SINT); case Accessor.ComponentTypeEnum.UNSIGNED_SHORT: return(MgFormat.R16_UINT); case Accessor.ComponentTypeEnum.UNSIGNED_INT: return(MgFormat.R32_UINT); default: throw new NotSupportedException(); } } else if (type == Accessor.TypeEnum.VEC2) { switch (componentType) { case Accessor.ComponentTypeEnum.BYTE: return(MgFormat.R8G8_SINT); case Accessor.ComponentTypeEnum.UNSIGNED_BYTE: return(MgFormat.R8G8_UINT); case Accessor.ComponentTypeEnum.FLOAT: return(MgFormat.R32G32_SFLOAT); case Accessor.ComponentTypeEnum.SHORT: return(MgFormat.R16G16_SINT); case Accessor.ComponentTypeEnum.UNSIGNED_SHORT: return(MgFormat.R16G16_UINT); case Accessor.ComponentTypeEnum.UNSIGNED_INT: return(MgFormat.R32G32_UINT); default: throw new NotSupportedException(); } } else if (type == Accessor.TypeEnum.VEC3) { switch (componentType) { case Accessor.ComponentTypeEnum.BYTE: return(MgFormat.R8G8B8_SINT); case Accessor.ComponentTypeEnum.UNSIGNED_BYTE: return(MgFormat.R8G8B8_UINT); case Accessor.ComponentTypeEnum.FLOAT: return(MgFormat.R32G32B32_SFLOAT); case Accessor.ComponentTypeEnum.SHORT: return(MgFormat.R16G16B16_SINT); case Accessor.ComponentTypeEnum.UNSIGNED_SHORT: return(MgFormat.R16G16B16_UINT); case Accessor.ComponentTypeEnum.UNSIGNED_INT: return(MgFormat.R32G32B32_UINT); default: throw new NotSupportedException(); } } else if (type == Accessor.TypeEnum.VEC4) { switch (componentType) { case Accessor.ComponentTypeEnum.BYTE: return(MgFormat.R8G8B8A8_SINT); case Accessor.ComponentTypeEnum.UNSIGNED_BYTE: return(MgFormat.R8G8B8A8_UINT); case Accessor.ComponentTypeEnum.FLOAT: return(MgFormat.R32G32B32A32_SFLOAT); case Accessor.ComponentTypeEnum.SHORT: return(MgFormat.R16G16B16A16_SINT); case Accessor.ComponentTypeEnum.UNSIGNED_SHORT: return(MgFormat.R16G16B16A16_UINT); case Accessor.ComponentTypeEnum.UNSIGNED_INT: return(MgFormat.R32G32B32A32_UINT); default: throw new NotSupportedException(); } } else { throw new NotSupportedException(); } }
private static int GetCountOfAccessorType(Accessor.TypeEnum type) => type switch {
public static dynamic AccessBuffer(Accessor.TypeEnum accessorType, int count, Accessor.ComponentTypeEnum componentType, int stride, byte[] arr) { dynamic result = null; var elementCount = count; //how many times do we need to do this? var componentCount = GetTypeMultiplier(accessorType);; //each time we do this, how many times do I need to read the buffer? var byteCount = GetComponentTypeMultiplier(componentType); //how many bytes is each component from ComponentTypeEnum var elementBytes = componentCount * byteCount; var strideDiff = stride > 0 ? stride - elementBytes : 0; using (var memoryStream = new MemoryStream(arr)) using (var reader = new BinaryReader(memoryStream)) { // TODO: clean this up switch (componentType) { case glTFLoader.Schema.Accessor.ComponentTypeEnum.BYTE: var listSByte = new List <sbyte>(); //loop through element count //loop through component count //if stride, position the reader appropriately // element bytes should be byteCount * componentCount // stride diff should be stride - elementbytes for (int i = 0; i < elementCount; i++) { for (int j = 0; j < componentCount; j++) { listSByte.Add(reader.ReadSByte()); } reader.BaseStream.Position += strideDiff; } result = listSByte; break; case glTFLoader.Schema.Accessor.ComponentTypeEnum.FLOAT: var listSingle = new List <Single>(); for (int i = 0; i < elementCount; i++) { for (int j = 0; j < componentCount; j++) { listSingle.Add(reader.ReadSingle()); } reader.BaseStream.Position += strideDiff; } result = listSingle; break; case glTFLoader.Schema.Accessor.ComponentTypeEnum.SHORT: var listShort = new List <Int16>(); for (int i = 0; i < elementCount; i++) { for (int j = 0; j < componentCount; j++) { listShort.Add(reader.ReadInt16()); } reader.BaseStream.Position += strideDiff; } result = listShort; break; case glTFLoader.Schema.Accessor.ComponentTypeEnum.UNSIGNED_BYTE: var listByte = new List <byte>(); for (int i = 0; i < elementCount; i++) { for (int j = 0; j < componentCount; j++) { listByte.Add(reader.ReadByte()); } reader.BaseStream.Position += strideDiff; } result = listByte; break; case glTFLoader.Schema.Accessor.ComponentTypeEnum.UNSIGNED_INT: var listUInt = new List <uint>(); for (int i = 0; i < elementCount; i++) { for (int j = 0; j < componentCount; j++) { listUInt.Add(reader.ReadUInt32()); } reader.BaseStream.Position += strideDiff; } result = listUInt; break; case glTFLoader.Schema.Accessor.ComponentTypeEnum.UNSIGNED_SHORT: var listUInt16 = new List <UInt16>(); for (int i = 0; i < elementCount; i++) { for (int j = 0; j < componentCount; j++) { listUInt16.Add(reader.ReadUInt16()); } reader.BaseStream.Position += strideDiff; } result = listUInt16; break; } } return(result); }