/// <summary> /// Initializes a new instance of the <see cref="ColorArray"/> struct. /// </summary> /// <param name="source">The array to wrap.</param> /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param> /// <param name="itemsCount">The number of <see cref="Vector4"/> items in <paramref name="source"/>.</param> /// <param name="byteStride"> /// The byte stride between elements. /// If the value is zero, the size of the item is used instead. /// </param> /// <param name="dimensions">The number of elements per item. Currently only values 3 and 4 are supported.</param> /// <param name="encoding">A value of <see cref="ENCODING"/>.</param> /// <param name="normalized">True if values are normalized.</param> public ColorArray(BYTES source, int byteOffset, int itemsCount, int byteStride, int dimensions = 4, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false) { Guard.MustBeBetweenOrEqualTo(dimensions, 3, 4, nameof(dimensions)); _Accessor = new FloatingAccessor(source, byteOffset, itemsCount, byteStride, dimensions, encoding, normalized); _Dimensions = dimensions; }
/// <summary> /// Parses a <see cref="MODEL"/> instance from a <see cref="byte"/> array representing a GLB file /// </summary> /// <param name="glb">A <see cref="byte"/> array representing a GLB file</param> /// <returns>A <see cref="MODEL"/> instance.</returns> public static MODEL ParseGLB(BYTES glb) { Guard.NotNull(glb, nameof(glb)); using (var m = new MemoryStream(glb.Array, glb.Offset, glb.Count, false)) { return(ReadGLB(m, new ReadSettings())); } }
public static long DefaultHeuristicPageCacheMemory() { // First check if we have a default override... string defaultMemoryOverride = System.getProperty("dbms.pagecache.memory.default.override"); if (!string.ReferenceEquals(defaultMemoryOverride, null)) { return(BYTES.apply(defaultMemoryOverride)); } double ratioOfFreeMem = 0.50; string defaultMemoryRatioOverride = System.getProperty("dbms.pagecache.memory.ratio.default.override"); if (!string.ReferenceEquals(defaultMemoryRatioOverride, null)) { ratioOfFreeMem = double.Parse(defaultMemoryRatioOverride); } // Try to compute (RAM - maxheap) * 0.50 if we can get reliable numbers... long maxHeapMemory = Runtime.Runtime.maxMemory(); if (0 < maxHeapMemory && maxHeapMemory < long.MaxValue) { try { long physicalMemory = OsBeanUtil.TotalPhysicalMemory; if (0 < physicalMemory && physicalMemory < long.MaxValue && maxHeapMemory < physicalMemory) { long heuristic = ( long )((physicalMemory - maxHeapMemory) * ratioOfFreeMem); long min = ByteUnit.mebiBytes(32); // We'd like at least 32 MiBs. long max = Math.Min(maxHeapMemory * 70, ByteUnit.gibiBytes(20)); // Don't heuristically take more than 20 GiBs, and don't take more than 70 times our max heap. // 20 GiBs of page cache memory is ~2.6 million 8 KiB pages. If each page has an overhead of // 72 bytes, then this will take up ~175 MiBs of heap memory. We should be able to tolerate that // in most environments. The "no more than 70 times heap" heuristic is based on the page size over // the per page overhead, 8192 / 72 ~= 114, plus leaving some extra room on the heap for the rest // of the system. This means that we won't heuristically try to create a page cache that is too // large to fit on the heap. return(Math.Min(max, Math.Max(min, heuristic))); } } catch (Exception) { } } // ... otherwise we just go with 2 GiBs. return(ByteUnit.gibiBytes(2)); }
private static IReadOnlyDictionary <Material, string> _WriteMaterials(IDictionary <String, BYTES> files, string baseName, IEnumerable <Material> materials) { // write all image files var images = materials .Select(item => item.DiffuseTexture) .Where(item => item.IsValid) .Distinct(); bool firstImg = true; foreach (var img in images) { var imgName = firstImg ? baseName : $"{baseName}_{files.Count}.{img.FileExtension}"; files[imgName] = new BYTES(img.Content.ToArray()); firstImg = false; } // write materials var mmap = new Dictionary <Material, string>(); var sb = new StringBuilder(); foreach (var m in materials) { mmap[m] = $"Material_{mmap.Count}"; sb.AppendLine($"newmtl {mmap[m]}"); sb.AppendLine("illum 2"); sb.AppendLine(Invariant($"Ka {m.DiffuseColor.X} {m.DiffuseColor.Y} {m.DiffuseColor.Z}")); sb.AppendLine(Invariant($"Kd {m.DiffuseColor.X} {m.DiffuseColor.Y} {m.DiffuseColor.Z}")); sb.AppendLine(Invariant($"Ks {m.SpecularColor.X} {m.SpecularColor.Y} {m.SpecularColor.Z}")); if (m.DiffuseTexture.IsValid) { var imgName = files.FirstOrDefault(kvp => new Memory.MemoryImage(kvp.Value) == m.DiffuseTexture).Key; sb.AppendLine($"map_Kd {imgName}"); } sb.AppendLine(); } // write material library _WriteTextContent(files, baseName + ".mtl", sb); return(mmap); }
/// <summary> /// Initializes a new instance of the <see cref="IntegerArray"/> struct. /// </summary> /// <param name="source">The array range to wrap.</param> /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param> /// <param name="itemsCount">The number of <see cref="UInt32"/> items in <paramref name="source"/>.</param> /// <param name="encoding">Byte encoding.</param> public IntegerArray(BYTES source, int byteOffset, int itemsCount, ENCODING encoding) { _Data = source.Slice(byteOffset); _ByteStride = encoding.ByteLength(); this._Setter = null; this._Getter = null; if (itemsCount < this.Count) { _Data = _Data.Slice(0, itemsCount * _ByteStride); } switch (encoding) { case ENCODING.UNSIGNED_BYTE: { this._Setter = this._SetValueU8; this._Getter = this._GetValueU8; break; } case ENCODING.UNSIGNED_SHORT: { this._Setter = this._SetValueU16; this._Getter = this._GetValueU16; break; } case ENCODING.UNSIGNED_INT: { this._Setter = this._SetValue <UInt32>; this._Getter = this._GetValue <UInt32>; break; } default: throw new ArgumentException(nameof(encoding)); } }
/// <summary> /// Initializes a new instance of the <see cref="IntegerArray"/> struct. /// </summary> /// <param name="source">The array range to wrap.</param> /// <param name="encoding">Byte encoding.</param> public IntegerArray(BYTES source, ENCODING encoding = ENCODING.UNSIGNED_INT) : this(source, 0, int.MaxValue, encoding) { }
public TextureBuilder WithImage(BYTES image) { this.ImageContent = image; return(this); }
public FloatingAccessor(BYTES source, int byteOffset, int itemsCount, int byteStride, int dimensions, ENCODING encoding, Boolean normalized) { var enclen = encoding.ByteLength(); this._Data = source.Slice(byteOffset); this._Getter = null; this._Setter = null; this._ByteStride = Math.Max(byteStride, enclen * dimensions); this._EncodedLen = enclen; this._ItemCount = this._Data.Count / this._ByteStride; // strided buffers usually have room for an extra item if ((_Data.Count % _ByteStride) >= enclen * dimensions) { ++_ItemCount; } _ItemCount = Math.Min(itemsCount, _ItemCount); if (encoding == ENCODING.FLOAT) { this._Setter = this._SetValue <Single>; this._Getter = this._GetValue <Single>; return; } if (normalized) { switch (encoding) { case ENCODING.BYTE: { this._Setter = this._SetNormalizedS8; this._Getter = this._GetNormalizedS8; break; } case ENCODING.UNSIGNED_BYTE: { this._Setter = this._SetNormalizedU8; this._Getter = this._GetNormalizedU8; break; } case ENCODING.SHORT: { this._Setter = this._SetNormalizedS16; this._Getter = this._GetNormalizedS16; break; } case ENCODING.UNSIGNED_SHORT: { this._Setter = this._SetNormalizedU16; this._Getter = this._GetNormalizedU16; break; } default: throw new ArgumentException(nameof(encoding)); } } else { switch (encoding) { case ENCODING.BYTE: { this._Setter = this._SetValueS8; this._Getter = this._GetValueS8; break; } case ENCODING.UNSIGNED_BYTE: { this._Setter = this._SetValueU8; this._Getter = this._GetValueU8; break; } case ENCODING.SHORT: { this._Setter = this._SetValueS16; this._Getter = this._GetValueS16; break; } case ENCODING.UNSIGNED_SHORT: { this._Setter = this._SetValueU16; this._Getter = this._GetValueU16; break; } case ENCODING.UNSIGNED_INT: { this._Setter = this._SetValueU32; this._Getter = this._GetValueU32; break; } case ENCODING.FLOAT: break; default: throw new ArgumentException(nameof(encoding)); } } }
/// <summary> /// Initializes a new instance of the <see cref="ColorArray"/> struct. /// </summary> /// <param name="source">The array to wrap.</param> /// <param name="byteStride"> /// The byte stride between elements. /// If the value is zero, the size of the item is used instead. /// </param> /// <param name="dimensions">The number of elements per item. Currently only values 3 and 4 are supported.</param> /// <param name="encoding">A value of <see cref="ENCODING"/>.</param> /// <param name="normalized">True if values are normalized.</param> public ColorArray(BYTES source, int byteStride = 0, int dimensions = 4, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false) : this(source, 0, int.MaxValue, byteStride, dimensions, encoding, normalized) { }
public static void setString(BYTES param, string value, int destOffset = 0) { byte[] bytes = stringToBytes(value); memcpy(param.mValue, bytes, destOffset, 0, bytes.Length); }
public static FloatingAccessor Create(BYTES data, Schema2.ComponentType type, Boolean normalized) { var accessor = new FloatingAccessor { _Data = data }; if (type == Schema2.ComponentType.FLOAT) { accessor._Setter = accessor._SetValue <Single>; accessor._Getter = accessor._GetValue <Single>; return(accessor); } if (normalized) { switch (type) { case Schema2.ComponentType.BYTE: { accessor._Setter = accessor._SetNormalizedS8; accessor._Getter = accessor._GetNormalizedS8; return(accessor); } case Schema2.ComponentType.UNSIGNED_BYTE: { accessor._Setter = accessor._SetNormalizedU8; accessor._Getter = accessor._GetNormalizedU8; return(accessor); } case Schema2.ComponentType.SHORT: { accessor._Setter = accessor._SetNormalizedS16; accessor._Getter = accessor._GetNormalizedS16; return(accessor); } case Schema2.ComponentType.UNSIGNED_SHORT: { accessor._Setter = accessor._SetNormalizedU16; accessor._Getter = accessor._GetNormalizedU16; return(accessor); } } } else { switch (type) { case Schema2.ComponentType.BYTE: { accessor._Setter = accessor._SetValueS8; accessor._Getter = accessor._GetValueS8; return(accessor); } case Schema2.ComponentType.UNSIGNED_BYTE: { accessor._Setter = accessor._SetValueU8; accessor._Getter = accessor._GetValueU8; return(accessor); } case Schema2.ComponentType.SHORT: { accessor._Setter = accessor._SetValueS16; accessor._Getter = accessor._GetValueS16; return(accessor); } case Schema2.ComponentType.UNSIGNED_SHORT: { accessor._Setter = accessor._SetValueU16; accessor._Getter = accessor._GetValueU16; return(accessor); } case Schema2.ComponentType.UNSIGNED_INT: { accessor._Setter = accessor._SetValueU32; accessor._Getter = accessor._GetValueU32; return(accessor); } case Schema2.ComponentType.FLOAT: break; } } throw new NotSupportedException(); }