MCPcopy Create free account
hub / github.com/defold/defold / LoadPrimitives

Function LoadPrimitives

engine/modelc/src/modelimporter_gltf.cpp:919–1142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

917}
918
919static void LoadPrimitives(Scene* scene, Model* model, cgltf_data* gltf_data, cgltf_mesh* gltf_mesh)
920{
921 InitSize(model->m_Meshes, gltf_mesh->primitives_count, gltf_mesh->primitives_count);
922
923 for (size_t i = 0; i < gltf_mesh->primitives_count; ++i)
924 {
925 if (scene->m_LoadError)
926 return;
927
928 cgltf_primitive* prim = &gltf_mesh->primitives[i];
929
930 for (cgltf_size ai = 0; ai < prim->attributes_count; ++ai)
931 {
932 cgltf_attribute* attr = &prim->attributes[ai];
933
934 // we only support JOINTS_0 and WEIGHTS_0, so we need to emit an error if any of these cases are true.
935 if (attr->type == cgltf_attribute_type_joints && attr->index > 0)
936 {
937 char buf[512];
938 dmSnPrintf(buf, sizeof(buf),
939 "GLTF mesh '%s', primitive %zu: multiple joint/weight attribute sets (e.g. JOINTS_%u) are not supported. Defold supports a single set of up to 4 bone influences per vertex, to use this content you need to fix the issues in an external tool.",
940 model->m_Name, i, (unsigned)attr->index);
941 dmLogError("%s", buf);
942 SetLoadError(scene, buf);
943 return;
944 }
945 if (attr->type == cgltf_attribute_type_weights && attr->index > 0)
946 {
947 char buf[512];
948 dmSnPrintf(buf, sizeof(buf),
949 "GLTF mesh '%s', primitive %zu: multiple joint/weight attribute sets (e.g. WEIGHTS_%u) are not supported. Defold supports a single set of up to 4 bone influences per vertex, to use this content you need to fix the issues in an external tool.",
950 model->m_Name, i, (unsigned)attr->index);
951 dmLogError("%s", buf);
952 SetLoadError(scene, buf);
953 return;
954 }
955 }
956
957 Mesh* mesh = &model->m_Meshes[i];
958 mesh->m_Name = CreateNameFromHash("mesh", i);
959
960 uint32_t material_index = FindIndex(gltf_data->materials, prim->material);
961 if (material_index != INVALID_INDEX)
962 {
963 mesh->m_Material = &scene->m_Materials[material_index];
964 mesh->m_VertexCount = 0;
965 }
966
967 //printf("primitive_type: %s\n", getPrimitiveTypeStr(prim->type));
968
969 for (uint32_t a = 0; a < prim->attributes_count; ++a)
970 {
971 cgltf_attribute* attribute = &prim->attributes[a];
972 cgltf_accessor* accessor = attribute->data;
973
974 mesh->m_VertexCount = accessor->count;
975
976 uint32_t num_components = (uint32_t)cgltf_num_components(accessor->type);

Callers 1

LoadMeshesFunction · 0.85

Calls 15

InitSizeFunction · 0.85
dmSnPrintfFunction · 0.85
SetLoadErrorFunction · 0.85
CreateNameFromHashFunction · 0.85
FindIndexFunction · 0.85
cgltf_num_componentsFunction · 0.85
ReadAccessorUint32Function · 0.85
ReadAccessorFloatFunction · 0.85
CalcAABBFunction · 0.85
SetMethod · 0.45

Tested by

no test coverage detected