+1 vote

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.

in Engine by (682 points)

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: https://pastebin.com/pdj7DE1W

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.

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.

1 Answer

+1 vote
Best answer

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

by (682 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.