system
August 17, 2017, 6:25pm
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
imekon
Old Version
Published before Godot 3 was released.
This is the code I’m using to create a simple two triangle mesh:
func createMesh(size):
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_color(Color(1, 0, 0))
st.add_uv(Vector2(0, 0))
st.add_normal(Vector3( 0, 0, size))
st.add_vertex(Vector3(-size, -size, 0))
st.add_vertex(Vector3( size, size, 0))
st.add_vertex(Vector3( size, -size, 0))
st.add_vertex(Vector3(-size, -size, 0))
st.add_vertex(Vector3(-size, size, 0))
st.add_vertex(Vector3( size, size, 0))
var mesh = st.commit()
meshInstance.set_mesh(mesh)
I’m guessing it has to do with add_uv?
system
August 17, 2017, 6:39pm
4
Reply From:
ingo_nikot
out of my head: you need to add uv coorinates to every vertex.
there may be an better solution but i didnt do mesh building for quite a while.
system
August 17, 2017, 8:29pm
5
Reply From:
Zylann
The code is correct, what you need is to add a DirectionalLight to provide light on your mesh. Otherwise, it will indeed be black.
I added an Omni light source, and I get a white spot on the surface, the rest is still black.
I tried a world environment which made it the same colour as the environment. I’ve tried add_uv but it doesn’t seem to make any difference.
func createMesh(size):
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_color(Color(1, 0, 0))
st.add_normal(Vector3( 0, 0, 1))
st.add_uv(Vector2(0, 0))
st.add_vertex(Vector3(-size, -size, 0))
st.add_uv(Vector2(1, 1))
st.add_vertex(Vector3( size, size, 0))
st.add_uv(Vector2(1, 0))
st.add_vertex(Vector3( size, -size, 0))
st.add_uv(Vector2(0, 0))
st.add_vertex(Vector3(-size, -size, 0))
st.add_uv(Vector2(0, 1))
st.add_vertex(Vector3(-size, size, 0))
st.add_uv(Vector2(1, 1))
st.add_vertex(Vector3( size, size, 0))
var mesh = st.commit()
meshInstance.set_mesh(mesh)
imekon | 2017-08-18 05:57
system
August 18, 2017, 6:15am
6
Reply From:
imekon
I found if I set the override material on the mesh instance, I could colour the mesh. Not sure why add_color had no effect, even with UV set.
My code has become this:
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_normal(Vector3( 0, 0, 1))
st.add_vertex(Vector3(-size, -size, 0))
st.add_vertex(Vector3( size, size, 0))
st.add_vertex(Vector3( size, -size, 0))
st.add_vertex(Vector3(-size, -size, 0))
st.add_vertex(Vector3(-size, size, 0))
st.add_vertex(Vector3( size, size, 0))
var mesh = st.commit()
meshInstance.set_mesh(mesh)
Setting the mesh instance override gets the colour if I used FixedMaterial
It needs a material and there is an option on the materials to use the vertex color (use_color_array
).
system
July 30, 2021, 4:43pm
7
Reply From:
Avishi
In the panel in which you change color, in the same pannel you can see a option named flag, click on it and the unshaded option then you can see the colours.