Godot Version
4.6 Stable
Question
So I had a go a thinking how to create this “flower of circles” , there could be probably a couple of doing but I try continue with loops and adding vertex .
Previously @normalized basically shown me how to do a very efficiently the loop, but as I trying to do a next loop based around a every 2nd point out of 3 ( so it could be shown with triangles ) I stuck with how to do loops in loops to makes it work .
I tried to check points but it clearly doesn’t rotate as I thought around new centre , should I add position_of_next_circle and some offset to determine a new point for rotation ?
for visualization the current result I would expect its something like this :
extends MeshInstance3D
func _ready():
var arrays := []
arrays.resize(Mesh.ARRAY_MAX)
arrays[Mesh.ARRAY_VERTEX] = PackedVector3Array()
arrays[Mesh.ARRAY_COLOR] = PackedColorArray()
var steps := 6
var angle_step := TAU / steps
# first circle
for i in steps:
arrays[Mesh.ARRAY_VERTEX].push_back(Vector3.ZERO)
arrays[Mesh.ARRAY_VERTEX].push_back(Vector3.LEFT.rotated(Vector3.UP, angle_step * i))
arrays[Mesh.ARRAY_VERTEX].push_back(Vector3.LEFT.rotated(Vector3.UP, angle_step * (i + 1)))
if i%3 == 0:
var color := Color.WHITE
arrays[Mesh.ARRAY_COLOR].append_array([color, color, color])
elif i%2 == 0:
var color := Color.from_hsv(randf(), 0.8, randf())
arrays[Mesh.ARRAY_COLOR].append_array([color, color, color])
arrays[Mesh.ARRAY_COLOR].append_array([color, color, color])
elif i%1 == 0 and i%3 != 0:
pass
# points for next circles
var vertex_size = int(arrays[Mesh.ARRAY_VERTEX].size())
for n in vertex_size:
if n%3 == 1:
var position_of_next_circle = arrays[Mesh.ARRAY_VERTEX].get(n)
for i in steps:
arrays[Mesh.ARRAY_VERTEX].push_back(Vector3(position_of_next_circle))
arrays[Mesh.ARRAY_VERTEX].push_back(Vector3(position_of_next_circle).rotated(Vector3.UP, angle_step * i))
arrays[Mesh.ARRAY_VERTEX].push_back(Vector3(position_of_next_circle).rotated(Vector3.UP, angle_step * (i + 1)))
var color := Color.RED
arrays[Mesh.ARRAY_COLOR].append_array([color, color, color])
print("n:", n, "i:", i,steps)
print(position_of_next_circle)
else:
pass
print(n)
#add it into points
print(arrays[Mesh.ARRAY_VERTEX])
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
log
Godot Engine v4.6.stable.custom_build - https://godotengine.org
Metal 4.0 - Forward+ - Using Device #0: Apple - Apple M2 Max (Apple8)
0
n:1i:06
n:1i:16
n:1i:26
n:1i:36
n:1i:46
n:1i:56
(-1.0, 0.0, 0.0)
2
3
n:4i:06
n:4i:16
n:4i:26
n:4i:36
n:4i:46
n:4i:56
(-0.5, 0.0, 0.866025)
5
6
n:7i:06
n:7i:16
n:7i:26
n:7i:36
n:7i:46
n:7i:56
(0.5, 0.0, 0.866025)
8
9
n:10i:06
n:10i:16
n:10i:26
n:10i:36
n:10i:46
n:10i:56
(1.0, 0.0, -0.0)
11
12
n:13i:06
n:13i:16
n:13i:26
n:13i:36
n:13i:46
n:13i:56
(0.5, 0.0, -0.866025)
14
15
n:16i:06
n:16i:16
n:16i:26
n:16i:36
n:16i:46
n:16i:56
(-0.5, 0.0, -0.866025)
17
[(0.0, 0.0, 0.0), (-1.0, 0.0, 0.0), (-0.5, 0.0, 0.866025), (0.0, 0.0, 0.0), (-0.5, 0.0, 0.866025), (0.5, 0.0, 0.866025), (0.0, 0.0, 0.0), (0.5, 0.0, 0.866025), (1.0, 0.0, -0.0), (0.0, 0.0, 0.0), (1.0, 0.0, -0.0), (0.5, 0.0, -0.866025), (0.0, 0.0, 0.0), (0.5, 0.0, -0.866025), (-0.5, 0.0, -0.866025), (0.0, 0.0, 0.0), (-0.5, 0.0, -0.866025), (-1.0, 0.0, 0.0), (-1.0, 0.0, 0.0), (-1.0, 0.0, 0.0), (-0.5, 0.0, 0.866025), (-1.0, 0.0, 0.0), (-0.5, 0.0, 0.866025), (0.5, 0.0, 0.866025), (-1.0, 0.0, 0.0), (0.5, 0.0, 0.866025), (1.0, 0.0, -0.0), (-1.0, 0.0, 0.0), (1.0, 0.0, -0.0), (0.5, 0.0, -0.866025), (-1.0, 0.0, 0.0), (0.5, 0.0, -0.866025), (-0.5, 0.0, -0.866025), (-1.0, 0.0, 0.0), (-0.5, 0.0, -0.866025), (-1.0, 0.0, 0.0), (-0.5, 0.0, 0.866025), (-0.5, 0.0, 0.866025), (0.5, 0.0, 0.866025), (-0.5, 0.0, 0.866025), (0.5, 0.0, 0.866025), (1.0, 0.0, -0.0), (-0.5, 0.0, 0.866025), (1.0, 0.0, -0.0), (0.5, 0.0, -0.866026), (-0.5, 0.0, 0.866025), (0.5, 0.0, -0.866026), (-0.5, 0.0, -0.866025), (-0.5, 0.0, 0.866025), (-0.5, 0.0, -0.866025), (-1.0, 0.0, -0.0), (-0.5, 0.0, 0.866025), (-1.0, 0.0, -0.0), (-0.5, 0.0, 0.866026), (0.5, 0.0, 0.866025), (0.5, 0.0, 0.866025), (1.0, 0.0, -0.0), (0.5, 0.0, 0.866025), (1.0, 0.0, -0.0), (0.5, 0.0, -0.866026), (0.5, 0.0, 0.866025), (0.5, 0.0, -0.866026), (-0.5, 0.0, -0.866025), (0.5, 0.0, 0.866025), (-0.5, 0.0, -0.866025), (-1.0, 0.0, 0.0), (0.5, 0.0, 0.866025), (-1.0, 0.0, 0.0), (-0.5, 0.0, 0.866025), (0.5, 0.0, 0.866025), (-0.5, 0.0, 0.866025), (0.5, 0.0, 0.866025), (1.0, 0.0, -0.0), (1.0, 0.0, -0.0), (0.5, 0.0, -0.866026), (1.0, 0.0, -0.0), (0.5, 0.0, -0.866026), (-0.5, 0.0, -0.866025), (1.0, 0.0, -0.0), (-0.5, 0.0, -0.866025), (-1.0, 0.0, 0.0), (1.0, 0.0, -0.0), (-1.0, 0.0, 0.0), (-0.5, 0.0, 0.866026), (1.0, 0.0, -0.0), (-0.5, 0.0, 0.866026), (0.5, 0.0, 0.866025), (1.0, 0.0, -0.0), (0.5, 0.0, 0.866025), (1.0, 0.0, -0.0), (0.5, 0.0, -0.866025), (0.5, 0.0, -0.866025), (-0.5, 0.0, -0.866025), (0.5, 0.0, -0.866025), (-0.5, 0.0, -0.866025), (-1.0, 0.0, 0.0), (0.5, 0.0, -0.866025), (-1.0, 0.0, 0.0), (-0.5, 0.0, 0.866026), (0.5, 0.0, -0.866025), (-0.5, 0.0, 0.866026), (0.5, 0.0, 0.866025), (0.5, 0.0, -0.866025), (0.5, 0.0, 0.866025), (1.0, 0.0, 0.0), (0.5, 0.0, -0.866025), (1.0, 0.0, 0.0), (0.5, 0.0, -0.866026), (-0.5, 0.0, -0.866025), (-0.5, 0.0, -0.866025), (-1.0, 0.0, -0.0), (-0.5, 0.0, -0.866025), (-1.0, 0.0, -0.0), (-0.5, 0.0, 0.866025), (-0.5, 0.0, -0.866025), (-0.5, 0.0, 0.866025), (0.5, 0.0, 0.866025), (-0.5, 0.0, -0.866025), (0.5, 0.0, 0.866025), (1.0, 0.0, 0.0), (-0.5, 0.0, -0.866025), (1.0, 0.0, 0.0), (0.5, 0.0, -0.866025), (-0.5, 0.0, -0.866025), (0.5, 0.0, -0.866025), (-0.5, 0.0, -0.866025)]












