+2 votes

The source is here: https://github.com/imekon/godot-unofficial-demo-projects-v3, in the project mesh.

The main.gd file has this:

extends Spatial

onready var meshInstance = $Mesh

var angle = 0

func _ready():
    var material = SpatialMaterial.new()
    material.albedo_color = Color(1.0, 0.0, 0.0)
    createMesh(10, material)

func createMesh(size, material):
    var surfaceTool = SurfaceTool.new()
    surfaceTool.begin(Mesh.PRIMITIVE_TRIANGLES)

    surfaceTool.add_normal(Vector3(    0,     0,  1))

    surfaceTool.add_vertex(Vector3(-size, -size,  0))
    surfaceTool.add_vertex(Vector3( size,  size,  0))
    surfaceTool.add_vertex(Vector3( size, -size,  0))
    surfaceTool.add_vertex(Vector3(-size, -size,  0))
    surfaceTool.add_vertex(Vector3(-size,  size,  0))
    surfaceTool.add_vertex(Vector3( size,  size,  0))

    var mesh = surfaceTool.commit()
    meshInstance.mesh = mesh
    meshInstance.set_surface_material(0, material)

func _process(delta):
    angle += delta * 30
    meshInstance.rotation_degrees = Vector3(0, 0, angle)

It creates a white surface not red, and I'm not clear why.

asked Feb 6, 2018 in Engine by imekon (229 points)

I can see red rectangle is rotating with your test code.
I'm testing with custom build v3.1.dev.dd4e593
would you try it with 3.0.1-official?

2 Answers

0 votes
material.albedo_color = Color(1.0, 0.0, 0.0, **1.0**)
meshInstance.set_material_override(material)

Miss alpha channel. Test it

answered Feb 27, 2018 by D3m0n92 (20 points)
edited Feb 27, 2018 by D3m0n92
+3 votes

I had the same problem until now - This works for me (Godot 3.0.2-stable)

var material = SpatialMaterial.new()
material.albedo_color = Color(0.8, 0.0, 0.0)
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.set_material(material)
st.add_vertex(Vector3(5, 0, 0))
st.add_vertex(Vector3(0, 5, 0))
st.add_vertex(Vector3(5, 5, 0))
st.generate_normals()
var mesh = Mesh.new()
st.commit(mesh)
var mesh_inst = MeshInstance.new()
mesh_inst.mesh = mesh
add_child(mesh_inst)

Mind, that you FIRST have to state SurfaceTool.begin(), and THEN SurfaceTool.set_material()
In this tutorial, they switched the lines (maybe worked in previous versions?)
http://www.gamefromscratch.com/post/2015/09/25/Godot-Engine-Tutorial-Part-15-Static-and-Programmatic-3D-Meshes.aspx

answered Mar 23, 2018 by phatsen (20 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.