0 votes

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

in Engine by (14 points)

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

Thanks for the advice on coding!

1 Answer

+1 vote

Hi,
try to add normals or

st.generate_normals ()

Before the commit!

This should help

by (3,932 points)

OK, I will have a try. Thank you!

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.

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

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.