Advertisement
Guest User

SymmThings 2.Something - ClonedSymmetryWCutting

a guest
Aug 13th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dim oCol, oSelection, oSelecto, oFinalSelect, BP, ScriptCancel, oDupe, oClone, oMerge, oGenOp, oSubdCtrl
  2. dim oModelo, oSelName, AfterDashCheck, SliceAway, oGenOp2, oSelectoSubdOgl, oSelectoSubdRdr
  3. dim oMergeScale, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, CtrlXtrans, CtrlYtrans, CtrlZtrans, CtrlScale
  4. dim oDupeScaleX, oDupeScaleY, oDupeScaleZ, oSelTest, oSelTest2, oSelTest3, oSelTest4, oSelTest5
  5. dim oDupeRotX, oDupeRotY, oDupeRotZ, oDupePosX, oDupePosY, oDupePosZ
  6. dim ModellingTest, ClonedTest, MergedTest, GatorTest
  7. dim regEx, Match, Matches, NumberCheck, objNumber, JustIncaseAbort
  8. dim oExpExist, ExpStr, oExpCheck, WereRenamed, oShrinkWrapCheck, SWStr
  9.  
  10. 'Set up a regExp for later use
  11. set regEx = New RegExp
  12.  
  13. 'Define a collection(oCol) for adding objects to
  14. Set oCol = CreateObject( "XSI.Collection" )
  15.  
  16. 'Swap to Object Select mode incase subcomponents are selected
  17. ActivateObjectSelTool
  18.  
  19. 'Check if something is selected
  20. if Application.Selection.count > 1 Then
  21.  
  22.     'Add the application selection to oCol
  23.     Set oSelection = Application.Selection
  24.    
  25.     for i = 0 to (oSelection.Count - 1)
  26.    
  27.         'Set a new Regex pattern that finds any letters after - at the end of its name
  28.         regEx.Pattern = "-[a-zA-Z]+$"
  29.        
  30.         'Reset oSubdCtrlCheck
  31.         oSubdCtrlCheck = "Nothing"
  32.        
  33.         'Execute the regex on the selection
  34.         Set Matches = regEx.Execute(oSelection(i))
  35.         For Each Match in Matches
  36.             oSubdCtrlCheck = Match.Value
  37.         Next
  38.        
  39.         'If the selection doesnt end in -SubdCtrl then add it to the oCol Collection.
  40.         if oSubdCtrlCheck <> "-SubdCtrl" then
  41.            
  42.             oCol.add oSelection(i)
  43.            
  44.         else
  45.            
  46.             Logmessage oSelection(i) & " was skipped"
  47.            
  48.         end if
  49.        
  50.     next   
  51.  
  52. elseIf Application.Selection.count = 1 Then
  53.  
  54.     oCol.add Application.Selection(0)
  55.    
  56. else
  57.  
  58.     'If no object is selected, start a picksession
  59.     LogMessage "Select a polymesh"
  60.     PickObject "Select a polymesh", " ", oSelecto
  61.  
  62.     'Add Picksession object to oCol
  63.     oCol.add oSelecto
  64.    
  65. end if
  66.  
  67. 'Create a collection to add objects to for selection at the end
  68. Set oFinalSelect = CreateObject( "XSI.Collection" )
  69.  
  70. for i = 0 to (oCol.count-1)
  71.     set oSelecto = oCol(i)
  72.    
  73.     'Make sure the oSelecto is a Polymesh, if it isn't then give the user one last try to select one
  74.     set oSelecto = Dictionary.GetObject( oSelecto, false )
  75.    
  76.     if oSelecto.Type = "polymsh" then
  77.    
  78.         ScriptCancel = "no"
  79.        
  80.     else
  81.    
  82.         LogMessage oSelecto & " is a " & oSelecto.Type & ",not a polymsh"
  83.        
  84.         BP = XSIUIToolkit.Msgbox( oSelecto & " is not a polymsh, do you want to select something else?", 4, "No Polygon Mesh Selected" )
  85.        
  86.             if BP = 6 then
  87.            
  88.                 PickObject "Please select a polygon mesh", " ", oSelecto
  89.                
  90.                 if oSelecto.Type = "polymsh" then  
  91.                    
  92.                     ScriptCancel = "no"
  93.                    
  94.                 else               
  95.                    
  96.                     XSIUIToolkit.Msgbox "Bah, I give up.. " & oSelecto & " is a " & oSelecto.Type & " !", 1, "No Polygon Mesh Selected"
  97.                     Logmessage "Script Cancelled - Next time select a Polygon Mesh instead of a " & oSelecto.Type & "! :)"
  98.                    
  99.                     ScriptCancel = "yes"
  100.                    
  101.                 end if
  102.                
  103.             else
  104.            
  105.             LogMessage "Script Cancelled - " & oSelecto & " isn't a polygon mesh"
  106.             ScriptCancel = "yes"
  107.            
  108.             end if
  109.        
  110.     end if
  111.    
  112.     if ScriptCancel = "no" then
  113.    
  114.         'Set a new Regex pattern that finds any letters after - at the end of its name
  115.         regEx.Pattern = "-[a-zA-Z]+$"
  116.        
  117.         'Reset AfterDashCheck
  118.         AfterDashCheck = "Nothing"
  119.        
  120.         'Execute the regex on the selection
  121.         Set Matches = regEx.Execute(oSelecto)
  122.         For Each Match in Matches
  123.             AfterDashCheck = Match.Value
  124.         Next
  125.        
  126.         'Get the original object's bounding box co-ordinates
  127.         oSelecto.Properties("visibility").Parameters("viewvis").Value = True
  128.         GetBBox oSelecto, TRUE, Xmin, Ymin, Zmin, Xmax, Ymax, Zmax
  129.        
  130.         'Calculate a nice small number relative to the scale of the object, for use in detecting if the object is half a mesh, as well as the merged mesh tolerance value
  131.         Tolerance = ( ( ( Xmax - Xmin ) / 2 ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 100
  132.        
  133.         'Reset SliceAway
  134.         SliceAway = "yes"
  135.        
  136.         'If the selection ends in -Modelling ask the user if they are sure they want to apply a(nother) slice op.
  137.         if AfterDashCheck = "-Modelling" then
  138.            
  139.             LogMessage oSelecto & " ends in -Modelling, should I cut ?"
  140.             BP = XSIUIToolkit.Msgbox( oSelecto & " could be a Modelling half, sure you want to cut it ?", 3, "Modelling Mesh Detected" )
  141.            
  142.                 if BP = 6 then
  143.                    
  144.                     LogMessage "OK, gonna cut " & oSelecto & " good, sorry for bothering you ! :)"
  145.                     SliceAway = "yes"
  146.                    
  147.                 elseIf BP = 7 then
  148.                    
  149.                     LogMessage "Alrighty, no slice and dice for " & oSelecto
  150.                     SliceAway = "no"
  151.                    
  152.                 else
  153.                    
  154.                     LogMessage "Skipping " & oSelecto & " completely"
  155.                     ScriptCancel = "yes"
  156.                    
  157.                 end if
  158.              
  159.         elseIf Xmin > (oSelecto.Kinematics.Local.Parameters("PosX").value - Tolerance) and Xmin < (oSelecto.Kinematics.Local.Parameters("PosX").value + Tolerance) then
  160.            
  161.             LogMessage oSelecto & " appears to only be half a mesh, should I cut ?"
  162.             BP = XSIUIToolkit.Msgbox( oSelecto & " seems to only be half a mesh, sure you want to cut it ?", 3, "Half as Mesh Detected" )
  163.            
  164.                 if BP = 6 then
  165.                    
  166.                     LogMessage "OK, gonna cut " & oSelecto & " good, sorry for bothering you ! :)"
  167.                     SliceAway = "yes"
  168.                    
  169.                 elseIf BP = 7 then
  170.                    
  171.                     LogMessage "Alrighty, no slice and dice for " & oSelecto
  172.                     SliceAway = "no"
  173.                    
  174.                 else
  175.                    
  176.                     LogMessage "Skipping " & oSelecto & " completely"
  177.                     ScriptCancel = "yes"
  178.                    
  179.                 end if         
  180.            
  181.         end if
  182.        
  183.         if ScriptCancel = "no" then
  184.            
  185.             'Store the original object's subdivision levels for later use
  186.             oSelectoSubdOgl = oSelecto.properties("Geometry Approximation").parameters("gapproxmosl").Value
  187.             oSelectoSubdRdr = oSelecto.properties("Geometry Approximation").parameters("gapproxmordrsl").Value
  188.            
  189.             'Duplicate original mesh
  190.             set oDupe = Duplicate (oSelecto, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
  191.             set oDupe = Dictionary.GetObject (oDupe, false)
  192.            
  193.             'mute any envelope operators oDupe may have
  194.             e = 0
  195.            
  196.             for e = 0 to (oDupe.Envelopes.Count-1)
  197.                 oDupe.Envelopes(e).Mute = True
  198.                 LogMessage oDupe.Envelopes(e) & " was muted"
  199.             next
  200.            
  201.             'Check to see if oDupe has a Cluster Shape Combiner
  202.             set ShapeCheck = Dictionary.GetObject( oDupe&".polymsh.clustershapecombiner", false )
  203.            
  204.             'If it does, mute it
  205.             if TypeName( ShapeCheck ) <> "Nothing" then
  206.                 SetValue ShapeCheck & ".mute", True
  207.                 LogMessage oSelecto & "'s Cluster Shape Combiner was muted"
  208.             end if
  209.            
  210.             'Make oDupe selectable (incase the input object wasnt)
  211.             oDupe.Properties("visibility").Parameters("selectability").Value = True
  212.            
  213.             'Check to see if the object's Geometry Approximation is local, make it local if it isn't
  214.            
  215.             q = 0
  216.            
  217.             for q = 0 to q = 1 
  218.                 on error resume next       
  219.                 Dictionary.GetObject ( oDupe.localproperties("Geometry Approximation") )
  220.                 if ( err <> 0 ) then
  221.                     MakeLocal oDupe.properties("Geometry Approximation")
  222.                 end if
  223.             next
  224.            
  225.             'Remove any animation on gemoetry approximation (incase the input object had any)
  226.             oDupe.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Disconnect
  227.             oDupe.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Disconnect
  228.            
  229.             'Set oDupe's subdivision levels to the same value as the input object
  230.             oDupe.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Value = oSelectoSubdOgl
  231.             oDupe.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Value = oSelectoSubdRdr
  232.            
  233.             if SliceAway = "yes" then
  234.                
  235.                 'Determine the local center of the mesh as a percentage for the slice polygons op
  236.                 oSelectoPosX = oSelecto.PosX.Value
  237.                 SlicePercentage = ( ( oSelectoPosX - Xmin ) / (xmax - xmin) ) * 100
  238.                
  239.                 'Slice the duplicate in half, set the reference plane to local, and delete -x polys
  240.                 set oSlice = ApplyTopoOp ( "SlicePolygons", oDupe, siUnspecified, siPersistentOperation )
  241.                 set oSlice = Dictionary.GetObject ( oSlice )
  242.                 oSlice.planeref.Value = 1
  243.                 oSlice.sliceaction.Value = 3
  244.                 oSlice.planeoffsetbboxpercentage.Value = SlicePercentage
  245.                
  246.             end if
  247.            
  248.             'Create a clone of the duplicate
  249.             set oClone = Clone (oDupe, , 1, 1, 0, 0, 1, 0, 1)
  250.             set oClone = Dictionary.GetObject ( oClone )
  251.            
  252.             'Merge the duplicate and clone, transfer all properties
  253.             oGenOp = ApplyGenOp ("MeshMerge", , oDupe &","& oClone, 3, siPersistentOperation, siKeepGenOpInputs)
  254.             set oGenOp = Dictionary.GetObject ( oGenOp )
  255.            
  256.             oMerge = replace (oGenOp, ".polymsh.mergemesh", "")
  257.             set oMerge = Dictionary.GetObject ( oMerge )
  258.            
  259.             TransferAllPropertiesAcrossGenOp oGenOp, oMerge, , True, True
  260.            
  261.             'Set the Merge tolerance to the tolerance value calculated earlier
  262.             if SliceAway = "yes" then
  263.                 oGenOp.tolerance.Value = Tolerance
  264.             else
  265.                 oGenOp.tolerance.Value = ( ( Xmax - Xmin ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 100
  266.             end if
  267.            
  268.             'Create a cube named SubdCtrl to control the merged mesh's subdivision levels via expressions
  269.             set oSubdCtrl = ActiveSceneRoot.AddGeometry( "Cube", "MeshSurface", "SubdCtrl" )
  270.            
  271.             'Make SubdCtrl and mergedmesh's geometry approximation local
  272.             MakeLocal oMerge.properties("Geometry Approximation")
  273.             MakeLocal oSubdCtrl.properties("Geometry Approximation")
  274.            
  275.             'Link MergedMesh's geometry approximation to SubdCtrl via expressions
  276.             oMerge.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").AddExpression(oSubdCtrl.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").FullName)
  277.             oMerge.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").AddExpression(oSubdCtrl.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").FullName)
  278.            
  279.             'Match SubdCtrl's subdivision levels to the original object
  280.             oSubdCtrl.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Value = oSelectoSubdOgl
  281.             oSubdCtrl.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Value = oSelectoSubdRdr
  282.            
  283.             'Give SubdCtrl the same material as the merged mesh
  284.             AssignMaterial oMerge & ".*," & oSubdCtrl, siLetLocalMaterialsOverlap
  285.            
  286.             'Set SubdCtrl's Visibility options
  287.             oSubdCtrl.Properties("visibility").Parameters("rendvis").Value = false
  288.            
  289.             'Set the clone's visibility options
  290.             oClone.Properties("visibility").Parameters("viewvis").Value = false
  291.             oClone.Properties("visibility").Parameters("rendvis").Value = false
  292.            
  293.             'Set oClone's subdivision levels to 0
  294.             oClone.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Value = 0
  295.             oClone.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Value =  0
  296.            
  297.             'Set the duplicate's Visibility options
  298.             oDupe.Properties("visibility").Parameters("viewvis").Value = True
  299.             oDupe.Properties("visibility").Parameters("rendvis").Value = False
  300.            
  301.             'Set the duplicate's Display options (0 is wireframe, 5 is bounding box)
  302.             MakeLocal oDupe.Properties("display"), siDefaultPropagation
  303.             oDupe.LocalProperties("display").Parameters("staticsel").Value = 0
  304.             oDupe.LocalProperties("display").Parameters("intsel").Value = 0
  305.             oDupe.LocalProperties("display").Parameters("playbacksel").Value = 0
  306.             oDupe.LocalProperties("display").Parameters("staticunselnear").Value = 5   
  307.             oDupe.LocalProperties("display").Parameters("intunselnear").Value = 5
  308.             oDupe.LocalProperties("display").Parameters("playbackunselnear").Value = 5
  309.             oDupe.LocalProperties("display").Parameters("staticunselfar").Value = 5
  310.             oDupe.LocalProperties("display").Parameters("intunselfar").Value = 5
  311.             oDupe.LocalProperties("display").Parameters("playbackunselfar").Value = 5
  312.            
  313.             'Disable the merged mesh's Selectability
  314.             oMerge.Properties("visibility").Parameters("selectability").Value = False
  315.            
  316.             'Disable Camera's override object properties option
  317.             SetValue "Camera.camdisp.mixviewmode", True
  318.            
  319.             'Change the duplicate's wireframe display colour
  320.             oDupe.LocalProperties("display").Parameters("wirecolorr").Value = 0.12
  321.             oDupe.LocalProperties("display").Parameters("wirecolorg").Value = 0.14
  322.             oDupe.LocalProperties("display").Parameters("wirecolorb").Value = 0.18
  323.            
  324.             'Set the clone's scale expressions linking it to the modelling half
  325.             oClone.sclx.AddExpression(oDupe.sclx.FullName & "*-1")
  326.             oClone.scly.AddExpression(oDupe.scly.FullName)
  327.             oClone.sclz.AddExpression(oDupe.sclz.FullName)
  328.            
  329.             'Set the clone's rotation expressions linking it to the modelling half
  330.             oClone.rotx.AddExpression(oDupe.rotx.FullName)
  331.             oClone.roty.AddExpression(oDupe.roty.FullName)
  332.             oClone.rotz.AddExpression(oDupe.rotz.FullName)
  333.            
  334.             'Set the clone's translation expressions linking it to the modelling half
  335.             oClone.posx.AddExpression(oDupe.posx.FullName)
  336.             oClone.posy.AddExpression(oDupe.posy.FullName)
  337.             oClone.posz.AddExpression(oDupe.posz.FullName)
  338.            
  339.             'Store oDupe's SRT to use for matching up oMerge's Center
  340.             oDupeScaleX = oSelecto.Kinematics.Global.Parameters("SclX").Value
  341.             oDupeScaleY = oSelecto.Kinematics.Global.Parameters("SclY").Value
  342.             oDupeScaleZ = oSelecto.Kinematics.Global.Parameters("SclZ").Value
  343.            
  344.             oDupeRotX = oSelecto.Kinematics.Global.Parameters("RotX").Value
  345.             oDupeRotY = oSelecto.Kinematics.Global.Parameters("RotY").Value
  346.             oDupeRotZ = oSelecto.Kinematics.Global.Parameters("RotZ").Value
  347.            
  348.             oDupePosX = oSelecto.Kinematics.Global.Parameters("PosX").Value
  349.             oDupePosY = oSelecto.Kinematics.Global.Parameters("PosY").Value
  350.             oDupePosZ = oSelecto.Kinematics.Global.Parameters("PosZ").Value
  351.            
  352.             'Match oMerge's Center to oDupe's SRT
  353.     '       oMerge.Kinematics.Local.Parameters("PSclX").Value = oSelecto.Kinematics.Global.Parameters("SclX").Value
  354.     '       oMerge.Kinematics.Local.Parameters("PSclY").Value = oSelecto.Kinematics.Global.Parameters("SclY").Value
  355.     '       oMerge.Kinematics.Local.Parameters("PSclZ").Value = oSelecto.Kinematics.Global.Parameters("SclZ").Value
  356.  
  357.     '       oMerge.Kinematics.Local.Parameters("PRotX").Value = oSelecto.Kinematics.Global.Parameters("RotX").Value
  358.     '       oMerge.Kinematics.Local.Parameters("PRotY").Value = oSelecto.Kinematics.Global.Parameters("RotY").Value
  359.     '       oMerge.Kinematics.Local.Parameters("PRotZ").Value = oSelecto.Kinematics.Global.Parameters("RotZ").Value
  360.  
  361.     '       oMerge.Kinematics.Local.Parameters("PPosX").Value = oSelecto.Kinematics.Global.Parameters("PosX").Value
  362.     '       oMerge.Kinematics.Local.Parameters("PPosY").Value = oSelecto.Kinematics.Global.Parameters("PosY").Value
  363.     '       oMerge.Kinematics.Local.Parameters("PPosZ").Value = oSelecto.Kinematics.Global.Parameters("PosZ").Value
  364.            
  365.             'Match oMerge's Center to oDupe's SRT
  366.             Translate oMerge, oDupePosX, oDupePosY, oDupePosZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , , , 0
  367.             Rotate oMerge, oDupeRotX, oDupeRotY, oDupeRotZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  368.             Scale oMerge, oDupeScaleX, oDupeScaleY, oDupeScaleZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  369.            
  370.             'Set the Merged Mesh's scale expressions linking it to the modelling half
  371.             oMerge.sclx.AddExpression(oDupe.sclx.FullName)
  372.             oMerge.scly.AddExpression(oDupe.scly.FullName)
  373.             oMerge.sclz.AddExpression(oDupe.sclz.FullName)
  374.            
  375.             'Set the Merged Mesh's rotation expressions linking it to the modelling half
  376.             oMerge.rotx.AddExpression(oDupe.rotx.FullName)
  377.             oMerge.roty.AddExpression(oDupe.roty.FullName)
  378.             oMerge.rotz.AddExpression(oDupe.rotz.FullName)
  379.            
  380.             'Set the Merged Mesh's translation expressions linking it to the modelling half
  381.             oMerge.posx.AddExpression(oDupe.posx.FullName)
  382.             oMerge.posy.AddExpression(oDupe.posy.FullName)
  383.             oMerge.posz.AddExpression(oDupe.posz.FullName)
  384.            
  385.             'Add the SubdCtrl object to the oFinalSelect collection
  386.             oFinalSelect.Add oSubdCtrl
  387.            
  388.             'Seperate the model object and the selection's name
  389.             set oModelo = Dictionary.GetObject( oSelecto.Model )
  390.             oSelName = oSelecto.Name
  391.            
  392.             'Set some dictionary lookups to check if anything created by this script in the past still exists
  393.             oSelTest = oSelecto & "-Modelling"
  394.             set ModellingTest = Dictionary.GetObject( oSelTest, false )
  395.             oSelTest = oSelecto & "-ClonedHalf"
  396.             set ClonedTest = Dictionary.GetObject( oSelTest, false )
  397.             oSelTest = oSelecto & "-MergedMesh"
  398.             set MergedTest = Dictionary.GetObject( oSelTest, false )
  399.             oSelTest = oSelecto & "-Gator"
  400.             set GatorTest = Dictionary.GetObject( oSelTest, false )
  401.            
  402.             'Reset WereRenamed
  403.             WereRenamed = 0
  404.            
  405.             'If the selected object is already created by one of my scripts, or has objects related to one of my scripts, find a new name for it and remove any annoyingness :P
  406.             if AfterDashCheck = "-MergedMesh" or AfterDashCheck = "-Gator" or AfterDashCheck = "-Modelling" or TypeName( ModellingTest ) <> "Nothing" or TypeName( ClonedTest ) <> "Nothing" or TypeName( MergedTest ) <> "Nothing" or TypeName( GatorTest ) <> "Nothing" then
  407.                
  408.                 if AfterDashCheck = "-MergedMesh" or AfterDashCheck = "-Gator" then
  409.                    
  410.                     LogMessage oSelName & " is already a merged result, removing expressions and finding a new name for it to keep things nice!"
  411.                     oDupe.Properties("visibility").Parameters("selectability").Value = True
  412.                     oSelName = Replace (oSelName, AfterDashCheck, "")
  413.                    
  414.                     oExpExist = "no"
  415.                    
  416.                     ExpStr = oDupe & ".kine.local.scl.sclx.Expression"
  417.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  418.                     if TypeName( oExpCheck ) <> "Nothing" then
  419.                         oDupe.SclX.Disconnect
  420.                         oExpExist = "yes"
  421.                     end if
  422.                    
  423.                     ExpStr = oDupe & ".kine.local.scl.scly.Expression"
  424.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  425.                     if TypeName( oExpCheck ) <> "Nothing" then
  426.                         oDupe.SclY.Disconnect
  427.                         oExpExist = "yes"
  428.                     end if
  429.                    
  430.                     ExpStr = oDupe & ".kine.local.scl.sclz.Expression"
  431.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  432.                     if TypeName( oExpCheck ) <> "Nothing" then
  433.                         oDupe.SclZ.Disconnect
  434.                         oExpExist = "yes"
  435.                     end if
  436.                    
  437.                     ExpStr = oDupe & ".kine.local.ori.euler.rotx.Expression"
  438.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  439.                     if TypeName( oExpCheck ) <> "Nothing" then
  440.                         oDupe.RotX.Disconnect
  441.                         oExpExist = "yes"
  442.                     end if
  443.                    
  444.                     ExpStr = oDupe & ".kine.local.ori.euler.roty.Expression"
  445.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  446.                     if TypeName( oExpCheck ) <> "Nothing" then
  447.                         oDupe.RotY.Disconnect
  448.                         oExpExist = "yes"
  449.                     end if
  450.                    
  451.                     ExpStr = oDupe & ".kine.local.ori.euler.rotz.Expression"
  452.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  453.                     if TypeName( oExpCheck ) <> "Nothing" then
  454.                         oDupe.RotZ.Disconnect
  455.                         oExpExist = "yes"
  456.                     end if
  457.                    
  458.                     ExpStr = oDupe & ".kine.local.pos.posx.Expression"
  459.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  460.                     if TypeName( oExpCheck ) <> "Nothing" then
  461.                         oDupe.PosX.Disconnect
  462.                         oExpExist = "yes"
  463.                     end if
  464.                    
  465.                     ExpStr = oDupe & ".kine.local.pos.posy.Expression"
  466.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  467.                     if TypeName( oExpCheck ) <> "Nothing" then
  468.                         oDupe.PosY.Disconnect
  469.                         oExpExist = "yes"
  470.                     end if
  471.                    
  472.                     ExpStr = oDupe & ".kine.local.pos.posz.Expression"
  473.                     set oExpCheck = Dictionary.GetObject( ExpStr, false )
  474.                     if TypeName( oExpCheck ) <> "Nothing" then
  475.                         oDupe.PosZ.Disconnect
  476.                         oExpExist = "yes"
  477.                     end if
  478.                    
  479.                 elseIf AfterDashCheck = "-Modelling" then
  480.                    
  481.                     LogMessage oSelName & " is a Modelling half, finding a new name for it to keep things nice!"
  482.                     oSelName = Replace (oSelName, "-Modelling", "")
  483.                    
  484.                     'Check if the new modelling half has a shrink wrap op, if it does, freeze it
  485.                     SWStr = oDupe & ".polymsh.shrinkwrap"
  486.                     set oShrinkWrapCheck = Dictionary.GetObject( SWStr, false )
  487.                     if TypeName( oShrinkWrapCheck ) <> "Nothing" then
  488.                         FreezeObj oDupe & ".polymsh.shrinkwrap"
  489.                         LogMessage SWStr & " was Frozen"
  490.                     end if
  491.                    
  492.                 else
  493.                    
  494.                     LogMessage oSelecto & " already has some objects previously created by this script, finding a new name"
  495.                    
  496.                     'Hide the original mesh
  497.                     oSelecto.Properties("visibility").Parameters("viewvis").Value = False
  498.                     oSelecto.Properties("visibility").Parameters("rendvis").Value = False
  499.                    
  500.                 end if
  501.                
  502.                 'Reset NumberCheck
  503.                 NumberCheck = "Nothing"
  504.                
  505.                 'Set a new Regex pattern that finds any numbers at the end of its name
  506.                 regEx.Pattern = "[0-9]+$"
  507.                
  508.                 'Execute the regex on the selection
  509.                 Set Matches = regEx.Execute(oSelName)
  510.                
  511.                 For Each Match in Matches
  512.                     NumberCheck = Match.Value
  513.                 Next
  514.                
  515.                 'If there are no numbers on the end then set objNumber to 0 (another 1 will be added on later)
  516.                 if NumberCheck = "Nothing" then
  517.                    
  518.                     objNumber = "0"
  519.                    
  520.                 else
  521.                    
  522.                     'If there is a number, set objNumber to the number found above
  523.                     objNumber = NumberCheck
  524.                    
  525.                     'Now get the name without and numbers
  526.                     regEx.Pattern =  "^.*?(?=[0-9])"              
  527.                     Set Matches = regEx.Execute(oSelName)
  528.                    
  529.                     For Each Match in Matches
  530.                         oSelName =  Match.Value
  531.                     Next
  532.                    
  533.                 end if
  534.                
  535.                 'Reset a counter I use to stop infinite loops, just incase :)
  536.                 JustIncaseAbort = 0
  537.                
  538.                 'Temporarily rename things to get them out of the way
  539.                 oDupe.Name = oSelName & "-modellingTemp"
  540.                 oClone.Name = oSelName & "-cloneTemp"
  541.                 oMerge.Name = oSelName & "-mergeTemp"
  542.                 WereRenamed = 1
  543.                
  544.                 'This Do part will add a number to the object's name then check if that name is already taken
  545.                 'if it is, it will loop and add on another number etc, until it finds a free name (or my failsafe reaches 1000)
  546.                
  547.                 '-----------------------------Loop Start-----------------------------'
  548.                
  549.                 Do
  550.                    
  551.                     'Increase objNumber by 1
  552.                     objNumber = objNumber + 1
  553.                    
  554.                     'Check if the model name needs to be added on to the test name
  555.                     if oModelo = "Scene_Root" then
  556.                        
  557.                         'Add on the new number to the name to see if it exists
  558.                         oSelTest = oSelName & objNumber
  559.                         oSelTest2 = oSelName & objNumber & "-MergedMesh"
  560.                         oSelTest3 = oSelName & objNumber & "-Modelling"
  561.                         oSelTest4 = oSelName & objNumber & "-ClonedHalf"
  562.                         oSelTest5 = oSelName & objNumber & "-Gator"
  563.                        
  564.                     else
  565.                        
  566.                         'Add on the model name aswell as the new number to the name to see if it exists
  567.                         oSelTest = oModelo & "." & oSelName & objNumber
  568.                         oSelTest2 = oModelo & "." & oSelName & objNumber & "-MergedMesh"
  569.                         oSelTest3 = oModelo & "." & oSelName & objNumber & "-Modelling"
  570.                         oSelTest4 = oModelo & "." & oSelName & objNumber & "-ClonedHalf"
  571.                         oSelTest5 = oModelo & "." & oSelName & objNumber & "-Gator"
  572.                        
  573.                     end if
  574.                    
  575.                     LogMessage "Checking if the name " & oSelTest & " is available .."
  576.                    
  577.                     set oSelTest = Dictionary.GetObject( oSelTest, false )
  578.                     set oSelTest2 = Dictionary.GetObject( oSelTest2, false )
  579.                     set oSelTest3 = Dictionary.GetObject( oSelTest3, false )
  580.                     set oSelTest4 = Dictionary.GetObject( oSelTest4, false )
  581.                     set oSelTest5 = Dictionary.GetObject( oSelTest5, false )
  582.                    
  583.                     'Add 1 onto the abort counter
  584.                     JustIncaseAbort = JustIncaseAbort + 1
  585.                    
  586.                     if TypeName( oSelTest ) <> "Nothing" then
  587.                         LogMessage oSelTest & " already exists"
  588.                     end if
  589.                    
  590.                     if TypeName( oSelTest2 ) <> "Nothing" then
  591.                         LogMessage oSelTest2 & " already exists"
  592.                     end if
  593.                    
  594.                     if TypeName( oSelTest3 ) <> "Nothing" then
  595.                         LogMessage oSelTest3 & " already exists"
  596.                     end if
  597.                    
  598.                     if TypeName( oSelTest4 ) <> "Nothing" then
  599.                         LogMessage oSelTest4 & " already exists"
  600.                     end if
  601.                    
  602.                     if TypeName( oSelTest5 ) <> "Nothing" then
  603.                         LogMessage oSelTest5 & " already exists"
  604.                     end if
  605.                    
  606.                 'Loop until there is a free name or the abort counter reaches 1000
  607.                 Loop Until TypeName( oSelTest ) = "Nothing" and TypeName( oSelTest2 ) = "Nothing" and TypeName( oSelTest3 ) = "Nothing" and TypeName( oSelTest4 ) = "Nothing"and TypeName( oSelTest5 ) = "Nothing"  or JustIncaseAbort = 1000
  608.                
  609.                 '-----------------------------Loop Finish-----------------------------'
  610.                
  611.                 'Add the final number onto oSelName
  612.                 oSelName = oSelName & objNumber
  613.                
  614.                 if JustIncaseAbort = 1000 then
  615.                    
  616.                     LogMessage "Name checking loop aborted after 1000 unsuccessfull attempts, doh!"
  617.                    
  618.                     else
  619.                    
  620.                     LogMessage "Woohoo, " & oSelName & " was available!"
  621.                    
  622.                 end if
  623.                
  624.             else
  625.                
  626.                 'Hide the original mesh
  627.                 oSelecto.Properties("visibility").Parameters("viewvis").Value = False
  628.                 oSelecto.Properties("visibility").Parameters("rendvis").Value = False
  629.                
  630.             end if     
  631.            
  632.             'Determine the correct scale and position for SubdCtrl (using the Bounding Box values from ~line 125)
  633.             If AfterDashCheck = "-Modelling" or Xmin = oSelecto.Kinematics.Local.Parameters("PosX").value then         
  634.                 oMergeScale = ( ( Xmax - Xmin ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 3              
  635.             else               
  636.                 oMergeScale = ( ( ( Xmax - Xmin ) / 2 ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 3              
  637.             end if
  638.            
  639.             CtrlXtrans = oDupePosX
  640.             CtrlYtrans = Ymax + ( oMergeScale / 2.2 )
  641.             CtrlZtrans = ( Zmin + Zmax ) / 2
  642.             CtrlScale = oMergeScale * 0.01
  643.            
  644.             'Move and scale SubdCtrl using the above values
  645.             Scale oSubdCtrl, CtrlScale, CtrlScale, CtrlScale, siRelative, siGlobal, siObj, siXYZ, , , , , , , , 0
  646.             Translate oSubdCtrl, CtrlXtrans, CtrlYtrans, CtrlZtrans, siAbsolute , siGlobal, siObj, siXYZ, , , , , , , , , , 0          
  647.            
  648.             'Parent SubdCtrl to the modelling mesh
  649.             oDupe.AddChild oSubdCtrl
  650.            
  651.             'Check to see if the merged mesh and the modelling mesh share the same parent object
  652.             if oDupe.Parent <> oMerge.Parent then
  653.                 set oDupeParent = Dictionary.GetObject(oDupe.Parent)
  654.                 'If they don't, give the merged mesh the same parent as the selection
  655.                 oDupeParent.AddChild oMerge
  656.             end if
  657.            
  658.             'Merge the duplicate and clone again, this time copying nothing across
  659.             set oGenOp2 = ApplyGenOp ("MeshMerge", , oDupe &","& oClone, 3, siPersistentOperation, siKeepGenOpInputs)
  660.             set oGenOp2 = Dictionary.GetObject( oGenOp2, False )
  661.            
  662.             oGator = replace (oGenOp2, ".polymsh.mergemesh", "")
  663.             set oGator = Dictionary.GetObject( oGator, False )
  664.            
  665.             'Set the Merge tolerance to 0.02
  666.             oGenOp2.tolerance.Value = 0.02
  667.            
  668.             'Match oGator's Center to oDupe's SRT
  669.             Translate oGator, oDupePosX, oDupePosY, oDupePosZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , , , 0
  670.             Rotate oGator, oDupeRotX, oDupeRotY, oDupeRotZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  671.             Scale oGator, oDupeScaleX, oDupeScaleY, oDupeScaleZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
  672.            
  673.             'Set the oGator's scale expressions linking it to the modelling half
  674.             oGator.sclx.AddExpression(oDupe.sclx.FullName)
  675.             oGator.scly.AddExpression(oDupe.scly.FullName)
  676.             oGator.sclz.AddExpression(oDupe.sclz.FullName)
  677.            
  678.             'Set the oGator's rotation expressions linking it to the modelling half
  679.             oGator.rotx.AddExpression(oDupe.rotx.FullName)
  680.             oGator.roty.AddExpression(oDupe.roty.FullName)
  681.             oGator.rotz.AddExpression(oDupe.rotz.FullName)
  682.            
  683.             'Set the oGator's translation expressions linking it to the modelling half
  684.             oGator.posx.AddExpression(oDupe.posx.FullName)
  685.             oGator.posy.AddExpression(oDupe.posy.FullName)
  686.             oGator.posz.AddExpression(oDupe.posz.FullName)
  687.            
  688.             'Apply Gator to oGator and transfer everything across from the original object
  689.             ApplyGenOp "Gator", , oGator & ";" & oSelecto, 3, siPersistentOperation, siKeepGenOpInputs
  690.             TransferAllPropertiesAcrossGenOp oGator & ".polymsh.TransferAttributes", oGator, , True
  691.             CopyAnimationAcrossGenerator oGator & ".polymsh.TransferAttributes", 0
  692.            
  693.             'Hide the Gator Mesh and disable its render visibility
  694.             oGator.Properties("visibility").Parameters("viewvis").Value = False
  695.             oGator.Properties("visibility").Parameters("rendvis").Value = False
  696.            
  697.             'Set oGator's subdivision levels to the same value as the input object
  698.             oGator.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Value = oSelectoSubdOgl
  699.             oGator.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Value = oSelectoSubdRdr
  700.            
  701.             'Rename things
  702.             oClone.Name = oSelName & "-ClonedHalf"
  703.             oMerge.Name = oSelName & "-MergedMesh"
  704.             oGator.Name = oSelName & "-Gator"
  705.             oSubdCtrl.Name = oSelName & "-Merged-SubdCtrl"
  706.             oDupe.Name = oSelName & "-Modelling"
  707.            
  708.             if oExpExist = "yes" then
  709.                 LogMessage "SRT expressions were removed from " & oDupe
  710.             end if
  711.            
  712.             LogMessage oDupe & ", " & oClone & ", " & oMerge & "," & oGator & ", and " & oSubdCtrl & " were created, happy days :)"
  713.            
  714.             'Check to see if the gator mesh and the modelling mesh share the same parent object
  715.             if oDupe.Parent <> oGator.Parent then
  716.                
  717.                 'If they don't, give the gator mesh the same parent as the selection
  718.                 oDupeParent.AddChild oGator
  719.                
  720.             end if
  721.            
  722.             'Add the -Modelling object to the oFinalSelect collection
  723.             oFinalSelect.Add oDupe
  724.            
  725.         end if
  726.        
  727.     end if
  728.    
  729. Next
  730.  
  731. 'Select all the objects in the oFinalSelect collection
  732. SelectObj oFinalSelect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement