+1 vote

Hi,

I'm trying to build procedural geometry from C# in 3.0RC1. I was using SurfaceTool but believe that it might be rather slow for what I'm trying to achieve (a call out every vertex addition), so I'm looking at directly creating the vertex, index etc arrays myself and using Mesh.AddSurfaceFromArrays() instead.

I'm running into confusion around the types of array I should be using. The C# Mesh.AddSurfaceFromArrays() method signature expects an object[] as the 'arrays' parameter, in order that each array contained in it can contain different types (Vector3, int, etc). So I've defined my object[] and it contains a verticesArray as object[] also and that's ok.

However at runtime I get the following error:

Condition ' parrays[ai].gettype() != Variant::POOLVECTOR3ARRAY ' is true. returned: ERRINVALIDPARAMETER
...
C Source: servers\visualserver.cpp:429
C Function: VisualServer::
surfacesetdata

This looks like it's wanting an array of type PoolVector3Array instead of an object[]. And I can't find any definition of this for C#. I have come across this link in the docs:

http://docs.godotengine.org/en/latest/learning/scripting/c_sharp/c_sharp_differences.html#array

which seems to imply that the implementation isn't finished yet for Array etc?

Where am I going wrong, or is it non-functional from C# at the moment? Should my verticesArray be of type Vector3[] instead of object[]? But then I have trouble assigning it "into" the object[] 'arrays' variable as it won't cast from Vector3[] to object[]. Confusion!

asked Jan 19, 2018 in Engine by madgit (22 points)

Played a bit more. If I ONLY specify vertices in the array-of-arrays then it "works", in that I get geometry coming out but obviously with no normals then it's just flat. If I add normals, or indices, or anything else then I start getting those errors as above about Pool types not being used.

Looked in master visual_server.cpp source at line 429 (as indicated in error above) and it's checking for the Pool type when normals are specified. Just above in the code (line 380) is where it's doing vertices, and it DOESN'T check for the type - and works just fine with the Vector3s I've passed in as an object[].

Same goes for indices (doesn't work, it's checking for a Pool type) and so forth.

So - should the checking be removed from everything else just like Vertices? Or should it be added to Vertices, and then somehow the Pool types implemented for C#? (as they don't exist as far as I can see, making it impossible to use this method atm from C#).

Or maybe I'm a million miles off, in which case I'd really appreciate being pointed at the Right Way To Do Things :)

1 Answer

0 votes

I'm using gdscript and came across the same problem. If I type the arrays as follows it works:

var normal_array = PoolVector3Array()
var uv_array = PoolVector2Array()
var vertex_array = PoolVector3Array()
var index_array = PoolIntArray()
...
var arrays = []
arrays.resize(Mesh.ARRAY_MAX)
arrays[Mesh.ARRAY_VERTEX] = vertex_array
arrays[Mesh.ARRAY_NORMAL] = normal_array
arrays[Mesh.ARRAY_TEX_UV] = uv_array
arrays[Mesh.ARRAY_INDEX] = index_array
answered 6 days ago by etherealmachine (14 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.