Hello! im trying to do mesh generation by code by reading data from a binary file. The problem is im getting weird errors that are not part of my code
servers/rendering_server.cpp:892 - Method/function failed. Returning: ERR_INVALID_DATA
scene/resources/mesh.cpp:1771 - Condition "err != OK" is true.
scene/3d/mesh_instance_3d.cpp:347 - Index p_surface = 0 is out of bounds (surface_override_materials.size() = 0).
to
scene/3d/mesh_instance_3d.cpp:347 - Index p_surface = 10 is out of bounds (surface_override_materials.size() = 0).
Any idea why these error could be apearing?
The mesh generation is done by using ArrayMesh, i simply assingn it Vertices, Indices, Normals, UV1, UV2 and Tangents. Sometimes UV2 and Tangent could be empty arrays, would that cause an issue? would it be better to leave those as null?
Here's how i generate the surfaces of the mesh
static func create_mesh(model_chunk: ModelChunk, skeleton: Skeleton3D, data_for_animations: Array[Array]) -> ArrayMesh:
var array_mesh = ArrayMesh.new()
print(model_chunk.texture_data.textures.size())
for texture in model_chunk.texture_data.textures:
var array = []
array.resize(Mesh.ARRAY_MAX)
var surface_indeces :Array[int] = get_surface_indices(texture, model_chunk.mesh_data)
var indices :Array[int] = []
var vertices :Array[Vector3] = []
var normals :Array[Vector3] = []
var uv1 :Array[Vector2] = []
var uv2 :Array[Vector2] = []
var tangents :Array[Vector3] = []
var bones = []
var weights = []
get_mesh_arrays(
surface_indeces,texture,model_chunk.mesh_data,
indices,vertices,normals,uv1,uv2,tangents,
model_chunk.texture_data.extra_uv == 1)
array[Mesh.ARRAY_VERTEX] = vertices
array[Mesh.ARRAY_INDEX] = indices
array[Mesh.ARRAY_NORMAL] = normals
array[Mesh.ARRAY_TEX_UV] = uv1
array[Mesh.ARRAY_TEX_UV2] = uv2
array[Mesh.ARRAY_TANGENT] = tangents
var surface_data = []
surface_data.append(vertices)
surface_data.append(indices)
surface_data.append(uv1)
data_for_animations.append(surface_data)
var use_8_bones = false
if model_chunk.weights.size() > 0:
use_8_bones = set_bone_weights(model_chunk,bones,weights, surface_indeces, skeleton)
array[Mesh.ARRAY_BONES] = bones
array[Mesh.ARRAY_WEIGHTS] = weights
array_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES,array)
return array_mesh
"get_mesh_arrays" simply takes the data from the forma of the binary file to the format that godot wants.