Skip to content

Commit

Permalink
js: Adjust simplify/simplifyWithAttributes assertions
Browse files Browse the repository at this point in the history
To make ErrorAbsolute mode useful in JS, it needs to allow values
outside of 0..1 range; for simplicity we just remove the upper bound for
now.

Also, previously flags could contain values that are not recognized as
valid options and this would silently work; these are now checked with
assertions to prevent mistakes.
  • Loading branch information
zeux committed Jun 25, 2024
1 parent 4a75b2a commit 47aafa5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions js/meshopt_simplifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ var MeshoptSimplifier = (function() {
assert(vertex_positions_stride >= 3);
assert(target_index_count >= 0 && target_index_count <= indices.length);
assert(target_index_count % 3 == 0);
assert(target_error >= 0 && target_error <= 1);
assert(target_error >= 0);

var options = 0;
for (var i = 0; i < (flags ? flags.length : 0); ++i) {
assert(flags[i] in simplifyOptions);
options |= simplifyOptions[flags[i]];
}

Expand All @@ -210,13 +211,14 @@ var MeshoptSimplifier = (function() {
assert(vertex_lock == null || vertex_lock.length == vertex_positions.length);
assert(target_index_count >= 0 && target_index_count <= indices.length);
assert(target_index_count % 3 == 0);
assert(target_error >= 0 && target_error <= 1);
assert(target_error >= 0);
assert(Array.isArray(attribute_weights));
assert(vertex_attributes_stride >= attribute_weights.length);
assert(attribute_weights.length <= 16);

var options = 0;
for (var i = 0; i < (flags ? flags.length : 0); ++i) {
assert(flags[i] in simplifyOptions);
options |= simplifyOptions[flags[i]];
}

Expand Down
6 changes: 4 additions & 2 deletions js/meshopt_simplifier.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 47aafa5

Please sign in to comment.