From efd6f6dbad69eb97366a9ad4ce42f9d2dc3d9f57 Mon Sep 17 00:00:00 2001 From: RevoluPowered Date: Fri, 6 Sep 2019 21:52:00 +0100 Subject: Implemented basic texture mapping for PBR material definitions This reads materials properly from Maya and expands on existing functionality to make this work properly. aiTextureType_SHININESS no longer used as not appropriate for PBR texture as it is legacy. This fix will be also present in assimp soon. --- modules/assimp/editor_scene_importer_assimp.cpp | 87 +++++++++++++++++++++---- 1 file changed, 74 insertions(+), 13 deletions(-) (limited to 'modules') diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp index e5439fd132..fee2001a07 100644 --- a/modules/assimp/editor_scene_importer_assimp.cpp +++ b/modules/assimp/editor_scene_importer_assimp.cpp @@ -679,6 +679,26 @@ Ref EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( // cull all back faces mat->set_cull_mode(SpatialMaterial::CULL_BACK); + // Now process materials + aiTextureType base_color = aiTextureType_BASE_COLOR; + { + String filename, path; + AssimpImageData image_data; + + if (AssimpUtils::GetAssimpTexture(state, ai_material, base_color, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + + // anything transparent must be culled + if (image_data.raw_image->detect_alpha() != Image::ALPHA_NONE) { + mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + mat->set_depth_draw_mode(SpatialMaterial::DepthDrawMode::DEPTH_DRAW_ALPHA_OPAQUE_PREPASS); + mat->set_cull_mode(SpatialMaterial::CULL_DISABLED); // since you can see both sides in transparent mode + } + + mat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, image_data.texture); + } + } + // Now process materials aiTextureType tex_diffuse = aiTextureType_DIFFUSE; { @@ -731,6 +751,60 @@ Ref EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( } } + aiTextureType tex_normal_camera = aiTextureType_NORMAL_CAMERA; + { + String filename, path; + Ref texture; + AssimpImageData image_data; + + // Process texture normal map + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_normal_camera, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + mat->set_feature(SpatialMaterial::Feature::FEATURE_NORMAL_MAPPING, true); + mat->set_texture(SpatialMaterial::TEXTURE_NORMAL, image_data.texture); + } + } + + aiTextureType tex_emission_color = aiTextureType_EMISSION_COLOR; + { + String filename, path; + Ref texture; + AssimpImageData image_data; + + // Process texture normal map + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_emission_color, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + mat->set_feature(SpatialMaterial::Feature::FEATURE_NORMAL_MAPPING, true); + mat->set_texture(SpatialMaterial::TEXTURE_NORMAL, image_data.texture); + } + } + + aiTextureType tex_metalness = aiTextureType_METALNESS; + { + String filename, path; + Ref texture; + AssimpImageData image_data; + + // Process texture normal map + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_metalness, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + mat->set_texture(SpatialMaterial::TEXTURE_METALLIC, image_data.texture); + } + } + + aiTextureType tex_roughness = aiTextureType_DIFFUSE_ROUGHNESS; + { + String filename, path; + Ref texture; + AssimpImageData image_data; + + // Process texture normal map + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_roughness, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + mat->set_texture(SpatialMaterial::TEXTURE_ROUGHNESS, image_data.texture); + } + } + aiTextureType tex_emissive = aiTextureType_EMISSIVE; { String filename = ""; @@ -772,19 +846,6 @@ Ref EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( } } - aiTextureType tex_roughness = aiTextureType_SHININESS; - { - String filename, path; - Ref texture; - AssimpImageData image_data; - - // Process texture normal map - if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_roughness, filename, path, image_data)) { - AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); - mat->set_texture(SpatialMaterial::TEXTURE_ROUGHNESS, image_data.texture); - } - } - Array array_mesh = st->commit_to_arrays(); Array morphs; morphs.resize(ai_mesh->mNumAnimMeshes); -- cgit v1.2.3 From 269ba00fd32c379bda0862e386ebfb3677a59fa6 Mon Sep 17 00:00:00 2001 From: RevoluPowered Date: Sun, 8 Sep 2019 18:10:12 +0100 Subject: Implemented maya stingray support --- modules/assimp/editor_scene_importer_assimp.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp index fee2001a07..30778a182e 100644 --- a/modules/assimp/editor_scene_importer_assimp.cpp +++ b/modules/assimp/editor_scene_importer_assimp.cpp @@ -699,7 +699,6 @@ Ref EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( } } - // Now process materials aiTextureType tex_diffuse = aiTextureType_DIFFUSE; { String filename, path; @@ -846,6 +845,20 @@ Ref EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( } } + aiTextureType tex_ao_map = aiTextureType_AMBIENT_OCCLUSION; + { + String filename, path; + Ref texture; + AssimpImageData image_data; + + // Process texture normal map + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_ao_map, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + mat->set_feature(SpatialMaterial::FEATURE_AMBIENT_OCCLUSION, true); + mat->set_texture(SpatialMaterial::TEXTURE_AMBIENT_OCCLUSION, image_data.texture); + } + } + Array array_mesh = st->commit_to_arrays(); Array morphs; morphs.resize(ai_mesh->mNumAnimMeshes); -- cgit v1.2.3