TerrainPrintMesh
Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Language.Object
The TerrainPrintMesh class makes a terrain's ground into a solid that a 3D printer can print: the ground on top, four straight sides, and a flat bottom. Detail finer than the printer's line width is left out. How large it prints is chosen before Build: - the size: as large as fits on the bed (UseFitToBed, the default: its longer side is 80% of the bed's shorter side), or a longer side of a number of millimeters (SetLongestSide); - the hills: how many times their true height they print (SetHillScale; 1, the default, is the same proportion as across); - the base: the solid under the lowest ground (SetBaseHeight, 2 millimeters by default). Hills too tall for the printer are lowered until they fit; the terrain keeps its size across (AreHillsLowered, GetHillScaleUsed). TerrainItem and Terrain use it in their Print actions. After Build, or after Measure (which works the size out without making the solid), the Get actions say how large the print is.
Example Code
use Libraries.Containers.Number32BitArray
use Libraries.Game.Graphics.Models.Data.ModelData
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
use Libraries.Fabrication.Profiles.Profile
// A 3 by 3 grid of heights with a bump in the middle, 1 unit apart.
Number32BitArray heights
heights:SetSize(9)
integer i = 0
repeat while i < 9
heights:Set(i, 0)
i = i + 1
end
heights:Set(4, 1)
Profile generic
TerrainPrintMesh builder
ModelData solid = builder:Build(heights, 3, 3, 1, generic)
output "The print is " + builder:GetWidth() + " mm across."
Variables
integer LONGEST_SIDE: The size choices (GetSizeMode).integer FIT_TO_BED: The size choices (GetSizeMode).
Actions
AreHillsLowered()
This action returns true if the last Measure or Build lowered the hills to fit the printer's height.
Returns
boolean: True if the hills were lowered.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
// builder:Measure(data, printer)
if builder:AreHillsLowered()
output "Lowered to " + builder:GetHillScaleUsed() + " times their true height"
end
Build(Libraries.Containers.Number32BitArray heights, integer columns, integer rows, number spacing, Libraries.Fabrication.Profiles.Profile profile)
This action makes a solid from a grid of heights, row by row: the first row's heights from left to right, then the next row, and so on. Rows run along z, columns along x, and neighbouring samples are spacing units apart.
Parameters
heightsLibraries.Containers.Number32BitArray: One height per sample, columns times rows of them.columnsinteger: How many samples across (along x), at least 2.rowsinteger: How many samples deep (along z), at least 2.spacingnumber: How far apart the samples are, in world units.profileLibraries.Fabrication.Profiles.Profile: The printer, for its bed size, height and line width.
Returns
Libraries.Game.Graphics.Models.Data.ModelData: The solid, in millimeters, ready for SliceJob.
Example
use Libraries.Containers.Number32BitArray
use Libraries.Game.Graphics.Models.Data.ModelData
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
use Libraries.Fabrication.Profiles.Profile
Number32BitArray heights
heights:SetSize(4)
heights:Set(0, 0)
heights:Set(1, 1)
heights:Set(2, 0)
heights:Set(3, 2)
Profile generic
TerrainPrintMesh builder
ModelData solid = builder:Build(heights, 2, 2, 10, generic)
Build(Libraries.Game.Graphics.Worlds.TerrainData data, Libraries.Fabrication.Profiles.Profile profile)
This action makes a solid from a TerrainData's regions. Samples in gaps between regions are given the lowest ground, so the print is one piece. On a large world only every few samples are read, as many as the printer can show.
Parameters
dataLibraries.Game.Graphics.Worlds.TerrainData: The terrain's heights.profileLibraries.Fabrication.Profiles.Profile: The printer, for its bed size and line width.
Returns
Libraries.Game.Graphics.Models.Data.ModelData: The solid, in millimeters, ready for SliceJob.
Example
use Libraries.Game.Graphics.Models.Data.ModelData
use Libraries.Game.Graphics.Worlds.TerrainData
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
use Libraries.Fabrication.Profiles.Profile
TerrainData data
data:SetRegionSize(64)
data:AddRegion(0, 0)
data:RaiseArea(32, 32, 10, 5)
Profile generic
TerrainPrintMesh builder
ModelData solid = builder:Build(data, generic)
Fits(Libraries.Fabrication.Profiles.Profile profile)
This action returns true if the last Measure or Build fits on the printer's bed.
Parameters
profileLibraries.Fabrication.Profiles.Profile: The printer.
Returns
boolean: True if it fits.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
use Libraries.Fabrication.Printers.CrealityEnder3
CrealityEnder3 printer
TerrainPrintMesh builder
// builder:Measure(data, printer)
output builder:Fits(printer)
GetBaseHeight()
This action returns the base under the lowest ground, in millimeters.
Returns
number: The base in millimeters.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
output builder:GetBaseHeight()
GetDepth()
This action returns how deep the last solid built is, along the printer's y axis.
Returns
number: The depth in millimeters.
GetHeight()
This action returns how tall the last solid built is, base included.
Returns
number: The height in millimeters.
GetHillScale()
This action returns the hill scale chosen (SetHillScale).
Returns
number: The hill scale.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
output builder:GetHillScale()
GetHillScaleUsed()
This action returns the hill scale the last Measure or Build used: the one chosen, or less if the hills were lowered to fit.
Returns
number: The hill scale used.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
output builder:GetHillScaleUsed()
GetLongestSide()
This action returns the longer side used by SetLongestSide, in millimeters (150 until it is set).
Returns
number: The longer side in millimeters.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
output builder:GetLongestSide()
GetMillimetersPerUnit()
This action returns how many millimeters one world unit became in the last solid built.
Returns
number: Millimeters per world unit.
GetSizeMode()
This action returns the size choice: FIT_TO_BED or LONGEST_SIDE.
Returns
integer: The size choice.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
if builder:GetSizeMode() = builder:FIT_TO_BED
output "As large as fits"
end
GetWidth()
This action returns how wide the last solid built is, along the printer's x axis.
Returns
number: The width in millimeters.
IsFlat()
This action returns true if the last terrain built had no hills or valleys, so the print is only the base.
Returns
boolean: True if the ground was flat.
Measure(Libraries.Game.Graphics.Worlds.TerrainData data, Libraries.Fabrication.Profiles.Profile profile)
This action works out how large a TerrainData would print with the current choices, without making the solid: afterwards GetWidth, GetDepth, GetHeight, GetMillimetersPerUnit, AreHillsLowered and Fits answer for it. It reads the heights as Build does, so on a large world it takes a moment, but far less than Build and slicing.
Parameters
dataLibraries.Game.Graphics.Worlds.TerrainData: The terrain's heights.profileLibraries.Fabrication.Profiles.Profile: The printer, for its bed size and line width.
Example
use Libraries.Game.Graphics.Worlds.TerrainData
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
use Libraries.Fabrication.Printers.CrealityEnder3
TerrainData data
data:SetRegionSize(64)
data:AddRegion(0, 0)
data:RaiseArea(32, 32, 10, 5)
CrealityEnder3 printer
TerrainPrintMesh builder
builder:SetHillScale(2)
builder:Measure(data, printer)
output "Prints " + builder:GetWidth() + " by " + builder:GetDepth() + " by " + builder:GetHeight() + " mm"
SetBaseHeight(number millimeters)
This action sets how thick the solid under the lowest ground is, in millimeters.
Parameters
millimetersnumber: The base, above 0.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
builder:SetBaseHeight(3)
SetHillScale(number scale)
This action sets how many times their true height the hills print: 1 is the same proportion as across; 2 makes them twice as tall, which helps gentle hills show.
Parameters
scalenumber: The hill scale, above 0.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
builder:SetHillScale(2)
SetLongestSide(number millimeters)
This action prints the terrain with its longer side a number of millimeters, whatever the bed's size (Fits says if it fits).
Parameters
millimetersnumber: The longer side, above 0.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
builder:SetLongestSide(150)
UseFitToBed()
This action prints the terrain as large as fits on the bed: its longer side is 80% of the bed's shorter side. It is the default.
Example
use Libraries.Game.Graphics.Worlds.TerrainPrintMesh
TerrainPrintMesh builder
builder:UseFitToBed()