Browse Source

Fixes how transform is applied to geometry in UV unwrap

Juan Linietsky 7 years ago
parent
commit
fa8a1fc420
2 changed files with 10 additions and 9 deletions
  1. 6 6
      editor/import/resource_importer_scene.cpp
  2. 4 3
      scene/resources/mesh.cpp

+ 6 - 6
editor/import/resource_importer_scene.cpp

@@ -849,15 +849,15 @@ void ResourceImporterScene::_find_meshes(Node *p_node, Map<Ref<ArrayMesh>, Trans
 
 		if (mesh.is_valid() && !meshes.has(mesh)) {
 			Spatial *s = mi;
-			while (s->get_parent_spatial()) {
+			Transform transform;
+			while (s) {
+				transform = transform * s->get_transform();
 				s = s->get_parent_spatial();
 			}
 
-			if (s == mi) {
-				meshes[mesh] = s->get_transform();
-			} else {
-				meshes[mesh] = s->get_transform() * mi->get_relative_transform(s);
-			}
+			meshes[mesh] = transform;
+
+			print_line("mesh transform: " + meshes[mesh]);
 		}
 	}
 	for (int i = 0; i < p_node->get_child_count(); i++) {

+ 4 - 3
scene/resources/mesh.cpp

@@ -1111,13 +1111,14 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe
 		for (int j = 0; j < vc; j++) {
 
 			Vector3 v = p_base_transform.xform(r[j]);
+			Vector3 n = p_base_transform.basis.xform(rn[j]).normalized();
 
 			vertices[(j + vertex_ofs) * 3 + 0] = v.x;
 			vertices[(j + vertex_ofs) * 3 + 1] = v.y;
 			vertices[(j + vertex_ofs) * 3 + 2] = v.z;
-			normals[(j + vertex_ofs) * 3 + 0] = rn[j].x;
-			normals[(j + vertex_ofs) * 3 + 1] = rn[j].y;
-			normals[(j + vertex_ofs) * 3 + 2] = rn[j].z;
+			normals[(j + vertex_ofs) * 3 + 0] = n.x;
+			normals[(j + vertex_ofs) * 3 + 1] = n.y;
+			normals[(j + vertex_ofs) * 3 + 2] = n.z;
 			uv_index[j + vertex_ofs] = Pair<int, int>(i, j);
 		}