public Color[] ReadColor() { if (!ValidateAccessorTypeAny(type, AccessorType.VEC3, AccessorType.VEC4)) return new Color[count]; Func<BufferedBinaryReader, float> floatReader = GetFloatReader(componentType); Color[] c = new Color[count]; if (bufferView != null) { BufferedBinaryReader reader = new BufferedBinaryReader(bufferView.stream, 1024); reader.Position = bufferView.byteOffset + byteOffset; int byteSkip = byteStride.HasValue ? byteStride.Value - GetComponentSize() : 0; if (type == AccessorType.VEC3) { for (int i = 0; i < count; i++) { c[i].r = floatReader(reader); c[i].g = floatReader(reader); c[i].b = floatReader(reader); reader.Skip(byteSkip); } } else if (type == AccessorType.VEC4) { for (int i = 0; i < count; i++) { c[i].r = floatReader(reader); c[i].g = floatReader(reader); c[i].b = floatReader(reader); c[i].a = floatReader(reader); reader.Skip(byteSkip); } } } if (sparse != null) { Func<BufferedBinaryReader, int> indexIntReader = GetIntReader(sparse.indices.componentType); BufferedBinaryReader indexReader = new BufferedBinaryReader(sparse.indices.bufferView.stream, 1024); indexReader.Position = sparse.indices.bufferView.byteOffset + sparse.indices.byteOffset; int[] indices = new int[sparse.count]; for (int i = 0; i < sparse.count; i++) { indices[i] = indexIntReader(indexReader); } BufferedBinaryReader valueReader = new BufferedBinaryReader(sparse.values.bufferView.stream, 1024); indexReader.Position = sparse.values.bufferView.byteOffset + sparse.values.byteOffset; if (type == AccessorType.VEC3) { for (int i = 0; i < sparse.count; i++) { int index = indices[i]; c[index].r = floatReader(valueReader); c[index].g = floatReader(valueReader); c[index].b = floatReader(valueReader); } } else if (type == AccessorType.VEC4) { for (int i = 0; i < sparse.count; i++) { int index = indices[i]; c[index].r = floatReader(valueReader); c[index].g = floatReader(valueReader); c[index].b = floatReader(valueReader); c[index].a = floatReader(valueReader); } } } return c; }
public int[] ReadInt() { if (!ValidateAccessorType(type, AccessorType.SCALAR)) return new int[count]; Func<BufferedBinaryReader, int> intReader = GetIntReader(componentType); int[] v = new int[count]; if (bufferView != null) { BufferedBinaryReader reader = new BufferedBinaryReader(bufferView.stream, 1024); reader.Position = bufferView.byteOffset + byteOffset; int byteSkip = byteStride.HasValue ? byteStride.Value - GetComponentSize() : 0; for (int i = 0; i < count; i++) { v[i] = intReader(reader); reader.Skip(byteSkip); } } if (sparse != null) { Func<BufferedBinaryReader, int> indexIntReader = GetIntReader(sparse.indices.componentType); BufferedBinaryReader indexReader = new BufferedBinaryReader(sparse.indices.bufferView.stream, 1024); indexReader.Position = sparse.indices.bufferView.byteOffset + sparse.indices.byteOffset; int[] indices = new int[sparse.count]; for (int i = 0; i < sparse.count; i++) { indices[i] = indexIntReader(indexReader); } BufferedBinaryReader valueReader = new BufferedBinaryReader(sparse.values.bufferView.stream, 1024); indexReader.Position = sparse.values.bufferView.byteOffset + sparse.values.byteOffset; for (int i = 0; i < sparse.count; i++) { int index = indices[i]; v[index] = intReader(valueReader); } } return v; }
public Vector2[] ReadVec2() { if (!ValidateAccessorType(type, AccessorType.VEC2)) { return(new Vector2[count]); } if (componentType != GLType.FLOAT) { Debug.LogError("Non-float componentType not supported. Got " + (int)componentType); return(new Vector2[count]); } Func <BufferedBinaryReader, float> floatReader = GetFloatReader(componentType); BufferedBinaryReader reader = new BufferedBinaryReader(bufferView.stream, 1024); Vector2[] verts = new Vector2[count]; reader.Position = bufferView.byteOffset + byteOffset; int byteSkip = byteStride.HasValue ? byteStride.Value - GetComponentSize() : 0; for (int i = 0; i < count; i++) { verts[i].x = floatReader(reader); verts[i].y = floatReader(reader); reader.Skip(byteSkip); } return(verts); }
public Color[] ReadColor() { if (!ValidateAccessorTypeAny(type, AccessorType.VEC3, AccessorType.VEC4)) { return(new Color[count]); } Func <BufferedBinaryReader, float> floatReader = GetFloatReader(componentType); BufferedBinaryReader reader = new BufferedBinaryReader(bufferView.stream, 1024); Color[] cols = new Color[count]; reader.Position = bufferView.byteOffset + byteOffset; int byteSkip = byteStride.HasValue ? byteStride.Value - GetComponentSize() : 0; if (type == AccessorType.VEC3) { for (int i = 0; i < count; i++) { cols[i].r = floatReader(reader); cols[i].g = floatReader(reader); cols[i].b = floatReader(reader); reader.Skip(byteSkip); } } else if (type == AccessorType.VEC4) { for (int i = 0; i < count; i++) { cols[i].r = floatReader(reader); cols[i].g = floatReader(reader); cols[i].b = floatReader(reader); cols[i].a = floatReader(reader); reader.Skip(byteSkip); } } return(cols); }
public Vector4[] ReadVec4() { if (!ValidateAccessorType(type, AccessorType.VEC4)) { return(new Vector4[count]); } Func <BufferedBinaryReader, float> floatReader = GetFloatReader(componentType); Vector4[] v = new Vector4[count]; if (bufferView != null) { BufferedBinaryReader reader = new BufferedBinaryReader(bufferView.stream, 1024); reader.Position = bufferView.byteOffset + byteOffset; int byteSkip = byteStride.HasValue ? byteStride.Value - GetComponentSize() : 0; for (int i = 0; i < count; i++) { v[i].x = floatReader(reader); v[i].y = floatReader(reader); v[i].z = floatReader(reader); v[i].w = floatReader(reader); reader.Skip(byteSkip); } } if (sparse != null) { Func <BufferedBinaryReader, int> indexIntReader = GetIntReader(sparse.indices.componentType); BufferedBinaryReader indexReader = new BufferedBinaryReader(sparse.indices.bufferView.stream, 1024); indexReader.Position = sparse.indices.bufferView.byteOffset + sparse.indices.byteOffset; int[] indices = new int[sparse.count]; for (int i = 0; i < sparse.count; i++) { indices[i] = indexIntReader(indexReader); } BufferedBinaryReader valueReader = new BufferedBinaryReader(sparse.values.bufferView.stream, 1024); indexReader.Position = sparse.values.bufferView.byteOffset + sparse.values.byteOffset; for (int i = 0; i < sparse.count; i++) { int index = indices[i]; v[index].x = floatReader(valueReader); v[index].y = floatReader(valueReader); v[index].z = floatReader(valueReader); v[index].w = floatReader(valueReader); } } return(v); }
internal static LocalUseSection BuildFrom(BufferedBinaryReader reader) { // octets 1-4 (Length of GDS) var length = reader.ReadUInt32(); var section = reader.ReadUInt8(); if (section != (int)SectionCode.LocalUseSection) { return(null); } var contentOffset = reader.Position; reader.Skip((int)length - 5); return(new LocalUseSection(length, section, contentOffset)); }
public int[] ReadInt() { if (!ValidateAccessorType(type, AccessorType.SCALAR)) { return(new int[count]); } Func <BufferedBinaryReader, int> intReader = GetIntReader(componentType); BufferedBinaryReader reader = new BufferedBinaryReader(bufferView.stream, 1024); int[] result = new int[count]; reader.Position = bufferView.byteOffset + byteOffset; int byteSkip = byteStride.HasValue ? byteStride.Value - GetComponentSize() : 0; for (int i = 0; i < count; i++) { result[i] = intReader(reader); reader.Skip(byteSkip); } return(result); }
internal static BitmapSection BuildFrom(BufferedBinaryReader raf, long dataPointsNumber) { var length = raf.ReadUInt32(); var section = raf.ReadUInt8(); if (section != (int)SectionCode.BitmapSection) { throw new UnexpectedGribSectionException( SectionCode.BitmapSection, section ); } var bitmapIndicator = raf.ReadUInt8(); var bitmapOffset = raf.Position; // Skip through the bitmap data // There is no need to load it now raf.Skip((int)length - 6); return(new BitmapSection(length, section, bitmapIndicator, dataPointsNumber, bitmapOffset)); }
public Vector3[] ReadVec3() { if (!ValidateAccessorType(type, AccessorType.VEC3)) { return(new Vector3[count]); } Func <BufferedBinaryReader, float> floatReader = GetFloatReader(componentType); BufferedBinaryReader reader = new BufferedBinaryReader(bufferView.stream, 1024); Vector3[] verts = new Vector3[count]; reader.Position = bufferView.byteOffset + byteOffset; int byteSkip = byteStride.HasValue ? byteStride.Value - GetComponentSize() : 0; for (int i = 0; i < count; i++) { verts[i].x = floatReader(reader); verts[i].y = floatReader(reader); verts[i].z = floatReader(reader); reader.Skip(byteSkip); } return(verts); }
internal static IndicatorSection BuildFrom(BufferedBinaryReader reader) { var fileStart = reader.Read(Constants.GribFileStart.Length); if (!Constants.GribFileStart.SequenceEqual(fileStart)) { throw new BadGribFormatException("Invalid file start."); } // Ignore the 2 reserved bytes reader.Skip(2); var disciplineNumber = reader.ReadUInt8(); var gribEdition = reader.ReadUInt8(); if (gribEdition != 2) { throw new NotSupportedException($"Only GRIB edition 2 is supported. GRIB edition {gribEdition} is not yet supported"); } var totalLength = reader.ReadUInt64(); return(new IndicatorSection(disciplineNumber, 2, totalLength)); }
internal static DataSection BuildFrom(BufferedBinaryReader reader) { // octets 1-4 (Length of DS) var length = reader.ReadUInt32(); // octet 5 section 7 var section = reader.ReadUInt8(); if (section != (int)SectionCode.DataSection) { throw new UnexpectedGribSectionException( SectionCode.DataSection, section ); } var dataOffset = reader.Position; var dataLength = length - 5; reader.Skip((int)dataLength); return(new DataSection(length, section, dataOffset, dataLength)); }
public Matrix4x4[] ReadMatrix4x4() { if (!ValidateAccessorType(type, AccessorType.MAT4)) { return(new Matrix4x4[count]); } Func <BufferedBinaryReader, float> floatReader = GetFloatReader(componentType); BufferedBinaryReader reader = new BufferedBinaryReader(bufferView.stream, 1024); Matrix4x4[] m = new Matrix4x4[count]; reader.Position = bufferView.byteOffset + byteOffset; int byteSkip = byteStride.HasValue ? byteStride.Value - GetComponentSize() : 0; for (int i = 0; i < count; i++) { m[i].m00 = floatReader(reader); m[i].m01 = floatReader(reader); m[i].m02 = floatReader(reader); m[i].m03 = floatReader(reader); m[i].m10 = floatReader(reader); m[i].m11 = floatReader(reader); m[i].m12 = floatReader(reader); m[i].m13 = floatReader(reader); m[i].m20 = floatReader(reader); m[i].m21 = floatReader(reader); m[i].m22 = floatReader(reader); m[i].m23 = floatReader(reader); m[i].m30 = floatReader(reader); m[i].m31 = floatReader(reader); m[i].m32 = floatReader(reader); m[i].m33 = floatReader(reader); reader.Skip(byteSkip); } return(m); }
public Matrix4x4[] ReadMatrix4x4() { if (!ValidateAccessorType(type, AccessorType.MAT4)) { return(new Matrix4x4[count]); } Func <BufferedBinaryReader, float> floatReader = GetFloatReader(componentType); Matrix4x4[] m = new Matrix4x4[count]; if (bufferView != null) { BufferedBinaryReader reader = new BufferedBinaryReader(bufferView.stream, 1024); reader.Position = bufferView.byteOffset + byteOffset; int byteSkip = byteStride.HasValue ? byteStride.Value - GetComponentSize() : 0; for (int i = 0; i < count; i++) { m[i].m00 = floatReader(reader); m[i].m01 = floatReader(reader); m[i].m02 = floatReader(reader); m[i].m03 = floatReader(reader); m[i].m10 = floatReader(reader); m[i].m11 = floatReader(reader); m[i].m12 = floatReader(reader); m[i].m13 = floatReader(reader); m[i].m20 = floatReader(reader); m[i].m21 = floatReader(reader); m[i].m22 = floatReader(reader); m[i].m23 = floatReader(reader); m[i].m30 = floatReader(reader); m[i].m31 = floatReader(reader); m[i].m32 = floatReader(reader); m[i].m33 = floatReader(reader); reader.Skip(byteSkip); } } if (sparse != null) { Func <BufferedBinaryReader, int> indexIntReader = GetIntReader(sparse.indices.componentType); BufferedBinaryReader indexReader = new BufferedBinaryReader(sparse.indices.bufferView.stream, 1024); indexReader.Position = sparse.indices.bufferView.byteOffset + sparse.indices.byteOffset; int[] indices = new int[sparse.count]; for (int i = 0; i < sparse.count; i++) { indices[i] = indexIntReader(indexReader); } BufferedBinaryReader valueReader = new BufferedBinaryReader(sparse.values.bufferView.stream, 1024); indexReader.Position = sparse.values.bufferView.byteOffset + sparse.values.byteOffset; for (int i = 0; i < sparse.count; i++) { int index = indices[i]; m[index].m00 = floatReader(valueReader); m[index].m01 = floatReader(valueReader); m[index].m02 = floatReader(valueReader); m[index].m03 = floatReader(valueReader); m[index].m10 = floatReader(valueReader); m[index].m11 = floatReader(valueReader); m[index].m12 = floatReader(valueReader); m[index].m13 = floatReader(valueReader); m[index].m20 = floatReader(valueReader); m[index].m21 = floatReader(valueReader); m[index].m22 = floatReader(valueReader); m[index].m23 = floatReader(valueReader); m[index].m30 = floatReader(valueReader); m[index].m31 = floatReader(valueReader); m[index].m32 = floatReader(valueReader); m[index].m33 = floatReader(valueReader); } } return(m); }