forked from bartvdbraak/blender
de-duplicate dominant axis calculation, exact same checks were in 6 different places.
added function: axis_dominant_v3(...)
This commit is contained in:
parent
20620a988a
commit
06c3d5bd09
@ -260,6 +260,8 @@ MINLINE void madd_sh_shfl(float r[9], const float sh[3], const float f);
|
||||
float form_factor_hemi_poly(float p[3], float n[3],
|
||||
float v1[3], float v2[3], float v3[3], float v4[3]);
|
||||
|
||||
void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -133,7 +133,8 @@ float area_poly_v3(int nr, float verts[][3], const float normal[3])
|
||||
float *cur, *prev;
|
||||
int a, px=0, py=1;
|
||||
|
||||
/* first: find dominant axis: 0==X, 1==Y, 2==Z */
|
||||
/* first: find dominant axis: 0==X, 1==Y, 2==Z
|
||||
* don't use 'axis_dominant_v3()' because we need max axis too */
|
||||
x= fabsf(normal[0]);
|
||||
y= fabsf(normal[1]);
|
||||
z= fabsf(normal[2]);
|
||||
@ -1689,6 +1690,18 @@ void plot_line_v2v2i(const int p1[2], const int p2[2], int (*callback)(int, int,
|
||||
|
||||
/****************************** Interpolation ********************************/
|
||||
|
||||
/* get the 2 dominant axis values, 0==X, 1==Y, 2==Z */
|
||||
void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3])
|
||||
{
|
||||
const float xn= fabsf(axis[0]);
|
||||
const float yn= fabsf(axis[1]);
|
||||
const float zn= fabsf(axis[2]);
|
||||
|
||||
if (zn >= xn && zn >= yn) { *axis_a= 0; *axis_b= 1; }
|
||||
else if (yn >= xn && yn >= zn) { *axis_a= 0; *axis_b= 2; }
|
||||
else { *axis_a= 1; *axis_b= 2; }
|
||||
}
|
||||
|
||||
static float tri_signed_area(const float v1[3], const float v2[3], const float v3[3], const int i, const int j)
|
||||
{
|
||||
return 0.5f*((v1[i]-v2[i])*(v2[j]-v3[j]) + (v1[j]-v2[j])*(v3[i]-v2[i]));
|
||||
@ -1696,17 +1709,10 @@ static float tri_signed_area(const float v1[3], const float v2[3], const float v
|
||||
|
||||
static int barycentric_weights(const float v1[3], const float v2[3], const float v3[3], const float co[3], const float n[3], float w[3])
|
||||
{
|
||||
float xn, yn, zn, a1, a2, a3, asum;
|
||||
short i, j;
|
||||
float a1, a2, a3, asum;
|
||||
int i, j;
|
||||
|
||||
/* find best projection of face XY, XZ or YZ: barycentric weights of
|
||||
the 2d projected coords are the same and faster to compute */
|
||||
xn= fabsf(n[0]);
|
||||
yn= fabsf(n[1]);
|
||||
zn= fabsf(n[2]);
|
||||
if(zn>=xn && zn>=yn) {i= 0; j= 1;}
|
||||
else if(yn>=xn && yn>=zn) {i= 0; j= 2;}
|
||||
else {i= 1; j= 2;}
|
||||
axis_dominant_v3(&i, &j, n);
|
||||
|
||||
a1= tri_signed_area(v2, v3, co, i, j);
|
||||
a2= tri_signed_area(v3, v1, co, i, j);
|
||||
|
@ -96,7 +96,7 @@ ListBase fillvertbase = {NULL, NULL};
|
||||
ListBase filledgebase = {NULL, NULL};
|
||||
ListBase fillfacebase = {NULL, NULL};
|
||||
|
||||
static short cox, coy;
|
||||
static int cox, coy;
|
||||
|
||||
/* **** FUBCTIONS FOR QSORT *************************** */
|
||||
|
||||
@ -825,19 +825,7 @@ int BLI_edgefill(short mat_nr)
|
||||
|
||||
if(len==0.0f) return 0; /* no fill possible */
|
||||
|
||||
norm[0]= fabs(norm[0]);
|
||||
norm[1]= fabs(norm[1]);
|
||||
norm[2]= fabs(norm[2]);
|
||||
|
||||
if(norm[2]>=norm[0] && norm[2]>=norm[1]) {
|
||||
cox= 0; coy= 1;
|
||||
}
|
||||
else if(norm[1]>=norm[0] && norm[1]>=norm[2]) {
|
||||
cox= 0; coy= 2;
|
||||
}
|
||||
else {
|
||||
cox= 1; coy= 2;
|
||||
}
|
||||
axis_dominant_v3(&cox, &coy, norm);
|
||||
|
||||
/* STEP 1: COUNT POLYS */
|
||||
eve= fillvertbase.first;
|
||||
|
@ -1342,16 +1342,9 @@ static int cube_project_exec(bContext *C, wmOperator *op)
|
||||
if(efa->f & SELECT) {
|
||||
tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
|
||||
normal_tri_v3( no,efa->v1->co, efa->v2->co, efa->v3->co);
|
||||
|
||||
no[0]= fabs(no[0]);
|
||||
no[1]= fabs(no[1]);
|
||||
no[2]= fabs(no[2]);
|
||||
|
||||
cox=0; coy= 1;
|
||||
if(no[2]>=no[0] && no[2]>=no[1]);
|
||||
else if(no[1]>=no[0] && no[1]>=no[2]) coy= 2;
|
||||
else { cox= 1; coy= 2; }
|
||||
|
||||
|
||||
axis_dominant_v3(&cox, &coy, no);
|
||||
|
||||
tf->uv[0][0]= 0.5f+0.5f*cube_size*(loc[cox] + efa->v1->co[cox]);
|
||||
tf->uv[0][1]= 0.5f+0.5f*cube_size*(loc[coy] + efa->v1->co[coy]);
|
||||
dx = floor(tf->uv[0][0]);
|
||||
|
@ -485,18 +485,12 @@ void makeraytree(Render *re)
|
||||
/* if(shi->osatex) */
|
||||
static void shade_ray_set_derivative(ShadeInput *shi)
|
||||
{
|
||||
float detsh, t00, t10, t01, t11, xn, yn, zn;
|
||||
float detsh, t00, t10, t01, t11;
|
||||
int axis1, axis2;
|
||||
|
||||
/* find most stable axis to project */
|
||||
xn= fabs(shi->facenor[0]);
|
||||
yn= fabs(shi->facenor[1]);
|
||||
zn= fabs(shi->facenor[2]);
|
||||
|
||||
if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
|
||||
else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
|
||||
else { axis1= 1; axis2= 2; }
|
||||
|
||||
axis_dominant_v3(&axis1, &axis2, shi->facenor);
|
||||
|
||||
/* compute u,v and derivatives */
|
||||
if(shi->obi->flag & R_TRANSFORMED) {
|
||||
float v1[3], v2[3], v3[3];
|
||||
|
@ -3494,17 +3494,11 @@ void render_realtime_texture(ShadeInput *shi, Image *ima)
|
||||
static void textured_face_generate_uv(float *uv, float *normal, float *hit, float *v1, float *v2, float *v3)
|
||||
{
|
||||
|
||||
float detsh, t00, t10, t01, t11, xn, yn, zn;
|
||||
float detsh, t00, t10, t01, t11;
|
||||
int axis1, axis2;
|
||||
|
||||
/* find most stable axis to project */
|
||||
xn= fabs(normal[0]);
|
||||
yn= fabs(normal[1]);
|
||||
zn= fabs(normal[2]);
|
||||
|
||||
if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
|
||||
else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
|
||||
else { axis1= 1; axis2= 2; }
|
||||
axis_dominant_v3(&axis1, &axis2, normal);
|
||||
|
||||
/* compute u,v and derivatives */
|
||||
t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];
|
||||
|
@ -756,17 +756,11 @@ void shade_input_set_uv(ShadeInput *shi)
|
||||
}
|
||||
else {
|
||||
/* most of this could become re-used for faces */
|
||||
float detsh, t00, t10, t01, t11, xn, yn, zn;
|
||||
float detsh, t00, t10, t01, t11;
|
||||
int axis1, axis2;
|
||||
|
||||
/* find most stable axis to project */
|
||||
xn= fabs(shi->facenor[0]);
|
||||
yn= fabs(shi->facenor[1]);
|
||||
zn= fabs(shi->facenor[2]);
|
||||
|
||||
if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
|
||||
else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
|
||||
else { axis1= 1; axis2= 2; }
|
||||
axis_dominant_v3(&axis1, &axis2, shi->facenor);
|
||||
|
||||
/* compute u,v and derivatives */
|
||||
t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];
|
||||
|
Loading…
Reference in New Issue
Block a user