PDA

View Full Version : Scale Plugin


vpii
03-15-2005, 09:33 PM
Does anyone know of a plugin that can scale an object, say a house that is out of scale. I know that a door is 8ft. Is the a plugin out there I can select the door type in 8 ft for y and the rest of the mesh will scale with it?

faulknermano
03-15-2005, 10:41 PM
Does anyone know of a plugin that can scale an object, say a house that is out of scale. I know that a door is 8ft. Is the a plugin out there I can select the door type in 8 ft for y and the rest of the mesh will scale with it?



vm;
main
{
mode = integer(recall("Mode",1));
if(mode == 1)
main1();
if(mode == 2)
main2();
}

main1 // setvalue
{
selmode(USER);
pc = editbegin() || error("No data.");

vm = VMap(VMTEXTURE,0);


stateX = integer(recall("stateX",1));
stateY = integer(recall("stateY",1));
stateZ = integer(recall("stateZ",1));

stateU = integer(recall("stateU",1));
stateV = integer(recall("stateV",1));

xValue = number(recall("xValue",0.0));
yValue = number(recall("yValue",0.0));
zValue = number(recall("zValue",0.0));
uValue = number(recall("uValue",0.0));
vValue = number(recall("vValue",0.0));

svselmode = integer(recall("svselmode",1));

editend();
reqbegin("Set Value");
reqsize(200,200);
c1 = ctlcheckbox("X",stateX);
c2 = ctlcheckbox("Y",stateY);
c3 = ctlcheckbox("Z",stateZ);
d1 = ctldistance("",xValue);
d2 = ctldistance("",yValue);
d3 = ctldistance("",zValue);

sep = ctlsep();

c4 = ctlcheckbox("U",stateU);
c5 = ctlcheckbox("V",stateV);

f1 = ctlnumber("",uValue);
f2 = ctlnumber("",vValue);

b1 = ctlchoice("Selmode",svselmode,@"User","Global","Con"@);

e1 = ctlbutton("Absolute Sizer",151,"goToSizer");

ctlposition(c1,5,5);
ctlposition(c2,5,29);
ctlposition(c3,5,53);
ctlposition(d1,5+40,5,140);
ctlposition(d2,5+40,29,140);
ctlposition(d3,5+40,53,140);


ctlposition(sep,0,77);

ctlposition(c4,5,77+5,39);
ctlposition(f1,5+40,77+5,50);

ctlposition(c5,100,77+5);
ctlposition(f2,100+40,77+5,50);

ctlposition(b1,18,77+24+5);
ctlposition(e1,18,77+24+24+5);

ctlactive(c1,"active",d1);
ctlactive(c2,"active",d2);
ctlactive(c3,"active",d3);

ctlactive(c4,"uv_active",f1);
ctlactive(c5,"uv_active",f2);




setvalue(c1,stateX);
setvalue(c2,stateY);
setvalue(c3,stateZ);
return if(!reqpost());
stateX = getvalue(c1);
stateY = getvalue(c2);
stateZ = getvalue(c3);
stateU = getvalue(c4);
stateV = getvalue(c5);

xValue = getvalue(d1);
yValue = getvalue(d2);
zValue = getvalue(d3);
uValue = getvalue(f1);
vValue = getvalue(f2);

svselmode = getvalue(b1);
if(svselmode == 1) // USER
{
pc = editbegin() || error("<br>No data.");
for(i=1;i<=pc;i++)
{
pnt = points[i];
if(stateX)
pnt.x = xValue;
if(stateY)
pnt.y = yValue;
if(stateZ)
pnt.z = zValue;

if(stateU)
u = uValue;
else
{
if(vm)
u = vm.getValue(pnt,1);
}
if(stateV)
v = vValue;
else
{
if(vm)
v = vm.getValue(pnt,2);
}
if((stateU || stateV) && vm)
{
b[1] = u;
b[2] = v;

vm.setValue(pnt,b);
}
}
}
if(svselmode == 2 || svselmode == 3) // GLOBAL & CONNECTED
{
pc = editbegin() || error("<br>No data.");
pnt = points[1];
diff = <0,0,0>;
if(stateX)
diff.x = xValue - pnt.x;
if(stateY)
diff.y = yValue - pnt.y;
if(stateZ)
diff.z = zValue - pnt.z;


editend();
if(svselmode == 2)
selmode(GLOBAL);
if(svselmode == 3)
selpoint(SET,CONNECT);
move(diff);

}

store("stateX",stateX);
store("stateY",stateY);
store("stateZ",stateZ);
store("stateU",stateU);
store("stateV",stateV);


store("xValue",xValue);
store("yValue",yValue);
store("zValue",zValue);
store("uValue",uValue);
store("vValue",vValue);


store("Mode",1);
store("svselmode",svselmode);
}
active: val
{
return(val);
}
uv_active: val
{
if(vm)
return(val);
else
return(false);
}
goToSizer
{
reqabort();
main2();
}
main2
{
selmode(USER);
if(pointcount() == 0)
error("No data.");
selectionmode = integer(recall("selectionmode",1));
stretch = integer(recall("stretch",1));
extentX = integer(recall("extentX",1));
extentY = integer(recall("extentY",1));
extentZ = integer(recall("extentZ",1));
sc = integer(recall("sc",1));
cSizeX = integer(recall("cSizeX",1));
cSizeY = integer(recall("cSizeY",1));
cSizeZ = integer(recall("cSizeZ",1));

// (lowX,highX,lowY,highY,lowZ,highZ) = findBoundingBox();
bb = boundingbox();
lowX = bb[1].x;
highX = bb[2].x;
lowY = bb[1].y;
highY = bb[2].y;
lowZ = bb[1].z;
highZ = bb[2].z;

(x,y,z) = calcSize(lowX,highX,lowY,highY,lowZ,highZ);
sizeX = x;
sizeY = y;
sizeZ = z;

selmode(USER);
reqbegin("Absolute Sizer");
reqsize(350,220);

c0 = ctlchoice("Selmode",selectionmode,@"USER","GLOBAL"@,true);
c00 = ctlcheckbox("Stretch",stretch);
c1 = ctlchoice("Scale Center",sc,@"User","Point","Origin","Center","Extents"@);
c2 = ctldistance("User X",0.0);
c3 = ctldistance("User Y",0.0);
c4 = ctldistance("User Z",0.0);
c5 = ctlchoice("Extent X",extentX,@"-Left","=Middle","+Right"@);
c6 = ctlchoice("Extent Y",extentY,@"-Bottom","=Middle","+Top"@);
c7 = ctlchoice("Extent Z",extentZ,@"-Rear","=Middle","+Front"@);
ctlvisible(c1,"visibleExtents",c5,c6,c7);
ctlvisible(c1,"visibleUser",c2,c3,c4);
ctlposition(c0,225,34,100);
ctlposition(c00,225,80,100);
ctlposition(c1,5,5);
ctlposition(c2,34,30);
ctlposition(c3,34,55);
ctlposition(c4,34,80);
ctlposition(c5,26,30);
ctlposition(c6,26,55);
ctlposition(c7,26,80);
sep1 = ctlsep();
ctlposition(sep1,0,105);
d1 = ctldistance("Size X",sizeX);
d2 = ctldistance("Size Y",sizeY);
d3 = ctldistance("Size Z",sizeZ);
e1 = ctlcheckbox("",cSizeX);
e2 = ctlcheckbox("",cSizeY);
e3 = ctlcheckbox("",cSizeZ);
f1 = ctlbutton("Set Value",150,"goToSetValue");
ctlactive(e1,"activeSize",d1);
ctlactive(e2,"activeSize",d2);
ctlactive(e3,"activeSize",d3);
ctlposition(d1,36,115);
ctlposition(d2,36,140);
ctlposition(d3,36,165);
ctlposition(e1,140,115);
ctlposition(e2,140,140);
ctlposition(e3,140,165);
ctlposition(f1,175,135,100,25);

return if(!reqpost());

selectionmode = getvalue(c0);
stretch = getvalue(c00);
sc = getvalue(c1);
userX = getvalue(c2);
userY = getvalue(c3);
userZ = getvalue(c4);
extentX = getvalue(c5);
extentY = getvalue(c6);
extentZ = getvalue(c7);
sizeX = getvalue(d1);
sizeY = getvalue(d2);
sizeZ = getvalue(d3);
cSizeX = getvalue(e1);
cSizeY = getvalue(e2);
cSizeZ = getvalue(e3);

store("stretch",stretch);
store("extentX",extentX);
store("extentY",extentY);
store("extentZ",extentZ);
store("sc",sc);
store("sizeX",sizeX);
store("sizeY",sizeY);
store("sizeZ",sizeZ);
store("cSizeX",cSizeX);
store("cSizeY",cSizeY);
store("cSizeZ",cSizeZ);

(fScaleX,fScaleY,fScaleZ) = calcScale(sizeX,sizeY,sizeZ,x,y,z);
if(cSizeX == 0)
fScaleX = 1.0;
if(cSizeY == 0)
fScaleY = 1.0;
if(cSizeZ == 0)
fScaleZ = 1.0;
if(sc == 1) // User
fCenter = <userX,userY,userZ>;
if(sc == 2) // point
{
editbegin();
fCenter = pointinfo(points[1]);
editend();
}
if(sc == 3) // Origin
fCenter = <0,0,0>;
if(sc == 4) // center
{
a = <lowX,lowY,lowZ>;
b = <highX,highY,highZ>;
fCenter = center(a,b);
}
if(sc == 5) // extents
{
if(extentX == 1) // left
a = lowX;
if(extentX == 2) // middle
a = ((highX - lowX) / 2) + lowX;
if(extentX == 3) // right
a = highX;

if(extentY == 1)
b = lowY;
if(extentY == 2) // middle
b = ((highY - lowY) / 2) + lowY;
if(extentY == 3)
b = highY;

if(extentZ == 1)
c = lowZ;
if(extentZ == 2)
c = ((highZ - lowZ) / 2) + lowZ;
if(extentZ == 3)
c = highZ;

fCenter = <a,b,c>;
}

fs = <fScaleX,fScaleY,fScaleZ>;
if(selectionmode == 2)
selmode(GLOBAL);
if(stretch == false)
{
if(cSizeX == true)
fs = <fScaleX,fScaleX,fScaleX>;
if(cSizeY == true)
fs = <fScaleY,fScaleY,fScaleY>;
if(cSizeZ == true)
fs = <fScaleZ,fScaleZ,fScaleZ>;
}

scale(fs,fCenter);
store("Mode",2);
}
findBoundingBox
{
pc = editbegin();
for(i=1;i<=pc;i++)
{
pix[i] = pointinfo(points[i]).x;
piy[i] = pointinfo(points[i]).y;
piz[i] = pointinfo(points[i]).z;
}
pix.sortA();
piy.sortA();
piz.sortA();
lowX = pix[1];
highX = pix[pix.size()];
lowY = piy[1];
highY = piy[piy.size()];
lowZ = piz[1];
highZ = piz[piz.size()];
editend();
return(lowX,highX,lowY,highY,lowZ,highZ);
}
calcSize: lx, hx, ly, hy, lz, hz
{
// find size through bounding box
x = hx - lx;
y = hy - ly;
z = hz - lz;
return(x,y,z);
}
calcScale: sizeX, sizeY, sizeZ, x, y, z
{
if(x == 0)
fScaleX = 1.0;
else
fScaleX = sizeX / x;
if(y == 0)
fScaleY = 1.0;
else
fScaleY = sizeY / y;
if(z == 0)
fScaleZ = 1.0;
else
fScaleZ = sizeZ / z;
return(fScaleX,fScaleY,fScaleZ);
}
visibleExtents: val
{
if(val == 5)
return(true);
else
return(false);
}
visibleUser: val
{
if(val == 1)
return(true);
else
return(false);
}
activeSize: val
{
return(val);
}
goToSetValue
{
reqabort();
main1();
}



note: this is actually two scripts in one: Absolute Sizer and Set Value. when you run the script you have to press the particular button that switches between the two. for your needs use the Absolute Sizer part of the script.


usage tip: in your given example, select your door, run the script, select Absolute Sizer (if it isnt already), select GLOBAL as the Selmode, DE-select Stretch, click on the Size Y checkbox and type in your desired dimensions, and make sure that Size X and Size Z are unchecked (so that they wont be modified).

vpii
03-16-2005, 06:19 AM
Thanks for the reply, this should be a big help.

thanks again

lardbros
03-18-2005, 08:40 AM
Am i being dumb? Wouldn't it also be possible if you parented everything you wanted to resize to the door and then resize/stretch the door however you want?

I'm probably completely wrong, so oops!

vpii
03-18-2005, 09:13 AM
That would work for layout. In modeler I have very high poly model that is on one layer that is not scaled in real world correctly. Now i can select just one small section, like a window that I know the size of resize it and the rest of the model will scale along with it.

lardbros
03-18-2005, 10:21 AM
Aahhhh i see, clever stuff!!

I assumed you meant layout... so the moral of the story is don't make assumptions! :D

Actually that script for modeller could be useful!