Fix T37486: Displacement bake from multires crashes when preview level is on 0

Revert "Code cleanup: remove unused block from multire baker"

This reverts commit 63b01f6beee8eced14ff013ca93732f5c176ad10.

Multires displacement baker in fact uses level 0 for the
original subdivided mesh. Missed this when was making an
original commit.
This commit is contained in:
Sergey Sharybin 2013-11-18 13:05:57 +06:00
parent 69cbf3d835
commit 8b3524c215

@ -611,9 +611,6 @@ static void get_ccgdm_data(DerivedMesh *lodm, DerivedMesh *hidm,
float crn_x, crn_y;
int grid_size, S, face_side;
int *grid_offset, g_index;
int side, grid_index, loc_offs, cell_index, cell_side, row, col;
BLI_assert(lvl > 0);
lodm->getTessFace(lodm, face_index, &mface);
@ -624,19 +621,25 @@ static void get_ccgdm_data(DerivedMesh *lodm, DerivedMesh *hidm,
face_side = (grid_size << 1) - 1;
side = (1 << (lvl - 1)) + 1;
grid_index = DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, face_index);
loc_offs = face_index % (1 << (2 * lvl));
cell_index = loc_offs % ((side - 1) * (side - 1));
cell_side = (grid_size - 1) / (side - 1);
row = cell_index / (side - 1);
col = cell_index % (side - 1);
if (lvl == 0) {
g_index = grid_offset[face_index];
S = mdisp_rot_face_to_crn(mface.v4 ? 4 : 3, face_side, u * (face_side - 1), v * (face_side - 1), &crn_x, &crn_y);
}
else {
int side = (1 << (lvl - 1)) + 1;
int grid_index = DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, face_index);
int loc_offs = face_index % (1 << (2 * lvl));
int cell_index = loc_offs % ((side - 1) * (side - 1));
int cell_side = (grid_size - 1) / (side - 1);
int row = cell_index / (side - 1);
int col = cell_index % (side - 1);
S = face_index / (1 << (2 * (lvl - 1))) - grid_offset[grid_index];
g_index = grid_offset[grid_index];
S = face_index / (1 << (2 * (lvl - 1))) - grid_offset[grid_index];
g_index = grid_offset[grid_index];
crn_y = (row * cell_side) + u * cell_side;
crn_x = (col * cell_side) + v * cell_side;
crn_y = (row * cell_side) + u * cell_side;
crn_x = (col * cell_side) + v * cell_side;
}
CLAMP(crn_x, 0.0f, grid_size);
CLAMP(crn_y, 0.0f, grid_size);