Skip to content

Commit

Permalink
Merge pull request zeux#627 from zeux/jsexp
Browse files Browse the repository at this point in the history
js: Mark simplifyWithAttributes and simplifyPoints as experimental
  • Loading branch information
zeux committed Oct 31, 2023
2 parents a95a6f6 + 6984420 commit 69a5292
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions demo/simplify.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@

function simplify()
{
MeshoptSimplifier.useExperimentalFeatures = true;

MeshoptSimplifier.ready.then(function() {
scene.traverse(function (object) {
if (object.isMesh) {
Expand Down
6 changes: 6 additions & 0 deletions js/meshopt_simplifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ var MeshoptSimplifier = (function() {
ready: ready,
supported: true,

// set this to true to be able to use simplifyPoints and simplifyWithAttributes
// note that these functions are experimental and may change interface/behavior in a way that will require revising calling code
useExperimentalFeatures: false,

compactMesh: function(indices) {
assert(indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array);
assert(indices.length % 3 == 0);
Expand Down Expand Up @@ -188,6 +192,7 @@ var MeshoptSimplifier = (function() {
},

simplifyWithAttributes: function(indices, vertex_positions, vertex_positions_stride, vertex_attributes, vertex_attributes_stride, attribute_weights, target_index_count, target_error, flags) {
assert(this.useExperimentalFeatures); // set useExperimentalFeatures to use this; note that this function is experimental and may change interface in a way that will require revising calling code
assert(indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array);
assert(indices.length % 3 == 0);
assert(vertex_positions instanceof Float32Array);
Expand Down Expand Up @@ -222,6 +227,7 @@ var MeshoptSimplifier = (function() {
},

simplifyPoints: function(vertex_positions, vertex_positions_stride, target_vertex_count, vertex_colors, vertex_colors_stride, color_weight) {
assert(this.useExperimentalFeatures); // set useExperimentalFeatures to use this; note that this function is experimental and may change interface in a way that will require revising calling code
assert(vertex_positions instanceof Float32Array);
assert(vertex_positions.length % vertex_positions_stride == 0);
assert(vertex_positions_stride >= 3);
Expand Down
4 changes: 4 additions & 0 deletions js/meshopt_simplifier.module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ export type Flags = "LockBorder";
export const MeshoptSimplifier: {
supported: boolean;
ready: Promise<void>;

useExperimentalFeatures: boolean;

compactMesh: (indices: Uint32Array) => [Uint32Array, number];

simplify: (indices: Uint32Array, vertex_positions: Float32Array, vertex_positions_stride: number, target_index_count: number, target_error: number, flags?: Flags[]) => [Uint32Array, number];

// Experimental; requires useExperimentalFeatures to be set to true
simplifyWithAttributes: (indices: Uint32Array, vertex_positions: Float32Array, vertex_positions_stride: number, vertex_attributes: Float32Array, vertex_attributes_stride: number, attribute_weights: number[], target_index_count: number, target_error: number, flags?: Flags[]) => [Uint32Array, number];

getScale: (vertex_positions: Float32Array, vertex_positions_stride: number) => number;

// Experimental; requires useExperimentalFeatures to be set to true
simplifyPoints: (vertex_positions: Float32Array, vertex_positions_stride: number, target_vertex_count: number, vertex_colors?: Float32Array, vertex_colors_stride?: number, color_weight?: number) => Uint32Array;
};
6 changes: 6 additions & 0 deletions js/meshopt_simplifier.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ var MeshoptSimplifier = (function() {
ready: ready,
supported: true,

// set this to true to be able to use simplifyPoints and simplifyWithAttributes
// note that these functions are experimental and may change interface/behavior in a way that will require revising calling code
useExperimentalFeatures: false,

compactMesh: function(indices) {
assert(indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array);
assert(indices.length % 3 == 0);
Expand Down Expand Up @@ -187,6 +191,7 @@ var MeshoptSimplifier = (function() {
},

simplifyWithAttributes: function(indices, vertex_positions, vertex_positions_stride, vertex_attributes, vertex_attributes_stride, attribute_weights, target_index_count, target_error, flags) {
assert(this.useExperimentalFeatures); // set useExperimentalFeatures to use this; note that this function is experimental and may change interface in a way that will require revising calling code
assert(indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array);
assert(indices.length % 3 == 0);
assert(vertex_positions instanceof Float32Array);
Expand Down Expand Up @@ -221,6 +226,7 @@ var MeshoptSimplifier = (function() {
},

simplifyPoints: function(vertex_positions, vertex_positions_stride, target_vertex_count, vertex_colors, vertex_colors_stride, color_weight) {
assert(this.useExperimentalFeatures); // set useExperimentalFeatures to use this; note that this function is experimental and may change interface in a way that will require revising calling code
assert(vertex_positions instanceof Float32Array);
assert(vertex_positions.length % vertex_positions_stride == 0);
assert(vertex_positions_stride >= 3);
Expand Down
2 changes: 2 additions & 0 deletions js/meshopt_simplifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ process.on('unhandledRejection', error => {
process.exit(1);
});

simplifier.useExperimentalFeatures = true;

var tests = {
compactMesh: function() {
var indices = new Uint32Array([
Expand Down

0 comments on commit 69a5292

Please sign in to comment.