Struggling with generating mesh via GDScript, multiple materials, surfaces

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DDoop

I’m trying to separate a given hexagonal tile into 18 congruent kite/deltoid shaped polygons (split the hex into sixths along each radius to outer vertex, and then each sub-triangle again into congruent thirds)
So imagine 6 sets of this triangle, arranged in a hexagon (I’ve highlighted the vertices):
enter image description here

If I know the precise location of each vertex (they can be calculated based on any hexagon of a given radius via known ratios), how would I go about creating a mesh with unique materials for each of the polygonal triangle components?

My current debug script (pastebin) produces this (I apologize for the names of the points in advance):
enter image description here
when I expected an equilateral triangle composed of 3 congruent polygons with different materials (that differ only in their albedo_color), essentially matching the prior example image.

I’ve checked some of the other questions on here about creating meshes at runtime and they haven’t made it clearer for me. I think my issue is in misunderstanding either/both:
a) the way meshes are constructed out of primitives
b) the way SurfaceTool applies colors to meshes, specifically how commit() overwrites surfaces that have already been committed (the green in my output screenshot is the final color I try to assign to a polygon, I tried 3 others before it in the program flow)

EDIT: as an addendum, I know the Vector3 values I’ve provided for the points are accurate since I constructed an example mesh in Blender and transferred the coordinate values (and determined the ratios, which will always be correct) from there.

I tried constructing a simpler version of the problem: 2 congruent right angle triangles, which together make a square, one blue, one red. Here is the code: extends Spatialonready var mesh: MeshInstance = $MeshInstancevar pt1 = V -

This just constructs a single red triangle, in the opposite position I would expect. I’ve tried messing with the surface tool, trying 1 instead of 2, etc and I’m still stumped.

EDIT: Point order matters, clearly. I modified the order in which some of them are added
to the surface tool and I got a full blue square now.

DDoop | 2020-07-07 23:17

This page in the docs is relevant but un-updated and doesn’t answer my question.
EDIT: this is the updated version (reading now)
EDIT2: this question, specifically the highest-rated answer was extremely useful in broadening my understanding. Still working on the original question though.

DDoop | 2020-07-08 18:05

:bust_in_silhouette: Reply From: DDoop

This script does what I wanted. I found ArrayMesh to be a much more useful interface than surface tool.
EDIT: image for the curious