Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | chibo |
Here is the deal:
extends MeshInstance
func _ready():
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_normal(Vector3(0, 0, -1))
st.add_color(Color(1, 0, 0, 1))
st.add_vertex(Vector3(-1, 0, 0))
st.add_normal(Vector3(0, 0, -1))
st.add_color(Color(0, 1, 0, 1))
st.add_vertex(Vector3(1, 0, 0))
st.add_normal(Vector3(0, 0, -1))
st.add_color(Color(0, 0, 1, 1))
st.add_vertex(Vector3(0, 2, 0))
st.add_index(0)
st.add_index(1)
st.add_index(2)
var my_mesh = Mesh.new()
st.commit(my_mesh)
$Surface_Tool_Triangle.mesh = my_mesh
Surface_Tool_Triangle is a child of Spatial, root node
I wanted to create a simple mesh, but instead I got:
Invalid set index 'mesh' (on base: 'null instance') with value of type 'ArrayMesh'.
~_~