diff --git a/js/meshopt_simplifier.js b/js/meshopt_simplifier.js index 16a710fb..7f5838cc 100644 --- a/js/meshopt_simplifier.js +++ b/js/meshopt_simplifier.js @@ -278,7 +278,8 @@ var MeshoptSimplifier = (function () { assert(vertex_attributes instanceof Float32Array); assert(vertex_attributes.length % vertex_attributes_stride == 0); assert(vertex_attributes_stride >= 0); - assert(vertex_lock == null || vertex_lock.length == vertex_positions.length); + assert(vertex_lock == null || vertex_lock instanceof Uint8Array); + assert(vertex_lock == null || vertex_lock.length == vertex_positions.length / vertex_positions_stride); assert(target_index_count >= 0 && target_index_count <= indices.length); assert(target_index_count % 3 == 0); assert(target_error >= 0); diff --git a/js/meshopt_simplifier.module.d.ts b/js/meshopt_simplifier.module.d.ts index c8b7763e..06686f73 100644 --- a/js/meshopt_simplifier.module.d.ts +++ b/js/meshopt_simplifier.module.d.ts @@ -27,7 +27,7 @@ export const MeshoptSimplifier: { vertex_attributes: Float32Array, vertex_attributes_stride: number, attribute_weights: number[], - vertex_lock: boolean[] | null, + vertex_lock: Uint8Array | null, target_index_count: number, target_error: number, flags?: Flags[] diff --git a/js/meshopt_simplifier.module.js b/js/meshopt_simplifier.module.js index 7f183f92..8c3a79d3 100644 --- a/js/meshopt_simplifier.module.js +++ b/js/meshopt_simplifier.module.js @@ -277,7 +277,8 @@ var MeshoptSimplifier = (function () { assert(vertex_attributes instanceof Float32Array); assert(vertex_attributes.length % vertex_attributes_stride == 0); assert(vertex_attributes_stride >= 0); - assert(vertex_lock == null || vertex_lock.length == vertex_positions.length); + assert(vertex_lock == null || vertex_lock instanceof Uint8Array); + assert(vertex_lock == null || vertex_lock.length == vertex_positions.length / vertex_positions_stride); assert(target_index_count >= 0 && target_index_count <= indices.length); assert(target_index_count % 3 == 0); assert(target_error >= 0); diff --git a/js/meshopt_simplifier.test.js b/js/meshopt_simplifier.test.js index a2a7e0bc..822b4e60 100644 --- a/js/meshopt_simplifier.test.js +++ b/js/meshopt_simplifier.test.js @@ -114,6 +114,23 @@ var tests = { assert.deepEqual(res[0], expected); }, + simplifyLockFlags: function () { + // 0 + // 1 2 + // 3 4 5 + var indices = new Uint32Array([0, 2, 1, 1, 2, 3, 3, 2, 4, 2, 5, 4]); + + var positions = new Float32Array([0, 2, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0]); + var locks = new Uint8Array([1, 1, 1, 1, 0, 1]); // only vertex 4 can move + + var res = simplifier.simplifyWithAttributes(indices, positions, 3, new Float32Array(), 1, [], locks, 3, 0.01); + + var expected = new Uint32Array([0, 2, 1, 1, 2, 3, 2, 5, 3]); + + assert.deepEqual(res[0], expected); + assert.equal(res[1], 0); // error + }, + getScale: function () { var positions = new Float32Array([0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3]);