Skip to content

Commit

Permalink
Allow at most 2 keyframes with the same t value
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasaglia committed Aug 28, 2024
1 parent 011aa98 commit f9496c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
5 changes: 4 additions & 1 deletion docs/specs/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ Their structure depends on whether it's animated or not:

{schema_object:properties/base-keyframe}

Keyframe arrays MUST be stored in order of strictly ascending `t` frame number. Two keyframes cannot have the same `t` value.
Keyframe arrays MUST be stored in order of ascending `t` frame number.

Two consecutive keyframes MAY have the same `t` value but a property MUST NOT have more that two keyframes with the same `t`.
If two keyframes share the `t` value, the implementation MUST render one of the two values at the given frame.

All keyframes MUST have an `i` and `o` value, unless-

Expand Down
35 changes: 28 additions & 7 deletions docs/static/js/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ function patch_schema_enum(schema)
}
}

function keyframe_has_t(kf)
{
return typeof kf == "object" && typeof kf.t == "number";
}

class Validator
{
constructor(AjvClass, schema_json)
Expand Down Expand Up @@ -359,14 +364,30 @@ class Validator
if ( index > 0 )
{
var prev_kf = data_cxt.parentData[index-1];
if ( typeof prev_kf == "object" && typeof prev_kf.t == "number" && typeof data.t == "number" && data.t <= prev_kf.t )
if ( keyframe_has_t(prev_kf) && typeof data.t == "number" )
{
validate_keyframe.errors.push({
message: `keyframe 't' must be strictly increasing`,
type: "error",
instancePath: data_cxt.instancePath,
parentSchema: parent_schema,
});
if ( data.t < prev_kf.t )
{
validate_keyframe.errors.push({
message: `keyframe 't' must be in ascending order`,
type: "error",
instancePath: data_cxt.instancePath,
parentSchema: parent_schema,
});
}
else if ( data.t == prev_kf.t && index > 1 )
{
var prev_prev = data_cxt.parentData[index-2];
if ( keyframe_has_t(prev_prev) && data.t == prev_prev.t )
{
validate_keyframe.errors.push({
message: `there can be at most 2 keyframes with the same 't' value`,
type: "error",
instancePath: data_cxt.instancePath,
parentSchema: parent_schema,
});
}
}
}
}

Expand Down

0 comments on commit f9496c4

Please sign in to comment.