Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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, oSelTest, oSelTest2, oSelTest3, oSelTest4, oSelTest5
- dim oDupeRotX, oDupeRotY, oDupeRotZ, oDupePosX, oDupePosY, oDupePosZ
- dim ModellingTest, ClonedTest, MergedTest, GatorTest
- dim regEx, Match, Matches, NumberCheck, objNumber, JustIncaseAbort
- dim oExpExist, ExpStr, oExpCheck, 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" )
- 'Swap to Object Select mode incase subcomponents are selected
- ActivateObjectSelTool
- '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
- oCol.add oSelection(i)
- else
- Logmessage oSelection(i) & " was skipped"
- 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
- 'Get the original object's bounding box co-ordinates
- oSelecto.Properties("visibility").Parameters("viewvis").Value = True
- GetBBox oSelecto, TRUE, Xmin, Ymin, Zmin, Xmax, Ymax, Zmax
- '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
- Tolerance = ( ( ( Xmax - Xmin ) / 2 ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 100
- '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
- elseIf Xmin > (oSelecto.Kinematics.Local.Parameters("PosX").value - Tolerance) and Xmin < (oSelecto.Kinematics.Local.Parameters("PosX").value + Tolerance) then
- LogMessage oSelecto & " appears to only be half a mesh, should I cut ?"
- BP = XSIUIToolkit.Msgbox( oSelecto & " seems to only be half a mesh, sure you want to cut it ?", 3, "Half as 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
- oSelectoSubdOgl = oSelecto.properties("Geometry Approximation").parameters("gapproxmosl").Value
- oSelectoSubdRdr = oSelecto.properties("Geometry Approximation").parameters("gapproxmordrsl").Value
- 'Duplicate original mesh
- set oDupe = Duplicate (oSelecto, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
- set oDupe = Dictionary.GetObject (oDupe, false)
- 'mute any envelope operators oDupe may have
- e = 0
- for e = 0 to (oDupe.Envelopes.Count-1)
- oDupe.Envelopes(e).Mute = True
- LogMessage oDupe.Envelopes(e) & " was muted"
- next
- '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)
- oDupe.Properties("visibility").Parameters("selectability").Value = True
- 'Check to see if the object's Geometry Approximation is local, make it local if it isn't
- q = 0
- for q = 0 to q = 1
- on error resume next
- Dictionary.GetObject ( oDupe.localproperties("Geometry Approximation") )
- if ( err <> 0 ) then
- MakeLocal oDupe.properties("Geometry Approximation")
- end if
- next
- 'Remove any animation on gemoetry approximation (incase the input object had any)
- oDupe.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Disconnect
- oDupe.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Disconnect
- 'Set oDupe's subdivision levels to the same value as the input object
- oDupe.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Value = oSelectoSubdOgl
- oDupe.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Value = oSelectoSubdRdr
- if SliceAway = "yes" then
- 'Determine the local center of the mesh as a percentage for the slice polygons op
- oSelectoPosX = oSelecto.PosX.Value
- SlicePercentage = ( ( oSelectoPosX - Xmin ) / (xmax - xmin) ) * 100
- 'Slice the duplicate in half, set the reference plane to local, and delete -x polys
- set oSlice = ApplyTopoOp ( "SlicePolygons", oDupe, siUnspecified, siPersistentOperation )
- set oSlice = Dictionary.GetObject ( oSlice )
- oSlice.planeref.Value = 1
- oSlice.sliceaction.Value = 3
- oSlice.planeoffsetbboxpercentage.Value = SlicePercentage
- end if
- 'Create a clone of the duplicate
- set oClone = Clone (oDupe, , 1, 1, 0, 0, 1, 0, 1)
- set oClone = Dictionary.GetObject ( oClone )
- 'Merge the duplicate and clone, transfer all properties
- oGenOp = ApplyGenOp ("MeshMerge", , oDupe &","& oClone, 3, siPersistentOperation, siKeepGenOpInputs)
- set oGenOp = Dictionary.GetObject ( oGenOp )
- oMerge = replace (oGenOp, ".polymsh.mergemesh", "")
- set oMerge = Dictionary.GetObject ( oMerge )
- TransferAllPropertiesAcrossGenOp oGenOp, oMerge, , True, True
- 'Set the Merge tolerance to the tolerance value calculated earlier
- if SliceAway = "yes" then
- oGenOp.tolerance.Value = Tolerance
- else
- oGenOp.tolerance.Value = ( ( Xmax - Xmin ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 100
- end if
- 'Create a cube named SubdCtrl to control the merged mesh's subdivision levels via expressions
- set oSubdCtrl = ActiveSceneRoot.AddGeometry( "Cube", "MeshSurface", "SubdCtrl" )
- 'Make SubdCtrl and mergedmesh's geometry approximation local
- MakeLocal oMerge.properties("Geometry Approximation")
- MakeLocal oSubdCtrl.properties("Geometry Approximation")
- 'Link MergedMesh's geometry approximation to SubdCtrl via expressions
- oMerge.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").AddExpression(oSubdCtrl.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").FullName)
- oMerge.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").AddExpression(oSubdCtrl.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").FullName)
- 'Match SubdCtrl's subdivision levels to the original object
- oSubdCtrl.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Value = oSelectoSubdOgl
- oSubdCtrl.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Value = oSelectoSubdRdr
- 'Give SubdCtrl the same material as the merged mesh
- AssignMaterial oMerge & ".*," & oSubdCtrl, siLetLocalMaterialsOverlap
- 'Set SubdCtrl's Visibility options
- oSubdCtrl.Properties("visibility").Parameters("rendvis").Value = false
- 'Set the clone's visibility options
- oClone.Properties("visibility").Parameters("viewvis").Value = false
- oClone.Properties("visibility").Parameters("rendvis").Value = false
- 'Set oClone's subdivision levels to 0
- oClone.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Value = 0
- oClone.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Value = 0
- 'Set the duplicate's Visibility options
- oDupe.Properties("visibility").Parameters("viewvis").Value = True
- oDupe.Properties("visibility").Parameters("rendvis").Value = False
- 'Set the duplicate's Display options (0 is wireframe, 5 is bounding box)
- MakeLocal oDupe.Properties("display"), siDefaultPropagation
- oDupe.LocalProperties("display").Parameters("staticsel").Value = 0
- oDupe.LocalProperties("display").Parameters("intsel").Value = 0
- oDupe.LocalProperties("display").Parameters("playbacksel").Value = 0
- oDupe.LocalProperties("display").Parameters("staticunselnear").Value = 5
- oDupe.LocalProperties("display").Parameters("intunselnear").Value = 5
- oDupe.LocalProperties("display").Parameters("playbackunselnear").Value = 5
- oDupe.LocalProperties("display").Parameters("staticunselfar").Value = 5
- oDupe.LocalProperties("display").Parameters("intunselfar").Value = 5
- oDupe.LocalProperties("display").Parameters("playbackunselfar").Value = 5
- 'Disable the merged mesh's Selectability
- oMerge.Properties("visibility").Parameters("selectability").Value = False
- 'Disable Camera's override object properties option
- SetValue "Camera.camdisp.mixviewmode", True
- 'Change the duplicate's wireframe display colour
- oDupe.LocalProperties("display").Parameters("wirecolorr").Value = 0.12
- oDupe.LocalProperties("display").Parameters("wirecolorg").Value = 0.14
- oDupe.LocalProperties("display").Parameters("wirecolorb").Value = 0.18
- 'Set the clone's scale expressions linking it to the modelling half
- oClone.sclx.AddExpression(oDupe.sclx.FullName & "*-1")
- oClone.scly.AddExpression(oDupe.scly.FullName)
- oClone.sclz.AddExpression(oDupe.sclz.FullName)
- 'Set the clone's rotation expressions linking it to the modelling half
- oClone.rotx.AddExpression(oDupe.rotx.FullName)
- oClone.roty.AddExpression(oDupe.roty.FullName)
- oClone.rotz.AddExpression(oDupe.rotz.FullName)
- 'Set the clone's translation expressions linking it to the modelling half
- oClone.posx.AddExpression(oDupe.posx.FullName)
- oClone.posy.AddExpression(oDupe.posy.FullName)
- oClone.posz.AddExpression(oDupe.posz.FullName)
- 'Store oDupe's SRT to use for matching up oMerge's Center
- oDupeScaleX = oSelecto.Kinematics.Global.Parameters("SclX").Value
- oDupeScaleY = oSelecto.Kinematics.Global.Parameters("SclY").Value
- oDupeScaleZ = oSelecto.Kinematics.Global.Parameters("SclZ").Value
- oDupeRotX = oSelecto.Kinematics.Global.Parameters("RotX").Value
- oDupeRotY = oSelecto.Kinematics.Global.Parameters("RotY").Value
- oDupeRotZ = oSelecto.Kinematics.Global.Parameters("RotZ").Value
- oDupePosX = oSelecto.Kinematics.Global.Parameters("PosX").Value
- oDupePosY = oSelecto.Kinematics.Global.Parameters("PosY").Value
- oDupePosZ = oSelecto.Kinematics.Global.Parameters("PosZ").Value
- 'Match oMerge's Center to oDupe's SRT
- ' oMerge.Kinematics.Local.Parameters("PSclX").Value = oSelecto.Kinematics.Global.Parameters("SclX").Value
- ' oMerge.Kinematics.Local.Parameters("PSclY").Value = oSelecto.Kinematics.Global.Parameters("SclY").Value
- ' oMerge.Kinematics.Local.Parameters("PSclZ").Value = oSelecto.Kinematics.Global.Parameters("SclZ").Value
- ' oMerge.Kinematics.Local.Parameters("PRotX").Value = oSelecto.Kinematics.Global.Parameters("RotX").Value
- ' oMerge.Kinematics.Local.Parameters("PRotY").Value = oSelecto.Kinematics.Global.Parameters("RotY").Value
- ' oMerge.Kinematics.Local.Parameters("PRotZ").Value = oSelecto.Kinematics.Global.Parameters("RotZ").Value
- ' oMerge.Kinematics.Local.Parameters("PPosX").Value = oSelecto.Kinematics.Global.Parameters("PosX").Value
- ' oMerge.Kinematics.Local.Parameters("PPosY").Value = oSelecto.Kinematics.Global.Parameters("PosY").Value
- ' oMerge.Kinematics.Local.Parameters("PPosZ").Value = oSelecto.Kinematics.Global.Parameters("PosZ").Value
- '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
- oMerge.sclx.AddExpression(oDupe.sclx.FullName)
- oMerge.scly.AddExpression(oDupe.scly.FullName)
- oMerge.sclz.AddExpression(oDupe.sclz.FullName)
- 'Set the Merged Mesh's rotation expressions linking it to the modelling half
- oMerge.rotx.AddExpression(oDupe.rotx.FullName)
- oMerge.roty.AddExpression(oDupe.roty.FullName)
- oMerge.rotz.AddExpression(oDupe.rotz.FullName)
- 'Set the Merged Mesh's translation expressions linking it to the modelling half
- oMerge.posx.AddExpression(oDupe.posx.FullName)
- oMerge.posy.AddExpression(oDupe.posy.FullName)
- oMerge.posz.AddExpression(oDupe.posz.FullName)
- 'Add the SubdCtrl object to the oFinalSelect collection
- oFinalSelect.Add oSubdCtrl
- 'Seperate the model object and the selection's name
- set oModelo = Dictionary.GetObject( oSelecto.Model )
- oSelName = oSelecto.Name
- 'Set some dictionary lookups to check if anything created by this script in the past still exists
- oSelTest = oSelecto & "-Modelling"
- set ModellingTest = Dictionary.GetObject( oSelTest, false )
- oSelTest = oSelecto & "-ClonedHalf"
- set ClonedTest = Dictionary.GetObject( oSelTest, false )
- oSelTest = oSelecto & "-MergedMesh"
- set MergedTest = Dictionary.GetObject( oSelTest, false )
- oSelTest = oSelecto & "-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!"
- oDupe.Properties("visibility").Parameters("selectability").Value = 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
- oDupe.SclX.Disconnect
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.scl.scly.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- oDupe.SclY.Disconnect
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.scl.sclz.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- oDupe.SclZ.Disconnect
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.ori.euler.rotx.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- oDupe.RotX.Disconnect
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.ori.euler.roty.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- oDupe.RotY.Disconnect
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.ori.euler.rotz.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- oDupe.RotZ.Disconnect
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.pos.posx.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- oDupe.PosX.Disconnect
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.pos.posy.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- oDupe.PosY.Disconnect
- oExpExist = "yes"
- end if
- ExpStr = oDupe & ".kine.local.pos.posz.Expression"
- set oExpCheck = Dictionary.GetObject( ExpStr, false )
- if TypeName( oExpCheck ) <> "Nothing" then
- oDupe.PosZ.Disconnect
- 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
- oSelecto.Properties("visibility").Parameters("viewvis").Value = False
- oSelecto.Properties("visibility").Parameters("rendvis").Value = 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.Name = oSelName & "-modellingTemp"
- oClone.Name = oSelName & "-cloneTemp"
- 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
- oSelecto.Properties("visibility").Parameters("viewvis").Value = False
- oSelecto.Properties("visibility").Parameters("rendvis").Value = False
- end if
- 'Determine the correct scale and position for SubdCtrl (using the Bounding Box values from ~line 125)
- If AfterDashCheck = "-Modelling" or Xmin = oSelecto.Kinematics.Local.Parameters("PosX").value then
- oMergeScale = ( ( Xmax - Xmin ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 3
- else
- oMergeScale = ( ( ( Xmax - Xmin ) / 2 ) + ( ( Ymax - Ymin ) / 2 ) + ( ( Zmax - Zmin ) / 2 ) ) / 3
- end if
- CtrlXtrans = oDupePosX
- 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
- 'Parent SubdCtrl to the modelling mesh
- oDupe.AddChild oSubdCtrl
- 'Check to see if the merged mesh and the modelling mesh share the same parent object
- if oDupe.Parent <> oMerge.Parent then
- set oDupeParent = Dictionary.GetObject(oDupe.Parent)
- 'If they don't, give the merged mesh the same parent as the selection
- oDupeParent.AddChild oMerge
- end if
- 'Merge the duplicate and clone again, this time copying nothing across
- set oGenOp2 = ApplyGenOp ("MeshMerge", , oDupe &","& oClone, 3, siPersistentOperation, siKeepGenOpInputs)
- set oGenOp2 = Dictionary.GetObject( oGenOp2, False )
- oGator = replace (oGenOp2, ".polymsh.mergemesh", "")
- set oGator = Dictionary.GetObject( oGator, False )
- 'Set the Merge tolerance to 0.02
- oGenOp2.tolerance.Value = 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
- oGator.sclx.AddExpression(oDupe.sclx.FullName)
- oGator.scly.AddExpression(oDupe.scly.FullName)
- oGator.sclz.AddExpression(oDupe.sclz.FullName)
- 'Set the oGator's rotation expressions linking it to the modelling half
- oGator.rotx.AddExpression(oDupe.rotx.FullName)
- oGator.roty.AddExpression(oDupe.roty.FullName)
- oGator.rotz.AddExpression(oDupe.rotz.FullName)
- 'Set the oGator's translation expressions linking it to the modelling half
- oGator.posx.AddExpression(oDupe.posx.FullName)
- oGator.posy.AddExpression(oDupe.posy.FullName)
- oGator.posz.AddExpression(oDupe.posz.FullName)
- '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
- oGator.Properties("visibility").Parameters("viewvis").Value = False
- oGator.Properties("visibility").Parameters("rendvis").Value = False
- 'Set oGator's subdivision levels to the same value as the input object
- oGator.LocalProperties("Geometry Approximation").Parameters("gapproxmosl").Value = oSelectoSubdOgl
- oGator.LocalProperties("Geometry Approximation").Parameters("gapproxmordrsl").Value = oSelectoSubdRdr
- 'Rename things
- oClone.Name = oSelName & "-ClonedHalf"
- oMerge.Name = oSelName & "-MergedMesh"
- oGator.Name = oSelName & "-Gator"
- oSubdCtrl.Name = oSelName & "-Merged-SubdCtrl"
- 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 :)"
- '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
- oDupeParent.AddChild oGator
- 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