PDA

View Full Version : Slicing-type lscript



TheWeedKiller
07-12-2004, 07:57 PM
Is there an lscript that slices an object at a specified distance(such as every 1 cm) on one axis? In between the slices it creates a polygon. So say you had a carrot model and sliced it, if you took one of the slices out that slice would be a completely enclosed model. If this is not already made, how would I go about making something like this?

faulknermano
07-13-2004, 02:41 PM
@warnings
@define LO 1
@define HI 2
@name fmJulienne
main
{
selmode(USER);

polyc = polycount();
if(polyc[1] == 0)
error("<br>No data.");

segx = 1;
segy = 1;
segz = 1;
spacing = <1,1,1>;
segmode = integer(recall("segmode",1));
layerfg = lyrfg();
layerempty = lyrempty();

if(layerfg.size() > 1)
error("<br>Select one layer.");

datalayer = layerfg[1];
emptylayer = layerempty[1];


reqbegin("fm Julienne");
c1 = ctlchoice("Mode",segmode,@"By Segment","By Spacing"@);
c2a = ctlinteger("Segments X",segx);
c2b = ctlinteger("Segments Y",segy);
c2c = ctlinteger("Segments Z",segz);
c3 = ctlvector("Spacing XYZ \(m\)",spacing);
ctlactive(c1,"c2_active",c2a,c2b,c2c);
ctlactive(c1,"c3_active",c3);

return if(!reqpost());

segmode = getvalue(c1);
segx = getvalue(c2a);
segy = getvalue(c2b);
segz = getvalue(c2c);
spacing = getvalue(c3);

reqend();

segxyz = <segx,segy,segz>;

bb = boundingbox(datalayer);
lyrsetfg(emptylayer);
editbegin();

if(segmode == 1) // by segment
{
pc = 0;
bbtot = <(bb[2].x - bb[1].x),(bb[2].y - bb[1].y),(bb[2].z - bb[1].z)>;
spc = <bbtot.x / segxyz.x,bbtot.y / segxyz.y,bbtot.z / segxyz.z>;

for(j=1;j<=3;j++) // per axis
{

if(j == 1)
seg = segx;
if(j == 2)
seg = segy;
if(j == 3)
seg = segz;

if(seg <= 1)
continue;
for(i=1;i<seg;i++)
{
if(j == 1) // X axis
{
a[1] = addpoint(<bb[LO].x + (spc.x * i),bb[LO].y - 0.1,bb[LO].z - 0.1>);
a[2] = addpoint(<bb[LO].x + (spc.x * i),bb[HI].y + 0.1,bb[LO].z - 0.1>);
a[3] = addpoint(<bb[LO].x + (spc.x * i),bb[HI].y + 0.1,bb[HI].z + 0.1>);
a[4] = addpoint(<bb[LO].x + (spc.x * i),bb[LO].y - 0.1,bb[HI].z + 0.1>);
}
if(j == 2) // Y Axis
{
a[1] = addpoint(<bb[LO].x - 0.1,bb[LO].y + (spc.y * i),bb[LO].z - 0.1>);
a[2] = addpoint(<bb[HI].x + 0.1,bb[LO].y + (spc.y * i),bb[LO].z - 0.1>);
a[3] = addpoint(<bb[HI].x + 0.1,bb[LO].y + (spc.y * i),bb[HI].z + 0.1>);
a[4] = addpoint(<bb[LO].x - 0.1,bb[LO].y + (spc.y * i),bb[HI].z + 0.1>);


}
if(j == 3) // Z Axis
{
a[1] = addpoint(<bb[LO].x - 0.1,bb[LO].y - 0.1,bb[LO].z + (spc.z * i)>);
a[2] = addpoint(<bb[HI].x + 0.1,bb[LO].y - 0.1,bb[LO].z + (spc.z * i)>);
a[3] = addpoint(<bb[HI].x + 0.1,bb[HI].y + 0.1,bb[LO].z + (spc.z * i)>);
a[4] = addpoint(<bb[LO].x - 0.1,bb[HI].y + 0.1,bb[LO].z + (spc.z * i)>);
}
p[++pc] = addquad(a);
a = nil;

}
}
editend();
lyrsetfg(datalayer);
lyrsetbg(emptylayer);
soliddrill(SLICE);
lyrsetfg(emptylayer);
delete();
lyrsetfg(datalayer);

}
if(segmode == 2) // by spacing
{
for(j=1;j<=3;j++) // per axis
{
for(i=1;i<seg;i++)
{
if(j == 1) // X axis
{
a[1] = addpoint(<bb[LO].x + (spc.x * i),bb[LO].y - 0.1,bb[LO].z - 0.1>);
a[2] = addpoint(<bb[LO].x + (spc.x * i),bb[HI].y + 0.1,bb[LO].z - 0.1>);
a[3] = addpoint(<bb[LO].x + (spc.x * i),bb[HI].y + 0.1,bb[HI].z + 0.1>);
a[4] = addpoint(<bb[LO].x + (spc.x * i),bb[LO].y - 0.1,bb[HI].z + 0.1>);
}
if(j == 2) // Y Axis
{
a[1] = addpoint(<bb[LO].x - 0.1,bb[LO].y + (spc.y * i),bb[LO].z - 0.1>);
a[2] = addpoint(<bb[HI].x + 0.1,bb[LO].y + (spc.y * i),bb[LO].z - 0.1>);
a[3] = addpoint(<bb[HI].x + 0.1,bb[LO].y + (spc.y * i),bb[HI].z + 0.1>);
a[4] = addpoint(<bb[LO].x - 0.1,bb[LO].y + (spc.y * i),bb[HI].z + 0.1>);


}
if(j == 3) // Z Axis
{
a[1] = addpoint(<bb[LO].x - 0.1,bb[LO].y - 0.1,bb[LO].z + (spc.z * i)>);
a[2] = addpoint(<bb[HI].x + 0.1,bb[LO].y - 0.1,bb[LO].z + (spc.z * i)>);
a[3] = addpoint(<bb[HI].x + 0.1,bb[HI].y + 0.1,bb[LO].z + (spc.z * i)>);
a[4] = addpoint(<bb[LO].x - 0.1,bb[HI].y + 0.1,bb[LO].z + (spc.z * i)>);
}
p[++pc] = addquad(a);
a = nil;

}
}
editend();
lyrsetfg(datalayer);
lyrsetbg(emptylayer);
soliddrill(SLICE);
lyrsetfg(emptylayer);
delete();
lyrsetfg(datalayer);

}


}
c2_active: val
{
if(val == 1)
return(true);
else
return(false);
}

c3_active: val
{
if(val == 2)
return(true);
else
return(false);
}


NOTE: this is an incomplete script. i'm not sure if it works on SPACING mode or SEGMENT mode. you can try to improve on it as you wish. hope this gives you a start.


btw: look at julienne in lightwave. it does something like this script.

TheWeedKiller
07-13-2004, 10:12 PM
wow thanks I wasn't expecting that much:D .