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

Function LoadMaterials

engine/modelc/src/modelimporter_gltf.cpp:825–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

823}
824
825static void LoadMaterials(Scene* scene, cgltf_data* gltf_data, dmHashTable64<void*>* cache)
826{
827 InitSize(scene->m_Materials, gltf_data->materials_count, gltf_data->materials_count);
828
829 for (uint32_t i = 0; i < gltf_data->materials_count; ++i)
830 {
831 cgltf_material* gltf_material = &gltf_data->materials[i];
832 Material* material = &scene->m_Materials[i];
833 memset(material, 0, sizeof(*material));
834
835 material->m_Name = DuplicateObjectName(gltf_material);
836 material->m_Index = i;
837
838 // a helper to avoid typos
839#define LOADPROP(DNAME, GNAME) \
840 if (gltf_material->has_ ## GNAME) \
841 { \
842 Load ## DNAME (&gltf_material-> GNAME, AllocStruct(&material->m_ ## DNAME), cache); \
843 }
844
845 LOADPROP(PbrMetallicRoughness, pbr_metallic_roughness);
846 LOADPROP(PbrSpecularGlossiness, pbr_specular_glossiness);
847 LOADPROP(Clearcoat, clearcoat);
848 LOADPROP(Transmission, transmission);
849 LOADPROP(Ior, ior);
850 LOADPROP(Specular, specular);
851 LOADPROP(Volume, volume);
852 LOADPROP(Sheen, sheen);
853 LOADPROP(EmissiveStrength, emissive_strength);
854 LOADPROP(Iridescence, iridescence);
855
856#undef LOADPROP
857
858 LoadTextureView(&gltf_material->normal_texture, &material->m_NormalTexture, cache);
859 LoadTextureView(&gltf_material->occlusion_texture, &material->m_OcclusionTexture, cache);
860 LoadTextureView(&gltf_material->emissive_texture, &material->m_EmissiveTexture, cache);
861
862 CopyArray(gltf_material->emissive_factor, material->m_EmissiveFactor);
863
864 material->m_AlphaCutoff = gltf_material->alpha_cutoff;
865 material->m_AlphaMode = (AlphaMode)gltf_material->alpha_mode;
866 material->m_DoubleSided = gltf_material->double_sided != 0;
867 material->m_Unlit = gltf_material->unlit != 0;
868 }
869}
870
871static void CalcAABB(uint32_t count, float* positions, Aabb* aabb)
872{

Callers 1

LoadSceneFunction · 0.85

Calls 4

InitSizeFunction · 0.85
DuplicateObjectNameFunction · 0.85
LoadTextureViewFunction · 0.85
CopyArrayFunction · 0.85

Tested by

no test coverage detected