Advertisement
nik684

Fuse knots

Dec 5th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. macroScript scale_all category:"For Home" tooltip:"Fuse_knotes" buttonText:"Fuse Knotes"
  2. (
  3. try( DestroyDialog ::Fuse_knotes )catch()
  4. rollout Fuse_knotes "Fuse Knotes" width:162 height:120
  5. (
  6. fn IsSpline obj = iskindof obj SplineShape OR iskindof obj Line
  7.  
  8. spinner knotsthreshold "Knots Thresh: " fieldwidth:60 align:#center range:[0.001,1e7,1]
  9. pickbutton btn_spl_base "Select Base Spline" width:140 filter:IsSpline align:#center
  10. pickbutton btn_spl_add "Select Add Spline" width:140 filter:IsSpline align:#center
  11. button btn_start "Start" width:140 height:31 align:#center
  12.  
  13. fn FuseSplineKnots splineA splineB thresh:0.01 =
  14. (
  15. if not (IsSpline splineA) then return false
  16. if not (IsSpline splineB) then return false
  17.  
  18. local knotsPositions = #()
  19. local knotsCount = numknots splineA
  20.  
  21. for sA = 1 to (numsplines splineA) do
  22. (
  23. for kA = 1 to (numknots splineA sA) do
  24. (
  25. append knotsPositions (getKnotPoint splineA sA kA)
  26. )
  27. )
  28.  
  29. undo "Fuse Knots" on
  30. (
  31. for sB = 1 to (numsplines splineB) do
  32. (
  33. for kB = 1 to (numknots splineB sB) do
  34. (
  35. local knotPos = getKnotPoint splineB sB kB
  36. local bestDist = 1e30
  37. local bestKnot
  38.  
  39. for kA = 1 to knotsCount do
  40. (
  41. local dist = distance knotsPositions[kA] knotPos
  42. if dist < thresh do
  43. (
  44. bestDist = dist
  45. bestKnot = kA
  46. )
  47. )
  48. if bestKnot != undefined then
  49. (
  50. setKnotPoint splineB sB kB knotsPositions[bestKnot]
  51. )
  52. )
  53. )
  54. updateShape splineB
  55. )
  56. )
  57.  
  58. on btn_spl_base picked spl do
  59. (
  60. if spl != undefined do btn_spl_base.text = spl.name
  61. )
  62.  
  63. on btn_spl_add picked spl do
  64. (
  65. if spl != undefined do btn_spl_add.text = spl.name
  66. )
  67.  
  68. on btn_start pressed do
  69. (
  70. local splineA = btn_spl_base.object
  71. local splineB = btn_spl_add.object
  72. FuseSplineKnots splineA splineB thresh:knotsthreshold.value
  73. )
  74. )
  75.  
  76. createDialog Fuse_knotes
  77. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement