0 votes

I am trying to use normals in Godot's ArrayMesh in C#. It asks for a PoolVector3Array, but I am unable to create one in C#. How do I create normals in a way that the "AddSurfaceFromArrays" function will recognize?

I've tried looking in various doc's for information about this and have found very little. The doc's indicate an array of Vector3's should be acceptable for this function.

using Godot;
using System;
using Godot.Collections;

public class Test : Spatial
{
    public override void _Ready()
    {
       Array<Vector3> verticies  = new Array<Vector3>();
       Array<Vector3> normals = new Array<Vector3>();

       verticies.Add(new Vector3(0, 0, 0));
       normals.Add(new Vector3(1, 0, 0));
       verticies.Add(new Vector3(0, 0, 1));
       normals.Add(new Vector3(1, 0, 0));
       verticies.Add(new Vector3(0, 1, 0));
       normals.Add(new Vector3(1, 0, 0));

       var array_mesh = new ArrayMesh();
       var arrays = new Godot.Collections.Array();
       arrays.Resize((int)ArrayMesh.ArrayType.Max);
       arrays[(int)ArrayMesh.ArrayType.Vertex] = verticies;
       arrays[(int)ArrayMesh.ArrayType.Normal] = normals;


      array_mesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles,arrays);

      MeshInstance m = new MeshInstance{Mesh = array_mesh};
      AddChild(m);
  }
}

Expected output is to have a triangle with normals applied.
Actual output is no object being created and the errors:

"Condition ' parrays[ai].gettype() != Variant::POOLVECTOR3ARRAY' is true. returned: ERRINVALIDPARAMETER"

"Invalid array format for surface"

asked Sep 8, 2019 in Engine by 295cade1 (12 points)

Is it working if you provide a Vector3[] instead of a Array<Vector3>?

THIS WORKED! You are the best, thanks!

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.