Godot Version
4.4
Question
Hey all, have a weird but simple problem, and I know the answer is simple but I just can’t figure it out. I have a MeshInstance3D That I have created and I am trying to add a texture to it. Right now I can just add the test texture to the albedo of the material. The texture applies, but incorrectly on one axis.
I want the texture to stretch over the whole mesh, and along the y axis it is working fine but along the x axis it is doing a weird thing:
You can see that it is cut up into lines. These lines happen every 1 unit, and I have no idea why. Here’s my code:
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
# Loop over grid cells (each cell is defined by four adjacent spheres)
for x in range(chunk_size.x - 1):
for y in range(chunk_size.y - 1):
var idx = x * chunk_size.y + y
# Get positions for the four corners of the cell
var pos_a = spheres[idx].position # lower left
var pos_b = spheres[idx + chunk_size.y].position # lower right
var pos_c = spheres[idx + 1].position # upper left
var pos_d = spheres[idx + chunk_size.y + 1].position # upper right
# Compute UVs based on grid coordinates.
var u_left = x / float(chunk_size.x - 1)
var u_right = (x + 1) / float(chunk_size.x - 1)
var v_top = y / float(chunk_size.y - 1)
var v_bottom = (y + 1) / float(chunk_size.y - 1)
# First triangle: lower left, lower right, upper left
st.set_uv(Vector2(u_left, v_bottom))
st.add_vertex(pos_a)
st.set_uv(Vector2(u_right, v_bottom))
st.add_vertex(pos_b)
st.set_uv(Vector2(u_left, v_top))
st.add_vertex(pos_c)
# Second triangle: lower right, upper right, upper left
st.set_uv(Vector2(u_right, v_bottom))
st.add_vertex(pos_b)
st.set_uv(Vector2(u_right, v_top))
st.add_vertex(pos_d)
st.set_uv(Vector2(u_left, v_top))
st.add_vertex(pos_c)


