Author Topic: Getting the position of each stud of a planted brick  (Read 690 times)

How would you go around doing this?

the middle? a corner? the side?

It's just a matter of knowing the dimensions and figuring out the math.

the middle? a corner? the side?

It's just a matter of knowing the dimensions and figuring out the math.
I mean all of them

%brick.getDatablock().brickSizeX/Y/Z ( or something like that, i forget )

I mean all of them
I meant of the stud texture. Do you want the center of the stud, the side of the stud, a corner of the stud?

I meant of the stud texture. Do you want the center of the stud, the side of the stud, a corner of the stud?
top of the stud

Code: [Select]
package studPack
{
function fxDTSBrick::onPlant(%this)
{
%r = parent::onPlant(%this);
%pos = %this.getPosition();
%datablock = %this.getDatablock();
%sizeX = %datablock.sizeX;
%sizeY = %datablock.sizeY;
%sizeZ = %datablock.sizeZ;
%cursor = %pos;
%cursor = vectorAdd(%cursor,%sizeX SPC %sizeY SPC %sizeZ); //corner it
%cursor = vectorAdd(%cursor,0.25 SPC 0.25 SPC 0.25); //put in the center of the stud

}
};activatepackage(studPack);

Would something like that work?

You'll have to multiply or divide by 2 because the sizes are in bricks, not units. I never remember if a unit is 2 bricks or vice versa.

You'll have to multiply or divide by 2 because the sizes are in bricks, not units. I never remember if a unit is 2 bricks or vice versa.
1 unit = 2 bricks


Horizontally yes
Vertical is 0.2 stud, 0.6 brick.

Wtf? If you only need to access the size of a planted brick, you might as well use .getWorldBox()

Code: [Select]
%sizeX = %datablock.sizeX;
%sizeY = %datablock.sizeY;
%sizeZ = %datablock.sizeZ;

It's brickSize*, not size*.

Code: [Select]
%cursor = vectorAdd(%cursor,%sizeX SPC %sizeY SPC %sizeZ); //corner it

The origin of a brick is at the center. Secondly, the brick size values are in studs. You'll end up with a position several studs away from the brick.
You should do this to each component (or just use getWorldBox):

x = x / 2
y = y / 2
z = z / 2 / 3


Code: [Select]
%cursor = vectorAdd(%cursor,0.25 SPC 0.25 SPC 0.25); //put in the center of the stud

What are you even trying to do?

Code: [Select]
package package
{
   function fxDTSBrick::onPlant(%brick)
   {
      %r = Parent::onPlant(%brick);
      %box = %brick.getWorldBox();
      %center = %brick.getPosition();
      %start = vectorSub(vectorSub(%center,vectorScale(%box,0.5)),"0.25 0.25 0");

      %xLim = getWord(%box,0) - 1;
      %yLim = getWord(%box,1) - 1;
      for(%x=0;%x<%xLim;%x+=0.5)
      {
         for(%y=0;%y<%yLim;%y+=0.5)
            echo("Stud at " @ vectorAdd(%start,%x SPC %y @ " 0");
      }
      return %r;
}
activatePackage(package);
I probably made a mistake somewhere in there, but you get the idea

Code: [Select]
package package
{
   function fxDTSBrick::onPlant(%brick)
   {
      %r = Parent::onPlant(%brick);
      %box = %brick.getWorldBox();
      %center = %brick.getPosition();
      %start = vectorSub(vectorSub(%center,vectorScale(%box,0.5)),"0.25 0.25 0");

      %xLim = getWord(%box,0) - 1;
      %yLim = getWord(%box,1) - 1;
      for(%x=0;%x<%xLim;%x+=0.5)
      {
         for(%y=0;%y<%yLim;%y+=0.5)
            echo("Stud at " @ vectorAdd(%start,%x SPC %y @ " 0");
      }
      return %r;
}
activatePackage(package);
I probably made a mistake somewhere in there, but you get the idea
what happened to Z.
That value is the most important value for what I'm making.

what happened to Z.
That value is the most important value for what I'm making.
What do you mean "what happened"
Z is equal to the z value for the center position of the brick plus half the height. This would be the correct height for the top of the brick. Since the script assumes all bricks are cuboid and have a regular stud pattern, the value of z never changes within the brick