Draw is a service API that offers drawing to a context (canvas) in an efficient way.
Things like lines, circles, paths and so on are what it provides. The terms canvas and context
will be used interchangeably.
It is important to note that
Draw is a commit based API. A brief tutorial
on using it can be found here: 2D drawing tutorial.
Draw can be used to draw game content with, but is also a great tool for debug visualization.
Many problems are a lot clearer when their details are drawn in the world, which Draw is very useful for.
The context can be drawn to once or updated frequently. For example you might draw a grid to the context,
and then leave it there which is a very efficient way to draw many lines.
Creates a new drawing context to draw with.
The set passed in is a RenderSet, which you normally get from a World via World.render_set(world).
This would place the canvas in the world to be rendered at the same time, as part of the world.
var canvas = Draw.create(World.render_set(app.world))
Creates a new drawing context to draw with.
The set passed in is a RenderSet, which you normally get from a World via World.render_set(world).
This would place the canvas in the world to be rendered at the same time, as part of the world.
tri_basis
Triangle Material Basis for the geometry
default luxe: material_basis/solid
text_basis
Text Material Basis
default luxe: material_basis/font
line_basis
Line Material Basis for 3D line geometry
default luxe: material_basis/debug_line3d
var canvas = Draw.create(World.render_set(app.world),
“luxe: material_basis/solid”,
“luxe: material_basis/font”,
“luxe: material_basis/debug_line3d”)
Commit the content that has been drawn to the context.
When using the Draw API, you can submit a bunch of drawing to happen,
but it won’t show up until it is committed.
You can think of the draw calls as a queue, commit will process
that queue, and the canvas contents will be updated. The content
will stay there until commit is called again.
Calling commit with nothing in the queue will clear the contents (see also Draw.clear).
var canvas = Draw.create(World.render_set(app.world))
Draw.rect_detailed(context : Any, x : Any, y : Any, z : Any, w : Any, h : Any, angle : Any, radius : Any, smoothness : Any, style : Any) : unknown
Draws a detailed rectangle outline using style (PathStyle) at x,y, with depth z, with width of w and height of h.
The rectangle will be rotated angle degrees.
“Detailed” means that the corners can be configured using the radius and smoothness values.
This allows drawing rounded rectangles, rectangles with inverted rounded corners, and with flat corners.
The radius controls the amount inset from the edges. With a smoothness of 0, the corners will be angled/flat.
The order is [bottom left, bottom right, top right, top left] for radius + smoothness.
Draw.quad_detailed(context : Any, x : Any, y : Any, z : Any, w : Any, h : Any, angle : Any, radius : Any, smoothness : Any, color : Any) : unknown
Draws a detailed rectangle using color at x,y, with depth z, with width of w and height of h.
The rectangle will be rotated angle degrees.
“Detailed” means that the corners can be configured using the radius and smoothness values.
This allows drawing rounded rectangles, rectangles with inverted rounded corners, and with flat corners.
The radius controls the amount inset from the edges. With a smoothness of 0, the corners will be angled/flat.
The order is [bottom left, bottom right, top right, top left] for radius + smoothness.
Draw.ngon(context : Any, ox : Any, oy : Any, oz : Any, rx : Any, ry : Any, sides : Any, angle : Any, style : Any) : unknown
Draw an ngon (like a triangle, hexagon, pentagon etc) outline at ox,oy at depth oz.
The rx and ry radius values control the size of the shape around its origin.
The number of sides controls how many sides the polygon will have (3 for a triangle, 6 for a hexagon).
sides must be bigger than 3 to make sense for this function, it will be clamped to 3.
Draw.ngon_solid(context : Any, ox : Any, oy : Any, oz : Any, rx : Any, ry : Any, sides : Any, angle : Any, color : Any) : unknown
Draw a solid ngon (like a triangle, hexagon, pentagon etc) at ox,oy at depth oz.
The rx and ry radius values control the size of the shape around its origin.
The number of sides controls how many sides the polygon will have (3 for a triangle, 6 for a hexagon).
sides must be bigger than 3 to make sense for this function.
:todo: this naming will change soon to be consistent across all draw APIs.
Draw a circle outline at ox,oy at depth oz. rx and ry control separate radius values
for x and y axis, to draw an ellipse.
start_angle and end_angle specify in degrees allow drawing
an open arc, instead of a closed circle. A closed circle has start_angle as 0 and end_angle as 360.
These angles match “the unit circle” in mathematics, where 0 is to the right, and 90 is pointing up.
:todo: smoothness controls how smooth the circle will be.
Draw.circle(context : Any, ox : Any, oy : Any, oz : Any, rx : Any, ry : Any, start_angle : Any, end_angle : Any, smoothness : Any, color : Any) : unknown
Draw a solid circle at ox,oy at depth oz. rx and ry control separate radius values
for x and y axis, to draw an ellipse.
start_angle and end_angle specify in degrees allow drawing
an open area, like a pie chart (or pacman) instead of a closed circle. A closed circle has start_angle as 0 and end_angle as 360.
These angles match “the unit circle” in mathematics, where 0 is to the right, and 90 is pointing up.
:todo: smoothness controls how smooth the circle will be.
If closed is true it is expected that the first and last point in points
have the same positions.
points is a List of [x, y] or [x,y,z] points.
If z is not specified for a point it will be 0.
Note that this is a 2D drawing function atm, so different z values may not be what you expect.
Draw a 3D camera frustum for the given 8 corner points using style.
(You can get one from Camera.get_frustum(entity) for example, but can use Draw.camera as well).
Draw.text(context : Any, x : Any, y : Any, z : Any, w : Any, h : Any, string : Any, size : Any, font : Any, color : Any, align : Any, align_vertical : Any) : unknown
Draw the specified string at x,y and depth z. w and h specify the bounds for the text, bottom left origin, y going up.
The size specifies the text size, and color the color. font is a font asset, e.g Asset.font(“luxe: font/lato”).
align and align_vertical control alignment within the bounds,
using the TextAlign enums such as TextAlign.left.
Draw.text(context : Any, x : Any, y : Any, z : Any, string : Any, size : Any, font : Any, color : Any, align : Any, align_vertical : Any) : unknown
Draw the specified string at x,y and depth z.
The size specifies the text size, and color the color. font is a font asset, e.g Asset.font(“luxe: font/lato”).
align and align_vertical control alignment relative to the specified position,
using the TextAlign enums such as TextAlign.left.
Draw.image(context : Any, x : Any, y : Any, z : Any, w : Any, h : Any, angle : Any, color : Any, uv : Any, material : Any) : unknown
Draw an image with the specified material at x,y and depth z.
The image will be rotated by angle degrees.
The uv value specifies a fixed rectangle like [left, top, right, bottom] in the 0..1 range,
where [0,0,1,1] is the default and displays the full image.
A uv value of [0.5, 0, 1, 0.5] would draw the top right corner of the image only.
A uv value of [0, 0, 4, 4] would tile the image 4 times (as long as the material has a repeat mode for the image).
var depth = 0
var angle = 30
var material = Assets.material("luxe: material/logo.sprite")
Draw a 3D sphere made from layered circles with layers number of circles and radius radius. Make the start_angle 0 and the end_angle 360 to make a full sphere, or 0/180 for a half sphere.
When drawing a path, a series of lines will be drawn and joined together.
The join of each connection can be configured when drawing paths using LineJoin.
:todo: images