internal AccessorSparseIndices(BufferView bv, int byteOffset, IndexEncodingType encoding) { Guard.NotNull(bv, nameof(bv)); Guard.MustBeGreaterThanOrEqualTo(byteOffset, _byteOffsetMinimum, nameof(byteOffset)); this._bufferView = bv.LogicalIndex; this._byteOffset = byteOffset.AsNullable(_byteOffsetDefault); this._componentType = encoding; }
internal AccessorSparse(BufferView indices, int indicesOffset, IndexEncodingType indicesEncoding, BufferView values, int valuesOffset, int count) { Guard.NotNull(indices, nameof(indices)); Guard.NotNull(values, nameof(values)); Guard.MustBeGreaterThanOrEqualTo(count, _countMinimum, nameof(count)); this._count = count; this._indices = new AccessorSparseIndices(indices, indicesOffset, indicesEncoding); this._values = new AccessorSparseValues(values, valuesOffset); }
protected override void DeserializeProperty(string jsonPropertyName, JsonReader reader) { switch (jsonPropertyName) { case "bufferView": _bufferView = DeserializePropertyValue <Int32>(reader); break; case "byteOffset": _byteOffset = DeserializePropertyValue <Int32?>(reader); break; case "componentType": _componentType = DeserializePropertyValue <IndexEncodingType>(reader); break; default: base.DeserializeProperty(jsonPropertyName, reader); break; } }
public static EncodingType ToComponent(this IndexEncodingType t) { switch (t) { case IndexEncodingType.UNSIGNED_BYTE: return(EncodingType.UNSIGNED_BYTE); case IndexEncodingType.UNSIGNED_SHORT: return(EncodingType.UNSIGNED_SHORT); case IndexEncodingType.UNSIGNED_INT: return(EncodingType.UNSIGNED_INT); default: throw new NotImplementedException(); } }
public static int ByteLength(this IndexEncodingType encoding) { switch (encoding) { case IndexEncodingType.UNSIGNED_BYTE: return(1); case IndexEncodingType.UNSIGNED_SHORT: return(2); case IndexEncodingType.UNSIGNED_INT: return(4); default: throw new NotImplementedException(); } }
/// <summary> /// Associates this <see cref="Accessor"/> with a <see cref="BufferView"/> /// </summary> /// <param name="buffer">The <see cref="BufferView"/> source.</param> /// <param name="bufferByteOffset">The start byte offset within <paramref name="buffer"/>.</param> /// <param name="itemCount">The number of items in the accessor.</param> /// <param name="encoding">The <see cref="IndexEncodingType"/> item encoding.</param> public void SetIndexData(BufferView buffer, int bufferByteOffset, int itemCount, IndexEncodingType encoding) { Guard.NotNull(buffer, nameof(buffer)); Guard.MustShareLogicalParent(this, buffer, nameof(buffer)); if (buffer.DeviceBufferTarget.HasValue) { Guard.IsTrue(buffer.DeviceBufferTarget.Value == BufferMode.ELEMENT_ARRAY_BUFFER, nameof(buffer)); } SetData(buffer, bufferByteOffset, itemCount, DimensionType.SCALAR, encoding.ToComponent(), false); }
/// <summary> /// Associates this <see cref="Accessor"/> with a <see cref="BufferView"/> /// </summary> /// <param name="buffer">The <see cref="BufferView"/> source.</param> /// <param name="bufferByteOffset">The start byte offset within <paramref name="buffer"/>.</param> /// <param name="itemCount">The number of items in the accessor.</param> /// <param name="encoding">The <see cref="IndexEncodingType"/> item encoding.</param> public void SetIndexData(BufferView buffer, int bufferByteOffset, int itemCount, IndexEncodingType encoding) { Guard.NotNull(buffer, nameof(buffer)); Guard.MustShareLogicalParent(this, buffer, nameof(buffer)); Guard.IsFalse(buffer.IsVertexBuffer, nameof(buffer)); SetData(buffer, bufferByteOffset, itemCount, DimensionType.SCALAR, encoding.ToComponent(), false); }
public static IEnumerable <(int, int, int)> GetTrianglesIndices(this PrimitiveType ptype, IEnumerable <UInt32> sourceIndices, IndexEncodingType sourceEncoding) { switch (ptype) { case PrimitiveType.TRIANGLES: { using (var ptr = sourceIndices.GetEnumerator()) { while (true) { if (!ptr.MoveNext()) { break; } var a = ptr.Current; if (!ptr.MoveNext()) { break; } var b = ptr.Current; if (!ptr.MoveNext()) { break; } var c = ptr.Current; if (!_IsDegenerated(a, b, c)) { yield return((int)a, (int)b, (int)c); } } } break; } case PrimitiveType.TRIANGLE_FAN: { using (var ptr = sourceIndices.GetEnumerator()) { if (!ptr.MoveNext()) { break; } var a = ptr.Current; if (!ptr.MoveNext()) { break; } var b = ptr.Current; while (true) { if (!ptr.MoveNext()) { break; } var c = ptr.Current; if (!_IsDegenerated(a, b, c)) { yield return((int)a, (int)b, (int)c); } b = c; } } break; } case PrimitiveType.TRIANGLE_STRIP: { using (var ptr = sourceIndices.GetEnumerator()) { if (!ptr.MoveNext()) { break; } var a = ptr.Current; if (!ptr.MoveNext()) { break; } var b = ptr.Current; bool reversed = false; while (true) { if (!ptr.MoveNext()) { break; } var c = ptr.Current; if (!_IsDegenerated(a, b, c)) { if (reversed) { yield return((int)b, (int)a, (int)c); } else { yield return((int)a, (int)b, (int)c); } } a = b; b = c; reversed = !reversed; } } break; } } }