Advertisement
gmo61520

Untitled

Dec 22nd, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. rollout SpringWeight "Spring weight tool" width:300 (
  2. button c_refresh "Refresh"
  3. dropdownList c_top_bone "Top bone"
  4. dropdownList c_bottom_bone "Bottom bone"
  5. editText c_sides "Sides"
  6. editText c_topVerticeId "Top vertice ID"
  7. editText c_bottomVerticeId "Bottom vertice ID"
  8. button c_start "Set weights"
  9. button c_cls "close"
  10. fn BlockUI = (
  11. c_top_bone.items = #()
  12. c_bottom_bone.items = #()
  13. c_top_bone.Enabled = false
  14. c_bottom_bone.Enabled = false
  15. c_start.Enabled = false
  16. c_sides.Enabled = false
  17. c_topVerticeId.Enabled = false
  18. c_bottomVerticeId.Enabled = false
  19. )
  20. fn UpdateUI = (
  21. global sk
  22. if($ == undefined or $.modifiers == undefined) then (
  23. Messagebox("Please select an object")
  24. BlockUI()
  25. ) else (
  26. if(ClassOf(sk = modpanel.getcurrentobject()) == Skin) then (
  27. global boneNames = for i=1 to (skinOps.GetNumberBones sk) collect (skinOps.GetBoneName sk i 0)
  28. c_top_bone.items = boneNames
  29. c_bottom_bone.items = boneNames
  30. if(skinOps.GetNumberBones sk >= 2) do (c_top_bone.selection = 2)
  31. c_top_bone.Enabled = true
  32. c_bottom_bone.Enabled = true
  33. c_start.Enabled = true
  34. c_sides.Enabled = true
  35. c_topVerticeId.Enabled = true
  36. c_bottomVerticeId.Enabled = true
  37. c_sides.text = "6"
  38. c_topVerticeId.text = "0"
  39. c_bottomVerticeId.text = (skinops.getnumbervertices(sk) - 1) as string
  40. ) else (
  41. Messagebox ("Please add and/or select the skin modifier from modifier list")
  42. BlockUI()
  43. )
  44. )
  45. )
  46. on c_cls pressed do (
  47. removeRollout(SpringWeight)
  48. DestroyDialog(SpringWeight)
  49. )
  50. on c_refresh pressed do (
  51. UpdateUI()
  52. )
  53. on SpringWeight open do (
  54. UpdateUI()
  55. )
  56. on c_start pressed do
  57. (
  58. if (sk == undefined or ClassOf(sk = modpanel.getcurrentobject()) != Skin) then (
  59. UpdateUI()
  60. ) else (
  61. if (c_sides.text == "") then (
  62. Messagebox("Enter number of sides!")
  63. ) else (
  64. local skinVerts = skinops.getnumbervertices(sk)
  65.  
  66. local topVerticeId = c_topVerticeId.text as integer + 1
  67. local bottomVerticeId = c_bottomVerticeId.text as integer + 1
  68. local sides = c_sides.text as integer
  69.  
  70. if (bottomVerticeId < topVerticeId) then (
  71. Messagebox("Not implemented!")
  72. throw "stop"
  73. )
  74.  
  75. print("topVerticeId: " + (topVerticeId as string))
  76. print("bvid: " + (bottomVerticeId as string))
  77. print("sides: " + (sides as string))
  78.  
  79. local totalVertices = 1 + bottomVerticeId - topVerticeId
  80. local steps = (totalVertices / sides) as integer - 1
  81. print("vnum: " + (totalVertices as string))
  82. print("steps: " + (steps as string))
  83.  
  84. skinOps.SetVertexWeights sk topVerticeId c_top_bone.selection 1.0
  85. skinOps.SetVertexWeights sk topVerticeId c_bottom_bone.selection 0.0
  86. skinOps.SetVertexWeights sk bottomVerticeId c_top_bone.selection 0.0
  87. skinOps.SetVertexWeights sk bottomVerticeId c_bottom_bone.selection 1.0
  88.  
  89. for i = 0 to steps do (
  90. local value = (i as float) / steps
  91.  
  92. for j = 0 to sides - 1 do (
  93. local verticeId = topVerticeId + i*sides + j
  94. skinOps.SetVertexWeights sk verticeId c_top_bone.selection (1.0 - value)
  95. skinOps.SetVertexWeights sk verticeId c_bottom_bone.selection value
  96. )
  97. )
  98.  
  99. print("OK")
  100. )
  101. )
  102. )
  103. )
  104. --addRollout SpringWeight
  105. try(destroyDialog SpringWeight)catch()
  106. createdialog SpringWeight
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement