babylon.meshSimplification.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var SimplificationSettings = (function () {
  4. function SimplificationSettings(quality, distance) {
  5. this.quality = quality;
  6. this.distance = distance;
  7. }
  8. return SimplificationSettings;
  9. })();
  10. BABYLON.SimplificationSettings = SimplificationSettings;
  11. /**
  12. * The implemented types of simplification.
  13. * At the moment only Quadratic Error Decimation is implemented.
  14. */
  15. (function (SimplificationType) {
  16. SimplificationType[SimplificationType["QUADRATIC"] = 0] = "QUADRATIC";
  17. })(BABYLON.SimplificationType || (BABYLON.SimplificationType = {}));
  18. var SimplificationType = BABYLON.SimplificationType;
  19. var DecimationTriangle = (function () {
  20. function DecimationTriangle(vertices) {
  21. this.vertices = vertices;
  22. this.error = new Array(4);
  23. this.deleted = false;
  24. this.isDirty = false;
  25. this.borderFactor = 0;
  26. }
  27. return DecimationTriangle;
  28. })();
  29. BABYLON.DecimationTriangle = DecimationTriangle;
  30. var DecimationVertex = (function () {
  31. function DecimationVertex(position, normal, uv, id) {
  32. this.position = position;
  33. this.normal = normal;
  34. this.uv = uv;
  35. this.id = id;
  36. this.isBorder = true;
  37. this.q = new QuadraticMatrix();
  38. this.triangleCount = 0;
  39. this.triangleStart = 0;
  40. }
  41. return DecimationVertex;
  42. })();
  43. BABYLON.DecimationVertex = DecimationVertex;
  44. var QuadraticMatrix = (function () {
  45. function QuadraticMatrix(data) {
  46. this.data = new Array(10);
  47. for (var i = 0; i < 10; ++i) {
  48. if (data && data[i]) {
  49. this.data[i] = data[i];
  50. } else {
  51. this.data[i] = 0;
  52. }
  53. }
  54. }
  55. QuadraticMatrix.prototype.det = function (a11, a12, a13, a21, a22, a23, a31, a32, a33) {
  56. var det = this.data[a11] * this.data[a22] * this.data[a33] + this.data[a13] * this.data[a21] * this.data[a32] + this.data[a12] * this.data[a23] * this.data[a31] - this.data[a13] * this.data[a22] * this.data[a31] - this.data[a11] * this.data[a23] * this.data[a32] - this.data[a12] * this.data[a21] * this.data[a33];
  57. return det;
  58. };
  59. QuadraticMatrix.prototype.addInPlace = function (matrix) {
  60. for (var i = 0; i < 10; ++i) {
  61. this.data[i] += matrix.data[i];
  62. }
  63. };
  64. QuadraticMatrix.prototype.addArrayInPlace = function (data) {
  65. for (var i = 0; i < 10; ++i) {
  66. this.data[i] += data[i];
  67. }
  68. };
  69. QuadraticMatrix.prototype.add = function (matrix) {
  70. var m = new QuadraticMatrix();
  71. for (var i = 0; i < 10; ++i) {
  72. m.data[i] = this.data[i] + matrix.data[i];
  73. }
  74. return m;
  75. };
  76. QuadraticMatrix.FromData = function (a, b, c, d) {
  77. return new QuadraticMatrix(QuadraticMatrix.DataFromNumbers(a, b, c, d));
  78. };
  79. //returning an array to avoid garbage collection
  80. QuadraticMatrix.DataFromNumbers = function (a, b, c, d) {
  81. return [a * a, a * b, a * c, a * d, b * b, b * c, b * d, c * c, c * d, d * d];
  82. };
  83. return QuadraticMatrix;
  84. })();
  85. BABYLON.QuadraticMatrix = QuadraticMatrix;
  86. var Reference = (function () {
  87. function Reference(vertexId, triangleId) {
  88. this.vertexId = vertexId;
  89. this.triangleId = triangleId;
  90. }
  91. return Reference;
  92. })();
  93. BABYLON.Reference = Reference;
  94. /**
  95. * An implementation of the Quadratic Error simplification algorithm.
  96. * Original paper : http://www1.cs.columbia.edu/~cs4162/html05s/garland97.pdf
  97. * Ported mostly from QSlim and http://voxels.blogspot.de/2014/05/quadric-mesh-simplification-with-source.html to babylon JS
  98. * @author RaananW
  99. */
  100. var QuadraticErrorSimplification = (function () {
  101. function QuadraticErrorSimplification(_mesh) {
  102. this._mesh = _mesh;
  103. this.initialised = false;
  104. this.syncIterations = 5000;
  105. this.aggressiveness = 7;
  106. this.decimationIterations = 100;
  107. }
  108. QuadraticErrorSimplification.prototype.simplify = function (settings, successCallback) {
  109. var _this = this;
  110. this.initWithMesh(this._mesh, function () {
  111. _this.runDecimation(settings, successCallback);
  112. });
  113. };
  114. QuadraticErrorSimplification.prototype.runDecimation = function (settings, successCallback) {
  115. var _this = this;
  116. var targetCount = ~~(this.triangles.length * settings.quality);
  117. var deletedTriangles = 0;
  118. var triangleCount = this.triangles.length;
  119. var iterationFunction = function (iteration, callback) {
  120. setTimeout(function () {
  121. if (iteration % 5 === 0) {
  122. _this.updateMesh(iteration === 0);
  123. }
  124. for (var i = 0; i < _this.triangles.length; ++i) {
  125. _this.triangles[i].isDirty = false;
  126. }
  127. var threshold = 0.000000001 * Math.pow((iteration + 3), _this.aggressiveness);
  128. var trianglesIterator = function (i) {
  129. var tIdx = ((_this.triangles.length / 2) + i) % _this.triangles.length;
  130. var t = _this.triangles[tIdx];
  131. if (!t)
  132. return;
  133. if (t.error[3] > threshold || t.deleted || t.isDirty) {
  134. return;
  135. }
  136. for (var j = 0; j < 3; ++j) {
  137. if (t.error[j] < threshold) {
  138. var deleted0 = [];
  139. var deleted1 = [];
  140. var i0 = t.vertices[j];
  141. var i1 = t.vertices[(j + 1) % 3];
  142. var v0 = _this.vertices[i0];
  143. var v1 = _this.vertices[i1];
  144. if (v0.isBorder !== v1.isBorder)
  145. continue;
  146. var p = BABYLON.Vector3.Zero();
  147. var n = BABYLON.Vector3.Zero();
  148. var uv = BABYLON.Vector2.Zero();
  149. _this.calculateError(v0, v1, p, n, uv);
  150. if (_this.isFlipped(v0, i1, p, deleted0, t.borderFactor))
  151. continue;
  152. if (_this.isFlipped(v1, i0, p, deleted1, t.borderFactor))
  153. continue;
  154. v0.position = p;
  155. v0.normal = n;
  156. v0.uv = uv;
  157. v0.q = v1.q.add(v0.q);
  158. var tStart = _this.references.length;
  159. deletedTriangles = _this.updateTriangles(v0.id, v0, deleted0, deletedTriangles);
  160. deletedTriangles = _this.updateTriangles(v0.id, v1, deleted1, deletedTriangles);
  161. var tCount = _this.references.length - tStart;
  162. if (tCount <= v0.triangleCount) {
  163. if (tCount) {
  164. for (var c = 0; c < tCount; c++) {
  165. _this.references[v0.triangleStart + c] = _this.references[tStart + c];
  166. }
  167. }
  168. } else {
  169. v0.triangleStart = tStart;
  170. }
  171. v0.triangleCount = tCount;
  172. break;
  173. }
  174. }
  175. };
  176. BABYLON.AsyncLoop.SyncAsyncForLoop(_this.triangles.length, _this.syncIterations, trianglesIterator, callback, function () {
  177. return (triangleCount - deletedTriangles <= targetCount);
  178. });
  179. }, 0);
  180. };
  181. BABYLON.AsyncLoop.Run(this.decimationIterations, function (loop) {
  182. if (triangleCount - deletedTriangles <= targetCount)
  183. loop.breakLoop();
  184. else {
  185. iterationFunction(loop.index, function () {
  186. loop.executeNext();
  187. });
  188. }
  189. }, function () {
  190. setTimeout(function () {
  191. successCallback(_this.reconstructMesh());
  192. }, 0);
  193. });
  194. };
  195. QuadraticErrorSimplification.prototype.initWithMesh = function (mesh, callback) {
  196. var _this = this;
  197. if (!mesh)
  198. return;
  199. this.vertices = [];
  200. this.triangles = [];
  201. this._mesh = mesh;
  202. //It is assumed that a mesh has positions, normals and either uvs or colors.
  203. var positionData = this._mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  204. var normalData = this._mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  205. var uvs = this._mesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
  206. var colorsData = this._mesh.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  207. var indices = mesh.getIndices();
  208. var vertexInit = function (i) {
  209. var uv;
  210. if (uvs[i * 2]) {
  211. uv = BABYLON.Vector2.FromArray(uvs, i * 2);
  212. }
  213. var vertex = new DecimationVertex(BABYLON.Vector3.FromArray(positionData, i * 3), BABYLON.Vector3.FromArray(normalData, i * 3), uv, i);
  214. if (!uv && colorsData[i * 3]) {
  215. vertex.color = BABYLON.Color3.FromArray(colorsData, i * 3);
  216. }
  217. _this.vertices.push(vertex);
  218. };
  219. var totalVertices = mesh.getTotalVertices();
  220. BABYLON.AsyncLoop.SyncAsyncForLoop(totalVertices, this.syncIterations, vertexInit, function () {
  221. var indicesInit = function (i) {
  222. var pos = i * 3;
  223. var i0 = indices[pos + 0];
  224. var i1 = indices[pos + 1];
  225. var i2 = indices[pos + 2];
  226. var triangle = new DecimationTriangle([_this.vertices[i0].id, _this.vertices[i1].id, _this.vertices[i2].id]);
  227. _this.triangles.push(triangle);
  228. };
  229. BABYLON.AsyncLoop.SyncAsyncForLoop(indices.length / 3, _this.syncIterations, indicesInit, function () {
  230. _this.init(callback);
  231. });
  232. });
  233. };
  234. QuadraticErrorSimplification.prototype.init = function (callback) {
  235. var _this = this;
  236. var triangleInit1 = function (i) {
  237. var t = _this.triangles[i];
  238. t.normal = BABYLON.Vector3.Cross(_this.vertices[t.vertices[1]].position.subtract(_this.vertices[t.vertices[0]].position), _this.vertices[t.vertices[2]].position.subtract(_this.vertices[t.vertices[0]].position)).normalize();
  239. for (var j = 0; j < 3; j++) {
  240. _this.vertices[t.vertices[j]].q.addArrayInPlace(QuadraticMatrix.DataFromNumbers(t.normal.x, t.normal.y, t.normal.z, -(BABYLON.Vector3.Dot(t.normal, _this.vertices[t.vertices[0]].position))));
  241. }
  242. };
  243. BABYLON.AsyncLoop.SyncAsyncForLoop(this.triangles.length, this.syncIterations, triangleInit1, function () {
  244. var triangleInit2 = function (i) {
  245. var t = _this.triangles[i];
  246. for (var j = 0; j < 3; ++j) {
  247. t.error[j] = _this.calculateError(_this.vertices[t.vertices[j]], _this.vertices[t.vertices[(j + 1) % 3]]);
  248. }
  249. t.error[3] = Math.min(t.error[0], t.error[1], t.error[2]);
  250. };
  251. BABYLON.AsyncLoop.SyncAsyncForLoop(_this.triangles.length, _this.syncIterations, triangleInit2, function () {
  252. _this.initialised = true;
  253. callback();
  254. });
  255. });
  256. };
  257. QuadraticErrorSimplification.prototype.reconstructMesh = function () {
  258. var newTriangles = [];
  259. var i;
  260. for (i = 0; i < this.vertices.length; ++i) {
  261. this.vertices[i].triangleCount = 0;
  262. }
  263. var t;
  264. var j;
  265. for (i = 0; i < this.triangles.length; ++i) {
  266. if (!this.triangles[i].deleted) {
  267. t = this.triangles[i];
  268. for (j = 0; j < 3; ++j) {
  269. this.vertices[t.vertices[j]].triangleCount = 1;
  270. }
  271. newTriangles.push(t);
  272. }
  273. }
  274. var newVerticesOrder = [];
  275. //compact vertices, get the IDs of the vertices used.
  276. var dst = 0;
  277. for (i = 0; i < this.vertices.length; ++i) {
  278. if (this.vertices[i].triangleCount) {
  279. this.vertices[i].triangleStart = dst;
  280. this.vertices[dst].position = this.vertices[i].position;
  281. this.vertices[dst].normal = this.vertices[i].normal;
  282. this.vertices[dst].uv = this.vertices[i].uv;
  283. newVerticesOrder.push(i);
  284. dst++;
  285. }
  286. }
  287. for (i = 0; i < newTriangles.length; ++i) {
  288. t = newTriangles[i];
  289. for (j = 0; j < 3; ++j) {
  290. t.vertices[j] = this.vertices[t.vertices[j]].triangleStart;
  291. }
  292. }
  293. this.vertices = this.vertices.slice(0, dst);
  294. var newPositionData = [];
  295. var newNormalData = [];
  296. var newUVsData = [];
  297. var newColorsData = [];
  298. for (i = 0; i < newVerticesOrder.length; ++i) {
  299. newPositionData.push(this.vertices[i].position.x);
  300. newPositionData.push(this.vertices[i].position.y);
  301. newPositionData.push(this.vertices[i].position.z);
  302. newNormalData.push(this.vertices[i].normal.x);
  303. newNormalData.push(this.vertices[i].normal.y);
  304. newNormalData.push(this.vertices[i].normal.z);
  305. if (this.vertices[i].uv) {
  306. newUVsData.push(this.vertices[i].uv.x);
  307. newUVsData.push(this.vertices[i].uv.y);
  308. } else if (this.vertices[i].color) {
  309. newColorsData.push(this.vertices[i].color.r);
  310. newColorsData.push(this.vertices[i].color.g);
  311. newColorsData.push(this.vertices[i].color.b);
  312. }
  313. }
  314. var newIndicesArray = [];
  315. for (i = 0; i < newTriangles.length; ++i) {
  316. newIndicesArray.push(newTriangles[i].vertices[0]);
  317. newIndicesArray.push(newTriangles[i].vertices[1]);
  318. newIndicesArray.push(newTriangles[i].vertices[2]);
  319. }
  320. //not cloning, to avoid geometry problems. Creating a whole new mesh.
  321. var newMesh = new BABYLON.Mesh(this._mesh + "Decimated", this._mesh.getScene());
  322. newMesh.material = this._mesh.material;
  323. newMesh.parent = this._mesh.parent;
  324. newMesh.setIndices(newIndicesArray);
  325. newMesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, newPositionData);
  326. newMesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, newNormalData);
  327. if (newUVsData.length > 0)
  328. newMesh.setVerticesData(BABYLON.VertexBuffer.UVKind, newUVsData);
  329. if (newColorsData.length > 0)
  330. newMesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, newColorsData);
  331. //preparing the skeleton support
  332. if (this._mesh.skeleton) {
  333. //newMesh.skeleton = this._mesh.skeleton.clone("", "");
  334. //newMesh.getScene().beginAnimation(newMesh.skeleton, 0, 100, true, 1.0);
  335. }
  336. return newMesh;
  337. };
  338. QuadraticErrorSimplification.prototype.isFlipped = function (vertex1, index2, point, deletedArray, borderFactor) {
  339. for (var i = 0; i < vertex1.triangleCount; ++i) {
  340. var t = this.triangles[this.references[vertex1.triangleStart + i].triangleId];
  341. if (t.deleted)
  342. continue;
  343. var s = this.references[vertex1.triangleStart + i].vertexId;
  344. var id1 = t.vertices[(s + 1) % 3];
  345. var id2 = t.vertices[(s + 2) % 3];
  346. if ((id1 === index2 || id2 === index2) && borderFactor < 2) {
  347. deletedArray[i] = true;
  348. continue;
  349. }
  350. var d1 = this.vertices[id1].position.subtract(point);
  351. d1 = d1.normalize();
  352. var d2 = this.vertices[id2].position.subtract(point);
  353. d2 = d2.normalize();
  354. if (Math.abs(BABYLON.Vector3.Dot(d1, d2)) > 0.999)
  355. return true;
  356. var normal = BABYLON.Vector3.Cross(d1, d2).normalize();
  357. deletedArray[i] = false;
  358. if (BABYLON.Vector3.Dot(normal, t.normal) < 0.2)
  359. return true;
  360. }
  361. return false;
  362. };
  363. QuadraticErrorSimplification.prototype.updateTriangles = function (vertexId, vertex, deletedArray, deletedTriangles) {
  364. var newDeleted = deletedTriangles;
  365. for (var i = 0; i < vertex.triangleCount; ++i) {
  366. var ref = this.references[vertex.triangleStart + i];
  367. var t = this.triangles[ref.triangleId];
  368. if (t.deleted)
  369. continue;
  370. if (deletedArray[i]) {
  371. t.deleted = true;
  372. newDeleted++;
  373. continue;
  374. }
  375. t.vertices[ref.vertexId] = vertexId;
  376. t.isDirty = true;
  377. t.error[0] = this.calculateError(this.vertices[t.vertices[0]], this.vertices[t.vertices[1]]) + (t.borderFactor / 2);
  378. t.error[1] = this.calculateError(this.vertices[t.vertices[1]], this.vertices[t.vertices[2]]) + (t.borderFactor / 2);
  379. t.error[2] = this.calculateError(this.vertices[t.vertices[2]], this.vertices[t.vertices[0]]) + (t.borderFactor / 2);
  380. t.error[3] = Math.min(t.error[0], t.error[1], t.error[2]);
  381. this.references.push(ref);
  382. }
  383. return newDeleted;
  384. };
  385. QuadraticErrorSimplification.prototype.identifyBorder = function () {
  386. for (var i = 0; i < this.vertices.length; ++i) {
  387. var vCount = [];
  388. var vId = [];
  389. var v = this.vertices[i];
  390. var j;
  391. for (j = 0; j < v.triangleCount; ++j) {
  392. var triangle = this.triangles[this.references[v.triangleStart + j].triangleId];
  393. for (var ii = 0; ii < 3; ii++) {
  394. var ofs = 0;
  395. var id = triangle.vertices[ii];
  396. while (ofs < vCount.length) {
  397. if (vId[ofs] === id)
  398. break;
  399. ++ofs;
  400. }
  401. if (ofs === vCount.length) {
  402. vCount.push(1);
  403. vId.push(id);
  404. } else {
  405. vCount[ofs]++;
  406. }
  407. }
  408. }
  409. for (j = 0; j < vCount.length; ++j) {
  410. if (vCount[j] === 1) {
  411. this.vertices[vId[j]].isBorder = true;
  412. } else {
  413. this.vertices[vId[j]].isBorder = false;
  414. }
  415. }
  416. }
  417. };
  418. QuadraticErrorSimplification.prototype.updateMesh = function (identifyBorders) {
  419. if (typeof identifyBorders === "undefined") { identifyBorders = false; }
  420. var i;
  421. if (!identifyBorders) {
  422. var newTrianglesVector = [];
  423. for (i = 0; i < this.triangles.length; ++i) {
  424. if (!this.triangles[i].deleted) {
  425. newTrianglesVector.push(this.triangles[i]);
  426. }
  427. }
  428. this.triangles = newTrianglesVector;
  429. }
  430. for (i = 0; i < this.vertices.length; ++i) {
  431. this.vertices[i].triangleCount = 0;
  432. this.vertices[i].triangleStart = 0;
  433. }
  434. var t;
  435. var j;
  436. var v;
  437. for (i = 0; i < this.triangles.length; ++i) {
  438. t = this.triangles[i];
  439. for (j = 0; j < 3; ++j) {
  440. v = this.vertices[t.vertices[j]];
  441. v.triangleCount++;
  442. }
  443. }
  444. var tStart = 0;
  445. for (i = 0; i < this.vertices.length; ++i) {
  446. this.vertices[i].triangleStart = tStart;
  447. tStart += this.vertices[i].triangleCount;
  448. this.vertices[i].triangleCount = 0;
  449. }
  450. var newReferences = new Array(this.triangles.length * 3);
  451. for (i = 0; i < this.triangles.length; ++i) {
  452. t = this.triangles[i];
  453. for (j = 0; j < 3; ++j) {
  454. v = this.vertices[t.vertices[j]];
  455. newReferences[v.triangleStart + v.triangleCount] = new Reference(j, i);
  456. v.triangleCount++;
  457. }
  458. }
  459. this.references = newReferences;
  460. if (identifyBorders) {
  461. this.identifyBorder();
  462. }
  463. };
  464. QuadraticErrorSimplification.prototype.vertexError = function (q, point) {
  465. var x = point.x;
  466. var y = point.y;
  467. var z = point.z;
  468. return q.data[0] * x * x + 2 * q.data[1] * x * y + 2 * q.data[2] * x * z + 2 * q.data[3] * x + q.data[4] * y * y + 2 * q.data[5] * y * z + 2 * q.data[6] * y + q.data[7] * z * z + 2 * q.data[8] * z + q.data[9];
  469. };
  470. QuadraticErrorSimplification.prototype.calculateError = function (vertex1, vertex2, pointResult, normalResult, uvResult) {
  471. var q = vertex1.q.add(vertex2.q);
  472. var border = vertex1.isBorder && vertex2.isBorder;
  473. var error = 0;
  474. var qDet = q.det(0, 1, 2, 1, 4, 5, 2, 5, 7);
  475. if (qDet !== 0 && !border) {
  476. if (!pointResult) {
  477. pointResult = BABYLON.Vector3.Zero();
  478. }
  479. pointResult.x = -1 / qDet * (q.det(1, 2, 3, 4, 5, 6, 5, 7, 8));
  480. pointResult.y = 1 / qDet * (q.det(0, 2, 3, 1, 5, 6, 2, 7, 8));
  481. pointResult.z = -1 / qDet * (q.det(0, 1, 3, 1, 4, 6, 2, 5, 8));
  482. error = this.vertexError(q, pointResult);
  483. //TODO this should be correctly calculated
  484. if (normalResult) {
  485. normalResult.copyFrom(vertex1.normal);
  486. uvResult.copyFrom(vertex1.uv);
  487. }
  488. } else {
  489. var p3 = (vertex1.position.add(vertex2.position)).divide(new BABYLON.Vector3(2, 2, 2));
  490. var norm3 = (vertex1.normal.add(vertex2.normal)).divide(new BABYLON.Vector3(2, 2, 2)).normalize();
  491. var error1 = this.vertexError(q, vertex1.position);
  492. var error2 = this.vertexError(q, vertex2.position);
  493. var error3 = this.vertexError(q, p3);
  494. error = Math.min(error1, error2, error3);
  495. if (error === error1) {
  496. if (pointResult) {
  497. pointResult.copyFrom(vertex1.position);
  498. normalResult.copyFrom(vertex1.normal);
  499. uvResult.copyFrom(vertex1.uv);
  500. }
  501. } else if (error === error2) {
  502. if (pointResult) {
  503. pointResult.copyFrom(vertex2.position);
  504. normalResult.copyFrom(vertex2.normal);
  505. uvResult.copyFrom(vertex2.uv);
  506. }
  507. } else {
  508. if (pointResult) {
  509. pointResult.copyFrom(p3);
  510. normalResult.copyFrom(norm3);
  511. uvResult.copyFrom(vertex1.uv);
  512. }
  513. }
  514. }
  515. return error;
  516. };
  517. return QuadraticErrorSimplification;
  518. })();
  519. BABYLON.QuadraticErrorSimplification = QuadraticErrorSimplification;
  520. })(BABYLON || (BABYLON = {}));
  521. //# sourceMappingURL=babylon.meshSimplification.js.map