Skip to content

Commit

Permalink
js: Add a unit test for simplifyWithAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
zeux committed Sep 28, 2023
1 parent 58317fe commit 83fea04
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions js/meshopt_simplifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,56 @@ var tests = {
assert.equal(res[1], 0); // error
},

simplifyAttr: function() {
var vb_pos = new Float32Array(8 * 3 * 3);
var vb_att = new Float32Array(8 * 3 * 3);

for (var y = 0; y < 8; ++y)
{
// first four rows are a blue gradient, next four rows are a yellow gradient
var r = (y < 4) ? 0.8 + y * 0.05 : 0;
var g = (y < 4) ? 0.8 + y * 0.05 : 0;
var b = (y < 4) ? 0 : 0.8 + (7 - y) * 0.05;

for (var x = 0; x < 3; ++x)
{
vb_pos[(y * 3 + x) * 3 + 0] = x;
vb_pos[(y * 3 + x) * 3 + 1] = y;
vb_pos[(y * 3 + x) * 3 + 2] = 0;
vb_att[(y * 3 + x) * 3 + 0] = r;
vb_att[(y * 3 + x) * 3 + 1] = g;
vb_att[(y * 3 + x) * 3 + 2] = b;
}
}

var ib = new Uint32Array(7 * 2 * 6);

for (var y = 0; y < 7; ++y)
{
for (var x = 0; x < 2; ++x)
{
ib[(y * 2 + x) * 6 + 0] = (y + 0) * 3 + (x + 0);
ib[(y * 2 + x) * 6 + 1] = (y + 0) * 3 + (x + 1);
ib[(y * 2 + x) * 6 + 2] = (y + 1) * 3 + (x + 0);
ib[(y * 2 + x) * 6 + 3] = (y + 1) * 3 + (x + 0);
ib[(y * 2 + x) * 6 + 4] = (y + 0) * 3 + (x + 1);
ib[(y * 2 + x) * 6 + 5] = (y + 1) * 3 + (x + 1);
}
}

var attr_weights = [0.01, 0.01, 0.01];

var res = simplifier.simplifyWithAttributes(ib, vb_pos, 3, vb_att, 3, attr_weights, 6 * 3, 1e-2);

var expected = new Uint32Array([
0, 2, 9, 9, 2, 11,
9, 11, 12, 12, 11, 14,
12, 14, 21, 21, 14, 23,
]);

assert.deepEqual(res[0], expected);
},

getScale: function() {
var positions = new Float32Array([
0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3
Expand Down

0 comments on commit 83fea04

Please sign in to comment.