Browse Source

SoftBody add MeshInstance Material correctly

Andrea Catania 7 years ago
parent
commit
7949ba771b
1 changed files with 4 additions and 2 deletions
  1. 4 2
      scene/3d/soft_body.cpp

+ 4 - 2
scene/3d/soft_body.cpp

@@ -453,6 +453,9 @@ void SoftBody::become_mesh_owner() {
 	if (!mesh_owner) {
 	if (!mesh_owner) {
 		mesh_owner = true;
 		mesh_owner = true;
 
 
+		Vector<Ref<Material> > copy_materials;
+		copy_materials.append_array(materials);
+
 		ERR_FAIL_COND(!mesh->get_surface_count());
 		ERR_FAIL_COND(!mesh->get_surface_count());
 
 
 		// Get current mesh array and create new mesh array with necessary flag for softbody
 		// Get current mesh array and create new mesh array with necessary flag for softbody
@@ -466,11 +469,10 @@ void SoftBody::become_mesh_owner() {
 		Ref<ArrayMesh> soft_mesh;
 		Ref<ArrayMesh> soft_mesh;
 		soft_mesh.instance();
 		soft_mesh.instance();
 		soft_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays, surface_blend_arrays, surface_format);
 		soft_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays, surface_blend_arrays, surface_format);
+		soft_mesh->surface_set_material(0, mesh->surface_get_material(0));
 
 
 		set_mesh(soft_mesh);
 		set_mesh(soft_mesh);
 
 
-		Vector<Ref<Material> > copy_materials;
-		copy_materials.append_array(materials);
 		for (int i = copy_materials.size() - 1; 0 <= i; --i) {
 		for (int i = copy_materials.size() - 1; 0 <= i; --i) {
 			set_surface_material(i, copy_materials[i]);
 			set_surface_material(i, copy_materials[i]);
 		}
 		}