sketch interface - Outerra/anteworld GitHub Wiki

Canvas interface is used to draw lines, texts, images etc. in scene (world).

Getting interface in script

JavaScript

    this.sketch = this.$query_interface("ot::js::sketch.get");

Lua

    self.sketch = query_interface("lua.ot.sketch.get")

Methods

uint create_group();
Parameter Description Returns Description
Group ID Creates an element group and selects it as the current group.
void delete_group(uint group_id);
Parameter Description Returns Description
group_id: ID of the group to delete Deletes the specified group.
void make_group_active(uint group_id);
Parameter Description Returns Description
group_id: ID of the group to activate Activates the specified group and sets it as the current group.
void set_group_visible(bool visible);
Parameter Description Returns Description
visible: true - visible, false - invisible Makes the current group visible or invisible.
void attach_to_element(entity_handle entity_id, bool fit_scale);
Parameter Description Returns Description
entity_id:ID of low level entity, to attach the group to
fit_scale: True to fit scale relative to the entity
Attaches current group to specified entity. Note: set_position, set_rotation and draws (not ecef variants) are relative to given entity.
void attach_to_entity(entity_handle entity_id, uint joint = -1);
Parameter Description Returns Description
entity_id: entity to attach the group to
joint: joint to attach to, -1 for root (default: -1)
Attach current group to entity and joint.
Note: set_position, set_rotation and draws (not ecef variants) are relative to given entity.
void set_position(const double3& pos);
Parameter Description Returns Description
pos: position Sets current group position. Position is relative to the attached entity if any, else ECEF.
const double3& get_position() const;
Parameter Description Returns Description
Position of current group Gets the position of the current group. Position is relative to the attached entity if any, else ECEF.
void set_rotation(const quat& rot);
Parameter Description Returns Description
rot: rotation quaternion Sets the rotation of the current group. Rotation is relative to the attached entity if any, else ECEF.
const quat& get_rotation() const;
Parameter Description Returns Description
Rotation quaternion Gets the rotation of the current group. Rotation is relative to the attached entity if any, else ECEF.
void set_hpr(const float3& hpr);
Parameter Description Returns Description
hpr: HPR angles (heading, pitch, roll) Sets the rotation of the current group as HPR angles. Rotation is relative to the attached entity if any, else ECEF.
float3 get_hpr() const;
Parameter Description Returns Description
HPR angles (heading, pitch, roll) Gets the rotation of the current group as HPR angles. Rotation is relative to the attached entity if any, else ECEF.
void set_scale(const float3& scale);
Parameter Description Returns Description
scale: scale Sets the scale of the current group.
const float3& get_scale() const;
Parameter Description Returns Description
Scale of the current group Gets the scale of the current group.
void fit_scale();
Parameter Description Returns Description
Fits the current group scale to the entity (multiply current group's scale with geom's OBB half vector).
Note: if group isn't attached to entity, nothing happens.
void set_color(ot::color color);
Parameter Description Returns Description
color: default color Sets the default color for the current group. This color is used in method calls without a color parameter.
ot::color get_color() const;
Parameter Description Returns Description
Default color Gets the default color of the current group.
void set_hidden_color(ot::color color);
Parameter Description Returns Description
color: hidden color Sets the hidden color (the hidden color refers to the color of a sketch concealed behind an object. This sketch becomes visible through the object and has the hidden color).
ot::color get_hidden_color() const;
Parameter Description Returns Description
Hidden color Gets the hidden color (the hidden color refers to the color of a sketch concealed behind an object. This sketch becomes visible through the object and has the hidden color).
void set_group_color(ot::color color);
Parameter Description Returns Description
color: color Sets the color multiplier for the current group. This multiplier is used for canvases as well.
ot::color get_group_color() const;
Parameter Description Returns Description
Color multiplier Gets the color multiplier of the current group. This multiplier is used for canvases as well.
void set_group_hidden_color(ot::color color);
Parameter Description Returns Description
color: hidden color multiplier Sets the hidden color multiplier for the current group. This multiplier is used for canvases as well.
ot::color get_group_hidden_color() const;
Parameter Description Returns Description
Hidden color multiplier Gets the hidden color multiplier of the current group. This multiplier is used for canvases as well.
void set_group_zorder(uchar zorder);
Parameter Description Returns Description
zorder: global z-order value Sets the global z-order for the current group.
uchar get_group_zorder() const;
Parameter Description Returns Description
Global z-order value Gets the global z-order of the current group.
void set_xray_mode(bool enable);
Parameter Description Returns Description
enable: true to enable, false to disable Sets x-ray mode. If true, 3D geometry will ignore the z-buffer.
bool is_xray_mode() const;
Parameter Description Returns Description
true if x-ray mode is enabled, false otherwise Checks whether x-ray mode is enabled.
void set_group_line_width(float width);
Parameter Description Returns Description
width: line width Sets the line width.
float get_group_line_width() const;
Parameter Description Returns Description
Line width Gets the line width.
void add_line(const float3& pos, ot::color color = ot::ColorAqua, bool restart = false, bool xray = false, ot::color hidden_color = ot::ColorWhite, float width = 1);
Parameter Description Returns Description
pos: position in camera space
color: line color (default: aqua)
restart: whether to restart the line
xray: whether the line ignores the z-buffer
hidden_color: hidden line color (default: white)
width: line width (default: 1)
Draws a line in camera space.
void draw_line_ecef(const double3& pos, bool restart = false);
Parameter Description Returns Description
pos: position in ECEF space
restart: whether to restart the line
Draws a line in ECEF space.
void draw_line_ecef2(const double3& pos, ot::color color = ot::ColorAqua, bool restart = false, bool xray = false, ot::color hidden_color = ot::ColorWhite, float width = 1);
Parameter Description Returns Description
pos: position in ECEF space
color: line color (default: aqua)
restart: whether to restart the line
xray: whether the line ignores the z-buffer
hidden_color: hidden line color (default: white)
width: line width (default: 1)
Draws a line in ECEF.
void draw_line(const float3& pos, bool restart = false);
Parameter Description Returns Description
pos: position in group space
restart: whether to restart the line
Draws a line in group space.
void draw_line2(const float3& pos, ot::color color = ot::ColorAqua, bool restart = false, bool xray = false, ot::color hidden_color = ot::ColorWhite, float width = 1);
Parameter Description Returns Description
pos: position in group space
color: line color (default: aqua)
restart: whether to restart the line
xray: whether the line ignores the z-buffer
hidden_color: hidden line color (default: white)
width: line width (default: 1)
Draws a line in group space.
uint create_canvas(uint grp = -1, const double3& offset = double3(0.0), const short2& offset_2d = short2(0));
Parameter Description Returns Description
grp: group ID (default: -1)
offset: 3D offset for the canvas (default: (0.0, 0.0, 0.0))
offset_2d: 2D offset for the canvas (default: (0, 0))
Canvas ID (uint) Creates a canvas and selects it as the current canvas.
void delete_canvas(uint id);
Parameter Description Returns Description
id: canvas ID to delete Deletes the specified canvas.
void make_canvas_active(uint canvas_id);
Parameter Description Returns Description
canvas_id: ID of the canvas to activate Activates the specified canvas.
void set_canvas_2d_offset(const short2& offset);
Parameter Description Returns Description
offset: 2D offset Sets a 2D offset for the canvas position.
void set_canvas_collider(const short2& min, const short2& max);
Parameter Description Returns Description
min: minimum bounds of the collider
max: maximum bounds of the collider
Sets canvas collider.
int4 get_collider_at_pos(const short2& pos) const;
Parameter Description Returns Description
pos: position rel pos x, rel pos y, id, group_id Gets collider details at the specified position (usage unclear).
void set_canvas_color(ot::color color);
Parameter Description Returns Description
color: global modulation color for the canvas Sets the global modulation color for the canvas.
void set_canvas_font(const coid::token& font_file);
Parameter Description Returns Description
font_file: file path for the font Sets the current font for text rendering on the canvas.
uint get_canvas_font_height();
Parameter Description Returns Description
Canvas font pixel height Returns the pixel height of the current font.
void clear_canvas();
Parameter Description Returns Description
Clears the content of the canvas.
void canvas_push_state();
Parameter Description Returns Description
Pushes the current state (matrix, clip region, etc.) onto the stack.
void canvas_pop_state();
Parameter Description Returns Description
Pops the state from the stack.
void canvas_translate(float x, float y);
Parameter Description Returns Description
x: translation on the X-axis
y: translation on the Y-axis
Applies a translation to the current matrix.
void canvas_rotate(float angle);
Parameter Description Returns Description
angle: angle in degrees Applies a rotation to the current matrix.
void draw_text(const float2& pos, ot::color color, const coid::token& text);
Parameter Description Returns Description
pos: position to draw text
color: text color
text: text
Draws text onto the active canvas.
void canvas_draw_line(const float2& pos0, const float2& pos1, ot::color color);
Parameter Description Returns Description
pos0: starting position of the line
pos1: ending position of the line
color: line color
Draws a line on the current canvas.
void canvas_fill_rect(const float2& pos, const float2& size, ot::color color);
Parameter Description Returns Description
pos: top-left corner position
size: width and height of the rectangle
color: fill color
Draws a filled rectangle on the canvas.
uint load_image(const coid::token& path);
Parameter Description Returns Description
path: path to the image file Image ID or -1 if not found Loads an image into the cache and returns its ID.
void free_image(uint image_id);
Parameter Description Returns Description
image_id: ID of the image to free Releases the allocated image memory. The release is deferred until the frame is rendered.
void draw_image(uint image_id, const float2& pos, ot::color color);
Parameter Description Returns Description
image_id: ID of the image to draw
pos: position to draw the image
color: modulation color for the image
Draws an image onto the active canvas. Note: Currently it can loads imgsets only (example in bin/ui/basic.imgset)
void draw_image_size(uint image_id, const float2& pos, const float2& size, ot::color color);
Parameter Description Returns Description
image_id: ID of the image to draw
pos: position to draw the image
size: dimensions of the image
color: color for the image
Draws an image with specific dimensions on the canvas (scale is in pixels). Note: currently it can loads imgsets only (example in bin/ui/basic.imgset)
const double3& camera_pos() const;
Parameter Description Returns Description
Camera position Returns the current camera position.
float3 get_screen_pix(uint group_id, const float3& offset);
Parameter Description Returns Description
group_id: ID of the group
offset: offset point relative to the group
Screen position in pixels Gets the offset point relative to the group (known bug: does not work correctly if the group is attached to an entity)
⚠️ **GitHub.com Fallback** ⚠️