diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-06-10 17:25:35 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-06-10 17:27:09 +0400 |
commit | 05fa464a25eb1d82bc05b8d1047df0529d8fb5f4 (patch) | |
tree | cccde6b07d94d250b24f6afb1dd38dd7a6b123ce /extern/carve/carve-util.cc | |
parent | 3286c8f8fb5d08c65c10ce555bfd3551ae13a0d1 (diff) |
Fix T40551: Boolean Modifier distorts UVs
Mapping to original face was never working 100% reliably actually,
now use more robust method for this.
Diffstat (limited to 'extern/carve/carve-util.cc')
-rw-r--r-- | extern/carve/carve-util.cc | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/extern/carve/carve-util.cc b/extern/carve/carve-util.cc index d02b786fd2a..1106fa16a21 100644 --- a/extern/carve/carve-util.cc +++ b/extern/carve/carve-util.cc @@ -498,7 +498,7 @@ static inline void add_newell_cross_v3_v3v3(const Vector &v_prev, } // Axis matrix is being set for non-flat ngons only. -bool carve_checkPolyPlanarAndGetNormal(const std::vector<Vector> &vertices, +bool carve_checkPolyPlanarAndGetNormal(const std::vector<MeshSet<3>::vertex_t> &vertex_storage, const int verts_per_poly, const int *verts_of_poly, Matrix3 *axis_matrix_r) @@ -510,10 +510,10 @@ bool carve_checkPolyPlanarAndGetNormal(const std::vector<Vector> &vertices, else if (verts_per_poly == 4) { // Presumably faster than using generig n-gon check for quads. - const Vector &v1 = vertices[verts_of_poly[0]], - &v2 = vertices[verts_of_poly[1]], - &v3 = vertices[verts_of_poly[2]], - &v4 = vertices[verts_of_poly[3]]; + const Vector &v1 = vertex_storage[verts_of_poly[0]].v, + &v2 = vertex_storage[verts_of_poly[1]].v, + &v3 = vertex_storage[verts_of_poly[2]].v, + &v4 = vertex_storage[verts_of_poly[3]].v; Vector vec1, vec2, vec3, cross; @@ -532,14 +532,14 @@ bool carve_checkPolyPlanarAndGetNormal(const std::vector<Vector> &vertices, return fabs(production) < magnitude; } else { - const Vector *vert_prev = &vertices[verts_of_poly[verts_per_poly - 1]]; - const Vector *vert_curr = &vertices[verts_of_poly[0]]; + const Vector *vert_prev = &vertex_storage[verts_of_poly[verts_per_poly - 1]].v; + const Vector *vert_curr = &vertex_storage[verts_of_poly[0]].v; Vector normal = carve::geom::VECTOR(0.0, 0.0, 0.0); for (int i = 0; i < verts_per_poly; i++) { add_newell_cross_v3_v3v3(*vert_prev, *vert_curr, &normal); vert_prev = vert_curr; - vert_curr = &vertices[verts_of_poly[(i + 1) % verts_per_poly]]; + vert_curr = &vertex_storage[verts_of_poly[(i + 1) % verts_per_poly]].v; } if (normal.length2() < FLT_EPSILON) { @@ -552,11 +552,11 @@ bool carve_checkPolyPlanarAndGetNormal(const std::vector<Vector> &vertices, normal.normalize(); axis_dominant_v3_to_m3__bli(axis_matrix_r, normal); - Vector first_projected = *axis_matrix_r * vertices[verts_of_poly[0]]; + Vector first_projected = *axis_matrix_r * vertex_storage[verts_of_poly[0]].v; double min_z = first_projected[2], max_z = first_projected[2]; for (int i = 1; i < verts_per_poly; i++) { - const Vector &vertex = vertices[verts_of_poly[i]]; + const Vector &vertex = vertex_storage[verts_of_poly[i]].v; Vector projected = *axis_matrix_r * vertex; if (projected[2] < min_z) { min_z = projected[2]; @@ -579,7 +579,7 @@ bool carve_checkPolyPlanarAndGetNormal(const std::vector<Vector> &vertices, namespace { -int triangulateNGon_carveTriangulator(const std::vector<Vector> &vertices, +int triangulateNGon_carveTriangulator(const std::vector<MeshSet<3>::vertex_t> &vertex_storage, const int verts_per_poly, const int *verts_of_poly, const Matrix3 &axis_matrix, @@ -590,7 +590,7 @@ int triangulateNGon_carveTriangulator(const std::vector<Vector> &vertices, std::vector<carve::geom::vector<2> > poly_2d; poly_2d.reserve(verts_per_poly); for (int i = 0; i < verts_per_poly; ++i) { - projected = axis_matrix * vertices[verts_of_poly[i]]; + projected = axis_matrix * vertex_storage[verts_of_poly[i]].v; poly_2d.push_back(carve::geom::VECTOR(projected[0], projected[1])); } @@ -602,7 +602,7 @@ int triangulateNGon_carveTriangulator(const std::vector<Vector> &vertices, int triangulateNGon_importerTriangulator(struct ImportMeshData *import_data, CarveMeshImporter *mesh_importer, - const std::vector<Vector> &vertices, + const std::vector<MeshSet<3>::vertex_t> &vertex_storage, const int verts_per_poly, const int *verts_of_poly, const Matrix3 &axis_matrix, @@ -615,7 +615,7 @@ int triangulateNGon_importerTriangulator(struct ImportMeshData *import_data, Vector2D *poly_2d = new Vector2D[verts_per_poly]; Vector projected; for (int i = 0; i < verts_per_poly; ++i) { - projected = axis_matrix * vertices[verts_of_poly[i]]; + projected = axis_matrix * vertex_storage[verts_of_poly[i]].v; poly_2d[i][0] = projected[0]; poly_2d[i][1] = projected[1]; } @@ -663,7 +663,6 @@ bool pushTriangle(int v1, int v2, int v3, assert(triangle.b < triangle.c); if (triangles_storage->find(triangle) == triangles_storage->end()) { - face_indices->push_back(3); face_indices->push_back(v1); face_indices->push_back(v2); face_indices->push_back(v3); @@ -680,7 +679,7 @@ bool pushTriangle(int v1, int v2, int v3, int carve_triangulatePoly(struct ImportMeshData *import_data, CarveMeshImporter *mesh_importer, - const std::vector<Vector> &vertices, + const std::vector<MeshSet<3>::vertex_t> &vertex_storage, const int verts_per_poly, const int *verts_of_poly, const Matrix3 &axis_matrix, @@ -725,14 +724,14 @@ int carve_triangulatePoly(struct ImportMeshData *import_data, if (mesh_importer->triangulate2DPoly) { triangulateNGon_importerTriangulator(import_data, mesh_importer, - vertices, + vertex_storage, verts_per_poly, verts_of_poly, axis_matrix, &triangles); } else { - triangulateNGon_carveTriangulator(vertices, + triangulateNGon_carveTriangulator(vertex_storage, verts_per_poly, verts_of_poly, axis_matrix, |