PDA

View Full Version : Rename Vmaps



xchrisx
12-11-2008, 05:43 PM
I have looked through the Lscript documentation and I dont see a way to rename vmaps (such as morphs). Does anyone have a solution to this or is it only accessible through the SDK?

thanks
-c

faulknermano
12-12-2008, 01:21 AM
have a look at this code of mine called RenameAppliedVmaps.ls. the only thing i can explain about this script is that it appears that my past self renamed the vmaps by going through all the points, getting the original vmap, looking at its value, and then applying a 'renamed' (i.e. new map) with the same value.

kinda crude, though; there should be a more straightforward way... though i'm unsure if there is.




@warnings 0
search; replace; renmode; vmaptype; renname;
main
{
selmode(USER);
search = string(recall("search","_L"));
replace = string(recall("replace","_R"));
renmode = integer(recall("renmode",1));
vmaptypeW = integer(recall("vmaptypeW",1));
vmaptypeT = integer(recall("vmaptypeT",0));
vmaptypeM = integer(recall("vmaptypeM",1));

renname = "";

reqbegin("Rename Applied VMaps");

c0a = ctlcheckbox("Weight",vmaptypeW);
c0b = ctlcheckbox("Texture",vmaptypeT);
c0c = ctlcheckbox("Morph",vmaptypeM);

c1 = ctlchoice("Renaming Mode",renmode,@"_L to _R","_R to _L","Search & Replace","Standard"@);

d1 = ctlstring("Search",search);
d2 = ctlstring("Replace",replace);

e1 = ctlstring("Name",renname);

ctlactive(c1,"sr_active",d1,d2);
ctlactive(c1,"std_active",e1);
ctlrefresh(e1,"std_refresh");

return if(!reqpost());

vmaptypeW = getvalue(c0a);
vmaptypeT = getvalue(c0b);
vmaptypeM = getvalue(c0c);

renmode = getvalue(c1);

search = getvalue(d1);
replace = getvalue(d2);

renname = getvalue(e1);

store("renmode",renmode);
store("search",search);
store("replace",replace);
store("renname",renname);
store("vmaptypeW",vmaptypeW);
store("vmaptypeT",vmaptypeT);
store("vmaptypeM",vmaptypeM);

reqend();

vi = 0;
pc = editbegin();
if(vmaptypeW == true)
{
v = VMap(VMWEIGHT);
while(v && v.type == VMWEIGHT)
{
vmw[++vi] = v;
v = v.next();
}
}
vi = 0;
if(vmaptypeT == true)
{
v = VMap(VMTEXTURE);

while(v && v.type == VMTEXTURE)
{
vmt[++vi] = v;
v = v.next();
}
}
vi = 0;
if(vmaptypeM == true)
{
v = VMap(VMMORPH);
while(v && v.type == VMMORPH)
{
vmm[++vi] = v;
v = v.next();
}
}

for(i=1;i<=pc;i++)
{
pnt = points[i];
if(vmaptypeW == true)
{
for(j=1;j<=vmw.size();j++)
{
if(vmw[j].isMapped(pnt))
{
val = vmw[j].getValue(pnt);
processThisPoint(val,pnt,vmw[j].name,1);
vmw[j].setValue(pnt,nil);
}

}
}
if(vmaptypeT == true)
{
for(j=1;j<=vmt.size();j++)
{
if(vmt[j].isMapped(pnt))
{
val = vmt[j].getValue(pnt);
processThisPoint(val,pnt,vmt[j].name,2);
vmt[j].setValue(pnt,nil);
}

}
}
if(vmaptypeM == true)
{
for(j=1;j<=vmm.size();j++)
{
if(vmm[j].isMapped(pnt))
{
val = vmm[j].getValue(pnt);
processThisPoint(val,pnt,vmm[j].name,3);
vmm[j].setValue(pnt,nil);
}

}
}


}
}
doRen: val
{

}
processThisPoint: val, pnt, vn, t
{
if(renmode == 1)
nn = searchAndReplace(vn,"_L","_R");
if(renmode == 2)
nn = searchAndReplace(vn,"_R","_L");
if(renmode == 3)
nn = searchAndReplace(vn,search,replace);
if(renmode == 4)
nn = doRen(renname);

if(t == 1)
{
v = VMap(VMWEIGHT,nn,1);
}
if(t == 2)
{
v = VMap(VMTEXTURE,nn,2);
}
if(t == 3)
v = VMap(VMMORPH,nn,3);

v.setValue(pnt,val);

}

std_refresh: val
{


}
sr_active: ndx
{
if(ndx == 3)
return(true);
else
return(false);
}
std_active: ndx
{
if(ndx == 4)
return(true);
else
return(false);

}
main2
{
polyc = polycount();
if(polyc[1] == 0)
error("No data.");
selmode(USER);
selectmode = integer(recall("selectmode",1));
axis = integer(recall("axis",1));
op = integer(recall("op",1));
surfList[1] = nil;
surf = Surface();
i = 0;
while(surf)
{
surfList[++i] = surf.name;
surf = surf.next();
}
reqbegin("fm Axis Drill");

c1 = ctlchoice("Select Mode",selectmode,@"Per-Polygon","Connected"@);
c2 = ctlchoice("Axis",axis,@"X","Y","Z"@);
c3 = ctlchoice("Operation",op,@"Core","Tunnel","Stencil","Slice"@);


if(surfList[1] != nil)
c4 = ctlpopup("Surface",1,surfList);


return if(!reqpost());

selectmode = getvalue(c1);
if((axis = getvalue(c2)) == 1)
axis = X;
if((axis = getvalue(c2)) == 2)
axis = Y;
if((axis = getvalue(c2)) == 3)
axis = Z;

if((op = getvalue(c3)) == 1)
op = CORE;
if((op = getvalue(c3)) == 2)
op = TUNNEL;
if((op = getvalue(c3)) == 3)
op = STENCIL;
if((op = getvalue(c3)) == 4)
op = SLICE;

surfName = surfList[getvalue(c4)];

store("axis",axis);
store("op",op);


store("selectmode",selectmode);

reqend();

fg = lyrfg();
empty = lyrempty(); // get two empty background layers
if(empty.size() < 1)
error("Need one empty layers");

editbegin();

foreach(x,polygons)
polys += x;

editend();

if(selectmode == 2)
selpolygon(SET,CONNECT);
copy();
lyrsetfg(empty[1]);
paste();
lyrsetfg(fg);

selpolygon(SET,POLYID,polys);
lyrsetbg(empty[1]);
if(op == STENCIL)
axisdrill(op,axis,surfName);
else
axisdrill(op,axis);

lyrsetfg(empty[1]);
delete();
lyrsetfg(fg);


}
searchAndReplace: oName, search, replace
{
exp = regexp(search,replace);
oName ~= exp;
return(oName);
}

Dodgy
12-12-2008, 02:16 AM
Nope, that's the problem, there's no meta vmap commands in lscript :P You have to do it the low level way...

xchrisx
12-12-2008, 02:31 AM
faulknermano: thanks for the code snippet ill see if i can modify or at least use it as a starting point for what I am trying to do.

dodgy: yeah, I had a feeling it didnt exist but I thought it never hurts to ask just to make sure :)