meshSimplification.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { Mesh } from "../Meshes/mesh";
  2. /**
  3. * A simplifier interface for future simplification implementations
  4. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/simplifyingMeshes
  5. */
  6. export interface ISimplifier {
  7. /**
  8. * Simplification of a given mesh according to the given settings.
  9. * Since this requires computation, it is assumed that the function runs async.
  10. * @param settings The settings of the simplification, including quality and distance
  11. * @param successCallback A callback that will be called after the mesh was simplified.
  12. * @param errorCallback in case of an error, this callback will be called. optional.
  13. */
  14. simplify(settings: ISimplificationSettings, successCallback: (simplifiedMeshes: Mesh) => void, errorCallback?: () => void): void;
  15. }
  16. /**
  17. * Expected simplification settings.
  18. * Quality should be between 0 and 1 (1 being 100%, 0 being 0%)
  19. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/simplifyingMeshes
  20. */
  21. export interface ISimplificationSettings {
  22. /**
  23. * Gets or sets the expected quality
  24. */
  25. quality: number;
  26. /**
  27. * Gets or sets the distance when this optimized version should be used
  28. */
  29. distance: number;
  30. /**
  31. * Gets an already optimized mesh
  32. */
  33. optimizeMesh?: boolean | undefined;
  34. }
  35. /**
  36. * Class used to specify simplification options
  37. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/simplifyingMeshes
  38. */
  39. export declare class SimplificationSettings implements ISimplificationSettings {
  40. /** expected quality */
  41. quality: number;
  42. /** distance when this optimized version should be used */
  43. distance: number;
  44. /** already optimized mesh */
  45. optimizeMesh?: boolean | undefined;
  46. /**
  47. * Creates a SimplificationSettings
  48. * @param quality expected quality
  49. * @param distance distance when this optimized version should be used
  50. * @param optimizeMesh already optimized mesh
  51. */
  52. constructor(
  53. /** expected quality */
  54. quality: number,
  55. /** distance when this optimized version should be used */
  56. distance: number,
  57. /** already optimized mesh */
  58. optimizeMesh?: boolean | undefined);
  59. }
  60. /**
  61. * Interface used to define a simplification task
  62. */
  63. export interface ISimplificationTask {
  64. /**
  65. * Array of settings
  66. */
  67. settings: Array<ISimplificationSettings>;
  68. /**
  69. * Simplification type
  70. */
  71. simplificationType: SimplificationType;
  72. /**
  73. * Mesh to simplify
  74. */
  75. mesh: Mesh;
  76. /**
  77. * Callback called on success
  78. */
  79. successCallback?: () => void;
  80. /**
  81. * Defines if parallel processing can be used
  82. */
  83. parallelProcessing: boolean;
  84. }
  85. /**
  86. * Queue used to order the simplification tasks
  87. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/simplifyingMeshes
  88. */
  89. export declare class SimplificationQueue {
  90. private _simplificationArray;
  91. /**
  92. * Gets a boolean indicating that the process is still running
  93. */
  94. running: boolean;
  95. /**
  96. * Creates a new queue
  97. */
  98. constructor();
  99. /**
  100. * Adds a new simplification task
  101. * @param task defines a task to add
  102. */
  103. addTask(task: ISimplificationTask): void;
  104. /**
  105. * Execute next task
  106. */
  107. executeNext(): void;
  108. /**
  109. * Execute a simplification task
  110. * @param task defines the task to run
  111. */
  112. runSimplification(task: ISimplificationTask): void;
  113. private _getSimplifier;
  114. }
  115. /**
  116. * The implemented types of simplification
  117. * At the moment only Quadratic Error Decimation is implemented
  118. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/simplifyingMeshes
  119. */
  120. export declare enum SimplificationType {
  121. /** Quadratic error decimation */
  122. QUADRATIC = 0
  123. }
  124. /**
  125. * An implementation of the Quadratic Error simplification algorithm.
  126. * Original paper : http://www1.cs.columbia.edu/~cs4162/html05s/garland97.pdf
  127. * Ported mostly from QSlim and http://voxels.blogspot.de/2014/05/quadric-mesh-simplification-with-source.html to babylon JS
  128. * @author RaananW
  129. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/simplifyingMeshes
  130. */
  131. export declare class QuadraticErrorSimplification implements ISimplifier {
  132. private _mesh;
  133. private _triangles;
  134. private _vertices;
  135. private _references;
  136. private _reconstructedMesh;
  137. /** Gets or sets the number pf sync iterations */
  138. syncIterations: number;
  139. /** Gets or sets the aggressiveness of the simplifier */
  140. aggressiveness: number;
  141. /** Gets or sets the number of allowed iterations for decimation */
  142. decimationIterations: number;
  143. /** Gets or sets the espilon to use for bounding box computation */
  144. boundingBoxEpsilon: number;
  145. /**
  146. * Creates a new QuadraticErrorSimplification
  147. * @param _mesh defines the target mesh
  148. */
  149. constructor(_mesh: Mesh);
  150. /**
  151. * Simplification of a given mesh according to the given settings.
  152. * Since this requires computation, it is assumed that the function runs async.
  153. * @param settings The settings of the simplification, including quality and distance
  154. * @param successCallback A callback that will be called after the mesh was simplified.
  155. */
  156. simplify(settings: ISimplificationSettings, successCallback: (simplifiedMesh: Mesh) => void): void;
  157. private _runDecimation;
  158. private _initWithMesh;
  159. private _init;
  160. private _reconstructMesh;
  161. private _initDecimatedMesh;
  162. private _isFlipped;
  163. private _updateTriangles;
  164. private _identifyBorder;
  165. private _updateMesh;
  166. private _vertexError;
  167. private _calculateError;
  168. }