static void get_ccgdm_data(DerivedMesh *lodm, DerivedMesh *hidm,
                           const int *index_mf_to_mpoly, const int *index_mp_to_orig,
                           const int lvl, const int face_index, const float u, const float v, float co[3], float n[3])
{
	MFace mface;
	CCGElem **grid_data;
	CCGKey key;
	float crn_x, crn_y;
	int grid_size, S, face_side;
	int *grid_offset, g_index;

	lodm->getTessFace(lodm, face_index, &mface);

	grid_size = hidm->getGridSize(hidm);
	grid_data = hidm->getGridData(hidm);
	grid_offset = hidm->getGridOffset(hidm);
	hidm->getGridKey(hidm, &key);

	face_side = (grid_size << 1) - 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];

		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);

	if (n != NULL)
		interp_bilinear_grid(&key, grid_data[g_index + S], crn_x, crn_y, 0, n);

	if (co != NULL)
		interp_bilinear_grid(&key, grid_data[g_index + S], crn_x, crn_y, 1, co);
}
Exemple #2
0
static void get_ccgdm_data(DerivedMesh *lodm, DerivedMesh *hidm,  const int lvl, const int face_index, const float u, const float v, float co[3], float n[3])
{
	MFace mface;
	DMGridData **grid_data;
	float crn_x, crn_y;
	int grid_size, S, face_side;
	int *grid_offset, g_index;

	lodm->getFace(lodm, face_index, &mface);

	grid_size= hidm->getGridSize(hidm);
	grid_data= hidm->getGridData(hidm);
	grid_offset= hidm->getGridOffset(hidm);

	face_side= (grid_size<<1)-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 {
		const int *index= lodm->getFaceDataArray(lodm, CD_ORIGINDEX);
		int side= (1 << (lvl-1)) + 1;
		int grid_index= index[face_index];
		int loc_offs= face_index % (1<<(2*lvl));
		int cell_index= loc_offs % ((side-1)*(side-1));
		int cell_side= grid_size / (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];

		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);

	if(n != NULL)
		interp_bilinear_grid(grid_data[g_index + S], grid_size, crn_x, crn_y, 0, n);

	if(co != NULL)
		interp_bilinear_grid(grid_data[g_index + S], grid_size, crn_x, crn_y, 1, co);
}