0 votes

I'm currently trying to modify the vertex attributes of a mesh at run time, more specifically, the color of each vertex. I want it to be done without ImmediateGeomety. How can I do that?

Here is a piece of my code.

#
var mesh_data = MeshDataTool.new()
    var image = color_array.get_data()
    image.decompress()
    image.lock()

    for surface in range(mesh.get_surface_count()):
           mesh_data.create_from_surface(mesh, surface)

           for vertex in range(mesh_data.get_vertex_count()):
                    var UV = mesh_data.get_vertex_uv(vertex)
                    var pixel = UV*image.get_size()
                    mesh_data.set_vertex_color(vertex, 
                        image.get_pixel(pixel.x, pixel.y))

           mesh_data.commit_to_surface(mesh)
           mesh_data.clear()

    image.unlock()

The code is supposed to work on a .obj file exported from Magicavoxel, saving the texture color array corresponding pixels in the vertex colors. The colors are not the corresponding ones though and I can't tell what's wrong.

in Engine by (12 points)

Please log in or register to answer this question.

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.