Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '-----------------------------------------------------------------------------------------------------------------'
- 'To use this script you must first create a point / edge cluster of all the components along the center that you 'want included in the shrinkwrap. The cluster should be named CL, but if it isn't this script wil do a few (very) 'simple checks for clusters it could use. Probably the best way is to have the cluster you want to use selected 'when you run this, and it will ask if you want to rename it to CL, otherwise it will look for a cluster named 'Edge, then a cluster named Point and ask if you want to use those hehe, clicking no to one check will just let 'the script go on to the next, at the end it will check if there is any CL cluster, if not it will cancel out.
- 'If the object(s) haven't already got a shrink center grid, click ok when it asks if you want to create one.
- 'With both of these things in place it will then create a new Shrink Wrap op on the CL cluster and move it into 'the animation stack.
- 'If there is already a Shrink Wrap op in place the script will ask you if you want to freeze the object, if you 'select no, it will count how many Shrink Wraps exist and then ask if you want to delete the highest one found, 'click yes if you have only one Shrink Wrap op in either the shape modelling or animation stacks, or click no if 'the existing shrink wrap(s) are all in the modelling stack. Since xsi renames operators depending where they are 'in the stack, and I have yet to find a way of determining where they are.. sigh, this is the best I could come up 'with for now :P
- '-----------------------------------------------------------------------------------------------------------------'
- dim oCol, oSelection, oSelecto, ScriptCancel, BP, POINTstr, EDGEstr, CLstr, oPointObj, oEdgeObj, oCLObj
- dim oShrinkCenter, oShrinkObj, oModelo, oSelName, oShrinky, SWstr, oObj, ShrinkWrapCount, StopLoop
- dim JustIncaseAbort, regEx, Match, Matches, oSubdCtrlCheck
- '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 an object 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) & " has a funny accent, added to oCol"
- oCol.add oSelection(i)
- else
- Logmessage oSelection(i) & " looked at me funny, 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 The Control Mesh (-Modelling)"
- PickObject "Select The Control Mesh (-Modelling)", " ", oSelecto
- 'Add Picksession object to oCol
- oCol.add oSelecto
- end if
- for i = 0 to (oCol.count-1)
- set oSelecto = oCol(i)
- 'Check if the cluster is selected instead of the mesh, saves having to re-select the mesh after creating the CL cluster
- if TypeName( oSelecto ) = "Cluster" then
- oSelecto = oSelecto.Parent3DObject
- end if
- 'Make sure the selection 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
- ScriptCancel = "yes"
- end if
- end if
- POINTstr = oSelecto & ".polymsh.cls.Point"
- EDGEstr = oSelecto & ".polymsh.cls.edge.clslist.Edge"
- CLstr = oSelecto & ".polymsh.cls.CL"
- set oPointObj = Dictionary.GetObject( POINTstr, false )
- set oEdgeObj = Dictionary.GetObject( EDGEstr, false )
- set oCLObj = Dictionary.GetObject( CLstr, false )
- 'Check if CL / point / edge cluster exists
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName( oEdgeObj ) = "Nothing" and TypeName( oPointObj ) = "Nothing" and TypeName( ocol(i) ) <> "Cluster" then
- XSIUIToolkit.Msgbox "You need to create an edge / point cluster of the center loop for " & oSelecto & " and name it CL", 1, "No CL Cluster Found"
- Logmessage "You need to create an edge / point cluster of the center loop for " & oSelecto & " and name it CL"
- ScriptCancel = "yes"
- end if
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName( oCol(i) ) = "Cluster" then
- Logmessage "Selection is a cluster"
- BP = XSIUIToolkit.Msgbox( oSelecto & " has no CL cluster but you had a cluster selected when you ran this script, do you want to rename it to CL ? (" & oCol(i) & ")", 4, "Edge Cluster Detected" )
- if BP = 6 then
- SetValue oCol(i) & ".Name", "CL"
- logmessage "Selected cluster renamed to CL"
- set oCLObj = Dictionary.GetObject( CLstr, false )
- end if
- end if
- 'If no CL cluster exists but an Edge cluster exists, ask if user wants to rename it to CL
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName ( oEdgeObj ) = "Cluster" and oCol(i).Name <> "Edge" then
- Logmessage "Edge Cluster Detected"
- BP = XSIUIToolkit.Msgbox( oSelecto & " has no CL cluster but an Edge cluster was detected, do you want to rename it to CL ?", 4, "Edge Cluster Detected" )
- if BP = 6 then
- SetValue oSelecto & ".polymsh.cls.edge.clslist.Edge.Name", "CL"
- logmessage "Edge cluster renamed to CL"
- set oCLObj = Dictionary.GetObject( CLstr, false )
- end if
- end if
- 'If no CL cluster exists but a Point cluster exists, ask if user wants to rename it to CL
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" and TypeName ( oPointObj ) = "Cluster" and oCol(i).Name <> "Point" then
- LogMessage "Point Cluster Detected"
- BP = XSIUIToolkit.Msgbox( oSelecto & " has no CL cluster but a Point cluster was detected, do you want to rename it to CL ?", 4, "Point Cluster Detected" )
- if BP = 6 then
- SetValue oSelecto & ".polymsh.cls.Point.Name", "CL"
- logmessage "Point cluster renamed to CL"
- set oCLObj = Dictionary.GetObject( CLstr, false )
- end if
- end if
- if ScriptCancel = "no" and TypeName( oCLObj ) = "Nothing" then
- ScriptCancel = "yes"
- LogMessage oSelecto & " was skipped since it has no CL cluster"
- end if
- 'Check if a ShrinkCenter object exists, if not ask the user if they want to create one
- oShrinkCenter = oSelecto&"-ShrinkCenter"
- set oShrinkObj = Dictionary.GetObject( oShrinkCenter, false )
- if ScriptCancel = "no" and TypeName( oShrinkObj ) = "Nothing" then
- LogMessage "No ShrinkCenter Object Found"
- BP = XSIUIToolkit.Msgbox( "No ShrinkCenter found for " & oSelecto & ", would you like to create one now?", 4, "No ShrinkCenter Object" )
- if BP = 6 then
- LogMessage "Creating a Shrinky Centery Gridy thingy!"
- 'Remove Model name from oSelecto
- oModelo = oSelecto.Model
- oSelName = replace( oSelecto, oModelo&".", "")
- 'Create a new grid to be used as a shrinkwrap target
- Preferences.SetPreferenceValue "Interaction.autoinspect", false
- set oShrinky = CreatePrim ("Grid", "MeshSurface", oSelName & "-ShrinkCenter")
- Preferences.SetPreferenceValue "Interaction.autoinspect", true
- 'Pose constrain the shrink center to original object
- ApplyCns "Pose", oShrinky, oSelecto
- 'Adjust the shrink center's pose constrain scale to 50x on all axis, and -90deg on z rotation axis
- SetValue oShrinky & ".kine.posecns.sclx", 50
- SetValue oShrinky & ".kine.posecns.scly", 50
- SetValue oShrinky & ".kine.posecns.sclz", 50
- SetValue oShrinky & ".kine.posecns.rotz", -90
- 'Disable all of the shrink center's visibility options
- SetValue oShrinky & ".visibility.shdwcast", False
- SetValue oShrinky & ".visibility.shdwrecv", False
- SetValue oShrinky & ".visibility.primray", False
- SetValue oShrinky & ".visibility.scndray", False
- SetValue oShrinky & ".visibility.trnscast", False
- SetValue oShrinky & ".visibility.trnsvis", False
- SetValue oShrinky & ".visibility.causvis", False
- SetValue oShrinky & ".visibility.globcast", False
- SetValue oShrinky & ".visibility.globvis", False
- SetValue oShrinky & ".visibility.viewvis", False
- SetValue oShrinky & ".visibility.rendvis", False
- ParentObj "B:" & oSelecto, oShrinky
- LogMessage "Created " & oShrinky
- else
- ScriptCancel = "yes"
- LogMessage "Script Cancelled since no ShrinkCenter object exists"
- end if
- end if
- 'Check if a ShrinkWrap op already exists
- SWstr = oSelecto & ".polymsh.shrinkwrap"
- set oMCobj = Dictionary.GetObject( SWstr, false )
- if TypeName( oMCobj ) <> "Nothing" and ScriptCancel = "no" then
- BP = XSIUIToolkit.Msgbox( "Do you want to freeze " & oSelecto & " ? : If there is more than one ShrinkWrap op in either the Shape Modelling or Animation stacks then this won't work (clicking no will determine how many Shrink Wrap ops there are, then ask if you want to delete the highest one)", 3, "Shrink Wrap Ops Detected, Freeze " & oselecto & "?" )
- if BP = 6 then
- LogMessage "Freezing Object"
- FreezeObj oSelecto
- elseIf BP = 7 then
- LogMessage "ShrinkWrap operator already in place, determining what number the new one will be"
- 'Reset some variables
- JustIncaseAbort = 0
- ShrinkWrapCount = 0
- StopLoop = "no"
- '-----------------------------Loop Start-----------------------------'
- do
- 'Add 1 onto the counter that will be used to see how many shrink wrap ops exist
- ShrinkWrapCount = ShrinkWrapCount + 1
- 'Check to see if a shrink wrap op with the count number exists e.g. shrinkwrap[15]
- SWstr = oSelecto & ".polymsh.shrinkwrap["&ShrinkWrapCount&"]"
- set oMCobj = Dictionary.GetObject( SWstr, false )
- if TypeName( oMCobj ) = "Nothing" then
- StopLoop = "yes"
- end if
- 'Increment an abort counter to stop an infinite loop
- JustIncaseAbort = JustIncaseAbort + 1
- Loop Until StopLoop = "yes" or JustIncaseAbort = 1000
- '-----------------------------Loop Finish-----------------------------'
- 'If the abort number has been reached then cancel the script
- if JustIncaseAbort = 10000 then
- LogMessage "Either something has gone horribly wrong or you have more than 1000 Shrink Wrap ops ?? in which case it might be time to freeze the modelling stack :)"
- ScriptCancel = "yes"
- end if
- LogMessage oSelecto & " had " & ShrinkWrapCount & " shrinkwraps"
- if ScriptCancel = "no" then
- BP = XSIUIToolkit.Msgbox( ShrinkWrapCount & " Shrink Wrap ops were found, is there one (singular) in either the Shape Modelling or Animation stack ? ( clicking yes will delete Shrink Wrap[" & ShrinkWrapCount - 1 &"] )", 3, "Move Component Ops Detected" )
- if BP = 6 then
- ShrinkWrapCount = ShrinkWrapCount - 1
- DeleteObj ".shrinkwrap[" & ShrinkWrapCount & "]"
- SWstr = oSelecto & ".polymsh.shrinkwrap[" & ShrinkWrapCount & "]"
- LogMessage oSelecto & ".polymsh.shrinkwrap[" & ShrinkWrapCount & "] was deleted"
- elseIf BP = 2 then
- LogMessage "Cancelling Script"
- ScriptCancel = "yes"
- end if
- end if
- else
- LogMessage "Cancelling Script"
- ScriptCancel = "yes"
- end if
- else
- SWstr = oSelecto & ".polymsh.shrinkwrap"
- end if
- if ScriptCancel = "no" then
- 'Apply a shrinkwrap op on the CL cluster, using the ShrinkCenter object as the target
- ApplyOp "ShrinkWrap", oSelecto&".polymsh.cls.CL;" & oShrinkCenter&";", 3, siPersistentOperation, , 0
- 'Move the shrinkwrap op to the animation stack
- MoveOperatorAfter oSelecto & ".polymsh", SWstr, oSelecto & ".polymsh.shapemarker"
- 'Set the shrinkwrap mode to closest surface
- SetValue SWstr & ".proj", 5
- LogMessage oSelecto&".polymsh.cls.CL" & " was shrinkwrapped to " & oShrinkCenter
- end if
- Next
- SelectObj oCol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement