+1 vote

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()
    for surface in range(0, strip.size()):
        var vertex = vertexList[strip[surface]]

        surfaceTool.add_vertex( vertex)
        #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)


    var mesh = Mesh.new()

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

in Engine by (47 points)
edited by

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) {


So i have to create the normals by my self

by (47 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.
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.