Proper fix T40156 Cycles Baking and applyRotation issues

This should be the final fix for the applyrotation issue. It baffles me
that the fix involves discarding the scale transformations for the
normals but it works so I'm happy with it.

Reviewers: campbellbarton

Differential Revision: https://developer.blender.org/D554
This commit is contained in:
Dalai Felinto 2014-05-29 12:20:29 -03:00
parent b2cad79500
commit 2057a3a2fc
Notes: blender-bot 2023-02-14 10:40:05 +01:00
Referenced by issue #40156, Cycles Baking and applyRotation issues
3 changed files with 22 additions and 15 deletions

View File

@ -522,11 +522,6 @@ static int bake(
if (ob_iter == ob_low)
continue;
if (!is_uniform_scaled_m4(ob_iter->obmat)) {
BKE_reportf(reports, RPT_INFO, "Selected objects must have uniform scale "
"(apply scale to object \"%s\" for correct results)", ob_iter->id.name + 2);
}
tot_highpoly ++;
}
@ -633,9 +628,14 @@ static int bake(
highpoly[i].ob->restrictflag &= ~OB_RESTRICT_RENDER;
/* lowpoly to highpoly transformation matrix */
copy_m4_m4(highpoly[i].mat_high, highpoly[i].ob->obmat);
invert_m4_m4(highpoly[i].imat_high, highpoly[i].mat_high);
highpoly[i].scale = mat4_to_scale(highpoly[i].mat_high);
copy_m4_m4(highpoly[i].obmat, highpoly[i].ob->obmat);
invert_m4_m4(highpoly[i].imat, highpoly[i].obmat);
/* rotation */
normalize_m4_m4(highpoly[i].rotmat, highpoly[i].imat);
zero_v3(highpoly[i].rotmat[3]);
if (is_negative_m4(highpoly[i].rotmat))
negate_m3(highpoly[i].rotmat);
i++;
}

View File

@ -61,9 +61,10 @@ typedef struct BakeHighPolyData {
struct ModifierData *tri_mod;
struct Mesh *me;
char restrict_flag;
float mat_high[4][4];
float imat_high[4][4];
float scale;
float obmat[4][4];
float imat[4][4];
float rotmat[4][4];
} BakeHighPolyData;
/* external_engine.c */

View File

@ -235,10 +235,10 @@ static bool cast_ray_highpoly(
hits[i].dist = 10000.0f;
/* transform the ray from the world space to the highpoly space */
mul_v3_m4v3(co_high, highpoly[i].imat_high, co);
mul_v3_m4v3(co_high, highpoly[i].imat, co);
copy_v3_v3(dir_high, dir);
mul_transposed_mat3_m4_v3(highpoly[i].mat_high, dir_high);
/* rotates */
mul_v3_m4v3(dir_high, highpoly[i].rotmat, dir);
normalize_v3(dir_high);
/* cast ray */
@ -248,7 +248,13 @@ static bool cast_ray_highpoly(
/* cull backface */
const float dot = dot_v3v3(dir_high, hits[i].no);
if (dot < 0.0f) {
float distance = hits[i].dist * highpoly[i].scale;
float distance;
float hit_world[3];
/* distance comparison in world space */
mul_v3_m4v3(hit_world, highpoly[i].obmat, hits[i].co);
distance = len_squared_v3v3(hit_world, co);
if (distance < hit_distance) {
hit_mesh = i;
hit_distance = distance;