Skip to content

Commit b1a6634

Browse files
authored
Merge pull request #849 from zeux/stabilize
Stabilize a set of experimental APIs
2 parents 4cee4aa + 14ba7af commit b1a6634

File tree

7 files changed

+15
-32
lines changed

7 files changed

+15
-32
lines changed

demo/simplify.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,6 @@
457457

458458
function simplify() {
459459
MeshoptSimplifier.ready.then(function () {
460-
MeshoptSimplifier.useExperimentalFeatures = true;
461-
462460
var threshold = Math.pow(10, -settings.errorThresholdLog10);
463461

464462
if (settings.autoLod) {

js/meshopt_simplifier.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,6 @@ var MeshoptSimplifier = (function () {
205205
ready: ready,
206206
supported: true,
207207

208-
// set this to true to be able to use simplifyPoints and simplifyWithAttributes
209-
// note that these functions are experimental and may change interface/behavior in a way that will require revising calling code
210-
useExperimentalFeatures: false,
211-
212208
compactMesh: function (indices) {
213209
assert(
214210
indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array
@@ -234,7 +230,6 @@ var MeshoptSimplifier = (function () {
234230
var options = 0;
235231
for (var i = 0; i < (flags ? flags.length : 0); ++i) {
236232
assert(flags[i] in simplifyOptions);
237-
assert(this.useExperimentalFeatures || flags[i] != 'Prune'); // set useExperimentalFeatures to use experimental flags like Prune
238233
options |= simplifyOptions[flags[i]];
239234
}
240235

@@ -267,7 +262,6 @@ var MeshoptSimplifier = (function () {
267262
target_error,
268263
flags
269264
) {
270-
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
271265
assert(
272266
indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array
273267
);
@@ -330,7 +324,6 @@ var MeshoptSimplifier = (function () {
330324
},
331325

332326
simplifyPoints: function (vertex_positions, vertex_positions_stride, target_vertex_count, vertex_colors, vertex_colors_stride, color_weight) {
333-
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
334327
assert(vertex_positions instanceof Float32Array);
335328
assert(vertex_positions.length % vertex_positions_stride == 0);
336329
assert(vertex_positions_stride >= 3);

js/meshopt_simplifier.module.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export const MeshoptSimplifier: {
66
supported: boolean;
77
ready: Promise<void>;
88

9-
useExperimentalFeatures: boolean;
10-
119
compactMesh: (indices: Uint32Array) => [Uint32Array, number];
1210

1311
simplify: (
@@ -19,7 +17,6 @@ export const MeshoptSimplifier: {
1917
flags?: Flags[]
2018
) => [Uint32Array, number];
2119

22-
// Experimental; requires useExperimentalFeatures to be set to true
2320
simplifyWithAttributes: (
2421
indices: Uint32Array,
2522
vertex_positions: Float32Array,
@@ -35,7 +32,6 @@ export const MeshoptSimplifier: {
3532

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

38-
// Experimental; requires useExperimentalFeatures to be set to true
3935
simplifyPoints: (
4036
vertex_positions: Float32Array,
4137
vertex_positions_stride: number,

js/meshopt_simplifier.module.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,6 @@ var MeshoptSimplifier = (function () {
204204
ready: ready,
205205
supported: true,
206206

207-
// set this to true to be able to use simplifyPoints and simplifyWithAttributes
208-
// note that these functions are experimental and may change interface/behavior in a way that will require revising calling code
209-
useExperimentalFeatures: false,
210-
211207
compactMesh: function (indices) {
212208
assert(
213209
indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array
@@ -233,7 +229,6 @@ var MeshoptSimplifier = (function () {
233229
var options = 0;
234230
for (var i = 0; i < (flags ? flags.length : 0); ++i) {
235231
assert(flags[i] in simplifyOptions);
236-
assert(this.useExperimentalFeatures || flags[i] != 'Prune'); // set useExperimentalFeatures to use experimental flags like Prune
237232
options |= simplifyOptions[flags[i]];
238233
}
239234

@@ -266,7 +261,6 @@ var MeshoptSimplifier = (function () {
266261
target_error,
267262
flags
268263
) {
269-
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
270264
assert(
271265
indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array
272266
);
@@ -329,7 +323,6 @@ var MeshoptSimplifier = (function () {
329323
},
330324

331325
simplifyPoints: function (vertex_positions, vertex_positions_stride, target_vertex_count, vertex_colors, vertex_colors_stride, color_weight) {
332-
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
333326
assert(vertex_positions instanceof Float32Array);
334327
assert(vertex_positions.length % vertex_positions_stride == 0);
335328
assert(vertex_positions_stride >= 3);

js/meshopt_simplifier.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ process.on('unhandledRejection', (error) => {
66
process.exit(1);
77
});
88

9-
simplifier.useExperimentalFeatures = true;
10-
119
var tests = {
1210
compactMesh: function () {
1311
var indices = new Uint32Array([0, 1, 3, 3, 1, 5]);

src/meshoptimizer.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ MESHOPTIMIZER_API size_t meshopt_encodeVertexBufferBound(size_t vertex_count, si
292292
*
293293
* level should be in the range [0, 3] with 0 being the fastest and 3 being the slowest and producing the best compression ratio.
294294
*/
295-
MESHOPTIMIZER_API size_t meshopt_encodeVertexBufferLevel(unsigned char* buffer, size_t buffer_size, const void* vertices, size_t vertex_count, size_t vertex_size, int level);
295+
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_encodeVertexBufferLevel(unsigned char* buffer, size_t buffer_size, const void* vertices, size_t vertex_count, size_t vertex_size, int level);
296296

297297
/**
298298
* Set vertex encoder format version
@@ -358,7 +358,7 @@ enum meshopt_EncodeExpMode
358358
meshopt_EncodeExpSharedVector,
359359
/* When encoding exponents, use shared value for each component of all vectors (best compression) */
360360
meshopt_EncodeExpSharedComponent,
361-
/* Experimental: When encoding exponents, use separate values for each component, but clamp to 0 (good quality if very small values are not important) */
361+
/* When encoding exponents, use separate values for each component, but clamp to 0 (good quality if very small values are not important) */
362362
meshopt_EncodeExpClamped,
363363
};
364364

@@ -399,7 +399,7 @@ enum
399399
MESHOPTIMIZER_API size_t meshopt_simplify(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error, unsigned int options, float* result_error);
400400

401401
/**
402-
* Experimental: Mesh simplifier with attribute metric
402+
* Mesh simplifier with attribute metric
403403
* The algorithm enhances meshopt_simplify by incorporating attribute values into the error metric used to prioritize simplification order; see meshopt_simplify documentation for details.
404404
* Note that the number of attributes affects memory requirements and running time; this algorithm requires ~1.5x more memory and time compared to meshopt_simplify when using 4 scalar attributes.
405405
*
@@ -408,7 +408,7 @@ MESHOPTIMIZER_API size_t meshopt_simplify(unsigned int* destination, const unsig
408408
* attribute_count must be <= 32
409409
* vertex_lock can be NULL; when it's not NULL, it should have a value for each vertex; 1 denotes vertices that can't be moved
410410
*/
411-
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifyWithAttributes(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, const float* vertex_attributes, size_t vertex_attributes_stride, const float* attribute_weights, size_t attribute_count, const unsigned char* vertex_lock, size_t target_index_count, float target_error, unsigned int options, float* result_error);
411+
MESHOPTIMIZER_API size_t meshopt_simplifyWithAttributes(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, const float* vertex_attributes, size_t vertex_attributes_stride, const float* attribute_weights, size_t attribute_count, const unsigned char* vertex_lock, size_t target_index_count, float target_error, unsigned int options, float* result_error);
412412

413413
/**
414414
* Experimental: Mesh simplifier (sloppy)
@@ -426,7 +426,7 @@ MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifyWithAttributes(unsigned int* d
426426
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifySloppy(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error, float* result_error);
427427

428428
/**
429-
* Experimental: Point cloud simplifier
429+
* Point cloud simplifier
430430
* Reduces the number of points in the cloud to reach the given target
431431
* Returns the number of points after simplification, with destination containing new index data
432432
* The resulting index buffer references vertices from the original vertex buffer.
@@ -437,7 +437,7 @@ MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifySloppy(unsigned int* destinati
437437
* vertex_colors should can be NULL; when it's not NULL, it should have float3 color in the first 12 bytes of each vertex
438438
* color_weight determines relative priority of color wrt position; 1.0 is a safe default
439439
*/
440-
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifyPoints(unsigned int* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, const float* vertex_colors, size_t vertex_colors_stride, float color_weight, size_t target_vertex_count);
440+
MESHOPTIMIZER_API size_t meshopt_simplifyPoints(unsigned int* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, const float* vertex_colors, size_t vertex_colors_stride, float color_weight, size_t target_vertex_count);
441441

442442
/**
443443
* Returns the error scaling factor used by the simplifier to convert between absolute and relative extents
@@ -565,17 +565,17 @@ MESHOPTIMIZER_API size_t meshopt_buildMeshletsBound(size_t index_count, size_t m
565565
* cone_weight should be set to 0 when cone culling is not used, and a value between 0 and 1 otherwise to balance between cluster size and cone culling efficiency; additionally, cone_weight can be set to a negative value to prioritize axis aligned clusters (for raytracing) instead
566566
* split_factor should be set to a non-negative value; when greater than 0, clusters that have large bounds may be split unless they are under the min_triangles threshold
567567
*/
568-
MESHOPTIMIZER_API size_t meshopt_buildMeshletsFlex(struct meshopt_Meshlet* meshlets, unsigned int* meshlet_vertices, unsigned char* meshlet_triangles, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t max_vertices, size_t min_triangles, size_t max_triangles, float cone_weight, float split_factor);
568+
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_buildMeshletsFlex(struct meshopt_Meshlet* meshlets, unsigned int* meshlet_vertices, unsigned char* meshlet_triangles, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t max_vertices, size_t min_triangles, size_t max_triangles, float cone_weight, float split_factor);
569569

570570
/**
571-
* Experimental: Meshlet optimizer
571+
* Meshlet optimizer
572572
* Reorders meshlet vertices and triangles to maximize locality to improve rasterizer throughput
573573
*
574574
* meshlet_triangles and meshlet_vertices must refer to meshlet triangle and vertex index data; when buildMeshlets* is used, these
575575
* need to be computed from meshlet's vertex_offset and triangle_offset
576576
* triangle_count and vertex_count must not exceed implementation limits (vertex_count <= 255 - not 256!, triangle_count <= 512)
577577
*/
578-
MESHOPTIMIZER_EXPERIMENTAL void meshopt_optimizeMeshlet(unsigned int* meshlet_vertices, unsigned char* meshlet_triangles, size_t triangle_count, size_t vertex_count);
578+
MESHOPTIMIZER_API void meshopt_optimizeMeshlet(unsigned int* meshlet_vertices, unsigned char* meshlet_triangles, size_t triangle_count, size_t vertex_count);
579579

580580
struct meshopt_Bounds
581581
{

src/simplifier.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,13 @@ static void classifyVertices(unsigned char* result, unsigned int* loop, unsigned
437437
{
438438
// vertex_lock may lock any wedge, not just the primary vertex, so we need to lock the primary vertex and relock any wedges
439439
for (size_t i = 0; i < vertex_count; ++i)
440-
if (vertex_lock[sparse_remap ? sparse_remap[i] : i])
440+
{
441+
unsigned int ri = sparse_remap ? sparse_remap[i] : unsigned(i);
442+
assert(vertex_lock[ri] <= 1); // values other than 0/1 are reserved for future use
443+
444+
if (vertex_lock[ri])
441445
result[remap[i]] = Kind_Locked;
446+
}
442447

443448
for (size_t i = 0; i < vertex_count; ++i)
444449
if (result[remap[i]] == Kind_Locked)

0 commit comments

Comments
 (0)