babylon.meshSimplification.ts 25 KB

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