| 891 | } |
| 892 | |
| 893 | LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_path, Lightmapper::BakeStepFunc p_bake_step, void *p_bake_userdata) { |
| 894 | if (p_image_data_path.is_empty()) { |
| 895 | if (get_light_data().is_null()) { |
| 896 | return BAKE_ERROR_NO_SAVE_PATH; |
| 897 | } |
| 898 | |
| 899 | p_image_data_path = get_light_data()->get_path(); |
| 900 | if (!p_image_data_path.is_resource_file()) { |
| 901 | return BAKE_ERROR_NO_SAVE_PATH; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | Ref<Lightmapper> lightmapper = Lightmapper::create(); |
| 906 | ERR_FAIL_COND_V(lightmapper.is_null(), BAKE_ERROR_NO_LIGHTMAPPER); |
| 907 | |
| 908 | BakeStepUD bsud; |
| 909 | bsud.func = p_bake_step; |
| 910 | bsud.ud = p_bake_userdata; |
| 911 | bsud.from_percent = 0.2; |
| 912 | bsud.to_percent = 0.8; |
| 913 | |
| 914 | if (p_bake_step) { |
| 915 | p_bake_step(0.0, RTR("Finding meshes, lights and probes"), p_bake_userdata, true); |
| 916 | } |
| 917 | /* STEP 1, FIND MESHES, LIGHTS AND PROBES */ |
| 918 | Vector<Lightmapper::MeshData> mesh_data; |
| 919 | Vector<LightsFound> lights_found; |
| 920 | Vector<Vector3> probes_found; |
| 921 | AABB bounds; |
| 922 | { |
| 923 | Vector<MeshesFound> meshes_found; |
| 924 | _find_meshes_and_lights(p_from_node ? p_from_node : get_parent(), meshes_found, lights_found, probes_found); |
| 925 | |
| 926 | if (meshes_found.is_empty()) { |
| 927 | return BAKE_ERROR_NO_MESHES; |
| 928 | } |
| 929 | // create mesh data for insert |
| 930 | |
| 931 | //get the base material textures, help compute atlas size and bounds |
| 932 | for (int m_i = 0; m_i < meshes_found.size(); m_i++) { |
| 933 | if (p_bake_step) { |
| 934 | float p = (float)(m_i) / meshes_found.size(); |
| 935 | p_bake_step(p * 0.1, vformat(RTR("Preparing geometry %d/%d"), m_i, meshes_found.size()), p_bake_userdata, false); |
| 936 | } |
| 937 | |
| 938 | MeshesFound &mf = meshes_found.write[m_i]; |
| 939 | |
| 940 | Size2i mesh_lightmap_size = mf.mesh->get_lightmap_size_hint(); |
| 941 | if (mesh_lightmap_size == Size2i(0, 0)) { |
| 942 | /// @todo We should compute a size if no lightmap hint is set, as we did in 3.x. |
| 943 | /// For now set to basic size to avoid crash. |
| 944 | mesh_lightmap_size = Size2i(64, 64); |
| 945 | } |
| 946 | // Double lightmap texel density if downsampling is enabled, as the final texture size will be halved before saving lightmaps. |
| 947 | Size2i lightmap_size = Size2i(Size2(mesh_lightmap_size) * mf.lightmap_scale * texel_scale) * (supersampling_enabled ? supersampling_factor : 1.0); |
| 948 | ERR_FAIL_COND_V(lightmap_size.x == 0 || lightmap_size.y == 0, BAKE_ERROR_LIGHTMAP_TOO_SMALL); |
| 949 | |
| 950 | TypedArray<RID> overrides; |
nothing calls this directly
no test coverage detected