Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '-----------------------------------------------------------------------------------------------------------------'
- '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.
- '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.
- '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".
- '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.
- '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.
- '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 ! :)
- '-----------------------------------------------------------------------------------------------------------------'
- dim oCol, oSelection, oSelecto, oFinalSelect, BP, ScriptCancel, oDupe, oClone, oMerge, oGenOp, oSubdCtrl
- dim oModelo, oSelName, AfterDashCheck, SliceAway, oGenOp2, oSelectoSubdOgl, oSelectoSubdRdr
- dim oMergeScale, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, CtrlXtrans, CtrlYtrans, CtrlZtrans, CtrlScale
- dim oDupeScaleX, oDupeScaleY, oDupeScaleZ, oSelTest3
- dim oDupeRotX, oDupeRotY, oDupeRotZ, oSelTest4
- dim oDupePosX, oDupePosY, oDupePosZ, oSelTest5
- dim ModellingTest, ClonedTest, MergedTest, GatorTest
- dim regEx, Match, Matches, NumberCheck, objNumber, JustIncaseAbort, oSelTest
- dim oExpExist, ExpStr, oExpCheck, oSelTest2, WereRenamed, oShrinkWrapCheck, SWStr
- 'Set up a regExp for later use
- set regEx = New RegExp
- 'Define a collection(oCol) for adding objects to
- Set oCol = CreateObject( "XSI.Collection" )
- 'Check if something is selected
- if Application.Selection.count > 1 Then
- 'Add the application selection to oCol
- Set oSelection = Application.Selection
- for i = 0 to (oSelection.Count - 1)
- 'Set a new Regex pattern that finds any letters after - at the end of its name
- regEx.Pattern = "-[a-zA-Z]+$"
- 'Reset oSubdCtrlCheck
- oSubdCtrlCheck = "Nothing"
- 'Execute the regex on the selection
- Set Matches = regEx.Execute(oSelection(i))
- For Each Match in Matches
- oSubdCtrlCheck = Match.Value
- Next
- 'If the selection doesnt end in -SubdCtrl then add it to the oCol Collection.
- if oSubdCtrlCheck <> "-SubdCtrl" then
- Logmessage oSelection(i) & " smells of roses, added to oCol"
- oCol.add oSelection(i)
- else
- Logmessage oSelection(i) & " smells of cheese, totally rejected!"
- end if
- next
- elseIf Application.Selection.count = 1 Then
- oCol.add Application.Selection(0)
- else
- 'If no object is selected, start a picksession
- LogMessage "Select a polymesh"
- PickObject "Select a polymesh", " ", oSelecto
- 'Add Picksession object to oCol
- oCol.add oSelecto
- end if
- 'Create a collection to add objects to for selection at the end
- Set oFinalSelect = CreateObject( "XSI.Collection" )
- for i = 0 to (oCol.count-1)
- set oSelecto = oCol(i)
- 'Make sure the oSelecto is a Polymesh, if it isn't then give the user one last try to select one
- set oSelecto = Dictionary.GetObject( oSelecto, false )
- if oSelecto.Type = "polymsh" then
- ScriptCancel = "no"
- else
- LogMessage oSelecto & " is a " & oSelecto.Type & ",not a polymsh"
- BP = XSIUIToolkit.Msgbox( oSelecto & " is not a polymsh, do you want to select something else?", 4, "No Polygon Mesh Selected" )
- if BP = 6 then
- PickObject "Please select a polygon mesh", " ", oSelecto
- if oSelecto.Type = "polymsh" then
- ScriptCancel = "no"
- else
- XSIUIToolkit.Msgbox "Bah, I give up.. " & oSelecto & " is a " & oSelecto.Type & " !", 1, "No Polygon Mesh Selected"
- Logmessage "Script Cancelled - Next time select a Polygon Mesh instead of a " & oSelecto.Type & "! :)"
- ScriptCancel = "yes"
- end if
- else
- LogMessage "Script Cancelled - " & oSelecto & " isn't a polygon mesh"
- ScriptCancel = "yes"
- end if
- end if
- if ScriptCancel = "no" then
- 'Set a new Regex pattern that finds any letters after - at the end of its name
- regEx.Pattern = "-[a-zA-Z]+$"
- 'Reset AfterDashCheck
- AfterDashCheck = "Nothing"
- 'Execute the regex on the selection
- Set Matches = regEx.Execute(oSelecto)
- For Each Match in Matches
- AfterDashCheck = Match.Value
- Next
- 'Reset SliceAway
- SliceAway = "yes"
- 'If the selection ends in -Modelling ask the user if they are sure they want to apply a(nother) slice op.
- if AfterDashCheck = "-Modelling" then
- LogMessage oSelecto & " ends in -Modelling, should I cut ?"
- BP = XSIUIToolkit.Msgbox( oSelecto & " could be a Modelling half, sure you want to cut it ?", 3, "Modelling Mesh Detected" )
- if BP = 6 then
- LogMessage "OK, gonna cut " & oSelecto & " good, sorry for bothering you ! :)"
- SliceAway = "yes"
- elseIf BP = 7 then
- LogMessage "Alrighty, no slice and dice for " & oSelecto
- SliceAway = "no"
- else
- LogMessage "Skipping " & oSelecto & " completely"
- ScriptCancel = "yes"
- end if
- end if
- if ScriptCancel = "no" then
- 'Store the original object's subdivision levels for later use
- set oSelectoSubdOgl = Dictionary.GetObject( oSelecto & ".geomapprox.gapproxmosl", false )
- set oSelectoSubdRdr = Dictionary.GetObject( oSelecto & ".geomapprox.gapproxmordrsl", false )
- oSelectoSubdOgl = oSelectoSubdOgl.Value
- oSelectoSubdRdr = oSelectoSubdRdr.Value
- 'Duplicate original mesh
- set oDupe = Duplicate (oSelecto, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
- 'Check to see if oDupe has an envelope operator
- set EnvelopeCheck = Dictionary.GetObject( oDupe&".polymsh.envelopop", false )
- 'If it does, mute it
- if TypeName( EnvelopeCheck ) <> "Nothing" then
- SetValue EnvelopeCheck & ".mute", True
- LogMessage oSelecto & "'s Envelope Operator was muted"
- end if
- 'Check to see if oDupe has a Cluster Shape Combiner
- set ShapeCheck = Dictionary.GetObject( oDupe&".polymsh.clustershapecombiner", false )
- 'If it does, mute it
- if TypeName( ShapeCheck ) <> "Nothing" then
- SetValue ShapeCheck & ".mute", True
- LogMessage oSelecto & "'s Cluster Shape Combiner was muted"
- end if
- 'Make oDupe selectable (incase the input object wasnt)
- SetValue oDupe & ".visibility.selectability", True
- 'Remove any animation on gemoetry approximation (incase the input object had any)
- RemoveAnimation oDupe & ".geomapprox.gapproxmosl", 10
- RemoveAnimation oDupe & ".geomapprox.gapproxmordrsl", 10
- 'Set oDupe's subdivision levels to the same value as the input object
- SetValue oDupe & ".geomapprox.gapproxmosl", oSelectoSubdOgl
- SetValue oDupe & ".geomapprox.gapproxmordrsl", oSelectoSubdRdr
- if SliceAway = "yes" then
- 'Slice the duplicate in half, set the reference plane to local, and delete -x polys
- ApplyTopoOp "SlicePolygons", oDupe, siUnspecified, siPersistentOperation
- SetValue oDupe&".polymsh.slicepolygonsop.planeref", 1
- SetValue oDupe&".polymsh.slicepolygonsop.sliceaction", 3
- end if
- 'Create a clone of the duplicate
- set oClone = Clone (oDupe, , 1, 1, 0, 0, 1, 0, 1)
- 'Merge the duplicate and clone, transfer all properties
- oGenOp = ApplyGenOp ("MeshMerge", , oDupe &","& oClone, 3, siPersistentOperation, siKeepGenOpInputs)
- oMerge = replace (oGenOp, ".polymsh.mergemesh", "")
- TransferAllPropertiesAcrossGenOp oGenOp, oMerge, , True, True
- 'Set the Merge tolerance to 0.1
- SetValue oGenOp & ".tolerance", 0.1
- 'Create a cube named SubdCtrl to control the merged mesh's subdivision levels via expressions
- Preferences.SetPreferenceValue "Interaction.autoinspect", false
- set oSubdCtrl = CreatePrim ("Cube", "MeshSurface", "SubdCtrl")
- Preferences.SetPreferenceValue "Interaction.autoinspect", true
- 'Make SubdCtrl and mergedmesh's geometry approximation local
- MakeLocal oMerge & ".geomapprox", siDefaultPropagation
- MakeLocal oSubdCtrl & ".geomapprox", siDefaultPropagation
- 'Link MergedMesh's geometry approximation to SubdCtrl via expressions
- SetExpr oMerge & ".geomapprox.gapproxmosl", oSubdCtrl & ".geomapprox.gapproxmosl"
- SetExpr oMerge & ".geomapprox.gapproxmordrsl", oSubdCtrl & ".geomapprox.gapproxmordrsl"
- 'Match SubdCtrl's subdivision levels to the original object
- SetValue oSubdCtrl & ".geomapprox.gapproxmosl", oSelectoSubdOgl
- SetValue oSubdCtrl & ".geomapprox.gapproxmordrsl", oSelectoSubdRdr
- 'Give SubdCtrl the same material as the merged mesh
- AssignMaterial oMerge & ".*," & oSubdCtrl, siLetLocalMaterialsOverlap
- 'Set SubdCtrl's Visibility options
- SetValue oSubdCtrl & ".visibility.rendvis", False
- SetValue oSubdCtrl & ".visibility.primray", False
- SetValue oSubdCtrl & ".visibility.scndray", False
- SetValue oSubdCtrl & ".visibility.shdwcast", False
- SetValue oSubdCtrl & ".visibility.shdwrecv", False
- SetValue oSubdCtrl & ".visibility.trnscast", False
- SetValue oSubdCtrl & ".visibility.trnsvis", False
- SetValue oSubdCtrl & ".visibility.globcast", False
- SetValue oSubdCtrl & ".visibility.globvis", False
- SetValue oSubdCtrl & ".visibility.causvis", False
- 'Set the clone's visibility options
- SetValue oClone & ".visibility.viewvis", False
- SetValue oClone & ".visibility.rendvis", False
- SetValue oClone & ".visibility.primray", False
- SetValue oClone & ".visibility.scndray", False
- SetValue oClone & ".visibility.shdwcast", False
- SetValue oClone & ".visibility.shdwrecv", False
- SetValue oClone & ".visibility.trnscast", False
- SetValue oClone & ".visibility.trnsvis", False
- SetValue oClone & ".visibility.globcast", False
- SetValue oClone & ".visibility.globvis", False
- SetValue oClone & ".visibility.causvis", False
- 'Set oClone's subdivision levels to 0
- SetValue oClone & ".geomapprox.gapproxmosl", 0
- SetValue oClone & ".geomapprox.gapproxmordrsl", 0
- 'Set the duplicate's Visibility options
- SetValue oDupe & ".visibility.viewvis", True
- SetValue oDupe & ".visibility.rendvis", False
- 'Set the duplicate's Display options (0 is wireframe, 5 is bounding box)
- MakeLocal oDupe & ".display", siDefaultPropagation
- SetValue oDupe & ".display.staticsel", 0
- SetValue oDupe & ".display.intsel", 0
- SetValue oDupe & ".display.playbacksel", 0
- SetValue oDupe & ".display.staticunselnear", 5
- SetValue oDupe & ".display.intunselnear", 5
- SetValue oDupe & ".display.playbackunselnear", 5
- SetValue oDupe & ".display.staticunselfar", 5
- SetValue oDupe & ".display.intunselfar", 5
- SetValue oDupe & ".display.playbackunselfar", 5
- 'Disable the merged mesh's Selectability
- SetValue oMerge & ".visibility.selectability", False
- 'Disable Camera's override object properties option
- SetValue "Camera.camdisp.mixviewmode", True
- 'Change the duplicate's wireframe display colour
- SetValue oDupe & ".display.wirecolorr", 0.12
- SetValue oDupe & ".display.wirecolorg", 0.14
- SetValue oDupe & ".display.wirecolorb", 0.18
- 'Set the clone's scale expressions linking it to the modelling half
- SetExpr oClone & ".kine.local.sclx", oDupe & ".kine.local.sclx*-1"
- SetExpr oClone & ".kine.local.scly", oDupe & ".kine.local.scly"
- SetExpr oClone & ".kine.local.sclz", oDupe & ".kine.local.sclz"
- 'Set the clone's rotation expressions linking it to the modelling half
- SetExpr oClone & ".kine.local.rotx", oDupe & ".kine.local.rotx"
- SetExpr oClone & ".kine.local.roty", oDupe & ".kine.local.roty"
- SetExpr oClone & ".kine.local.rotz", oDupe & ".kine.local.rotz"
- 'Set the clone's translation expressions linking it to the modelling half
- SetExpr oClone & ".kine.local.posx", oDupe & ".kine.local.posx"
- SetExpr oClone & ".kine.local.posy", oDupe & ".kine.local.posy"
- SetExpr oClone & ".kine.local.posz", oDupe & ".kine.local.posz"
- 'Store oDupe's SRT to use for matching up oMerge's Center
- oDupeScaleX = GetValue (oSelecto & ".kine.Global.scl.sclx")
- oDupeScaleY = GetValue (oSelecto & ".kine.Global.scl.sclY")
- oDupeScaleZ = GetValue (oSelecto & ".kine.Global.scl.sclZ")
- oDupeRotX = GetValue (oSelecto & ".kine.Global.ori.euler.rotx")
- oDupeRotY = GetValue (oSelecto & ".kine.Global.ori.euler.rotY")
- oDupeRotZ = GetValue (oSelecto & ".kine.Global.ori.euler.rotZ")
- oDupePosX = GetValue (oSelecto & ".kine.Global.pos.posx")
- oDupePosY = GetValue (oSelecto & ".kine.Global.pos.posY")
- oDupePosZ = GetValue (oSelecto & ".kine.Global.pos.posZ")
- 'Match oMerge's Center to oDupe's SRT
- Translate oMerge, oDupePosX, oDupePosY, oDupePosZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , , , 0
- Rotate oMerge, oDupeRotX, oDupeRotY, oDupeRotZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
- Scale oMerge, oDupeScaleX, oDupeScaleY, oDupeScaleZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
- 'Set the Merged Mesh's scale expressions linking it to the modelling half
- SetExpr oMerge & ".kine.local.sclx", oDupe & ".kine.local.sclx"
- SetExpr oMerge & ".kine.local.scly", oDupe & ".kine.local.scly"
- SetExpr oMerge & ".kine.local.sclz", oDupe & ".kine.local.sclz"
- 'Set the Merged Mesh's rotation expressions linking it to the modelling half
- SetExpr oMerge & ".kine.local.rotx", oDupe & ".kine.local.rotx"
- SetExpr oMerge & ".kine.local.roty", oDupe & ".kine.local.roty"
- SetExpr oMerge & ".kine.local.rotz", oDupe & ".kine.local.rotz"
- 'Set the Merged Mesh's translation expressions linking it to the modelling half
- SetExpr oMerge & ".kine.local.posx", oDupe & ".kine.local.posx"
- SetExpr oMerge & ".kine.local.posy", oDupe & ".kine.local.posy"
- SetExpr oMerge & ".kine.local.posz", oDupe & ".kine.local.posz"
- 'Get oMerge's bounding box co-ordinates to use in setting up relative values for SubdCtrl
- GetBBox oMerge, TRUE, Xmin, Ymin, Zmin, Xmax, Ymax, Zmax
- oMergeScale = ( ( ( Xmax - Xmin ) / 2 ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 3
- CtrlXtrans = ( Xmin + Xmax ) / 2
- CtrlYtrans = Ymax + ( oMergeScale / 2.2 )
- CtrlZtrans = ( Zmin + Zmax ) / 2
- CtrlScale = oMergeScale * 0.01
- 'Move and scale SubdCtrl using the above values
- Scale oSubdCtrl, CtrlScale, CtrlScale, CtrlScale, siRelative, siGlobal, siObj, siXYZ, , , , , , , , 0
- Translate oSubdCtrl, CtrlXtrans, CtrlYtrans, CtrlZtrans, siAbsolute , siGlobal, siObj, siXYZ, , , , , , , , , , 0
- 'Add the SubdCtrl object to the oFinalSelect collection
- oFinalSelect.Add oSubdCtrl
- 'Remove the model name from selection
- oModelo = oSelecto.Model
- oSelName = replace( oSelecto, oModelo&".", "")
- 'Set some dictionary lookups to check if anything created by this script in the past still exists
- oSelTest = oCol(i) & "-Modelling"
- set ModellingTest = Dictionary.GetObject( oSelTest, false )
- oSelTest = oCol(i) & "-ClonedHalf"
- set ClonedTest = Dictionary.GetObject( oSelTest, false )
- oSelTest = oCol(i) & "-MergedMesh"
- set MergedTest = Dictionary.GetObject( oSelTest, false )
- oSelTest = oCol(i) & "-Gator"
- set GatorTest = Dictionary.GetObject( oSelTest, false )
- 'Reset WereRenamed
- WereRenamed = 0
- '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
- 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
- if AfterDashCheck = "-MergedMesh" or AfterDashCheck = "-Gator" then
- LogMessage oSelName & " is already a merged result, removing expressions and finding a new name for it to keep things nice!"
- SetValue oDupe & ".visibility.selectability", True
- oSelName = Replace (oSelName, AfterDashCheck, "")
- oExpExist = "no"
- ExpStr = oDupe & ".kine.local.scl.sclx.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- RemoveAnimation oDupe & ".kine.local.sclx", 1
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.scl.scly.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- RemoveAnimation oDupe & ".kine.local.scly", 1
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.scl.sclz.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- RemoveAnimation oDupe & ".kine.local.sclz", 1
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.ori.euler.rotx.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- RemoveAnimation oDupe & ".kine.local.rotx", 1
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.ori.euler.roty.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- RemoveAnimation oDupe & ".kine.local.roty", 1
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.ori.euler.rotz.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- RemoveAnimation oDupe & ".kine.local.rotz", 1
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.pos.posx.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- RemoveAnimation oDupe & ".kine.local.posx", 1
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.pos.posy.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- RemoveAnimation oDupe & ".kine.local.posy", 1
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.pos.posz.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- RemoveAnimation oDupe & ".kine.local.posz", 1
- oExpExist = "yes"
- end if
- elseIf AfterDashCheck = "-Modelling" then
- LogMessage oSelName & " is a Modelling half, finding a new name for it to keep things nice!"
- oSelName = Replace (oSelName, "-Modelling", "")
- 'Check if the new modelling half has a shrink wrap op, if it does, freeze it
- SWStr = oDupe & ".polymsh.shrinkwrap"
- set oShrinkWrapCheck = Dictionary.GetObject( SWStr, false )
- if TypeName( oShrinkWrapCheck ) <> "Nothing" then
- FreezeObj oDupe & ".polymsh.shrinkwrap"
- LogMessage SWStr & " was Frozen"
- end if
- else
- LogMessage oSelecto & " already has some objects previously created by this script, finding a new name"
- 'Hide the original mesh
- SetValue oSelecto & ".visibility.viewvis", False
- SetValue oSelecto & ".visibility.rendvis", False
- end if
- 'Reset NumberCheck
- NumberCheck = "Nothing"
- 'Set a new Regex pattern that finds any numbers at the end of its name
- regEx.Pattern = "[0-9]+$"
- 'Execute the regex on the selection
- Set Matches = regEx.Execute(oSelName)
- For Each Match in Matches
- NumberCheck = Match.Value
- Next
- 'If there are no numbers on the end then set objNumber to 0 (another 1 will be added on later)
- if NumberCheck = "Nothing" then
- objNumber = "0"
- else
- 'If there is a number, set objNumber to the number found above
- objNumber = NumberCheck
- 'Now get the name without and numbers
- regEx.Pattern = "^.*?(?=[0-9])"
- Set Matches = regEx.Execute(oSelName)
- For Each Match in Matches
- oSelName = Match.Value
- Next
- end if
- 'Reset a counter I use to stop infinite loops, just incase :)
- JustIncaseAbort = 0
- 'Temporarily rename things to get them out of the way
- oDupe = SetValue (oDupe & ".Name", oSelName & "-modellingTemp")
- oClone = SetValue (oClone & ".Name", oSelName & "-cloneTemp")
- oMerge = SetValue (oMerge & ".Name", oSelName & "-mergeTemp")
- WereRenamed = 1
- 'This Do part will add a number to the object's name then check if that name is already taken
- 'if it is, it will loop and add on another number etc, until it finds a free name (or my failsafe reaches 1000)
- '-----------------------------Loop Start-----------------------------'
- Do
- 'Increase objNumber by 1
- objNumber = objNumber + 1
- 'Check if the model name needs to be added on to the test name
- if oModelo = "Scene_Root" then
- 'Add on the new number to the name to see if it exists
- oSelTest = oSelName & objNumber
- oSelTest2 = oSelName & objNumber & "-MergedMesh"
- oSelTest3 = oSelName & objNumber & "-Modelling"
- oSelTest4 = oSelName & objNumber & "-ClonedHalf"
- oSelTest5 = oSelName & objNumber & "-Gator"
- else
- 'Add on the model name aswell as the new number to the name to see if it exists
- oSelTest = oModelo & "." & oSelName & objNumber
- oSelTest2 = oModelo & "." & oSelName & objNumber & "-MergedMesh"
- oSelTest3 = oModelo & "." & oSelName & objNumber & "-Modelling"
- oSelTest4 = oModelo & "." & oSelName & objNumber & "-ClonedHalf"
- oSelTest5 = oModelo & "." & oSelName & objNumber & "-Gator"
- end if
- LogMessage "Checking if the name " & oSelTest & " is available .."
- set oSelTest = Dictionary.GetObject( oSelTest, false )
- set oSelTest2 = Dictionary.GetObject( oSelTest2, false )
- set oSelTest3 = Dictionary.GetObject( oSelTest3, false )
- set oSelTest4 = Dictionary.GetObject( oSelTest4, false )
- set oSelTest5 = Dictionary.GetObject( oSelTest5, false )
- 'Add 1 onto the abort counter
- JustIncaseAbort = JustIncaseAbort + 1
- if TypeName( oSelTest ) <> "Nothing" then
- LogMessage oSelTest & " already exists"
- end if
- if TypeName( oSelTest2 ) <> "Nothing" then
- LogMessage oSelTest2 & " already exists"
- end if
- if TypeName( oSelTest3 ) <> "Nothing" then
- LogMessage oSelTest3 & " already exists"
- end if
- if TypeName( oSelTest4 ) <> "Nothing" then
- LogMessage oSelTest4 & " already exists"
- end if
- if TypeName( oSelTest5 ) <> "Nothing" then
- LogMessage oSelTest5 & " already exists"
- end if
- 'Loop until there is a free name or the abort counter reaches 1000
- Loop Until TypeName( oSelTest ) = "Nothing" and TypeName( oSelTest2 ) = "Nothing" and TypeName( oSelTest3 ) = "Nothing" and TypeName( oSelTest4 ) = "Nothing"and TypeName( oSelTest5 ) = "Nothing" or JustIncaseAbort = 1000
- '-----------------------------Loop Finish-----------------------------'
- 'Add the final number onto oSelName
- oSelName = oSelName & objNumber
- if JustIncaseAbort = 1000 then
- LogMessage "Name checking loop aborted after 1000 unsuccessfull attempts, doh!"
- else
- LogMessage "Woohoo, " & oSelName & " was available!"
- end if
- else
- 'Hide the original mesh
- SetValue oSelecto & ".visibility.viewvis", False
- SetValue oSelecto & ".visibility.rendvis", False
- end if
- 'If the selection is in a model and things were renamed earlier..
- if oModelo <> "Scene_Root" and WereRenamed = 1 then
- 'Add the model name back into oClone and oDupe
- oClone = oModelo & "." & oClone
- oDupe = oModelo & "." & oDupe
- end if
- 'Parent SubdCtrl to the modelling mesh
- ParentObj "B:" & oDupe, oSubdCtrl
- set oDupe = Dictionary.GetObject( oDupe, False )
- set oMerge = Dictionary.GetObject( oMerge, False )
- 'Check to see if the merged mesh and the modelling mesh share the same parent object
- if oDupe.Parent <> oMerge.Parent then
- 'If they don't, give the merged mesh the same parent as the selection
- ParentObj "B:" & oDupe.Parent, oMerge
- end if
- 'Merge the duplicate and clone again, this time copying nothing across
- oGenOp2 = ApplyGenOp ("MeshMerge", , oDupe &","& oClone, 3, siPersistentOperation, siKeepGenOpInputs)
- oGator = replace (oGenOp2, ".polymsh.mergemesh", "")
- 'Set the Merge tolerance to 0.02
- SetValue oGenOp2 & ".tolerance", 0.02
- 'Match oGator's Center to oDupe's SRT
- Translate oGator, oDupePosX, oDupePosY, oDupePosZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , , , 0
- Rotate oGator, oDupeRotX, oDupeRotY, oDupeRotZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
- Scale oGator, oDupeScaleX, oDupeScaleY, oDupeScaleZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
- 'Set the oGator's scale expressions linking it to the modelling half
- SetExpr oGator & ".kine.local.sclx", oDupe & ".kine.local.sclx"
- SetExpr oGator & ".kine.local.scly", oDupe & ".kine.local.scly"
- SetExpr oGator & ".kine.local.sclz", oDupe & ".kine.local.sclz"
- 'Set the oGator's rotation expressions linking it to the modelling half
- SetExpr oGator & ".kine.local.rotx", oDupe & ".kine.local.rotx"
- SetExpr oGator & ".kine.local.roty", oDupe & ".kine.local.roty"
- SetExpr oGator & ".kine.local.rotz", oDupe & ".kine.local.rotz"
- 'Set the oGator's translation expressions linking it to the modelling half
- SetExpr oGator & ".kine.local.posx", oDupe & ".kine.local.posx"
- SetExpr oGator & ".kine.local.posy", oDupe & ".kine.local.posy"
- SetExpr oGator & ".kine.local.posz", oDupe & ".kine.local.posz"
- 'Apply Gator to oGator and transfer everything across from the original object
- ApplyGenOp "Gator", , oGator & ";" & oSelecto, 3, siPersistentOperation, siKeepGenOpInputs
- TransferAllPropertiesAcrossGenOp oGator & ".polymsh.TransferAttributes", oGator, , True
- CopyAnimationAcrossGenerator oGator & ".polymsh.TransferAttributes", 0
- 'Hide the Gator Mesh and disable its render visibility
- SetValue oGator & ".visibility.viewvis", False
- SetValue oGator & ".visibility.rendvis", False
- 'Set oGator's subdivision levels to the same value as the input object
- SetValue oGator & ".geomapprox.gapproxmosl", oSelectoSubdOgl
- SetValue oGator & ".geomapprox.gapproxmordrsl", oSelectoSubdRdr
- 'Rename things
- oClone = SetValue (oClone & ".Name", oSelName & "-ClonedHalf")
- oMerge = SetValue (oMerge & ".Name", oSelName & "-MergedMesh")
- oGator = SetValue (oGator & ".Name", oSelName & "-Gator")
- oSubdCtrl = SetValue (oSubdCtrl & ".Name", oSelName & "-Merged-SubdCtrl")
- oDupe = SetValue (oDupe & ".Name", oSelName & "-Modelling")
- if oExpExist = "yes" then
- LogMessage "SRT expressions were removed from " & oDupe
- end if
- LogMessage oDupe & ", " & oClone & ", " & oMerge & "," & oGator & ", and " & oSubdCtrl & " were created, happy days :)"
- 'Each time I rename something it loses it's model name so
- if oModelo <> "Scene_Root" then
- oDupe = oModelo & "." & oDupe
- oMerge = oModelo & "." & oMerge
- end if
- set oDupe = Dictionary.GetObject( oDupe, false )
- set oGator = Dictionary.GetObject( oGator, false )
- 'Check to see if the gator mesh and the modelling mesh share the same parent object
- if oDupe.Parent <> oGator.Parent then
- 'If they don't, give the gator mesh the same parent as the selection
- ParentObj "B:" & oDupe.Parent, oGator
- end if
- 'Inspect the Slice Polygons Op if selection count was less than 2
- if oCol.Count < 2 then
- InspectOBJ oDupe&".polymsh.slicepolygonsop"
- end if
- 'Add the -Modelling object to the oFinalSelect collection
- oFinalSelect.Add oDupe
- end if
- end if
- Next
- 'Select all the objects in the oFinalSelect collection
- SelectObj oFinalSelect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement