Set the color of a written mesh

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Eden

Hi, Community!

I am writing a mesh by SurfaceTool object in Godot 3.2.2. I try to set the colour of the mesh vertices and surfaces by adding a material with a colour, or by using MeshDataTool to access the vertices to change the colour. But the colour stays "Black". 

The following is my simple code:

 # mesh
var tmpMesh = Mesh.new()
var vertices = PoolVector3Array()
var mat = SpatialMaterial.new()
var color = Color(225,0,0,1)
var st = SurfaceTool.new()

# add color to the surface
mat.albedo_color = color
st.set_material(mat)
	
# draw mesh
st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)

for v in vertices.size():
	st.add_color(color)
	st.add_vertex(vertices[v])

st.commit(tmpMesh)
mesh = tmpMesh

How could I fix it up?

Thank you in advance!

-Eden

var color = Color(225,0,0,1)

Note, 225 is crazy HDR bright. If you just want red, Color(1,0,0,1) should be enough

Zylann | 2020-09-17 12:39

Thanks for the advice on coding!

Eden | 2020-09-18 08:21

:bust_in_silhouette: Reply From: klaas

Hi,
try to add normals or

st.generate_normals ()

Before the commit!

This should help

OK, I will have a try. Thank you!

Eden | 2020-09-18 08:20

set a normal doesn’t actually work. It is a problem of material setting.

If I set: mat.flags_unshaded = true, it is able to work then.

Eden | 2020-10-05 04:39

if you set unshaded the normals dont get in effect so it must not be a material problem.

klaas | 2020-10-05 13:06