internal void ValidateNormals(Validation.ValidationContext result) { result = result.GetContext(this); SourceBufferView.ValidateBufferUsageGPU(result, BufferMode.ARRAY_BUFFER); result.CheckLinkMustBeAnyOf(nameof(Dimensions), Dimensions, DimensionType.VEC3); if (!this.LogicalParent.MeshQuantizationAllowed) { result.CheckLinkMustBeAnyOf(nameof(Normalized), Normalized, false); result.CheckLinkMustBeAnyOf(nameof(Encoding), Encoding, EncodingType.FLOAT); } else { if (Normalized) { result.CheckLinkMustBeAnyOf(nameof(Encoding), Encoding, EncodingType.BYTE, EncodingType.SHORT); } else { result.CheckLinkMustBeAnyOf(nameof(Encoding), Encoding, EncodingType.FLOAT); } } var normals = this.AsVector3Array(); for (int i = 0; i < normals.Count; ++i) { if (result.TryFixUnitLengthOrError(i, normals[i])) { normals[i] = normals[i].SanitizeNormal(); } } }
protected override void OnValidateReferences(Validation.ValidationContext validate) { validate.IsGreaterOrEqual("ByteLength", _byteLength, _byteLengthMinimum); // result.CheckSchemaIsMultipleOf("ByteLength", _byteLength, 4); base.OnValidateReferences(validate); }
internal void ValidateBounds(Validation.ValidationContext result) { if (_min.Count == 0 && _max.Count == 0) { return; } var dimensions = this.Dimensions.DimCount(); if (_min.Count != dimensions) { result.AddError(this, $"min bounds length mismatch; expected {dimensions} but found {_min.Count}"); return; } if (_max.Count != dimensions) { result.AddError(this, $"max bounds length mismatch; expected {dimensions} but found {_max.Count}"); return; } for (int i = 0; i < _min.Count; ++i) { if (_min[i] > _max[i]) { result.AddError(this, $"min[{i}] is larger than max[{i}]"); } } if (this.Encoding != EncodingType.FLOAT) { return; } var current = new float[dimensions]; var minimum = this._min.ConvertAll(item => (float)item); var maximum = this._max.ConvertAll(item => (float)item); var array = new MultiArray(this.SourceBufferView.Content, this.ByteOffset, this.Count, this.SourceBufferView.ByteStride, dimensions, this.Encoding, false); for (int i = 0; i < array.Count; ++i) { array.CopyItemTo(i, current); for (int j = 0; j < current.Length; ++j) { var v = current[j]; if (!v._IsReal()) { result.AddError(this, $"Item[{j}][{i}] is not a finite number: {v}"); } var min = minimum[j]; var max = maximum[j]; if (v < min || v > max) { result.AddError(this, $"Item[{j}][{i}] is out of bounds. {min} <= {v} <= {max}"); } } } }
internal void ValidateSkinning(Validation.ValidationContext result, int jointsCount) { foreach (var p in Primitives) { p.ValidateSkinning(result, jointsCount); } }
internal void ValidateTangents(Validation.ValidationContext result) { var tangents = this.AsVector4Array(); for (int i = 0; i < tangents.Count; ++i) { var tgt = tangents[i]; if (!tgt._IsReal()) { result.AddError(this, $"TANGENT[{i}] value {tgt} has non finite values"); } var len = new Vector3(tgt.X, tgt.Y, tgt.Z).Length(); if (len < 0.99f || len > 1.01f) { result.AddError(this, $"TANGENT[{i}] length {len} is not unit length"); } if (tgt.W != 1 && tgt.W != -1) { result.AddError(this, $"TANGENT[{i}].W {tgt.W} has invalid value"); } } }
internal void ValidateJoints(Validation.ValidationContext result, int jwset, int jointsCount) { var jj = this.AsVector4Array(); void _CheckJoint(Validation.ValidationContext r, float v, int idx, string n) { if (!v._IsReal()) { result.AddError(this, $"JOINTS_{jwset}[{idx}].{n} value {v} is not finite"); } if ((v % 1) != 0) { result.AddError(this, $"JOINTS_{jwset}[{idx}].{n} value {v} should be a round value"); } if (v < 0 || v >= jointsCount) { result.AddError(this, $"JOINTS_{jwset}[{idx}].{n} value {v} is out of range 0-{jointsCount}"); } } for (int i = 0; i < jj.Count; ++i) { var jjjj = jj[i]; _CheckJoint(result, jjjj.X, i, "X"); _CheckJoint(result, jjjj.Y, i, "Y"); _CheckJoint(result, jjjj.Z, i, "Z"); _CheckJoint(result, jjjj.W, i, "W"); } }
internal void ValidateWeights(Validation.ValidationContext result, int jwset) { var ww = this.AsVector4Array(); void _CheckWeight(Validation.ValidationContext r, float v, int idx, string n) { if (!v._IsReal()) { result.AddError(this, $"WEIGHTS_{jwset}[{idx}].{n} value {v} is not finite"); } if (v < 0 || v > 1) { result.AddError(this, $"WEIGHTS_{jwset}[{idx}].{n} value {v} is out of range 0-1"); } } for (int i = 0; i < ww.Count; ++i) { var wwww = ww[i]; _CheckWeight(result, wwww.X, i, "X"); _CheckWeight(result, wwww.Y, i, "Y"); _CheckWeight(result, wwww.Z, i, "Z"); _CheckWeight(result, wwww.W, i, "W"); // theoretically, the sum of all the weights should give 1, ASSUMING there's only one weight set. // but in practice, that seems not to be true. } }
internal void ValidateIndices(Validation.ValidationContext result, uint vertexCount, PrimitiveType drawingType) { result = result.GetContext(this); SourceBufferView.ValidateBufferUsageGPU(result, BufferMode.ELEMENT_ARRAY_BUFFER); result.CheckLinkMustBeAnyOf(nameof(Normalized), Normalized, false); result.CheckLinkMustBeAnyOf(nameof(Encoding), Encoding, EncodingType.UNSIGNED_BYTE, EncodingType.UNSIGNED_SHORT, EncodingType.UNSIGNED_INT); result.CheckLinkMustBeAnyOf(nameof(Dimensions), Dimensions, DimensionType.SCALAR); uint restart_value = 0xff; if (this.Encoding == EncodingType.UNSIGNED_SHORT) { restart_value = 0xffff; } if (this.Encoding == EncodingType.UNSIGNED_INT) { restart_value = 0xffffffff; } var indices = this.AsIndicesArray(); for (int i = 0; i < indices.Count; ++i) { result.CheckVertexIndex(i, indices[i], vertexCount, restart_value); } }
protected override void OnValidateReferences(Validation.ValidationContext validate) { validate .IsGreater(nameof(Primitives), this.Primitives.Count, 0) .IsSetCollection(nameof(Primitives), _primitives); base.OnValidateReferences(validate); }
public IEnumerable <Exception> Validate() { var result = new Validation.ValidationContext(); Validate(result); return(result.Exceptions); }
protected override void OnValidateContent(Validation.ValidationContext validate) { validate .NotNull("Content", _Content) .IsLessOrEqual("ByteLength", _byteLength, _Content.Length); base.OnValidateContent(validate); }
protected override void OnValidateReferences(Validation.ValidationContext result) { base.OnValidateReferences(result); result.CheckSchemaIsValidURI("Uri", this._uri, EMBEDDEDGLTFBUFFER, EMBEDDEDOCTETSTREAM); result.CheckSchemaIsInRange("ByteLength", _byteLength, _byteLengthMinimum, int.MaxValue); // result.CheckSchemaIsMultipleOf("ByteLength", _byteLength, 4); }
protected override void OnValidateReferences(Validation.ValidationContext result) { base.OnValidateReferences(result); result.CheckSchemaIsValidURI("Uri", this._uri); result.CheckArrayIndexAccess("BufferView", _bufferView, this.LogicalParent.LogicalBufferViews); }
protected override void OnValidateReferences(Validation.ValidationContext validate) { base.OnValidateReferences(validate); validate .IsNullOrValidURI(nameof(_uri), this._uri, Memory.MemoryImage._EmbeddedHeaders) .IsNullOrIndex("BufferView", _bufferView, validate.Root.LogicalBufferViews); }
internal override void Validate(Validation.ValidationContext result) { base.Validate(result); foreach (var p in this.Primitives) { p.Validate(result); } }
protected override void OnValidate(Validation.ValidationContext result) { base.OnValidate(result); if (_Content.Length < _byteLength) { result.AddDataError("ByteLength", $"Actual data length {_Content.Length} is less than the declared buffer byteLength {_byteLength}."); } }
protected override void OnValidateReferences(Validation.ValidationContext result) { base.OnValidateReferences(result); result.CheckLinksInCollection("Primitives", _primitives); foreach (var p in this.Primitives) { p.ValidateReferences(result); } }
protected override void OnValidateReferences(Validation.ValidationContext result) { base.OnValidateReferences(result); result.CheckSchemaIsDefined("BufferView", _bufferView); result.CheckArrayIndexAccess("BufferView", _bufferView, this.LogicalParent.LogicalBufferViews); result.CheckSchemaNonNegative("ByteOffset", _byteOffset); result.CheckSchemaIsInRange("Count", _count, _countMinimum, int.MaxValue); _sparse?.ValidateReferences(result); }
internal override void Validate(Validation.ValidationContext result) { base.Validate(result); if (this._extras != null) { if (!IO.JsonUtils.IsSerializable(this._extras)) { result.InvalidJson(this, "Extras"); } } }
protected override void OnValidateContent(Validation.ValidationContext validate) { if (_weights.Count > 0) { foreach (var p in this.Primitives) { validate.GetContext(p).AreEqual("MorphTargetsCount", p.MorphTargetsCount, _weights.Count); } } base.OnValidateContent(validate); }
protected override void OnValidateReferences(Validation.ValidationContext result) { base.OnValidateReferences(result); // check out of range indices foreach (var idx in this._nodes) { result.CheckArrayIndexAccess(nameof(VisualChildren), idx, this.LogicalParent.LogicalNodes); } // check duplicated indices // if (this._nodes.Distinct().Count() != this._nodes.Count) result.AddError(this, "has duplicated node references"); }
protected override void OnValidate(Validation.ValidationContext result) { base.OnValidate(result); _sparse?.Validate(result); BufferView.CheckAccess(result, this.SourceBufferView, this.ByteOffset, this.Dimensions, this.Encoding, this.Normalized, this.Count); ValidateBounds(result); // at this point we don't know which kind of data we're accessing, so it's up to the components // using this accessor to validate the data. }
internal void ValidatePositions(Validation.ValidationContext result) { var positions = this.AsVector3Array(); for (int i = 0; i < positions.Count; ++i) { var pos = positions[i]; if (!pos._IsReal()) { result.AddError(this, $"POSITION[{i}] value {pos} has non finite values"); } } }
internal void ValidateMatrices(Validation.ValidationContext result) { result = result.GetContext(this); SourceBufferView.ValidateBufferUsageData(result); result.CheckLinkMustBeAnyOf(nameof(Dimensions), Dimensions, DimensionType.MAT4); var matrices = this.AsMatrix4x4Array(); for (int i = 0; i < matrices.Count; ++i) { result.CheckIsMatrix(i, matrices[i]); } }
internal void ValidateNormals(Validation.ValidationContext result) { var normals = this.AsVector3Array(); for (int i = 0; i < normals.Count; ++i) { var nrm = normals[i]; if (!nrm.IsValidNormal()) { result.AddError(this, $"NORMAL[{i}] value {nrm} is invalid"); } } }
internal void OnValidateBinaryChunk(Validation.ValidationContext result, Byte[] binaryChunk) { if (_uri == null) { if (binaryChunk == null) { result.GetContext(this).AddSchemaError("Binary chunk not found"); return; } if (_byteLength > binaryChunk.Length) { result.GetContext(this).AddSchemaError("Buffer length larger than Binary chunk"); } } }
protected override void OnValidateReferences(Validation.ValidationContext result) { base.OnValidateReferences(result); foreach (var ext in this.Extensions) { ext.ValidateReferences(result); } if (this._extras is JsonSerializable js) { js.ValidateReferences(result); } }
internal void ValidateBufferUsageGPU(Validation.ValidationContext result, BufferMode usingMode) { result = result.GetContext(this); if (!this._target.HasValue) { return; } if (usingMode == this._target.Value) { return; } result.AddLinkError("Device Buffer Target", $"is set as {this._target.Value}. But an accessor wants to use it as '{usingMode}'."); }
public static void ValidateWeightsSum(Validation.ValidationContext result, MemoryAccessor weights0, MemoryAccessor weights1) { int idx = 0; if (weights1 == null) { if (weights0 == null) { return; } foreach (var item in weights0.GetItemsAsRawBytes()) { if (!_CheckWeightSum(item, weights0.Attribute.Encoding)) { result.AddDataError($"Weight Sum invalid at Index {idx}"); } ++idx; } return; } if (weights0 == null) { result.AddLinkError(""); return; } var len = weights0.Attribute.ItemByteLength; Span <Byte> dst = stackalloc byte[len * 2]; var zip = weights0.GetItemsAsRawBytes().Zip(weights1.GetItemsAsRawBytes(), (a, b) => (a, b)); foreach (var(a, b) in zip) { a.AsSpan().CopyTo(dst); b.AsSpan().CopyTo(dst.Slice(len)); if (!_CheckWeightSum(dst, weights0.Attribute.Encoding)) { result.AddDataError($"Weight Sum invalid at Index {idx}"); } ++idx; } }
protected override void OnValidateReferences(Validation.ValidationContext validate) { if (_type == CameraType.perspective) { validate.IsDefined("perspective", _perspective); validate.IsUndefined("orthographic", _orthographic); } if (_type == CameraType.orthographic) { validate.IsUndefined("perspective", _perspective); validate.IsDefined("orthographic", _orthographic); } base.OnValidateReferences(validate); }