Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/multires.c')
-rw-r--r--source/blender/blenkernel/intern/multires.c388
1 files changed, 0 insertions, 388 deletions
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index e7320ddf5dc..dbac2e756a5 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -1948,225 +1948,8 @@ void multires_topology_changed(Scene *scene, Object *ob)
}
#endif // BMESH_TODO
-/* makes displacement along grid boundary symmetrical */
-void multires_mdisp_smooth_bounds(MDisps *disps)
-{
- int x, y, side, S, corners;
- float (*out)[3];
-
- corners = multires_mdisp_corners(disps);
- side = sqrt(disps->totdisp / corners);
-
- out = disps->disps;
- for(S = 0; S < corners; S++) {
- for(y = 0; y < side; ++y) {
- for(x = 0; x < side; ++x, ++out) {
- float (*dispgrid)[3];
- float *data;
-
- if(x != 0 && y != 0) continue;
-
- if(corners == 4) {
- if(S == 0) {
- if(y == 0) {
- dispgrid = &disps->disps[1*side*side];
- data = dispgrid[side * x + 0];
-
- (*out)[0] = (*out)[0] + data[1];
- (*out)[1] = (*out)[1] - data[0];
- (*out)[2] = (*out)[2] + data[2];
-
- mul_v3_fl(*out, 0.5);
-
- data[0] = -(*out)[1];
- data[1] = (*out)[0];
- data[2] = (*out)[2];
- } else if (x == 0) {
- dispgrid = &disps->disps[3 * side * side];
- data = dispgrid[side * 0 + y];
-
- (*out)[0] = (*out)[0] - data[1];
- (*out)[1] = (*out)[1] + data[0];
- (*out)[2] = (*out)[2] + data[2];
-
- mul_v3_fl(*out, 0.5);
-
- data[0] = (*out)[1];
- data[1] = -(*out)[0];
- data[2] = (*out)[2];
- }
- } else if (S == 2) {
- if(y == 0) {
- dispgrid = &disps->disps[3 * side * side];
- data = dispgrid[side * x + 0];
-
- (*out)[0] = (*out)[0] + data[1];
- (*out)[1] = (*out)[1] - data[0];
- (*out)[2] = (*out)[2] + data[2];
-
- mul_v3_fl(*out, 0.5);
-
- data[0] = -(*out)[1];
- data[1] = (*out)[0];
- data[2] = (*out)[2];
- } else if(x == 0) {
- dispgrid = &disps->disps[1 * side * side];
- data = dispgrid[side * 0 + y];
-
- (*out)[0] = (*out)[0] - data[1];
- (*out)[1] = (*out)[1] + data[0];
- (*out)[2] = (*out)[2] + data[2];
-
- mul_v3_fl(*out, 0.5);
-
- data[0] = (*out)[1];
- data[1] = -(*out)[0];
- data[2] = (*out)[2];
- }
- }
- } else if (corners == 3) {
- if(S == 0) {
- if(y == 0) {
- dispgrid = &disps->disps[1*side*side];
- data = dispgrid[side * x + 0];
-
- (*out)[0] = (*out)[0] + data[1];
- (*out)[1] = (*out)[1] - data[0];
- (*out)[2] = (*out)[2] + data[2];
-
- mul_v3_fl(*out, 0.5);
-
- data[0] = -(*out)[1];
- data[1] = (*out)[0];
- data[2] = (*out)[2];
- } else if (x == 0) {
- dispgrid = &disps->disps[2 * side * side];
- data = dispgrid[side * 0 + y];
-
- (*out)[0] = (*out)[0] - data[1];
- (*out)[1] = (*out)[1] + data[0];
- (*out)[2] = (*out)[2] + data[2];
-
- mul_v3_fl(*out, 0.5);
-
- data[0] = (*out)[1];
- data[1] = -(*out)[0];
- data[2] = (*out)[2];
- }
- } else if (S == 2) {
- if(x == 0) {
- dispgrid = &disps->disps[1 * side * side];
- data = dispgrid[side * 0 + y];
-
- (*out)[0] = (*out)[0] - data[1];
- (*out)[1] = (*out)[1] + data[0];
- (*out)[2] = (*out)[2] + data[2];
-
- mul_v3_fl(*out, 0.5);
-
- data[0] = (*out)[1];
- data[1] = -(*out)[0];
- data[2] = (*out)[2];
- }
- }
- }
- }
- }
- }
-}
-
/***************** Multires interpolation stuff *****************/
-static void mdisp_get_crn_rect(int face_side, float crn[3][4][2])
-{
- float offset = face_side*0.5f - 0.5f;
- float mid[2];
-
- mid[0] = offset * 4 / 3;
- mid[1] = offset * 2 / 3;
-
- crn[0][0][0] = mid[0]; crn[0][0][1] = mid[1];
- crn[0][1][0] = offset; crn[0][1][1] = 0;
- crn[0][2][0] = 0; crn[0][2][1] = 0;
- crn[0][3][0] = offset; crn[0][3][1] = offset;
-
- crn[1][0][0] = mid[0]; crn[1][0][1] = mid[1];
- crn[1][1][0] = offset * 2; crn[1][1][1] = offset;
- crn[1][2][0] = offset * 2; crn[1][2][1] = 0;
- crn[1][3][0] = offset; crn[1][3][1] = 0;
-
- crn[2][0][0] = mid[0]; crn[2][0][1] = mid[1];
- crn[2][1][0] = offset; crn[2][1][1] = offset;
- crn[2][2][0] = offset * 2; crn[2][2][1] = offset * 2;
- crn[2][3][0] = offset * 2; crn[2][3][1] = offset;
-}
-
-static int mdisp_pt_in_crn(float p[2], float crn[4][2])
-{
- float v[2][2];
- float a[2][2];
-
- sub_v2_v2v2(v[0], crn[1], crn[0]);
- sub_v2_v2v2(v[1], crn[3], crn[0]);
-
- sub_v2_v2v2(a[0], p, crn[0]);
- sub_v2_v2v2(a[1], crn[2], crn[0]);
-
- if(cross_v2v2(a[0], v[0]) * cross_v2v2(a[1], v[0]) < 0)
- return 0;
-
- if(cross_v2v2(a[0], v[1]) * cross_v2v2(a[1], v[1]) < 0)
- return 0;
-
- return 1;
-}
-
-static void face_to_crn_interp(float u, float v, float v1[2], float v2[2], float v3[2], float v4[2], float *x)
-{
- float a = (v4[1]-v3[1])*v2[0]+(-v4[1]+v3[1])*v1[0]+(-v2[1]+v1[1])*v4[0]+(v2[1]-v1[1])*v3[0];
- float b = (v3[1]-v)*v2[0]+(v4[1]-2*v3[1]+v)*v1[0]+(-v4[1]+v3[1]+v2[1]-v1[1])*u+(v4[0]-v3[0])*v-v1[1]*v4[0]+(-v2[1]+2*v1[1])*v3[0];
- float c = (v3[1]-v)*v1[0]+(-v3[1]+v1[1])*u+v3[0]*v-v1[1]*v3[0];
- float d = b * b - 4 * a * c;
- float x1, x2;
-
- if(a == 0) {
- *x = -c / b;
- return;
- }
-
- x1 = (-b - sqrtf(d)) / (2 * a);
- x2 = (-b + sqrtf(d)) / (2 * a);
-
- *x = maxf(x1, x2);
-}
-
-void mdisp_rot_crn_to_face(const int S, const int corners, const int face_side, const float x, const float y, float *u, float *v)
-{
- float offset = face_side*0.5f - 0.5f;
-
- if(corners == 4) {
- if(S == 1) { *u= offset + x; *v = offset - y; }
- if(S == 2) { *u= offset + y; *v = offset + x; }
- if(S == 3) { *u= offset - x; *v = offset + y; }
- if(S == 0) { *u= offset - y; *v = offset - x; }
- } else {
- float crn[3][4][2], vec[4][2];
- float p[2];
-
- mdisp_get_crn_rect(face_side, crn);
-
- interp_v2_v2v2(vec[0], crn[S][0], crn[S][1], x / offset);
- interp_v2_v2v2(vec[1], crn[S][3], crn[S][2], x / offset);
- interp_v2_v2v2(vec[2], crn[S][0], crn[S][3], y / offset);
- interp_v2_v2v2(vec[3], crn[S][1], crn[S][2], y / offset);
-
- isect_seg_seg_v2_point(vec[0], vec[1], vec[2], vec[3], p);
-
- (*u) = p[0];
- (*v) = p[1];
- }
-}
-
/* Find per-corner coordinate with given per-face UV coord */
int mdisp_rot_face_to_crn(const int corners, const int face_side, const float u, const float v, float *x, float *y)
{
@@ -2210,174 +1993,3 @@ int mdisp_rot_face_to_crn(const int corners, const int face_side, const float u,
return S;
}
-
-/* Find per-corner coordinate with given per-face UV coord
- Practically as the previous funciton but it assumes a bit different coordinate system for triangles
- which is optimized for MDISP layer interpolation:
-
- v
- ^
- | /|
- | / |
- | / |
- |/______|___> u
-
- */
-int mdisp_rot_face_to_quad_crn(const int corners, const int face_side, const float u, const float v, float *x, float *y)
-{
- const float offset = face_side*0.5f - 0.5f;
- int S = 0;
-
- if (corners == 4) {
- if(u <= offset && v <= offset) S = 0;
- else if(u > offset && v <= offset) S = 1;
- else if(u > offset && v > offset) S = 2;
- else if(u <= offset && v >= offset) S = 3;
-
- if(S == 0) {
- *y = offset - u;
- *x = offset - v;
- } else if(S == 1) {
- *x = u - offset;
- *y = offset - v;
- } else if(S == 2) {
- *y = u - offset;
- *x = v - offset;
- } else if(S == 3) {
- *x= offset - u;
- *y = v - offset;
- }
- } else {
- float crn[3][4][2];
- float p[2] = {u, v};
-
- mdisp_get_crn_rect(face_side, crn);
-
- for (S = 0; S < 3; ++S) {
- if (mdisp_pt_in_crn(p, crn[S]))
- break;
- }
-
- face_to_crn_interp(u, v, crn[S][0], crn[S][1], crn[S][3], crn[S][2], &p[0]);
- face_to_crn_interp(u, v, crn[S][0], crn[S][3], crn[S][1], crn[S][2], &p[1]);
-
- *x = p[0] * offset;
- *y = p[1] * offset;
- }
-
- return S;
-}
-
-void mdisp_apply_weight(const int S, const int corners, int x, int y, const int face_side,
- float crn_weight[4][2], float *u_r, float *v_r)
-{
- float u, v, xl, yl;
- float mid1[2], mid2[2], mid3[2];
-
- mdisp_rot_crn_to_face(S, corners, face_side, x, y, &u, &v);
-
- if(corners == 4) {
- xl = u / (face_side - 1);
- yl = v / (face_side - 1);
-
- mid1[0] = crn_weight[0][0] * (1 - xl) + crn_weight[1][0] * xl;
- mid1[1] = crn_weight[0][1] * (1 - xl) + crn_weight[1][1] * xl;
- mid2[0] = crn_weight[3][0] * (1 - xl) + crn_weight[2][0] * xl;
- mid2[1] = crn_weight[3][1] * (1 - xl) + crn_weight[2][1] * xl;
- mid3[0] = mid1[0] * (1 - yl) + mid2[0] * yl;
- mid3[1] = mid1[1] * (1 - yl) + mid2[1] * yl;
- } else {
- yl = v / (face_side - 1);
-
- if(v == face_side - 1) xl = 1;
- else xl = 1 - (face_side - 1 - u) / (face_side - 1 - v);
-
- mid1[0] = crn_weight[0][0] * (1 - xl) + crn_weight[1][0] * xl;
- mid1[1] = crn_weight[0][1] * (1 - xl) + crn_weight[1][1] * xl;
- mid3[0] = mid1[0] * (1 - yl) + crn_weight[2][0] * yl;
- mid3[1] = mid1[1] * (1 - yl) + crn_weight[2][1] * yl;
- }
-
- *u_r = mid3[0];
- *v_r = mid3[1];
-}
-
-void mdisp_flip_disp(const int S, const int corners, const float axis_x[2], const float axis_y[2], float disp[3])
-{
- float crn_x[2], crn_y[2];
- float vx[2], vy[2], coord[2];
-
- if (corners == 4) {
- float x[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
- float y[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
-
- copy_v2_v2(crn_x, x[S]);
- copy_v2_v2(crn_y, y[S]);
-
- mul_v2_v2fl(vx, crn_x, disp[0]);
- mul_v2_v2fl(vy, crn_y, disp[1]);
- add_v2_v2v2(coord, vx, vy);
-
- project_v2_v2v2(vx, coord, axis_x);
- project_v2_v2v2(vy, coord, axis_y);
-
- disp[0] = len_v2(vx);
- disp[1] = len_v2(vy);
-
- if(dot_v2v2(vx, axis_x) < 0)
- disp[0] = -disp[0];
-
- if(dot_v2v2(vy, axis_y) < 0)
- disp[1] = -disp[1];
- } else {
- /* XXX: it was very overhead code to support displacement flipping
- for case of tris without visible profit.
- Maybe its not really big limitation? for now? (nazgul) */
- disp[0] = 0;
- disp[1] = 0;
- }
-}
-
-/* Join two triangular displacements into one quad
- Corners mapping:
- 2 -------- 3
- | \ tri2 |
- | \ |
- | tri1 \ |
- 0 -------- 1 */
-void mdisp_join_tris(MDisps *dst, MDisps *tri1, MDisps *tri2)
-{
- int side, st;
- int S, x, y, crn;
- float face_u, face_v, crn_u, crn_v;
- float (*out)[3];
- MDisps *src;
-
- if(dst->disps)
- MEM_freeN(dst->disps);
-
- side = sqrt(tri1->totdisp / 3);
- st = (side<<1)-1;
-
- dst->totdisp = 4 * side * side;
- out = dst->disps = MEM_callocN(3*dst->totdisp*sizeof(float), "join disps");
-
- for(S = 0; S < 4; S++)
- for(y = 0; y < side; ++y)
- for(x = 0; x < side; ++x, ++out) {
- mdisp_rot_crn_to_face(S, 4, st, x, y, &face_u, &face_v);
- face_u = st - 1 - face_u;
-
- if(face_v > face_u) {
- src = tri2;
- face_u = st - 1 - face_u;
- face_v = st - 1 - face_v;
- } else src = tri1;
-
- crn = mdisp_rot_face_to_quad_crn(3, st, face_u, face_v, &crn_u, &crn_v);
-
- old_mdisps_bilinear((*out), &src->disps[crn*side*side], side, crn_u, crn_v);
- (*out)[0] = 0;
- (*out)[1] = 0;
- }
-}