Trying to make a textured double sided plane mesh at run-time. What am I doing wrong?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By trollworkout
:warning: Old Version Published before Godot 3 was released.

This is my code attached to a Node in my main scene (main.tscn/main.gd)

func _ready():	
	var surface = SurfaceTool.new()
	var mesh = Mesh.new()
	var texture = ImageTexture.new()
	var material = FixedMaterial.new()
	var meshInstance = MeshInstance.new()
	
	surface.begin(VisualServer.PRIMITIVE_TRIANGLE_STRIP)
	surface.add_vertex(Vector3(0,0,0))
	surface.add_vertex(Vector3(0,1,0))
	surface.add_vertex(Vector3(1,0,0))
	surface.add_vertex(Vector3(1,1,0))
	surface.commit(mesh)
	
	texture.load("res://001.png")
	material.set_texture(material.PARAM_DIFFUSE, texture)
	material.set_flag(material.FLAG_DOUBLE_SIDED, true)
	material.set_flag(material.FLAG_UNSHADED, true)

	meshInstance.set_mesh(mesh)
	meshInstance.set_material_override(material)
	
	add_child(meshInstance)

I got much closer now but I think I may be missing the UV because texture does not show up

Think about add_vertex() as a way to commit a vertex.
You can add UVs by calling surface.add_uv() before each vertices.

Also, you can get the texture more simply with this instead:
var texture = load("res://001.png")

Zylann | 2016-05-26 23:03