Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

Maxscript - copy and paste vertex weight

Hi

I found some script (Maxscript) for 3ds Max. "Single Skin Copy and Paste"

The script copy and paste vertex weight between models. It works good but with only one select vertex. I would like to it to work with more vertex than only one. I mean if I'll secect 5, 12, 20 or more vertex.

I'm not scripter so maybe can someone change it for me :) and sorry for my English

Here it's a code.
  1. global BoneArray
  2. global BoneNArray
  3. global WeightArray
  4. global PasteArray
  5.  
  6.  
  7. -- Pass the vert id to extract all the weights to arrays
  8. fn CopyWeight theVert =
  9. (
  10. -- Empty the arrays
  11. BoneArray = #()
  12. BoneNArray =#()
  13. WeightArray = #()
  14.  
  15. theSkin = $.modifiers[#skin]
  16. BNumber = skinOps.getVertexWeightCount theSkin theVert
  17. BN = BNumber as string
  18.  
  19. for i = 1 to BNumber do
  20. (
  21. boneID = skinOps.getVertexWeightBoneId theSkin theVert i
  22. boneName = skinOps.GetBoneName theSkin boneID 0
  23. boneWeight = skinOps.getVertexWeight theSkin theVert i
  24.  
  25. append BoneArray boneID
  26. append BoneNArray boneName
  27. append WeightArray boneWeight
  28. )
  29. )
  30.  
  31.  
  32.  
  33.  
  34. fn PasteWeight pVert =
  35. (
  36. disableSceneredraw()
  37.  
  38. theSkin = $.modifiers[#skin]
  39.  
  40. print "these are the stored arrays for copying"
  41. print pastearray
  42. print weightarray
  43.  
  44. skinOps.ReplaceVertexWeights theskin pVert pasteArray WeightArray
  45.  
  46.  
  47. enableSceneredraw()
  48. redrawViews()
  49. )
  50.  
  51.  
  52.  
  53. fn find_mirror arrayIndex =
  54. (
  55. -- Build arrays of all the bones in the system
  56. theSkin = $.modifiers[#skin]
  57. totalbones = skinops.getnumberbones theSkin
  58.  
  59. totalBoneNArray =#()
  60.  
  61. for i = 1 to totalbones do
  62. (
  63. boneName = skinOps.GetBoneName theSkin i 0
  64. append totalBoneNArray boneName
  65. )
  66.  
  67.  
  68.  
  69. -- Now we know all the bones, lets parse of list of weighted bones
  70.  
  71.  
  72. SB = BoneNArray[arrayIndex] as string
  73. boneToFind=SB
  74.  
  75. -- Find bone names beginning with CHAR
  76. if (substring SB 1 4 == "Char") then
  77. (
  78. BNprefix=substring SB 1 7 as string
  79. BNsuffix= substring SB 8 255 as string
  80.  
  81. newPrefix=BNprefix
  82. if BNprefix == "Char L " then newPrefix= "Char R "
  83. if BNprefix == "Char R " then newPrefix= "Char L "
  84.  
  85. boneToFind = newPrefix + BNsuffix
  86. )
  87.  
  88. if (substring SB 2 1 == " ") then
  89. (
  90. BNprefix=substring SB 1 2 as string
  91. BNsuffix= substring SB 3 255 as string
  92.  
  93. newPrefix=BNprefix
  94. if BNprefix == "L " then newPrefix= "R "
  95. if BNprefix == "R " then newPrefix= "L "
  96.  
  97. boneToFind = newPrefix + BNsuffix
  98. )
  99.  
  100. -- ok, at this stage we have an arracy of bone names, and we know what name
  101. -- we are looking for. so cycle the array and find the index!
  102. theIndex = 0
  103.  
  104. -- Do we need to find a new bone?
  105.  
  106. if (boneToFind != SB) then
  107. (
  108. print bonearray
  109. for i = 1 to totalbones do
  110. (
  111. thecheck= totalBoneNArray[i] as string
  112. if thecheck == bonetofind then theIndex = i
  113. )
  114.  
  115. pasteArray[arrayIndex]=theIndex
  116.  
  117. )
  118. )
  119.  
  120.  
  121.  
  122. rollout blank "Single Skin Copy and Paste"
  123. (
  124. label lbl1 "Select vert, press copy, then select vert and press paste." pos:[9,8] width:197 height:48
  125. button ButtonC "Copy" pos:[18,40] width:75 height:24
  126. button ButtonP "Paste" pos:[110,40] width:75 height:24
  127.  
  128.  
  129. on ButtonP pressed do
  130. (
  131. theSkin = selection[1].modifiers[#Skin]
  132. n = skinOps.getNumberVertices theSkin
  133.  
  134. selVert=0
  135.  
  136. for i = 1 to n do
  137. (
  138. if (skinops.isVertexSelected theSkin i == 1) then
  139. (
  140. selVert=i
  141. )
  142. )
  143.  
  144. -- Call the copy function
  145. PasteWeight selVert
  146. )
  147.  
  148.  
  149.  
  150.  
  151. on ButtonC pressed do
  152. (
  153. -- Get vert id
  154. theSkin = selection[1].modifiers[#Skin]
  155. n = skinOps.getNumberVertices theSkin
  156.  
  157. selVert=0
  158.  
  159. for i = 1 to n do
  160. (
  161. if (skinops.isVertexSelected theSkin i == 1) then
  162. (
  163. selVert=i
  164. )
  165. )
  166.  
  167. -- Call the copy function
  168. CopyWeight selVert
  169.  
  170. -- We now have 3 arrays - bone id, bone name, and bone weight.
  171. -- some of the bones might need to be mirrored so for each bone, find the possible mirror
  172. n = BoneArray.count
  173. pastearray = bonearray
  174.  
  175. for i = 1 to n do
  176. (
  177. find_mirror i
  178. )
  179. )
  180. )
  181.  
  182. -- Create floater
  183. theNewFloater = newRolloutFloater "Rollout title" 220 100
  184.  
  185. -- Add the rollout section
  186. addRollout blank theNewFloater
Sign In or Register to comment.