+2 votes

I'm attempting to set a texture on a quad that I generate with the surface tool. On the mesh instance I set a material override of spatial material. I then set the texture to a png file in the albedo section. The texture I am using is a 16 x 16 png with an alpha channel. The top half of the texture is red and bottom half is blue. When I run the code I see a quad that is one solid color and that is purple. I'm new to godot and am completely lost to what is wrong. Any help is appreciated.

extends MeshInstance

func _ready():

  var surfTool = SurfaceTool.new()
  var mesh = Mesh.new()
  var vert_array = Array()
  var uv_array = Array()
  var st = SurfaceTool.new()

  vert_array.push_back(Vector3(0,0,0))
  vert_array.push_back(Vector3(0,1,0))
  vert_array.push_back(Vector3(1,1,0))

  vert_array.push_back(Vector3(0,0,0))
  vert_array.push_back(Vector3(1,1,0))
  vert_array.push_back(Vector3(1,0,0))

  uv_array.push_back(Vector2(0,0))
  uv_array.push_back(Vector2(0,1))
  uv_array.push_back(Vector2(1,1))

  uv_array.push_back(Vector2(0,0))
  uv_array.push_back(Vector2(1,1))
  uv_array.push_back(Vector2(1,0))

  st.begin(Mesh.PRIMITIVE_TRIANGLES)
  for i in range(6):
    st.add_vertex(vert_array[i])
    st.add_uv(uv_array[i])
  st.commit(mesh)
  self.set_mesh(mesh)
in Engine by (25 points)

1 Answer

+1 vote
Best answer

It turns out the add_uv line needs to be called before the add_vertex line. With those two lines swapped everything works fine.

by (25 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.