+3 votes

I want to generate a mesh not using SurfaceTool because its API is impractical to use in my case.

So I looked at Mesh.add_surface, but the documentation of this method looks completely off from what the function prototype says: http://docs.godotengine.org/en/latest/classes/class_mesh.html?highlight=Mesh#member-function-description

It doesn't says what arrays should contain, and doesn't describe morph_arrays or alphasort.

So I don't understand how to use this function at all :s

in Engine by (29,118 points)

1 Answer

+1 vote
Best answer

Looking at the git repo I learned this:

Arrays is an array of arrays, you can pass null arrays for those you don't use, the first array is for vertex information (ARRAY_VERTEX = 0), next are normals, tanget, etc.

I didn't look at what morphs do (animation maybe?) but it looks like you can left it with the default value, same for alphasort (if your mesh has transparency this helps to fix rendering artifacts).

I cannot test it at this time, but I hope this may guide you.

by (1,002 points)
selected by

Is there an array for indices? Or should all vertices be specified redundantly for all triangles/lines?

Oh... that's it, am I right? https://github.com/godotengine/godot/blob/master/drivers/gles2/rasterizer_gles2.cpp#L1934

It would be the 9th array (ARRAYINDEX = 8), or you could specify the type as PRIMITIVETRIANGLES and every 3 vertices a triangle is created, as I mentioned I only looked at the repo and have not tested it.

Yes, that's the code I looked at.

I think I won't use PRIMITIVE_TRIANGLES because I need to make quads, so with indexes I can specify 4 vertices instead of 6 (or even less if it's a strip).
We'll see if 3.0 changes this API, thanks for the answer!

Not tested though, will do that once I get back home :)

I just wanted to know whether one can resize the arrays and reposition the vertices on the fly, without creating a new one? Thanks.

You probably can in raw OpenGL, but not to my knowledge in Godot API. You have to regenerate the whole surface (not the whole mesh though if you use multiple materials).

@Zylann I see, I'll have to create a custom C++ class and expose it to GDScript, thanks.

Note that in Godot, raw OpenGL is located deep in the rendering engine, you would have to add the feature in there.

@Zylann I'll keep that in mind, thanks.

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 Frequently asked questions and 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 [email protected] with your username.