Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'This is a small script to make merging meshes in xsi a bit less tedious for me :). Once it's started select
- 'objects / groups that you want to be included in the merge operation and right click when you have selected
- 'everything you want.
- 'By default the merged mesh's center SRT, name, and parent will be based on the first object selected, to override
- 'this hold ctrl while clicking any object to use its SRT values, hold shift while clicking on an object to use its
- 'name, and Ctrl+Shift to select a parent object. Middle click will select an object as the parent, aso opposed to
- 'ctrl shift that will set the selections's parent as the parent...
- 'Any object picked as a name / srt / parent shouldn't be added to the merge, click on them normally if you want
- 'them included aswell.
- '------------
- DeselectAll
- 'create a collection for adding polygon meshes to for using in the merge op
- Set oCol = CreateObject( "XSI.Collection" )
- 'create a string to tell if an object has been picked using ctrl for use as a center
- sCenterObject = "no"
- 'Create a string to store an objects name when shift is held down
- sName = "nope"
- 'Create a string to store the parent object when Ctrl + shift / middle mouse are used
- sParent = "natta"
- 'create an integer to count how many objects have been added to the collection
- iObjNumber = 1
- do 'Start a pick session loop, adding each viable polygon mesh to oCol
- PickObject "Select polygon mesh #" & iObjNumber, "Select Parent", oSelecto, iButton, iModifier
- if iModifier = 2 then 'if Ctrl was pressed when the object was selected then store the objects SRT for the merged result's center
- oSelectoScaleX = oSelecto.Kinematics.Global.Parameters("SclX").Value
- oSelectoScaleY = oSelecto.Kinematics.Global.Parameters("SclY").Value
- oSelectoScaleZ = oSelecto.Kinematics.Global.Parameters("SclZ").Value
- oSelectoRotX = oSelecto.Kinematics.Global.Parameters("RotX").Value
- oSelectoRotY = oSelecto.Kinematics.Global.Parameters("RotY").Value
- oSelectoRotZ = oSelecto.Kinematics.Global.Parameters("RotZ").Value
- oSelectoPosX = oSelecto.Kinematics.Global.Parameters("PosX").Value
- oSelectoPosY = oSelecto.Kinematics.Global.Parameters("PosY").Value
- oSelectoPosZ = oSelecto.Kinematics.Global.Parameters("PosZ").Value
- sCenterObject = "yes"
- logmessage "Center set to " & oSelecto
- elseif iModifier = 1 then 'if shift was held down when selecting the object then store its name
- sName = oSelecto.name
- logmessage "Name set to " & sName
- elseif iModifier = 3 then 'if both control and shift were held down then use the selected object's parent as the parent for the merged result
- sParent = oSelecto.Parent
- logmessage "Parent set to " & sParent
- elseif iButton = 2 then
- sParent = dictionary.GetObject ( oSelecto ) 'if middle mouse button is pressed then make that object the parent
- logmessage "Parent set to " & sParent
- else 'if there were no modifiers...
- 'create a string to differentiate between objects that have already been added to the colelction and anything else
- sAlreadyAdded = "no"
- if oCol.Count > 0 then 'If there is at least one object then
- for each oEqualsCheck in oCol 'for every object already added to the collection,
- if oEqualsCheck.IsEqualTo(oSelecto) = "True" then 'if it has already been added then
- sAlreadyAdded = "yes" 'change the string to something other than "no"...
- end if
- next
- end if
- if sAlreadyAdded = "no" and sCenterObject = "no" and sName = "nope" and sParent = "natta" then 'so that it will miss out on this part.
- if TypeName( oSelecto ) = "Group" then 'If the selection is a group then
- for each oMember in oSelecto.Members 'for every object in that group,
- 'reset sAlreadyAdded
- sAlreadyAdded = "no"
- 'Check if it has already been added
- if oCol.Count > 0 then
- for each oEqualsCheck in oCol
- if oEqualsCheck.IsEqualTo(oMember) = "True" then
- sAlreadyAdded = "yes"
- end if
- next
- end if
- if sAlreadyAdded = "no" and oMember.Type = "polymsh" then 'if it is a new object and a polygon mesh then
- oCol.Add oMember 'add it to the collection,
- iObjNumber = iObjNumber + 1 'and increase the object counter.
- elseif sAlreadyAdded = "yes" then
- logmessage oMember & " has already been added, skipping"
- else
- logmessage oMember & " isn't a polygon mesh, skipping"
- end if
- next
- elseif oSelecto.Type = "polymsh" then
- oCol.Add oSelecto
- iObjNumber = iObjNumber + 1
- else
- logmessage oMember & " isn't a polygon mesh, skipping"
- end if
- else
- logmessage oSelecto & " has already been selected, skipping"
- end if
- end if
- loop until iButton = 0 'Stop the loop when the user right clicks or hits escape
- if oCol.Count > 1 then 'if more than 1 polygon meshes were added to the collection then start to merge
- 'Get the first object selected
- set oSelecto = Dictionary.GetObject( oCol(0), false )
- 'Merge all the objects in the collection
- oGenOp = ApplyGenOp ("MeshMerge", , oCol, 3, siPersistentOperation, siKeepGenOpInputs)
- 'Get the gen op and the merged result
- set oGenOp = Dictionary.GetObject ( oGenOp )
- sMerge = replace (oGenOp, ".polymsh.mergemesh", "")
- set oMergedResult = Dictionary.GetObject ( sMerge )
- 'transfer all properties from the input objects to the merged result(disabled) and set tollerance to 0.002
- 'TransferAllPropertiesAcrossGenOp oGenOp, oMergedResult, , True, True
- oGenOp.tolerance.Value = 0.02
- if sName = "nope" then 'if no name object was selected then use the 1st object's name
- oMergedResult.Name = oSelecto.Name
- else 'otherwise use the selected object
- oMergedResult.Name = sName
- end if
- if sParent = "natta" then 'if no parent object was selected... blah :)
- oSelecto.Parent.AddChild oMergedResult
- else
- set sParent = Dictionary.GetObject( sParent, false )
- sParent.AddChild oMergedResult
- end if
- 'If no center object was selected then use the first object selected's SRT instead
- if sCenterObject = "no" then
- oSelectoScaleX = oSelecto.Kinematics.Global.Parameters("SclX").Value
- oSelectoScaleY = oSelecto.Kinematics.Global.Parameters("SclY").Value
- oSelectoScaleZ = oSelecto.Kinematics.Global.Parameters("SclZ").Value
- oSelectoRotX = oSelecto.Kinematics.Global.Parameters("RotX").Value
- oSelectoRotY = oSelecto.Kinematics.Global.Parameters("RotY").Value
- oSelectoRotZ = oSelecto.Kinematics.Global.Parameters("RotZ").Value
- oSelectoPosX = oSelecto.Kinematics.Global.Parameters("PosX").Value
- oSelectoPosY = oSelecto.Kinematics.Global.Parameters("PosY").Value
- oSelectoPosZ = oSelecto.Kinematics.Global.Parameters("PosZ").Value
- end if
- 'Match the merged result's center to the oSelecto's values above
- Translate oMergedResult, oSelectoPosX, oSelectoPosY, oSelectoPosZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , , , 0
- Rotate oMergedResult, oSelectoRotX, oSelectoRotY, oSelectoRotZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
- Scale oMergedResult, oSelectoScaleX, oSelectoScaleY, oSelectoScaleZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
- else
- logmessage "not enough polygon meshes to merge, operation aborted"
- end if
- inspectobj oGenOp, , , siLockAndForceNew
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement