Advertisement
spookymunky

QuickMerge 0.9n

Sep 28th, 2013
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'This is a small script to make merging meshes in xsi a bit less tedious for me :). Once it's started select
  2. 'objects / groups that you want to be included in the merge operation and right click when you have selected
  3. 'everything you want.
  4.  
  5. 'By default the merged mesh's center SRT, name, and parent will be based on the first object selected, to override
  6. 'this hold ctrl while clicking any object to use its SRT values, hold shift while clicking on an object to use its
  7. 'name, and Ctrl+Shift to select a parent object. Middle click will select an object as the parent, aso opposed to
  8. 'ctrl shift that will set the selections's parent as the parent...
  9.  
  10. 'Any object picked as a name / srt / parent shouldn't be added to the merge, click on them normally if you want
  11. 'them included aswell.
  12. '------------
  13.  
  14. DeselectAll
  15.  
  16. 'create a collection for adding polygon meshes to for using in the merge op
  17. Set oCol = CreateObject( "XSI.Collection" )
  18.  
  19. 'create a string to tell if an object has been picked using ctrl for use as a center
  20. sCenterObject = "no"
  21.  
  22. 'Create a string to store an objects name when shift is held down
  23. sName = "nope"
  24.  
  25. 'Create a string to store the parent object when Ctrl + shift / middle mouse are used
  26. sParent = "natta"
  27.  
  28. 'create an integer to count how many objects have been added to the collection
  29. iObjNumber = 1
  30.  
  31. do  'Start a pick session loop, adding each viable polygon mesh to oCol
  32.  
  33.     PickObject "Select polygon mesh #" & iObjNumber, "Select Parent", oSelecto, iButton, iModifier
  34.    
  35.     if iModifier = 2 then   'if Ctrl was pressed when the object was selected then store the objects SRT for the merged result's center
  36.        
  37.         oSelectoScaleX = oSelecto.Kinematics.Global.Parameters("SclX").Value
  38.         oSelectoScaleY = oSelecto.Kinematics.Global.Parameters("SclY").Value
  39.         oSelectoScaleZ = oSelecto.Kinematics.Global.Parameters("SclZ").Value
  40.        
  41.         oSelectoRotX = oSelecto.Kinematics.Global.Parameters("RotX").Value
  42.         oSelectoRotY = oSelecto.Kinematics.Global.Parameters("RotY").Value
  43.         oSelectoRotZ = oSelecto.Kinematics.Global.Parameters("RotZ").Value
  44.        
  45.         oSelectoPosX = oSelecto.Kinematics.Global.Parameters("PosX").Value
  46.         oSelectoPosY = oSelecto.Kinematics.Global.Parameters("PosY").Value
  47.         oSelectoPosZ = oSelecto.Kinematics.Global.Parameters("PosZ").Value  
  48.        
  49.         sCenterObject = "yes"
  50.        
  51.         logmessage "Center set to " & oSelecto
  52.        
  53.     elseif iModifier = 1 then   'if shift was held down when selecting the object then store its name
  54.        
  55.         sName = oSelecto.name
  56.        
  57.         logmessage "Name set to " & sName
  58.        
  59.     elseif iModifier = 3 then   'if both control and shift were held down then use the selected object's parent as the parent for the merged result
  60.        
  61.         sParent = oSelecto.Parent
  62.         logmessage "Parent set to " & sParent
  63.        
  64.     elseif iButton = 2 then
  65.        
  66.         sParent = dictionary.GetObject ( oSelecto )     'if middle mouse button is pressed then make that object the parent
  67.         logmessage "Parent set to " & sParent
  68.        
  69.     else 'if there were no modifiers...
  70.        
  71.         'create a string to differentiate between objects that have already been added to the colelction and anything else
  72.         sAlreadyAdded = "no"
  73.        
  74.         if oCol.Count > 0 then  'If there is at least one object then
  75.            
  76.             for each oEqualsCheck in oCol   'for every object already added to the collection,
  77.                
  78.                 if oEqualsCheck.IsEqualTo(oSelecto) = "True" then   'if it has already been added then
  79.                    
  80.                     sAlreadyAdded = "yes"   'change the string to something other than "no"...
  81.                    
  82.                 end if
  83.                
  84.             next
  85.            
  86.         end if
  87.        
  88.         if sAlreadyAdded = "no" and sCenterObject = "no" and sName = "nope" and sParent = "natta" then    'so that it will miss out on this part.
  89.            
  90.             if TypeName( oSelecto )  = "Group" then     'If the selection is a group then
  91.                
  92.                 for each oMember in oSelecto.Members    'for every object in that group,
  93.                    
  94.                     'reset sAlreadyAdded
  95.                     sAlreadyAdded = "no"
  96.                    
  97.                     'Check if it has already been added
  98.                     if oCol.Count > 0 then
  99.                         for each oEqualsCheck in oCol  
  100.                             if oEqualsCheck.IsEqualTo(oMember) = "True" then
  101.                                 sAlreadyAdded = "yes"
  102.                             end if
  103.                         next
  104.                     end if
  105.                    
  106.                     if sAlreadyAdded = "no" and oMember.Type = "polymsh" then   'if it is a new object and a polygon mesh then
  107.                        
  108.                         oCol.Add oMember                'add it to the collection,
  109.                         iObjNumber = iObjNumber + 1     'and increase the object counter.
  110.                        
  111.                     elseif sAlreadyAdded = "yes" then
  112.                        
  113.                         logmessage oMember & " has already been added, skipping"
  114.                        
  115.                     else
  116.                        
  117.                         logmessage oMember & " isn't a polygon mesh, skipping"
  118.                        
  119.                     end if
  120.                    
  121.                 next
  122.                
  123.             elseif oSelecto.Type = "polymsh" then
  124.                
  125.                 oCol.Add oSelecto
  126.                 iObjNumber = iObjNumber + 1
  127.                
  128.             else
  129.                
  130.                 logmessage oMember & " isn't a polygon mesh, skipping"
  131.                
  132.             end if
  133.            
  134.         else
  135.            
  136.             logmessage oSelecto & " has already been selected, skipping"
  137.            
  138.         end if
  139.        
  140.     end if
  141.    
  142. loop until iButton = 0  'Stop the loop when the user right clicks or hits escape
  143.  
  144. if oCol.Count > 1 then 'if more than 1 polygon meshes were added to the collection then start to merge
  145.  
  146.     'Get the first object selected
  147.     set oSelecto = Dictionary.GetObject( oCol(0), false )
  148.  
  149.     'Merge all the objects in the collection
  150.     oGenOp = ApplyGenOp ("MeshMerge", , oCol, 3, siPersistentOperation, siKeepGenOpInputs)
  151.  
  152.     'Get the gen op and the merged result
  153.     set oGenOp = Dictionary.GetObject ( oGenOp )
  154.     sMerge = replace (oGenOp, ".polymsh.mergemesh", "")
  155.     set oMergedResult = Dictionary.GetObject ( sMerge )
  156.  
  157.     'transfer all properties from the input objects to the merged result(disabled) and set tollerance to 0.002
  158.     'TransferAllPropertiesAcrossGenOp oGenOp, oMergedResult, , True, True
  159.     oGenOp.tolerance.Value = 0.02
  160.    
  161.     if sName = "nope" then  'if no name object was selected then use the 1st object's name
  162.        
  163.         oMergedResult.Name = oSelecto.Name
  164.        
  165.     else    'otherwise use the selected object
  166.        
  167.         oMergedResult.Name = sName
  168.        
  169.     end if
  170.  
  171.     if sParent = "natta" then   'if no parent object was selected... blah :)
  172.        
  173.         oSelecto.Parent.AddChild oMergedResult
  174.        
  175.     else
  176.        
  177.         set sParent = Dictionary.GetObject( sParent, false )
  178.         sParent.AddChild oMergedResult
  179.        
  180.     end if
  181.  
  182.     'If no center object was selected then use the first object selected's SRT instead
  183.     if sCenterObject = "no" then
  184.        
  185.         oSelectoScaleX = oSelecto.Kinematics.Global.Parameters("SclX").Value
  186.         oSelectoScaleY = oSelecto.Kinematics.Global.Parameters("SclY").Value
  187.         oSelectoScaleZ = oSelecto.Kinematics.Global.Parameters("SclZ").Value
  188.        
  189.         oSelectoRotX = oSelecto.Kinematics.Global.Parameters("RotX").Value
  190.         oSelectoRotY = oSelecto.Kinematics.Global.Parameters("RotY").Value
  191.         oSelectoRotZ = oSelecto.Kinematics.Global.Parameters("RotZ").Value
  192.        
  193.         oSelectoPosX = oSelecto.Kinematics.Global.Parameters("PosX").Value
  194.         oSelectoPosY = oSelecto.Kinematics.Global.Parameters("PosY").Value
  195.         oSelectoPosZ = oSelecto.Kinematics.Global.Parameters("PosZ").Value
  196.        
  197.     end if
  198.    
  199.     'Match the merged result's center to the oSelecto's values above
  200.     Translate oMergedResult, oSelectoPosX, oSelectoPosY, oSelectoPosZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , , , 0
  201.     Rotate oMergedResult, oSelectoRotX, oSelectoRotY, oSelectoRotZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  202.     Scale oMergedResult, oSelectoScaleX, oSelectoScaleY, oSelectoScaleZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  203.  
  204. else
  205.  
  206.     logmessage "not enough polygon meshes to merge, operation aborted"
  207.    
  208. end if
  209.  
  210. inspectobj oGenOp, , , siLockAndForceNew
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement