0 votes

Hi try to generate procetual mesh and start with a simple cube implementation.
But i run into basic problems like coloring and texturing. It not works

here my simple code

extends MeshInstance

#export(SpatialMaterial)  var material = null

func _ready():
    var size = 5
    var vertexList = [
        Vector3(size,   size,   size),
        Vector3(-size,  size,   size),
        Vector3(size,   size,   -size),
        Vector3(-size,  size,   -size),
        Vector3(size,   -size,  size),
        Vector3(-size,  -size,  size),
        Vector3(-size,  -size,  -size),
        Vector3(size,   -size,  -size)]
    var strip  = [ 3, 2, 6, 7, 4, 2, 0, 3, 1, 6, 5, 4, 1, 0 ]

    var surfaceTool = SurfaceTool.new()
    surfaceTool.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
    for surface in range(0, strip.size()):
        var vertex = vertexList[strip[surface]]

        surfaceTool.add_vertex( vertex)
        surfaceTool.add_color(Color(0,0,1,1))
        #surfaceTool.add_uv( Vector2(1/vertex.x, 1/vertex.y))
        #surfaceTool.add_uv2( Vector2(1/vertex.x, 1/vertex.y))  


    var material = SpatialMaterial.new()
    #material.albedo_color = Color(0,0,1,1)

    surfaceTool.generate_normals()
    surfaceTool.set_material(material)
    surfaceTool.index()

    var mesh = Mesh.new()
    surfaceTool.commit(mesh)
    set_mesh(mesh)

the loop to set the color not works, only when i set globaly the material color it works.
same for textures, what i doing wrong?

I guess is a problem of normals, after reading offical docu

void generate_normals( bool flip=false )
Generates normals from Vertices so you do not have to do it manually.

Setting "flip" true inverts resulting normals.

Requires primitive type to be set to PRIMITIVE_TRIANGLES.

Is realy only type PRIMITIVE_TRIANGLES supported?

Thanks for help

asked Aug 11 in Engine by NullPointer (21 points)
edited Aug 11 by NullPointer

1 Answer

0 votes

I find the answer by my self.

The function generate_normals of SurfaceTool works only with PRIMITIVE_TRIANGLES

void SurfaceTool::generate_normals(bool p_flip) {

    ERR_FAIL_COND(primitive != Mesh::PRIMITIVE_TRIANGLES);

So i have to create the normals by my self

answered 4 days ago by NullPointer (21 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.