@warnings
@script generic
@name SymWeightAssign3
//Globals for UI Helper function
var GRIDSIZE = 24;
var SKEW = floor(GRIDSIZE / 2);
var OFFSET = floor(SKEW / 2);
var nullflag = true;
var LW_CONTROL = 0;
var LW_MAIN = 1;
var LW_SEPARATOR = 2;
var c1..8;
var wMapList = nil;
var wMapNames = nil;
var objlist = nil;
var wMap = VMap(VMWEIGHT);
var rtbn, rtwt, ltbn, ltwt;
var objcnt;
generic{
//This script symmetrically assigns wt map names to selected
//Bones. , based on User set tags for right and left on bones
//and weight maps.
//Variables
var a[4];
//Get Weight Maps
while(wMap){
if(wMap.type == VMWEIGHT){
wMapList += wMap;
wMapNames += wMap.name;
}
wMap = wMap.next();
}
//Let's see what the user has selected...
var objs = Scene().getSelect();
//If it isn't a bone, then we'll need to error out...
for(i=1; i<= objs.count();i++){
if(objs[i].genus == 4) objlist += objs[i];
}
if(!objlist) error("No bones selected to work on!");
objcnt = objlist.count();
//Now that we've got a list of our bones, let's open our interface\
//and do some work...
//Initialize Requester
//recall what got entered so the user doesn't have to type in things again...
//or assign it a default value if there is no entry...
rtwt = recall("smp_SWA_rtwt","_RT");
ltwt = recall("smp_SWA_ltwt","_LT");
ltbn = recall("smp_SWA_ltbn","Lft_");
rtbn = recall("smp_SWA_rtbn","Rgt_");
wtidx = 1;
reqbegin("Sym. Weight Assign"); a=gbox2(LW_MAIN,0,0,12,10); reqsize(a[3],a[4]);
t1 = ctltext("","Weight Map"); a = gbox2(LW_CONTROL, 0,0,5,1); ctlposition(t1,a[1],a[2],a[3],a[4]);
c1 = ctlstring("Right",rtwt); a = gbox2(LW_CONTROL,0,1,5,1); ctlposition(c1,a[1],a[2],a[3],a[4]);
c2 = ctlstring("Left",ltwt); a = gbox2(LW_CONTROL,0,2,5,1); ctlposition(c2,a[1],a[2],a[3],a[4]);
t2 = ctltext("", "Bone Name"); a = gbox2(LW_CONTROL, 6,0,5,1); ctlposition(t2,a[1],a[2],a[3],a[4]);
c3 = ctlstring("Right",rtbn); a= gbox2(LW_CONTROL,6,1,5,1); ctlposition(c3,a[1],a[2],a[3],a[4]);
c4 = ctlstring("Left",ltbn); a = gbox2(LW_CONTROL,6,2,5,1); ctlposition(c4,a[1],a[2],a[3],a[4]);
a = gbox2(LW_SEPARATOR,0,3,11,1); s1 = ctlsep(a[1],a[3]); ctlposition(s1,a[1],a[2],a[3],a[4]);
c5 = ctlpopup("Weight Map",wtidx,wMapNames); a= gbox2(LW_CONTROL, 0,4,11,1); ctlposition(c5,a[1],a[2],a[3],a[4]);
a = gbox2(LW_SEPARATOR,0,5,11,1); s2 = ctlsep(a[1],a[3]); ctlposition(s2,a[1],a[2],a[3],a[4]);
a = gbox2(LW_CONTROL,0,6,3,1); c6 = ctlbutton("Parent",a[3],"parentbutton");ctlposition(c6,a[1],a[2],a[3],a[4]);
a = gbox2(LW_CONTROL,4,6,3,1); c7 = ctlbutton("Assign",a[3],"assignbutton");ctlposition(c7,a[1],a[2],a[3],a[4]);
a = gbox2(LW_CONTROL,8,6,3,1); c8 = ctlbutton("Child ",a[3],"childbutton");ctlposition(c8,a[1],a[2],a[3],a[4]);
return if !reqpost();
//-->
rtwt = getvalue(c1);
ltwt = getvalue(c2);
rtbn = getvalue(c3);
ltbn = getvalue(c4);
wtidx = getvalue(c5);
//<--
reqend();
/
//Store what got entered so the user doesn't have to type in things again...
store("smp_SWA_rtwt",rtwt);
store("smp_SWA_ltwt",ltwt);
store("smp_SWA_ltbn",ltbn);
store("smp_SWA_rtbn",rtbn);
}
gbox2 : w_mode, w_x, w_y, w_h, w_w
{
//w_mode 0 = normal, 1 = main box, 2 = Separator
//All values are GRID coordinates
//w_x, w_y = (x,y) coordinates of control;
//w_h, w_w = (height, width) of control;
//Return Values array
var retv[4];
//Convert from Grid coordinates to screen coordinates
retv[1] = (w_x * GRIDSIZE) + OFFSET;
retv[2] = (w_y * GRIDSIZE) + OFFSET;
retv[3] = (w_h * GRIDSIZE);
retv[4] = (w_w * GRIDSIZE);
//Mode Handling
if (w_mode == 1){
retv[3] += SKEW;
retv[4] += OFFSET;
}
if (w_mode == 2) retv[2] += SKEW;
return(retv);
}
dorefreshstuff : q_obj
{
obj_list = nil;
objlist += q_obj;
objcnt = 1;
SelectByName(objlist[1].name);
RefreshNow();
}
parentbutton
{
tmp_obj = objlist[1];
if(tmp_obj.parent) tmp_obj = tmp_obj.parent;
dorefreshstuff(tmp_obj);
}
assignbutton
{
//-->
rtwt = getvalue(c1);
ltwt = getvalue(c2);
rtbn = getvalue(c3);
ltbn = getvalue(c4);
wtidx = getvalue(c5);
//debug();
//Ok, we've got our info from the user, let's add some wt. maps to bones...
for(i=1; i<=objcnt;i++){
//Symmetry flags
var mode1 = 0; // if this is true, the bone has a match for symmetry
var mode2 = 0; // If this is true, the wt. map has a match for symmetry.
var bone1 = objlist[i].name;
var bone2 = bone1;
var wmap1 = wMapNames[wtidx];
var wmap2 = wmap1;
var expr1 = regexp(rtwt);
var expr2 = regexp(ltwt);
var expr3 = regexp(rtbn);
var expr4 = regexp(ltbn);
var repl3;
var repl4;
//first, check for symmetric bones... and set mode1 if they exist.
if(bone1 == expr3){
mode1 = 1;
repl3 = regexp(rtbn,ltbn);
}
if(bone1 == expr4){
mode1 = 1;
repl3 = regexp(ltbn,rtbn);
}
//likewise, check for symmetric wt maps, and set mode2 if they exist.
if(wmap1 == expr1){
mode2 = 1;
repl4 = regexp(rtwt,ltwt);
}
if(wmap1 == expr2){
mode2 = 1;
repl4 = regexp(ltwt,rtwt);
}
//Now, let's assign weights based on modes
modenum = (2 * mode2) + mode1;
switch(modenum)
{
case 1:
//Symmetric Bones, but no symmetric weights.
bone2 ~= repl3;
//Set Weight Maps on symm. bones...
SelectByName(bone1);
BoneWeightMapName(wmap1);
SelectByName(bone2);
BoneWeightMapName(wmap2);
break;
case 3:
//We have symmetric bones and weights!
//If Symmetry exists, generate names for Symm. Bones and Weights
bone2 ~= repl3;
wmap2 ~= repl4;
//Set Weight Maps on symm. bones...
SelectByName(bone1);
BoneWeightMapName(wmap1);
SelectByName(bone2);
BoneWeightMapName(wmap2);
break;
default:
SelectByName(bone1);
BoneWeightMapName(wmap1);
break;
}
}
//Let's restore the selected objects from the start...
for(i=1; i<=objcnt;i++){
if(i==1){
SelectByName(objlist[i].name);
} else {
AddToSelection(objlist[i].name);
}
}
//<--
}
childbutton
{
tmp_obj = objlist[1];
tmp_obj = tmp_obj.firstChild();
if(!tmp_obj) tmp_obj = tmp_obj.nextChild();
if(!tmp_obj) tmp_obj = objlist[1];
dorefreshstuff(tmp_obj);
}