@@ -99,49 +99,6 @@ static void _attach_meta_to_extras(Ref<Resource> p_node, Dictionary &p_json) {
9999 }
100100}
101101
102- static Ref<ImporterMesh> _mesh_to_importer_mesh (Ref<Mesh> p_mesh) {
103- Ref<ImporterMesh> importer_mesh;
104- importer_mesh.instantiate ();
105- if (p_mesh.is_null ()) {
106- return importer_mesh;
107- }
108-
109- Ref<ArrayMesh> array_mesh = p_mesh;
110- if (p_mesh->get_blend_shape_count ()) {
111- ArrayMesh::BlendShapeMode shape_mode = ArrayMesh::BLEND_SHAPE_MODE_NORMALIZED;
112- if (array_mesh.is_valid ()) {
113- shape_mode = array_mesh->get_blend_shape_mode ();
114- }
115- importer_mesh->set_blend_shape_mode (shape_mode);
116- for (int morph_i = 0 ; morph_i < p_mesh->get_blend_shape_count (); morph_i++) {
117- importer_mesh->add_blend_shape (p_mesh->get_blend_shape_name (morph_i));
118- }
119- }
120- for (int32_t surface_i = 0 ; surface_i < p_mesh->get_surface_count (); surface_i++) {
121- Array array = p_mesh->surface_get_arrays (surface_i);
122- Ref<Material> mat = p_mesh->surface_get_material (surface_i);
123- const String surface_name = array_mesh.is_valid () ? array_mesh->surface_get_name (surface_i) : String ();
124- String mat_name;
125- if (mat.is_valid ()) {
126- mat_name = mat->get_name ();
127- if (mat_name.is_empty ()) {
128- mat_name = surface_name;
129- }
130- } else {
131- mat_name = surface_name;
132- // Assign default material when no material is assigned.
133- mat.instantiate ();
134- mat->set_name (mat_name);
135- }
136- importer_mesh->add_surface (p_mesh->surface_get_primitive_type (surface_i),
137- array, p_mesh->surface_get_blend_shape_arrays (surface_i), p_mesh->surface_get_lods (surface_i), mat,
138- mat_name, p_mesh->surface_get_format (surface_i));
139- }
140- importer_mesh->merge_meta_from (*p_mesh);
141- importer_mesh->set_name (p_mesh->get_name ());
142- return importer_mesh;
143- }
144-
145102Error GLTFDocument::_serialize (Ref<GLTFState> p_state) {
146103 for (Ref<GLTFDocumentExtension> ext : document_extensions) {
147104 ERR_CONTINUE (ext.is_null ());
@@ -4074,7 +4031,6 @@ GLTFMeshIndex GLTFDocument::_convert_mesh_to_gltf(Ref<GLTFState> p_state, MeshIn
40744031 Ref<Material> mat = p_mesh_instance->get_active_material (surface_i);
40754032 instance_materials.append (mat);
40764033 }
4077- Ref<ImporterMesh> current_mesh = _mesh_to_importer_mesh (mesh_resource);
40784034 Vector<float > blend_weights;
40794035 int32_t blend_count = mesh_resource->get_blend_shape_count ();
40804036 blend_weights.resize (blend_count);
@@ -4089,7 +4045,7 @@ GLTFMeshIndex GLTFDocument::_convert_mesh_to_gltf(Ref<GLTFState> p_state, MeshIn
40894045 gltf_mesh->set_name (_gen_unique_name (p_state, mesh_resource->get_name ()));
40904046 }
40914047 gltf_mesh->set_instance_materials (instance_materials);
4092- gltf_mesh->set_mesh (current_mesh );
4048+ gltf_mesh->set_mesh (ImporterMesh::from_mesh (mesh_resource) );
40934049 gltf_mesh->set_blend_weights (blend_weights);
40944050 GLTFMeshIndex mesh_i = p_state->meshes .size ();
40954051 p_state->meshes .push_back (gltf_mesh);
@@ -4354,7 +4310,7 @@ void GLTFDocument::_convert_grid_map_to_gltf(GridMap *p_grid_map, GLTFNodeIndex
43544310 Vector3 (cell_location.x , cell_location.y , cell_location.z )));
43554311 Ref<GLTFMesh> gltf_mesh;
43564312 gltf_mesh.instantiate ();
4357- gltf_mesh->set_mesh (_mesh_to_importer_mesh (p_grid_map->get_mesh_library ()->get_item_mesh (cell)));
4313+ gltf_mesh->set_mesh (ImporterMesh::from_mesh (p_grid_map->get_mesh_library ()->get_item_mesh (cell)));
43584314 gltf_mesh->set_original_name (p_grid_map->get_mesh_library ()->get_item_name (cell));
43594315 const String unique_name = _gen_unique_name (p_state, p_grid_map->get_mesh_library ()->get_item_name (cell));
43604316 gltf_mesh->set_name (unique_name);
@@ -4385,29 +4341,7 @@ void GLTFDocument::_convert_multi_mesh_instance_to_gltf(
43854341 }
43864342 gltf_mesh->set_original_name (multi_mesh->get_name ());
43874343 gltf_mesh->set_name (multi_mesh->get_name ());
4388- Ref<ImporterMesh> importer_mesh;
4389- importer_mesh.instantiate ();
4390- Ref<ArrayMesh> array_mesh = multi_mesh->get_mesh ();
4391- if (array_mesh.is_valid ()) {
4392- importer_mesh->set_blend_shape_mode (array_mesh->get_blend_shape_mode ());
4393- for (int32_t blend_i = 0 ; blend_i < array_mesh->get_blend_shape_count (); blend_i++) {
4394- importer_mesh->add_blend_shape (array_mesh->get_blend_shape_name (blend_i));
4395- }
4396- }
4397- for (int32_t surface_i = 0 ; surface_i < mesh->get_surface_count (); surface_i++) {
4398- Ref<Material> mat = mesh->surface_get_material (surface_i);
4399- String material_name;
4400- if (mat.is_valid ()) {
4401- material_name = mat->get_name ();
4402- }
4403- Array blend_arrays;
4404- if (array_mesh.is_valid ()) {
4405- blend_arrays = array_mesh->surface_get_blend_shape_arrays (surface_i);
4406- }
4407- importer_mesh->add_surface (mesh->surface_get_primitive_type (surface_i), mesh->surface_get_arrays (surface_i),
4408- blend_arrays, mesh->surface_get_lods (surface_i), mat, material_name, mesh->surface_get_format (surface_i));
4409- }
4410- gltf_mesh->set_mesh (importer_mesh);
4344+ gltf_mesh->set_mesh (ImporterMesh::from_mesh (mesh));
44114345 GLTFMeshIndex mesh_index = p_state->meshes .size ();
44124346 p_state->meshes .push_back (gltf_mesh);
44134347 for (int32_t instance_i = 0 ; instance_i < multi_mesh->get_instance_count ();
0 commit comments