Merging fluidcontrol to trunk from rev16649 fluidcontrol branch. Code provided by Nils Thuerey.
This commit is contained in:
@@ -674,94 +674,6 @@ static void calc_vertexnormals(Render *re, ObjectRen *obr, int do_tangent, int d
|
||||
MEM_freeN(vtangents);
|
||||
}
|
||||
|
||||
// NT same as calc_vertexnormals, but dont modify the existing vertex normals
|
||||
// only recalculate other render data. If this is at some point used for other things than fluidsim,
|
||||
// this could be made on option for the normal calc_vertexnormals
|
||||
static void calc_fluidsimnormals(Render *re, ObjectRen *obr, int do_nmap_tangent)
|
||||
{
|
||||
int a;
|
||||
|
||||
/* dont clear vertex normals here */
|
||||
// OFF for(a=0; a<obr->totvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); ver->n[0]=ver->n[1]=ver->n[2]= 0.0; }
|
||||
/* calculate cos of angles and point-masses, use as weight factor to add face normal to vertex */
|
||||
for(a=0; a<obr->totvlak; a++) {
|
||||
VlakRen *vlr= RE_findOrAddVlak(obr, a);
|
||||
if(vlr->flag & ME_SMOOTH) {
|
||||
VertRen *v1= vlr->v1;
|
||||
VertRen *v2= vlr->v2;
|
||||
VertRen *v3= vlr->v3;
|
||||
VertRen *v4= vlr->v4;
|
||||
float n1[3], n2[3], n3[3], n4[3];
|
||||
float fac1, fac2, fac3, fac4=0.0f;
|
||||
|
||||
if(re->flag & R_GLOB_NOPUNOFLIP)
|
||||
vlr->flag |= R_NOPUNOFLIP;
|
||||
|
||||
VecSubf(n1, v2->co, v1->co);
|
||||
Normalize(n1);
|
||||
VecSubf(n2, v3->co, v2->co);
|
||||
Normalize(n2);
|
||||
if(v4==NULL) {
|
||||
VecSubf(n3, v1->co, v3->co);
|
||||
Normalize(n3);
|
||||
fac1= saacos(-n1[0]*n3[0]-n1[1]*n3[1]-n1[2]*n3[2]);
|
||||
fac2= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]);
|
||||
fac3= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]);
|
||||
}
|
||||
else {
|
||||
VecSubf(n3, v4->co, v3->co);
|
||||
Normalize(n3);
|
||||
VecSubf(n4, v1->co, v4->co);
|
||||
Normalize(n4);
|
||||
|
||||
fac1= saacos(-n4[0]*n1[0]-n4[1]*n1[1]-n4[2]*n1[2]);
|
||||
fac2= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]);
|
||||
fac3= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]);
|
||||
fac4= saacos(-n3[0]*n4[0]-n3[1]*n4[1]-n3[2]*n4[2]);
|
||||
|
||||
if(!(vlr->flag & R_NOPUNOFLIP)) {
|
||||
if( check_vnormal(vlr->n, v4->n) ) fac4= -fac4;
|
||||
}
|
||||
}
|
||||
|
||||
//if(do_nmap_tangent)
|
||||
// calc_tangent_vector(obr, vlr, fac1, fac2, fac3, fac4);
|
||||
}
|
||||
if(do_nmap_tangent) {
|
||||
/* tangents still need to be calculated for flat faces too */
|
||||
/* weighting removed, they are not vertexnormals */
|
||||
//calc_tangent_vector(obr, vlr);
|
||||
}
|
||||
}
|
||||
|
||||
/* do solid faces */
|
||||
for(a=0; a<obr->totvlak; a++) {
|
||||
VlakRen *vlr= RE_findOrAddVlak(obr, a);
|
||||
if((vlr->flag & ME_SMOOTH)==0) {
|
||||
float *f1= vlr->v1->n;
|
||||
if(f1[0]==0.0 && f1[1]==0.0 && f1[2]==0.0) VECCOPY(f1, vlr->n);
|
||||
f1= vlr->v2->n;
|
||||
if(f1[0]==0.0 && f1[1]==0.0 && f1[2]==0.0) VECCOPY(f1, vlr->n);
|
||||
f1= vlr->v3->n;
|
||||
if(f1[0]==0.0 && f1[1]==0.0 && f1[2]==0.0) VECCOPY(f1, vlr->n);
|
||||
if(vlr->v4) {
|
||||
f1= vlr->v4->n;
|
||||
if(f1[0]==0.0 && f1[1]==0.0 && f1[2]==0.0) VECCOPY(f1, vlr->n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* normalize vertex normals */
|
||||
for(a=0; a<obr->totvert; a++) {
|
||||
VertRen *ver= RE_findOrAddVert(obr, a);
|
||||
Normalize(ver->n);
|
||||
if(do_nmap_tangent) {
|
||||
float *tav= RE_vertren_get_tangent(obr, ver, 0);
|
||||
if(tav) Normalize(tav);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Autosmoothing: */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -3181,12 +3093,6 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
|
||||
}
|
||||
}
|
||||
|
||||
if((ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) &&
|
||||
(ob->fluidsimSettings->type & OB_FLUIDSIM_DOMAIN)&&
|
||||
(ob->fluidsimSettings->meshSurface) ) {
|
||||
useFluidmeshNormals = 1;
|
||||
}
|
||||
|
||||
mvert= dm->getVertArray(dm);
|
||||
totvert= dm->getNumVerts(dm);
|
||||
|
||||
@@ -3209,17 +3115,6 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
|
||||
if(do_autosmooth==0) /* autosmooth on original unrotated data to prevent differences between frames */
|
||||
MTC_Mat4MulVecfl(mat, ver->co);
|
||||
|
||||
if(useFluidmeshNormals) {
|
||||
/* normals are inverted in render */
|
||||
xn = -mvert->no[0]/ 32767.0;
|
||||
yn = -mvert->no[1]/ 32767.0;
|
||||
zn = -mvert->no[2]/ 32767.0;
|
||||
/* transfor to cam space */
|
||||
ver->n[0]= imat[0][0]*xn+imat[0][1]*yn+imat[0][2]*zn;
|
||||
ver->n[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn;
|
||||
ver->n[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn;
|
||||
} // useFluidmeshNormals
|
||||
|
||||
if(orco) {
|
||||
ver->orco= orco;
|
||||
orco+=3;
|
||||
@@ -3399,12 +3294,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
|
||||
autosmooth(re, obr, mat, me->smoothresh);
|
||||
}
|
||||
|
||||
if(useFluidmeshNormals) {
|
||||
// do not recalculate, only init render data
|
||||
calc_fluidsimnormals(re, obr, need_tangent||need_nmap_tangent);
|
||||
} else {
|
||||
calc_vertexnormals(re, obr, need_tangent, need_nmap_tangent);
|
||||
}
|
||||
calc_vertexnormals(re, obr, need_tangent, need_nmap_tangent);
|
||||
|
||||
if(need_stress)
|
||||
calc_edge_stress(re, obr, me);
|
||||
@@ -5292,7 +5182,7 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float *
|
||||
//fsvec[0] = fsvec[1] = fsvec[2] = fsvec[3] = 0.; fsvec[2] = 2.; // NT fixed test
|
||||
for(j=0;j<3;j++) fsvec[j] = vverts[a].co[j];
|
||||
|
||||
/* (bad) HACK insert average velocity if none is there (see previous comment */
|
||||
/* (bad) HACK insert average velocity if none is there (see previous comment) */
|
||||
if((fsvec[0] == 0.0) && (fsvec[1] == 0.0) && (fsvec[2] == 0.0))
|
||||
{
|
||||
fsvec[0] = avgvel[0];
|
||||
@@ -5436,6 +5326,7 @@ void RE_Database_FromScene_Vectors(Render *re, Scene *sce)
|
||||
oldobi= table->first;
|
||||
for(obi= re->instancetable.first; obi && oldobi; obi= obi->next) {
|
||||
int ok= 1;
|
||||
FluidsimModifierData *fluidmd;
|
||||
|
||||
if(!(obi->obr->flag & R_NEED_VECTORS))
|
||||
continue;
|
||||
@@ -5459,7 +5350,8 @@ void RE_Database_FromScene_Vectors(Render *re, Scene *sce)
|
||||
}
|
||||
|
||||
// NT check for fluidsim special treatment
|
||||
if((obi->ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) && (obi->ob->fluidsimSettings->type & OB_FLUIDSIM_DOMAIN)) {
|
||||
fluidmd = (FluidsimModifierData *)modifiers_findByType(obi->ob, eModifierType_Fluidsim);
|
||||
if(fluidmd && fluidmd->fss && (fluidmd->fss->type & OB_FLUIDSIM_DOMAIN)) {
|
||||
// use preloaded per vertex simulation data , only does calculation for step=1
|
||||
// NOTE/FIXME - velocities and meshes loaded unnecessarily often during the database_fromscene_vectors calls...
|
||||
load_fluidsimspeedvectors(re, obi, oldobi->vectors, step);
|
||||
|
||||
Reference in New Issue
Block a user