threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

splitEdge.ts 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Author: Axel Antoine
  3. * mail: ax.antoine@gmail.com
  4. * website: http://axantoine.com
  5. * Created on Tue Oct 25 2022
  6. *
  7. * Loki, Inria project-team with Université de Lille
  8. * within the Joint Research Unit UMR 9189
  9. * CNRS - Centrale Lille - Université de Lille, CRIStAL
  10. * https://loki.lille.inria.fr
  11. *
  12. * Licence: Licence.md
  13. */
  14. import { Vector3 } from "three";
  15. import { Halfedge } from "../core/Halfedge";
  16. import { HalfedgeDS } from "../core/HalfedgeDS";
  17. import { Vertex } from "../core/Vertex";
  18. export function splitEdge(
  19. struct: HalfedgeDS,
  20. halfedge: Halfedge,
  21. position: Vector3,
  22. tolerance = 1e-10) {
  23. /**
  24. * From
  25. * A -------------- he -------------> B
  26. * A <------------ twin ------------- B
  27. * To
  28. * A ---- he ----> v ---- newhe ----> B
  29. * A <--- twin --- v <--- newtwin --- B
  30. */
  31. const twin = halfedge.twin;
  32. const A = halfedge.vertex;
  33. const B = twin.vertex;
  34. // No need to split if position matches A or B
  35. if (A.matchesPosition(position, tolerance)) {
  36. return A;
  37. }
  38. if (B.matchesPosition(position, tolerance)) {
  39. return B;
  40. }
  41. const newVertex = new Vertex();
  42. newVertex.position.copy(position);
  43. // Create the new halfegdes
  44. const newHalfedge = new Halfedge(newVertex);
  45. const newTwin = new Halfedge(B);
  46. newHalfedge.twin = newTwin;
  47. newTwin.twin = newHalfedge;
  48. // Update vertices halfedge refs
  49. A.halfedge = halfedge;
  50. newVertex.halfedge = newHalfedge;
  51. B.halfedge = newTwin;
  52. // Copy the face refs
  53. newHalfedge.face = halfedge.face;
  54. newTwin.face = twin.face;
  55. // Update next and prev refs
  56. newHalfedge.next = halfedge.next;
  57. newHalfedge.prev = halfedge;
  58. halfedge.next = newHalfedge;
  59. newTwin.next = twin;
  60. newTwin.prev = twin.prev;
  61. twin.prev = newTwin;
  62. // Update structure
  63. struct.vertices.push(newVertex);
  64. struct.halfedges.push(newHalfedge);
  65. struct.halfedges.push(newTwin);
  66. return newVertex;
  67. }