Skip to content

MarchingSquaresMesh

Extends: MeshInstance2D

Description

This class converts a 2d array of bits into a shape using an algorithm called March Squares.

Properties

String LookupID
bool IsDrawing
bool IsEmpty
ArrayMesh arrayMesh
BitMap bitmap
int MapWidth
int MapHeight
float CellSize
float OffsetScale
BitMap[] brushes
BitMap previousBitmap

Methods

Dictionary Save ( )
void Load ( Dictionary data )
void Resize ( int x, int y, int w, int h )
void OnDrawingBegin ( )
void OnDrawingEnd ( )
void CreateNewBitmap ( )
void SetBitmap ( BitMap bitmap )
void Clear ( )
void SetCircle ( Vector2 position, int size, bool value )
void UpdateMesh ( )

Property Descriptions

  • String LookupID:
    Used by the Level to identify the mesh.

  • bool IsDrawing:
    Check if the user is currently drawing onto this mesh.

  • bool IsEmpty:
    Check if the mesh is empty. READ ONLY.

  • ArrayMesh arrayMesh:
    The internal Godot class that actually draws the mesh onto the screen.

  • BitMap bitmap:
    Reference to the bits that is read by the algorithm to draw the shape.

  • int MapWidth:
    Width of the bitmap. Automatically set based on canvas size. DO NOT MODIFY.

  • int MapHeight:
    Height of the bitmap. Automatically set based on canvas size. DO NOT MODIFY.

  • float CellSize:
    Gets the size of each cell of the mesh. READ ONLY.

  • float OffsetScale:
    Gets or sets the amount of jitter to randomize the positions of each mesh cell point.

  • BitMap[] brushes:
    Gets the list of BitMaps representing the different brush sizes.

  • BitMap previousBitmap:
    Gets the previous bitmap just before the latest edit. Used to record Undo history.

Method Descriptions

  • Dictionary Save ( ):
    Save the mesh into the save file format and return it as a Dictionary.

  • void Load ( Dictionary data ):
    Load a saved mesh data. Used by a saved map file to load existing meshes.

  • void Resize ( int x, int y, int w, int h ):
    Called automatically when the canvas is resized. DO NOT CALL DIRECTLY. FOR REFERENCE ONLY.


  • void OnDrawingEnd ( ):
    Finishes the mesh for drawing and records an Undo history.

  • void CreateNewBitmap ( ):
    Create or replace the bitmap with an empty one of the right size.

  • void SetBitmap ( BitMap bitmap ):
    Replace the bitmap with a specific one and updates the visuals. WARNING: THE SIZE MUST MATCH!

  • void Clear ( ):
    Delete the visuals and data of this mesh without destroying the instance.

  • void SetCircle ( Vector2 position, int size, bool value ):
    Draws a circle at the position onto the mesh if value is true or erase if false.

  • void UpdateMesh ( ):
    Update the mesh. Heavy CPU workload.