|
|
@@ -126,137 +126,124 @@ namespace SharpGLTF.Schema2
|
|
|
|
|
|
#region Index Buffer API
|
|
|
|
|
|
- public Accessor WithIndexData(Geometry.MemoryAccessor src)
|
|
|
+ public void SetIndexData(Geometry.MemoryAccessor src)
|
|
|
{
|
|
|
var bv = this.LogicalParent.UseBufferView(src.Data, src.Attribute.ByteStride, BufferMode.ELEMENT_ARRAY_BUFFER);
|
|
|
- return this.WithIndexData(bv, src.Attribute.ByteOffset, src.Attribute.ItemsCount, src.Attribute.Encoding.ToIndex());
|
|
|
+ SetIndexData(bv, src.Attribute.ByteOffset, src.Attribute.ItemsCount, src.Attribute.Encoding.ToIndex());
|
|
|
}
|
|
|
|
|
|
- public Accessor WithIndexData(BufferView buffer, int byteOffset, IReadOnlyList<Int32> items, IndexEncodingType encoding = IndexEncodingType.UNSIGNED_INT)
|
|
|
+ public void SetIndexData(BufferView buffer, int byteOffset, IReadOnlyList<Int32> items, IndexEncodingType encoding = IndexEncodingType.UNSIGNED_INT)
|
|
|
{
|
|
|
Guard.MustShareLogicalParent(this, buffer, nameof(buffer));
|
|
|
|
|
|
- WithIndexData(buffer, byteOffset, items.Count, encoding)
|
|
|
- .AsIndicesArray()
|
|
|
- .FillFrom(0, items);
|
|
|
+ SetIndexData(buffer, byteOffset, items.Count, encoding);
|
|
|
|
|
|
- this.UpdateBounds();
|
|
|
+ AsIndicesArray().FillFrom(0, items);
|
|
|
|
|
|
- return this;
|
|
|
+ this.UpdateBounds();
|
|
|
}
|
|
|
|
|
|
- public Accessor WithIndexData(BufferView buffer, int byteOffset, IReadOnlyList<UInt32> items, IndexEncodingType encoding = IndexEncodingType.UNSIGNED_INT)
|
|
|
+ public void SetIndexData(BufferView buffer, int byteOffset, IReadOnlyList<UInt32> items, IndexEncodingType encoding = IndexEncodingType.UNSIGNED_INT)
|
|
|
{
|
|
|
Guard.MustShareLogicalParent(this, buffer, nameof(buffer));
|
|
|
|
|
|
- WithIndexData(buffer, byteOffset, items.Count, encoding)
|
|
|
- .AsIndicesArray()
|
|
|
- .FillFrom(0, items);
|
|
|
+ SetIndexData(buffer, byteOffset, items.Count, encoding);
|
|
|
|
|
|
- this.UpdateBounds();
|
|
|
+ AsIndicesArray().FillFrom(0, items);
|
|
|
|
|
|
- return this;
|
|
|
+ this.UpdateBounds();
|
|
|
}
|
|
|
|
|
|
- public Accessor WithIndexData(BufferView buffer, int byteOffset, int itemCount, IndexEncodingType encoding)
|
|
|
+ public void SetIndexData(BufferView buffer, int byteOffset, 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));
|
|
|
|
|
|
- return WithData(buffer, byteOffset, itemCount, DimensionType.SCALAR, encoding.ToComponent(), false);
|
|
|
+ WithData(buffer, byteOffset, itemCount, DimensionType.SCALAR, encoding.ToComponent(), false);
|
|
|
}
|
|
|
|
|
|
- public Memory.IntegerArray AsIndicesArray()
|
|
|
+ public IntegerArray AsIndicesArray()
|
|
|
{
|
|
|
Guard.IsFalse(this.IsSparse, nameof(IsSparse));
|
|
|
Guard.IsTrue(this.Dimensions == DimensionType.SCALAR, nameof(Dimensions));
|
|
|
|
|
|
- return new Memory.IntegerArray(SourceBufferView.Content, this.ByteOffset, this._count, this.Encoding.ToIndex());
|
|
|
+ return new IntegerArray(SourceBufferView.Content, this.ByteOffset, this._count, this.Encoding.ToIndex());
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Vertex Buffer API
|
|
|
|
|
|
- public Accessor WithVertexData(Geometry.MemoryAccessor src)
|
|
|
+ public void SetVertexData(Geometry.MemoryAccessor src)
|
|
|
{
|
|
|
var bv = this.LogicalParent.UseBufferView(src.Data, src.Attribute.ByteStride, BufferMode.ARRAY_BUFFER);
|
|
|
- return this.WithVertexData(bv, src.Attribute.ByteOffset, src.Attribute.ItemsCount, src.Attribute.Dimensions, src.Attribute.Encoding, src.Attribute.Normalized);
|
|
|
+
|
|
|
+ SetVertexData(bv, src.Attribute.ByteOffset, src.Attribute.ItemsCount, src.Attribute.Dimensions, src.Attribute.Encoding, src.Attribute.Normalized);
|
|
|
}
|
|
|
|
|
|
- public Accessor WithVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Single> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
+ public void SetVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Single> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
{
|
|
|
Guard.MustShareLogicalParent(this, buffer, nameof(buffer));
|
|
|
Guard.MustBePositiveAndMultipleOf(DimensionType.SCALAR.DimCount() * encoding.ByteLength(), 4, nameof(encoding));
|
|
|
|
|
|
- WithVertexData(buffer, bufferByteOffset, items.Count, DimensionType.SCALAR, encoding, normalized)
|
|
|
- .AsScalarArray()
|
|
|
- .FillFrom(0, items);
|
|
|
+ SetVertexData(buffer, bufferByteOffset, items.Count, DimensionType.SCALAR, encoding, normalized);
|
|
|
|
|
|
- this.UpdateBounds();
|
|
|
+ AsScalarArray().FillFrom(0, items);
|
|
|
|
|
|
- return this;
|
|
|
+ this.UpdateBounds();
|
|
|
}
|
|
|
|
|
|
- public Accessor WithVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Vector2> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
+ public void SetVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Vector2> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
{
|
|
|
Guard.MustShareLogicalParent(this, buffer, nameof(buffer));
|
|
|
Guard.MustBePositiveAndMultipleOf(DimensionType.VEC2.DimCount() * encoding.ByteLength(), 4, nameof(encoding));
|
|
|
|
|
|
- WithVertexData(buffer, bufferByteOffset, items.Count, DimensionType.VEC2, encoding, normalized)
|
|
|
- .AsVector2Array()
|
|
|
- .FillFrom(0, items);
|
|
|
+ SetVertexData(buffer, bufferByteOffset, items.Count, DimensionType.VEC2, encoding, normalized);
|
|
|
|
|
|
- this.UpdateBounds();
|
|
|
+ AsVector2Array().FillFrom(0, items);
|
|
|
|
|
|
- return this;
|
|
|
+ this.UpdateBounds();
|
|
|
}
|
|
|
|
|
|
- public Accessor WithVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Vector3> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
+ public void SetVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Vector3> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
{
|
|
|
Guard.MustShareLogicalParent(this, buffer, nameof(buffer));
|
|
|
Guard.MustBePositiveAndMultipleOf(DimensionType.VEC3.DimCount() * encoding.ByteLength(), 4, nameof(encoding));
|
|
|
|
|
|
- WithVertexData(buffer, bufferByteOffset, items.Count, DimensionType.VEC3, encoding, normalized)
|
|
|
- .AsVector3Array()
|
|
|
- .FillFrom(0, items);
|
|
|
+ SetVertexData(buffer, bufferByteOffset, items.Count, DimensionType.VEC3, encoding, normalized);
|
|
|
|
|
|
- this.UpdateBounds();
|
|
|
+ AsVector3Array().FillFrom(0, items);
|
|
|
|
|
|
- return this;
|
|
|
+ this.UpdateBounds();
|
|
|
}
|
|
|
|
|
|
- public Accessor WithVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Vector4> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
+ public void SetVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Vector4> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
{
|
|
|
Guard.MustShareLogicalParent(this, buffer, nameof(buffer));
|
|
|
Guard.MustBePositiveAndMultipleOf(DimensionType.VEC4.DimCount() * encoding.ByteLength(), 4, nameof(encoding));
|
|
|
|
|
|
- WithVertexData(buffer, bufferByteOffset, items.Count, DimensionType.VEC4, encoding, normalized)
|
|
|
- .AsVector4Array()
|
|
|
- .FillFrom(0, items);
|
|
|
+ SetVertexData(buffer, bufferByteOffset, items.Count, DimensionType.VEC4, encoding, normalized);
|
|
|
|
|
|
- this.UpdateBounds();
|
|
|
+ AsVector4Array().FillFrom(0, items);
|
|
|
|
|
|
- return this;
|
|
|
+ this.UpdateBounds();
|
|
|
}
|
|
|
|
|
|
- public Accessor WithVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Quaternion> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
+ public void SetVertexData(BufferView buffer, int bufferByteOffset, IReadOnlyList<Quaternion> items, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
{
|
|
|
Guard.MustShareLogicalParent(this, buffer, nameof(buffer));
|
|
|
Guard.MustBePositiveAndMultipleOf(DimensionType.VEC4.DimCount() * encoding.ByteLength(), 4, nameof(encoding));
|
|
|
|
|
|
- WithVertexData(buffer, bufferByteOffset, items.Count, DimensionType.VEC4, encoding, normalized)
|
|
|
- .AsQuaternionArray()
|
|
|
- .FillFrom(0, items);
|
|
|
+ SetVertexData(buffer, bufferByteOffset, items.Count, DimensionType.VEC4, encoding, normalized);
|
|
|
|
|
|
- this.UpdateBounds();
|
|
|
+ AsQuaternionArray().FillFrom(0, items);
|
|
|
|
|
|
- return this;
|
|
|
+ this.UpdateBounds();
|
|
|
}
|
|
|
|
|
|
- public Accessor WithVertexData(BufferView buffer, int bufferByteOffset, int itemCount, DimensionType dimensions = DimensionType.VEC3, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
+ public void SetVertexData(BufferView buffer, int bufferByteOffset, int itemCount, DimensionType dimensions = DimensionType.VEC3, EncodingType encoding = EncodingType.FLOAT, Boolean normalized = false)
|
|
|
{
|
|
|
Guard.NotNull(buffer, nameof(buffer));
|
|
|
Guard.MustShareLogicalParent(this, buffer, nameof(buffer));
|
|
|
@@ -264,7 +251,7 @@ namespace SharpGLTF.Schema2
|
|
|
|
|
|
if (buffer.DeviceBufferTarget.HasValue) Guard.IsTrue(buffer.DeviceBufferTarget.Value == BufferMode.ARRAY_BUFFER, nameof(buffer));
|
|
|
|
|
|
- return WithData(buffer, bufferByteOffset, itemCount, dimensions, encoding, normalized);
|
|
|
+ WithData(buffer, bufferByteOffset, itemCount, dimensions, encoding, normalized);
|
|
|
}
|
|
|
|
|
|
public IEncodedArray<float> AsScalarArray()
|