Hi everyone. I'm trying to sort out a script I need for combining and readying building assets for Unity for Maya.
My outliner looks like this:
I have to click on storehouse_t0_LOD0 in this example and when I run the script it goes through and deletes history, freezes transformations and combines the msh_ groups that are there.
The problem that I'm having is that I use a lot of instanced geometry, and the script won't work once it hits anything that is instanced. It also won't merge instances.
I was hoping someone good with scripting could help me out with this.
Here's the script that I'm using:
// ---- EVEN EVEN More Better Combine
// // Looks through all nodes under current selection.
// Check if node name is the same as the strings we are looking for.
// Plug that name into the EVEN More Better Combine V2.3 to combine
//scriptEditorInfo -clearHistory;
{
//The strings we are looking for
string $targetMeshes[] = {"msh_roof","msh_building","msh_alpha","msh_sign"};
int $targetMeshesSize = size($targetMeshes);
//List of nodes as a full path
string $targetGroups[];
//List of nodes for selected object
//string $nodes[] = `ls -sl -dag`;
string $nodes[] = `ls -sl`;
//Stores child name of node to compare with $targetMeshes[]
string $nodeChildren[]={};
//Stores full path to node we are looking for
string $nodeChildrenFull[]={};
int $nodeChildrenSize;
int $nodeTokens;
int $k=0;
//K LOOP
do
{
//cyle through all nodes in the scene
for($node in $nodes)
{
//get child of current node
$nodeChildren =`listRelatives -c $node`;
//get full path name
$nodeChildrenFull = `listRelatives -f $node`;
$nodeChildrenSize = size($nodeChildren);
//cycle through targetMeshes array
$h=0;
//H LOOP
do
{
//if the child has the same name as the target mesh
if($nodeChildren[$h] == $targetMeshes[$k])
{
//add the full path of the desired node to the $targetGroups array
//$targetGroups is what the EVEN More Better Combine V2.3 looks at
$targetGroups[size($targetGroups)] = $nodeChildrenFull[$h];
}
$h++;
}
while ($h <= $nodeChildrenSize);
}
$k++;
}
while ($k <= $targetMeshesSize);
int $targetGroupSize = size($targetGroups);
int $m=0;
//print($targetGroups);
//print($targetGroups[0]);
//print($targetGroups[1]);
while($m <= $targetGroupSize)
{
if($targetGroups[$m] != ""){
// ---- EVEN More Better Combine V2.3
//
// Combines Polygons deletes history and keeps it within it's Group if it is in one.
// Also Keeps the name of the first Poly selected.
// Now it merges verts and Centers the pivot as requested. =D
// the initial Tolerance of the merge vert can be changed below or you can change it in the history after.
//
Change these values for the Merge Vert Tolorance
//
string $onOff = "on";
float $k = 0.001;
//
Change these values for the Merge Vert Tolorance
//
//edited line
string $sel[]={$targetGroups[$m]};
string $fpo = `firstParentOf $sel[0]`;
string $buffer[];
string $selBuffer[];
int $numTokens = `tokenize $fpo "|" $buffer`;
string $newPoly[] = `polyUnite -ch 0 -n $sel[0] $sel`;
int $j=0;
int $i=0;
if ($fpo != "")
{
while ($j<= $numTokens)
{
if (!`objExists $buffer[$j]`)
{
if($j != 0)
{
$j--;
}
//group -em -n $buffer[$j];
if (`objExists $buffer[$j]`)
{
parent $newPoly $buffer[$j];
}
break;
}
$j++;
}
}
int $selNumTokens = `tokenize $sel[0] "|" $selBuffer`;
$i = $selNumTokens -1;
$newPoly[0] = `rename $newPoly $selBuffer[$i]`;
if ($onOff == "on")
{
polyMergeVertex -d $k -am 1 -ch 0 $newPoly;
}
xform -cp $newPoly;
select -r $newPoly;
}
$m++;
}
}
Replies
Do you have anything similar to your script that merges and cleans up references, or is that a whole different thing? I have no idea with scripting.
Thanks again.
You'll want to have "storehouse" selected when you run the script.
Here's a before and after simulation:
BEFORE
AFTER
The naming conventions don't matter as long as you maintain a three-group hierarchy (main asset name, the group with whatever "t0" means, and the LOD group.
I tried to comment everything so you can see what's going on. It looks like a jumbled mess here but it's easier to read inside the Script Editor I don't really work with references so I've never written anything to deal with them. Sorry!
The real issue I'm having is that its combining and giving me the wrong groups.
Like, if you see the hierarchy in that image I supplied, I need the exact same hiearchy, except I need it to go through and take msh building, msh alpha, msh roof groups, etc. and combine them, rename the resulting mesh and keep it where its group was before.
I hope that makes sense.
Thanks for the help so far. The instancing one is awesome so far.
Thanks a lot.