Advertisement
spookymunky

SymmThings 2.0 - Cloned Symmetry With Cutting (VBS)

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