2
\$\begingroup\$

Using Godot3, I have a camera and added a MeshInstance node to the Spatial node and attached this script. Why am I not seeing any triangle yet?

extends MeshInstance

func _ready():
    var size = 10
    var st = SurfaceTool.new()
    var mat = SpatialMaterial.new()
    mat.albedo_color = Color(1.0, 0.0, 0.0)
    st.set_material(mat)
    st.begin(Mesh.PRIMITIVE_TRIANGLES)
    st.add_uv(Vector2(0, 0))
    st.add_vertex(Vector3(-size, -size,  0))
    st.add_uv(Vector2(1, 1))
    st.add_vertex(Vector3( size,  size,  0))
    st.add_uv(Vector2(1, 0))
    st.add_vertex(Vector3( size, -size,  0))
    st.generate_normals()
    var mesh = st.commit()
    self.set_mesh(mesh)
\$\endgroup\$
1
  • 5
    \$\begingroup\$ I know nothing about Godot in particular, but - in general - the winding order of a triangle matters. Try reversing the 2nd and 3rd points and seeing if that helps? \$\endgroup\$ Commented Apr 2, 2019 at 14:01

1 Answer 1

1
\$\begingroup\$

Use Clock wise winding order.

Here's the modified code,

extends MeshInstance

func _ready():
    var size = 10
    var st = SurfaceTool.new()
    var mat = SpatialMaterial.new()
    mat.albedo_color = Color(1.0, 0.0, 0.0)
    st.set_material(mat)
    st.begin(Mesh.PRIMITIVE_TRIANGLES)
    st.add_uv(Vector2(0, 0))
    st.add_vertex(Vector3(-size, -size,  0))
    st.add_uv(Vector2(1, 1))
    st.add_vertex(Vector3( -size,  size,  0))
    st.add_uv(Vector2(1, 0))
    st.add_vertex(Vector3( size, -size,  0))
    st.generate_normals()
    var mesh = st.commit()
    self.set_mesh(mesh)

Also move your camera back to see the traingle

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .