QuadricMeshSimplification

require.mx('mxjs/mesh/quadric-mesh-simplification.js');

An adaption of the mesh simplification method from https://github.com/sp4cerat/Fast-Quadric-Mesh-Simplification

StatusName

Class: Simplify

This class is used to access the simplification algorithm. Here's a simple example of using the simplifier:

// mesh is a MeshTA object.
 // calculate normals (you can skip this if they already exist).
 mesh.calculateNormalsCW();

// create the Simplify object. const simplify = new LibSimplify.Simplify(mesh, { PreserveBorders: true, PreserveTunnels: true });

// initialize the simplifier. simplify.initializeAndUpdateMesh();

// after initialization, we can check the minimum and maximum error caused // by collapsing any edge (if we want to). const minMax = []; simplify.minMaxError(minMax);

// perform the actual simplification. see the documentation for the // simplifyMesh function for more options. simplify.simplifyMesh({ maxIterations: 50, aggressiveness: 6 });

// remove deleted triangles and vertices from the MeshTA object. simplify.compactMesh();

// now we can write 'mesh' out to a table, etc.

StatusName
(constructor) ( MeshTA ↓Mesh, Object ↓Settings )

Construct a new Simplify object. The following properties are supported in the Settings parameter:

  • PreserveBorders {Bool} should the simplifier avoid collapsing edges on the border of the mesh?
  • PreserveTunnels {Bool} should the simplifier try to avoid collapsing edges that would result in a tunnel closing (which would cause previously 2-manifold surfaces to become non-manifold)?
  • MaximumEdgeLengthRatio {Number} if present, the simplifier will check the minimum to maximum edge length ratio of triangles that would result from an edge collapse, and avoid the collapse if any triangle's ratio would exceed this value (enabling this check will greatly slow down the simplifier).
  • MinimumInteriorAngleDegrees {Number} if present, the simplifier will check the interior angles of triangles that would result from an edge collapse, and avoid the collapse if any triangle would have an interior angle lower than this value (in degrees).

compactMesh ( )

Called to perform final mesh compacting after the simplification process is complete (i.e. after calling simplifyMesh). This will delete unused triangles and vertices from the associated Mesh object.

initializeAndUpdateMesh ( )

Called once, after the Simplify object is created, but before the simplification process begins, to do initial error calculations.

minMaxError ( Array ↑minmax )

Can be called after initializeAndUpdateMesh to determine the minimum and maximum error values associated with edge collapses throughout the mesh. This can be used, for example, to determine what range of thresholds should be iterated over for a threshold function.

simplifyMesh ( Object settings )

Main simplification function. Several iterations are performed to simplify the mesh. Typically, the threshold will increase with each iteration (so that more edges are eligible for collapsing), and the process will cease when a maximum number of iterations is reached, or a target triangle count is reached. Alternatively, one might perform a fixed number of iterations with their own thresholds, without regard to the triangle count achieved. The settings parameter supports the following properties:

  • breakFn function(triangleCount) -> boolean (optional) a function that receives the current triangle count, and returns true if the simplification process should stop.
  • targetTriangleCount number (optional) stop the simplification process when the triangle count is less than or equal to this number. This is only used if breakFn is not defined.
  • thresholdFn function(iteration) -> threshold (optional) a function that receives the current iteration (number) and returns the threshold to use for this iteration (number). The simplifier will only consider collapsing edges if the error introduced by the edge collapse would be lower than this threshold.
  • aggressivness number (optional) used to determine a threshold for each iteration, if thresholdFn is not provided. 5..8 are reasonable values. If no thresholdFn is provided, and no aggressiveness is defined, then 8 will be used as a default.
  • maxIterations number maximum number of iterations to perform (defaults to 50).

Simplify.(constructor) ( ↓Mesh, ↓Settings )

Construct a new Simplify object. The following properties are supported in the Settings parameter:

  • PreserveBorders {Bool} should the simplifier avoid collapsing edges on the border of the mesh?
  • PreserveTunnels {Bool} should the simplifier try to avoid collapsing edges that would result in a tunnel closing (which would cause previously 2-manifold surfaces to become non-manifold)?
  • MaximumEdgeLengthRatio {Number} if present, the simplifier will check the minimum to maximum edge length ratio of triangles that would result from an edge collapse, and avoid the collapse if any triangle's ratio would exceed this value (enabling this check will greatly slow down the simplifier).
  • MinimumInteriorAngleDegrees {Number} if present, the simplifier will check the interior angles of triangles that would result from an edge collapse, and avoid the collapse if any triangle would have an interior angle lower than this value (in degrees).

Parameters:
  • MeshTA ↓Mesh - a MeshTA object containing the mesh to simplify.
  • Object ↓Settings - an object containing the settings for this simplifier.
Simplify.compactMesh ( )

Called to perform final mesh compacting after the simplification process is complete (i.e. after calling simplifyMesh). This will delete unused triangles and vertices from the associated Mesh object.

Parameters:
Simplify.initializeAndUpdateMesh ( )

Called once, after the Simplify object is created, but before the simplification process begins, to do initial error calculations.

Parameters:
Simplify.minMaxError ( ↑minmax )

Can be called after initializeAndUpdateMesh to determine the minimum and maximum error values associated with edge collapses throughout the mesh. This can be used, for example, to determine what range of thresholds should be iterated over for a threshold function.

Parameters:
  • Array ↑minmax - receives [min_error, max_error]
Simplify.simplifyMesh ( settings )

Main simplification function. Several iterations are performed to simplify the mesh. Typically, the threshold will increase with each iteration (so that more edges are eligible for collapsing), and the process will cease when a maximum number of iterations is reached, or a target triangle count is reached. Alternatively, one might perform a fixed number of iterations with their own thresholds, without regard to the triangle count achieved. The settings parameter supports the following properties:

  • breakFn function(triangleCount) -> boolean (optional) a function that receives the current triangle count, and returns true if the simplification process should stop.
  • targetTriangleCount number (optional) stop the simplification process when the triangle count is less than or equal to this number. This is only used if breakFn is not defined.
  • thresholdFn function(iteration) -> threshold (optional) a function that receives the current iteration (number) and returns the threshold to use for this iteration (number). The simplifier will only consider collapsing edges if the error introduced by the edge collapse would be lower than this threshold.
  • aggressivness number (optional) used to determine a threshold for each iteration, if thresholdFn is not provided. 5..8 are reasonable values. If no thresholdFn is provided, and no aggressiveness is defined, then 8 will be used as a default.
  • maxIterations number maximum number of iterations to perform (defaults to 50).

Parameters:
  • Object settings - the settings