Example 6

Example 6 demonstrates how operations are executed for certain fragments by use of the for condition and a counting variable.

volumedata = structure:getvolumedata (0);
volumedata.reset ();
fragment=volumedata:addmeshtoraster();

cell01=fragment:randomize(1,1,1,50);
cell02=fragment:randomize(1,1,1,50);
cell03=fragment:randomize(1,1,1,50);
cell04=cell01:randomize(1,1,1,50);
cell05=cell01:randomize(1,1,1,50);
cell06=cell02:randomize(1,1,1,50);
cell07=cell04:randomize(1,1,1,50);

cell09=cell01:randomize(1,1,1,50);
cell10=cell02:randomize(1,1,1,50);
cell11=cell03:randomize(1,1,1,50);
cell12=cell04:randomize(1,1,1,50);
cell13=cell05:randomize(1,1,1,50);
cell14=cell06:randomize(1,1,1,50);
cell15=cell07:randomize(1,1,1,50);
cell16=fragment:randomize(1,1,1,50);

cell_a=structure:getcell(0);
cell_b=structure:getcell(1);

for a=0, volumedata.fragmentcount-1, 2 do
fragment_a = volumedata:getfragment(a);
fragment_a.cell = cell_a
end;

for b=1, volumedata.fragmentcount-1, 2 do
fragment_b = volumedata:getfragment (b);
fragment_b.cell = cell_b;
end;

As in Example 4, the basic fragment of the part is split into 16 random fragments. After that, the first two cells of the structure are loaded into the script, referred to as cell_a and cell_b.

Then, the first loop block applies to every second fragment of the volume data (jump distance: 2), starting with the first (a=0) and running through to the end (fragmentcount-1).

For each of these fragments, a new fragment (fragment_a) is loaded into the script. This new fragment is filled with cell_a.

In the second loop block, the same process is repeated, only for those fragments starting with the second fragment of the part (b=1). This time, it is cell_b that is assigned to the fragments. That way, every second fragment of the randomized part receivescell_a and all others receive cell_b.

Note: The internal counting requires -1 for the fragment count and other count variables because while Lua traditionally counts starting with 1, Netfabb starts at 0. For example, the number of the last fragment is the overall count of fragments minus one.