How do you apply normals to an array mesh using C#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 295cade1

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[(int)ArrayMesh.ArrayType.Vertex] = verticies;
       arrays[(int)ArrayMesh.ArrayType.Normal] = normals;


      MeshInstance m = new MeshInstance{Mesh = array_mesh};

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

“Condition ’ p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY’ is true. returned: ERR_INVALID_PARAMETER”

“Invalid array format for surface”

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

Zylann | 2019-09-09 00:52

THIS WORKED! You are the best, thanks!

295cade1 | 2019-09-09 15:28