Merge branch 'master' into blender2.8

This commit is contained in:
2018-12-01 08:17:00 +11:00
7 changed files with 284 additions and 274 deletions

View File

@@ -167,9 +167,9 @@ char *BLI_cpu_brand_string(void)
int result[4] = { 0 };
__cpuid(result, 0x80000000);
if (result[0] >= (int)0x80000004) {
__cpuid((int*)(buf + 0), 0x80000002);
__cpuid((int*)(buf + 16), 0x80000003);
__cpuid((int*)(buf + 32), 0x80000004);
__cpuid((int *)(buf + 0), 0x80000002);
__cpuid((int *)(buf + 16), 0x80000003);
__cpuid((int *)(buf + 32), 0x80000004);
char *brand = BLI_strdup(buf);
/* TODO(sergey): Make it a bit more presentable by removing trademark. */
return brand;

View File

@@ -152,7 +152,7 @@ static bool collision_response(ClothModifierData *clmd, CollisionModifierData *c
return false; /* XXX tested before already? */
/* only handle static collisions here */
if ( collpair->flag & COLLISION_IN_FUTURE )
if (collpair->flag & COLLISION_IN_FUTURE)
return false;
/* velocity */
@@ -263,8 +263,8 @@ static void cloth_setup_constraints(ClothModifierData *clmd, ColliderContacts *c
* collisions*/
static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothModifierData *clmd, float (*initial_cos)[3], float UNUSED(step), float dt)
{
Cloth *cloth= clmd->clothObject;
float (*cos)[3] = (float (*)[3])MEM_callocN(sizeof(float[3]) * cloth->mvert_num, "cos cloth_calc_helper_forces");
Cloth *cloth = clmd->clothObject;
float(*cos)[3] = (float(*)[3])MEM_callocN(sizeof(float[3]) * cloth->mvert_num, "cos cloth_calc_helper_forces");
float *masses = (float *)MEM_callocN(sizeof(float) * cloth->mvert_num, "cos cloth_calc_helper_forces");
LinkNode *node;
ClothSpring *spring;
@@ -284,8 +284,8 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo
}
steps = 55;
for (i=0; i<steps; i++) {
for (node=cloth->springs; node; node=node->next) {
for (i = 0; i < steps; i++) {
for (node = cloth->springs; node; node = node->next) {
/* ClothVertex *cv1, *cv2; */ /* UNUSED */
int v1, v2;
float len, c, l, vec[3];
@@ -325,7 +325,7 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo
/*compute forces*/
sub_v3_v3v3(vec, cos[i], cv->tx);
mul_v3_fl(vec, cv->mass*dt*20.0f);
mul_v3_fl(vec, cv->mass * dt * 20.0f);
add_v3_v3(cv->tv, vec);
//copy_v3_v3(cv->tx, cos[i]);
}
@@ -521,7 +521,7 @@ static void cloth_calc_force(Scene *scene, ClothModifierData *clmd, float UNUSED
/* handle external forces like wind */
if (effectors) {
/* cache per-vertex forces to avoid redundant calculation */
float (*winvec)[3] = (float (*)[3])MEM_callocN(sizeof(float[3]) * mvert_num, "effector forces");
float(*winvec)[3] = (float(*)[3])MEM_callocN(sizeof(float[3]) * mvert_num, "effector forces");
for (i = 0; i < cloth->mvert_num; i++) {
float x[3], v[3];
EffectedPoint epoint;
@@ -566,8 +566,8 @@ static void cloth_calc_force(Scene *scene, ClothModifierData *clmd, float UNUSED
else
BPH_mass_spring_force_vertex_wind(data, i, 1.0f, winvec);
}
}
#endif
}
MEM_freeN(winvec);
}
@@ -784,16 +784,16 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt)
zero_v3(b);
offset[axis] = shift * clmd->hair_grid_cellsize;
a[(axis+1) % 3] = clmd->hair_grid_max[(axis+1) % 3] - clmd->hair_grid_min[(axis+1) % 3];
b[(axis+2) % 3] = clmd->hair_grid_max[(axis+2) % 3] - clmd->hair_grid_min[(axis+2) % 3];
a[(axis + 1) % 3] = clmd->hair_grid_max[(axis + 1) % 3] - clmd->hair_grid_min[(axis + 1) % 3];
b[(axis + 2) % 3] = clmd->hair_grid_max[(axis + 2) % 3] - clmd->hair_grid_min[(axis + 2) % 3];
BKE_sim_debug_data_clear_category(clmd->debug_data, "grid velocity");
for (j = 0; j < size; ++j) {
for (i = 0; i < size; ++i) {
float x[3], v[3], gvel[3], gvel_smooth[3], gdensity;
madd_v3_v3v3fl(x, offset, a, (float)i / (float)(size-1));
madd_v3_v3fl(x, b, (float)j / (float)(size-1));
madd_v3_v3v3fl(x, offset, a, (float)i / (float)(size - 1));
madd_v3_v3fl(x, b, (float)j / (float)(size - 1));
zero_v3(v);
BPH_hair_volume_grid_interpolate(grid, x, &gdensity, gvel, gvel_smooth, NULL, NULL);
@@ -970,10 +970,10 @@ int BPH_cloth_solve(Depsgraph *depsgraph, Object *ob, float frame, ClothModifier
Scene *scene = DEG_get_evaluated_scene(depsgraph);
const bool is_hair = (clmd->hairdata != NULL);
unsigned int i=0;
float step=0.0f, tf=clmd->sim_parms->timescale;
unsigned int i = 0;
float step = 0.0f, tf = clmd->sim_parms->timescale;
Cloth *cloth = clmd->clothObject;
ClothVertex *verts = cloth->verts/*, *cv*/;
ClothVertex *verts = cloth->verts /*, *cv*/;
unsigned int mvert_num = cloth->mvert_num;
float dt = clmd->sim_parms->dt * clmd->sim_parms->timescale;
Implicit_Data *id = cloth->implicit;

View File

@@ -67,7 +67,7 @@ public:
coeffRef(k) = v[k];
}
Vector3& operator = (const ctype &v)
Vector3& operator =(const ctype &v)
{
for (int k = 0; k < 3; ++k)
coeffRef(k) = v[k];
@@ -98,7 +98,7 @@ public:
coeffRef(l, k) = v[k][l];
}
Matrix3& operator = (const ctype &v)
Matrix3& operator =(const ctype &v)
{
for (int k = 0; k < 3; ++k)
for (int l = 0; l < 3; ++l)
@@ -126,18 +126,18 @@ public:
}
template <typename T>
lVector3f& operator = (T rhs)
lVector3f& operator =(T rhs)
{
base_t::operator=(rhs);
return *this;
}
float* v3(int vertex)
float *v3(int vertex)
{
return &coeffRef(3 * vertex);
}
const float* v3(int vertex) const
const float *v3(int vertex) const
{
return &coeffRef(3 * vertex);
}

View File

@@ -93,7 +93,7 @@ typedef struct HairGrid {
float cellsize, inv_cellsize;
} HairGrid;
#define HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, axis) ( min_ii( max_ii( (int)((vec[axis] - gmin[axis]) * scale), 0), res[axis]-2 ) )
#define HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, axis) (min_ii(max_ii( (int)((vec[axis] - gmin[axis]) * scale), 0), res[axis] - 2) )
BLI_INLINE int hair_grid_offset(const float vec[3], const int res[3], const float gmin[3], float scale)
{
@@ -101,7 +101,7 @@ BLI_INLINE int hair_grid_offset(const float vec[3], const int res[3], const floa
i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0);
j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1);
k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2);
return i + (j + k*res[1])*res[0];
return i + (j + k * res[1]) * res[0];
}
BLI_INLINE int hair_grid_interp_weights(const int res[3], const float gmin[3], float scale, const float vec[3], float uvw[3])
@@ -111,7 +111,7 @@ BLI_INLINE int hair_grid_interp_weights(const int res[3], const float gmin[3], f
i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0);
j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1);
k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2);
offset = i + (j + k*res[1])*res[0];
offset = i + (j + k * res[1]) * res[0];
uvw[0] = (vec[0] - gmin[0]) * scale - (float)i;
uvw[1] = (vec[1] - gmin[1]) * scale - (float)j;
@@ -124,7 +124,8 @@ BLI_INLINE int hair_grid_interp_weights(const int res[3], const float gmin[3], f
return offset;
}
BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3], const float gmin[3], float scale, const float vec[3],
BLI_INLINE void hair_grid_interpolate(
const HairGridVert *grid, const int res[3], const float gmin[3], float scale, const float vec[3],
float *density, float velocity[3], float vel_smooth[3], float density_gradient[3], float velocity_gradient[3][3])
{
HairGridVert data[8];
@@ -138,56 +139,56 @@ BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3]
muvw[2] = 1.0f - uvw[2];
data[0] = grid[offset ];
data[1] = grid[offset +1];
data[2] = grid[offset +res[0] ];
data[3] = grid[offset +res[0]+1];
data[4] = grid[offset+res2 ];
data[5] = grid[offset+res2 +1];
data[6] = grid[offset+res2+res[0] ];
data[7] = grid[offset+res2+res[0]+1];
data[1] = grid[offset + 1];
data[2] = grid[offset + res[0] ];
data[3] = grid[offset + res[0] + 1];
data[4] = grid[offset + res2 ];
data[5] = grid[offset + res2 + 1];
data[6] = grid[offset + res2 + res[0] ];
data[7] = grid[offset + res2 + res[0] + 1];
if (density) {
*density = muvw[2]*( muvw[1]*( muvw[0]*data[0].density + uvw[0]*data[1].density ) +
uvw[1]*( muvw[0]*data[2].density + uvw[0]*data[3].density ) ) +
uvw[2]*( muvw[1]*( muvw[0]*data[4].density + uvw[0]*data[5].density ) +
uvw[1]*( muvw[0]*data[6].density + uvw[0]*data[7].density ) );
*density = muvw[2] * (muvw[1] * (muvw[0] * data[0].density + uvw[0] * data[1].density) +
uvw[1] * (muvw[0] * data[2].density + uvw[0] * data[3].density)) +
uvw[2] * (muvw[1] * (muvw[0] * data[4].density + uvw[0] * data[5].density) +
uvw[1] * (muvw[0] * data[6].density + uvw[0] * data[7].density));
}
if (velocity) {
int k;
for (k = 0; k < 3; ++k) {
velocity[k] = muvw[2]*( muvw[1]*( muvw[0]*data[0].velocity[k] + uvw[0]*data[1].velocity[k] ) +
uvw[1]*( muvw[0]*data[2].velocity[k] + uvw[0]*data[3].velocity[k] ) ) +
uvw[2]*( muvw[1]*( muvw[0]*data[4].velocity[k] + uvw[0]*data[5].velocity[k] ) +
uvw[1]*( muvw[0]*data[6].velocity[k] + uvw[0]*data[7].velocity[k] ) );
velocity[k] = muvw[2] * (muvw[1] * (muvw[0] * data[0].velocity[k] + uvw[0] * data[1].velocity[k]) +
uvw[1] * (muvw[0] * data[2].velocity[k] + uvw[0] * data[3].velocity[k]) ) +
uvw[2] * (muvw[1] * (muvw[0] * data[4].velocity[k] + uvw[0] * data[5].velocity[k]) +
uvw[1] * (muvw[0] * data[6].velocity[k] + uvw[0] * data[7].velocity[k]) );
}
}
if (vel_smooth) {
int k;
for (k = 0; k < 3; ++k) {
vel_smooth[k] = muvw[2]*( muvw[1]*( muvw[0]*data[0].velocity_smooth[k] + uvw[0]*data[1].velocity_smooth[k] ) +
uvw[1]*( muvw[0]*data[2].velocity_smooth[k] + uvw[0]*data[3].velocity_smooth[k] ) ) +
uvw[2]*( muvw[1]*( muvw[0]*data[4].velocity_smooth[k] + uvw[0]*data[5].velocity_smooth[k] ) +
uvw[1]*( muvw[0]*data[6].velocity_smooth[k] + uvw[0]*data[7].velocity_smooth[k] ) );
vel_smooth[k] = muvw[2] * (muvw[1] * (muvw[0] * data[0].velocity_smooth[k] + uvw[0] * data[1].velocity_smooth[k]) +
uvw[1] * (muvw[0] * data[2].velocity_smooth[k] + uvw[0] * data[3].velocity_smooth[k]) ) +
uvw[2] * (muvw[1] * (muvw[0] * data[4].velocity_smooth[k] + uvw[0] * data[5].velocity_smooth[k]) +
uvw[1] * (muvw[0] * data[6].velocity_smooth[k] + uvw[0] * data[7].velocity_smooth[k]) );
}
}
if (density_gradient) {
density_gradient[0] = muvw[1] * muvw[2] * ( data[0].density - data[1].density ) +
uvw[1] * muvw[2] * ( data[2].density - data[3].density ) +
muvw[1] * uvw[2] * ( data[4].density - data[5].density ) +
uvw[1] * uvw[2] * ( data[6].density - data[7].density );
density_gradient[0] = muvw[1] * muvw[2] * (data[0].density - data[1].density) +
uvw[1] * muvw[2] * (data[2].density - data[3].density) +
muvw[1] * uvw[2] * (data[4].density - data[5].density) +
uvw[1] * uvw[2] * (data[6].density - data[7].density);
density_gradient[1] = muvw[2] * muvw[0] * ( data[0].density - data[2].density ) +
uvw[2] * muvw[0] * ( data[4].density - data[6].density ) +
muvw[2] * uvw[0] * ( data[1].density - data[3].density ) +
uvw[2] * uvw[0] * ( data[5].density - data[7].density );
density_gradient[1] = muvw[2] * muvw[0] * (data[0].density - data[2].density) +
uvw[2] * muvw[0] * (data[4].density - data[6].density) +
muvw[2] * uvw[0] * (data[1].density - data[3].density) +
uvw[2] * uvw[0] * (data[5].density - data[7].density);
density_gradient[2] = muvw[2] * muvw[0] * ( data[0].density - data[4].density ) +
uvw[2] * muvw[0] * ( data[1].density - data[5].density ) +
muvw[2] * uvw[0] * ( data[2].density - data[6].density ) +
uvw[2] * uvw[0] * ( data[3].density - data[7].density );
density_gradient[2] = muvw[2] * muvw[0] * (data[0].density - data[4].density) +
uvw[2] * muvw[0] * (data[1].density - data[5].density) +
muvw[2] * uvw[0] * (data[2].density - data[6].density) +
uvw[2] * uvw[0] * (data[3].density - data[7].density);
}
if (velocity_gradient) {
@@ -196,7 +197,8 @@ BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3]
}
}
void BPH_hair_volume_vertex_grid_forces(HairGrid *grid, const float x[3], const float v[3],
void BPH_hair_volume_vertex_grid_forces(
HairGrid *grid, const float x[3], const float v[3],
float smoothfac, float pressurefac, float minpressure,
float f[3], float dfdx[3][3], float dfdv[3][3])
{
@@ -220,13 +222,15 @@ void BPH_hair_volume_vertex_grid_forces(HairGrid *grid, const float x[3], const
mul_m3_fl(dfdv, smoothfac);
}
void BPH_hair_volume_grid_interpolate(HairGrid *grid, const float x[3],
void BPH_hair_volume_grid_interpolate(
HairGrid *grid, const float x[3],
float *density, float velocity[3], float velocity_smooth[3], float density_gradient[3], float velocity_gradient[3][3])
{
hair_grid_interpolate(grid->verts, grid->res, grid->gmin, grid->inv_cellsize, x, density, velocity, velocity_smooth, density_gradient, velocity_gradient);
}
void BPH_hair_volume_grid_velocity(HairGrid *grid, const float x[3], const float v[3],
void BPH_hair_volume_grid_velocity(
HairGrid *grid, const float x[3], const float v[3],
float fluid_factor,
float r_v[3])
{
@@ -287,20 +291,20 @@ BLI_INLINE int hair_grid_weights(const int res[3], const float gmin[3], float sc
i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0);
j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1);
k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2);
offset = i + (j + k*res[1])*res[0];
offset = i + (j + k * res[1]) * res[0];
uvw[0] = (vec[0] - gmin[0]) * scale;
uvw[1] = (vec[1] - gmin[1]) * scale;
uvw[2] = (vec[2] - gmin[2]) * scale;
weights[0] = dist_tent_v3f3(uvw, (float)i , (float)j , (float)k );
weights[1] = dist_tent_v3f3(uvw, (float)(i+1), (float)j , (float)k );
weights[2] = dist_tent_v3f3(uvw, (float)i , (float)(j+1), (float)k );
weights[3] = dist_tent_v3f3(uvw, (float)(i+1), (float)(j+1), (float)k );
weights[4] = dist_tent_v3f3(uvw, (float)i , (float)j , (float)(k+1));
weights[5] = dist_tent_v3f3(uvw, (float)(i+1), (float)j , (float)(k+1));
weights[6] = dist_tent_v3f3(uvw, (float)i , (float)(j+1), (float)(k+1));
weights[7] = dist_tent_v3f3(uvw, (float)(i+1), (float)(j+1), (float)(k+1));
weights[1] = dist_tent_v3f3(uvw, (float)(i + 1), (float)j , (float)k );
weights[2] = dist_tent_v3f3(uvw, (float)i , (float)(j + 1), (float)k );
weights[3] = dist_tent_v3f3(uvw, (float)(i + 1), (float)(j + 1), (float)k );
weights[4] = dist_tent_v3f3(uvw, (float)i , (float)j , (float)(k + 1));
weights[5] = dist_tent_v3f3(uvw, (float)(i + 1), (float)j , (float)(k + 1));
weights[6] = dist_tent_v3f3(uvw, (float)i , (float)(j + 1), (float)(k + 1));
weights[7] = dist_tent_v3f3(uvw, (float)(i + 1), (float)(j + 1), (float)(k + 1));
// BLI_assert(fabsf(weights_sum(weights) - 1.0f) < 0.0001f);
@@ -329,8 +333,8 @@ void BPH_hair_volume_add_vertex(HairGrid *grid, const float x[3], const float v[
for (di = 0; di < 2; ++di) {
for (dj = 0; dj < 2; ++dj) {
for (dk = 0; dk < 2; ++dk) {
int voffset = offset + di + (dj + dk*res[1])*res[0];
int iw = di + dj*2 + dk*4;
int voffset = offset + di + (dj + dk * res[1]) * res[0];
int iw = di + dj * 2 + dk * 4;
grid->verts[voffset].density += weights[iw];
madd_v3_v3fl(grid->verts[voffset].velocity, v, weights[iw]);
@@ -340,7 +344,8 @@ void BPH_hair_volume_add_vertex(HairGrid *grid, const float x[3], const float v[
}
#if 0
BLI_INLINE void hair_volume_eval_grid_vertex(HairGridVert *vert, const float loc[3], float radius, float dist_scale,
BLI_INLINE void hair_volume_eval_grid_vertex(
HairGridVert *vert, const float loc[3], float radius, float dist_scale,
const float x2[3], const float v2[3], const float x3[3], const float v3[3])
{
float closest[3], lambda, dist, weight;
@@ -368,7 +373,8 @@ BLI_INLINE int major_axis_v3(const float v[3])
return a > b ? (a > c ? 0 : 2) : (b > c ? 1 : 2);
}
BLI_INLINE void hair_volume_add_segment_2D(HairGrid *grid,
BLI_INLINE void hair_volume_add_segment_2D(
HairGrid *grid,
const float UNUSED(x1[3]), const float UNUSED(v1[3]), const float x2[3], const float v2[3],
const float x3[3], const float v3[3], const float UNUSED(x4[3]), const float UNUSED(v4[3]),
const float UNUSED(dir1[3]), const float dir2[3], const float UNUSED(dir3[3]),
@@ -383,9 +389,9 @@ BLI_INLINE void hair_volume_add_segment_2D(HairGrid *grid,
/* boundary checks to be safe */
CLAMP_MIN(jmin, 0);
CLAMP_MAX(jmax, resj-1);
CLAMP_MAX(jmax, resj - 1);
CLAMP_MIN(kmin, 0);
CLAMP_MAX(kmax, resk-1);
CLAMP_MAX(kmax, resk - 1);
HairGridVert *vert_j = vert + jmin * stride_j;
float loc_j[3] = { loc[0], loc[1], loc[2] };
@@ -429,7 +435,8 @@ BLI_INLINE void hair_volume_add_segment_2D(HairGrid *grid,
*
*
*/
void BPH_hair_volume_add_segment(HairGrid *grid,
void BPH_hair_volume_add_segment(
HairGrid *grid,
const float x1[3], const float v1[3], const float x2[3], const float v2[3],
const float x3[3], const float v3[3], const float x4[3], const float v4[3],
const float dir1[3], const float dir2[3], const float dir3[3])
@@ -461,7 +468,7 @@ void BPH_hair_volume_add_segment(HairGrid *grid,
/* range along primary direction */
const int imin = max_ii(floor_int(start[axis0]) - 1, 0);
const int imax = min_ii(floor_int(end[axis0]) + 2, res[axis0]-1);
const int imax = min_ii(floor_int(end[axis0]) + 2, res[axis0] - 1);
float h = 0.0f;
HairGridVert *vert0;
@@ -500,14 +507,16 @@ void BPH_hair_volume_add_segment(HairGrid *grid,
loc0[axis1] = 0.0f;
loc0[axis2] = 0.0f;
hair_volume_add_segment_2D(grid, x1, v1, x2, v2, x3, v3, x4, v4, dir1, dir2, dir3,
res[axis1], res[axis2], jmin-1, jmax+2, kmin-1, kmax+2,
hair_volume_add_segment_2D(
grid, x1, v1, x2, v2, x3, v3, x4, v4, dir1, dir2, dir3,
res[axis1], res[axis2], jmin - 1, jmax + 2, kmin - 1, kmax + 2,
vert0, stride1, stride2, loc0, axis1, axis2,
i);
}
}
#else
BLI_INLINE void hair_volume_eval_grid_vertex_sample(HairGridVert *vert, const float loc[3], float radius, float dist_scale,
BLI_INLINE void hair_volume_eval_grid_vertex_sample(
HairGridVert *vert, const float loc[3], float radius, float dist_scale,
const float x[3], const float v[3])
{
float dist, weight;
@@ -526,7 +535,8 @@ BLI_INLINE void hair_volume_eval_grid_vertex_sample(HairGridVert *vert, const fl
/* XXX simplified test implementation using a series of discrete sample along the segment,
* instead of finding the closest point for all affected grid vertices.
*/
void BPH_hair_volume_add_segment(HairGrid *grid,
void BPH_hair_volume_add_segment(
HairGrid *grid,
const float UNUSED(x1[3]), const float UNUSED(v1[3]), const float x2[3], const float v2[3],
const float x3[3], const float v3[3], const float UNUSED(x4[3]), const float UNUSED(v4[3]),
const float UNUSED(dir1[3]), const float UNUSED(dir2[3]), const float UNUSED(dir3[3]))
@@ -544,16 +554,16 @@ void BPH_hair_volume_add_segment(HairGrid *grid,
float x[3], v[3];
int i, j, k;
float f = (float)s / (float)(num_samples-1);
float f = (float)s / (float)(num_samples - 1);
interp_v3_v3v3(x, x2, x3, f);
interp_v3_v3v3(v, v2, v3, f);
int imin = max_ii(floor_int(x[0]) - 2, 0);
int imax = min_ii(floor_int(x[0]) + 2, res[0]-1);
int imax = min_ii(floor_int(x[0]) + 2, res[0] - 1);
int jmin = max_ii(floor_int(x[1]) - 2, 0);
int jmax = min_ii(floor_int(x[1]) + 2, res[1]-1);
int jmax = min_ii(floor_int(x[1]) + 2, res[1] - 1);
int kmin = max_ii(floor_int(x[2]) - 2, 0);
int kmax = min_ii(floor_int(x[2]) + 2, res[2]-1);
int kmax = min_ii(floor_int(x[2]) + 2, res[2] - 1);
for (k = kmin; k <= kmax; ++k) {
for (j = jmin; j <= jmax; ++j) {
@@ -576,7 +586,7 @@ void BPH_hair_volume_normalize_vertex_grid(HairGrid *grid)
for (i = 0; i < size; i++) {
float density = grid->verts[i].density;
if (density > 0.0f)
mul_v3_fl(grid->verts[i].velocity, 1.0f/density);
mul_v3_fl(grid->verts[i].velocity, 1.0f / density);
}
}
@@ -620,16 +630,16 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target
#define MARGIN_i0 (i < 1)
#define MARGIN_j0 (j < 1)
#define MARGIN_k0 (k < 1)
#define MARGIN_i1 (i >= resA[0]-1)
#define MARGIN_j1 (j >= resA[1]-1)
#define MARGIN_k1 (k >= resA[2]-1)
#define MARGIN_i1 (i >= resA[0] - 1)
#define MARGIN_j1 (j >= resA[1] - 1)
#define MARGIN_k1 (k >= resA[2] - 1)
#define NEIGHBOR_MARGIN_i0 (i < 2)
#define NEIGHBOR_MARGIN_j0 (j < 2)
#define NEIGHBOR_MARGIN_k0 (k < 2)
#define NEIGHBOR_MARGIN_i1 (i >= resA[0]-2)
#define NEIGHBOR_MARGIN_j1 (j >= resA[1]-2)
#define NEIGHBOR_MARGIN_k1 (k >= resA[2]-2)
#define NEIGHBOR_MARGIN_i1 (i >= resA[0] - 2)
#define NEIGHBOR_MARGIN_j1 (j >= resA[1] - 2)
#define NEIGHBOR_MARGIN_k1 (k >= resA[2] - 2)
BLI_assert(num_cells >= 1);
@@ -895,18 +905,18 @@ BLI_INLINE void hair_volume_filter_box_convolute(HairVertexGrid *grid, float inv
{
int res = grid->res;
int p, q, r;
int minp = max_ii(i - kernel_size[0], 0), maxp = min_ii(i + kernel_size[0], res-1);
int minq = max_ii(j - kernel_size[1], 0), maxq = min_ii(j + kernel_size[1], res-1);
int minr = max_ii(k - kernel_size[2], 0), maxr = min_ii(k + kernel_size[2], res-1);
int minp = max_ii(i - kernel_size[0], 0), maxp = min_ii(i + kernel_size[0], res - 1);
int minq = max_ii(j - kernel_size[1], 0), maxq = min_ii(j + kernel_size[1], res - 1);
int minr = max_ii(k - kernel_size[2], 0), maxr = min_ii(k + kernel_size[2], res - 1);
int offset, kernel_offset, kernel_dq, kernel_dr;
HairGridVert *verts;
float *vel_smooth;
offset = i + (j + k*res)*res;
offset = i + (j + k * res) * res;
verts = grid->verts;
vel_smooth = verts[offset].velocity_smooth;
kernel_offset = minp + (minq + minr*res)*res;
kernel_offset = minp + (minq + minr * res) * res;
kernel_dq = res;
kernel_dr = res * res;
for (r = minr; r <= maxr; ++r) {
@@ -935,7 +945,7 @@ void BPH_hair_volume_vertex_grid_filter_box(HairVertexGrid *grid, int kernel_siz
return;
tot = kernel_size * 2 + 1;
invD = 1.0f / (float)(tot*tot*tot);
invD = 1.0f / (float)(tot * tot * tot);
/* clear values for convolution */
for (i = 0; i < size; ++i) {
@@ -1063,7 +1073,7 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd,
float weights[8];
int di, dj, dk;
for (v=0; v < col->collmd->numverts; v++, loc0++, loc1++) {
for (v = 0; v < col->collmd->numverts; v++, loc0++, loc1++) {
int offset;
if (!hair_grid_point_valid(loc1->co, gmin, gmax))
@@ -1076,8 +1086,8 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd,
for (di = 0; di < 2; ++di) {
for (dj = 0; dj < 2; ++dj) {
for (dk = 0; dk < 2; ++dk) {
int voffset = offset + di + (dj + dk*res)*res;
int iw = di + dj*2 + dk*4;
int voffset = offset + di + (dj + dk * res) * res;
int iw = di + dj * 2 + dk * 4;
collgrid[voffset].density += weights[iw];
madd_v3_v3fl(collgrid[voffset].velocity, vel, weights[iw]);
@@ -1093,7 +1103,7 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd,
for (i = 0; i < size; i++) {
float density = collgrid[i].density;
if (density > 0.0f)
mul_v3_fl(collgrid[i].velocity, 1.0f/density);
mul_v3_fl(collgrid[i].velocity, 1.0f / density);
}
return collgrid;

View File

@@ -108,11 +108,11 @@ void BPH_mass_spring_force_drag(struct Implicit_Data *data, float drag);
/* Custom external force */
void BPH_mass_spring_force_extern(struct Implicit_Data *data, int i, const float f[3], float dfdx[3][3], float dfdv[3][3]);
/* Wind force, acting on a face */
void BPH_mass_spring_force_face_wind(struct Implicit_Data *data, int v1, int v2, int v3, const float (*winvec)[3]);
void BPH_mass_spring_force_face_wind(struct Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3]);
/* Wind force, acting on an edge */
void BPH_mass_spring_force_edge_wind(struct Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float (*winvec)[3]);
void BPH_mass_spring_force_edge_wind(struct Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float(*winvec)[3]);
/* Wind force, acting on a vertex */
void BPH_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float radius, const float (*winvec)[3]);
void BPH_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float radius, const float(*winvec)[3]);
/* Linear spring force between two points */
bool BPH_mass_spring_force_spring_linear(struct Implicit_Data *data, int i, int j, float restlen,
float stiffness_tension, float damping_tension,

View File

@@ -135,7 +135,7 @@ static void print_fvector(float m3[3])
// long float vector float (*)[3]
///////////////////////////
/* print long vector on console: for debug output */
DO_INLINE void print_lfvector(float (*fLongVector)[3], unsigned int verts)
DO_INLINE void print_lfvector(float(*fLongVector)[3], unsigned int verts)
{
unsigned int i = 0;
for (i = 0; i < verts; i++) {
@@ -152,7 +152,7 @@ DO_INLINE lfVector *create_lfvector(unsigned int verts)
// return (lfVector *)cloth_aligned_malloc(&MEMORY_BASE, verts * sizeof(lfVector));
}
/* delete long vector */
DO_INLINE void del_lfvector(float (*fLongVector)[3])
DO_INLINE void del_lfvector(float(*fLongVector)[3])
{
if (fLongVector != NULL) {
MEM_freeN(fLongVector);
@@ -160,12 +160,12 @@ DO_INLINE void del_lfvector(float (*fLongVector)[3])
}
}
/* copy long vector */
DO_INLINE void cp_lfvector(float (*to)[3], float (*from)[3], unsigned int verts)
DO_INLINE void cp_lfvector(float(*to)[3], float(*from)[3], unsigned int verts)
{
memcpy(to, from, verts * sizeof(lfVector));
}
/* init long vector with float[3] */
DO_INLINE void init_lfvector(float (*fLongVector)[3], float vector[3], unsigned int verts)
DO_INLINE void init_lfvector(float(*fLongVector)[3], float vector[3], unsigned int verts)
{
unsigned int i = 0;
for (i = 0; i < verts; i++) {
@@ -173,12 +173,12 @@ DO_INLINE void init_lfvector(float (*fLongVector)[3], float vector[3], unsigned
}
}
/* zero long vector with float[3] */
DO_INLINE void zero_lfvector(float (*to)[3], unsigned int verts)
DO_INLINE void zero_lfvector(float(*to)[3], unsigned int verts)
{
memset(to, 0.0f, verts * sizeof(lfVector));
}
/* multiply long vector with scalar*/
DO_INLINE void mul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float scalar, unsigned int verts)
DO_INLINE void mul_lfvectorS(float(*to)[3], float(*fLongVector)[3], float scalar, unsigned int verts)
{
unsigned int i = 0;
@@ -188,7 +188,7 @@ DO_INLINE void mul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float scal
}
/* multiply long vector with scalar*/
/* A -= B * float */
DO_INLINE void submul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float scalar, unsigned int verts)
DO_INLINE void submul_lfvectorS(float(*to)[3], float(*fLongVector)[3], float scalar, unsigned int verts)
{
unsigned int i = 0;
for (i = 0; i < verts; i++) {
@@ -196,7 +196,7 @@ DO_INLINE void submul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float s
}
}
/* dot product for big vector */
DO_INLINE float dot_lfvector(float (*fLongVectorA)[3], float (*fLongVectorB)[3], unsigned int verts)
DO_INLINE float dot_lfvector(float(*fLongVectorA)[3], float(*fLongVectorB)[3], unsigned int verts)
{
long i = 0;
float temp = 0.0;
@@ -211,7 +211,7 @@ DO_INLINE float dot_lfvector(float (*fLongVectorA)[3], float (*fLongVectorB)[3],
return temp;
}
/* A = B + C --> for big vector */
DO_INLINE void add_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], unsigned int verts)
DO_INLINE void add_lfvector_lfvector(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], unsigned int verts)
{
unsigned int i = 0;
@@ -221,7 +221,7 @@ DO_INLINE void add_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], f
}
/* A = B + C * float --> for big vector */
DO_INLINE void add_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], float bS, unsigned int verts)
DO_INLINE void add_lfvector_lfvectorS(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], float bS, unsigned int verts)
{
unsigned int i = 0;
@@ -231,7 +231,7 @@ DO_INLINE void add_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3],
}
}
/* A = B * float + C * float --> for big vector */
DO_INLINE void add_lfvectorS_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], float aS, float (*fLongVectorB)[3], float bS, unsigned int verts)
DO_INLINE void add_lfvectorS_lfvectorS(float(*to)[3], float(*fLongVectorA)[3], float aS, float(*fLongVectorB)[3], float bS, unsigned int verts)
{
unsigned int i = 0;
@@ -240,7 +240,7 @@ DO_INLINE void add_lfvectorS_lfvectorS(float (*to)[3], float (*fLongVectorA)[3],
}
}
/* A = B - C * float --> for big vector */
DO_INLINE void sub_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], float bS, unsigned int verts)
DO_INLINE void sub_lfvector_lfvectorS(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], float bS, unsigned int verts)
{
unsigned int i = 0;
for (i = 0; i < verts; i++) {
@@ -249,7 +249,7 @@ DO_INLINE void sub_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3],
}
/* A = B - C --> for big vector */
DO_INLINE void sub_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], unsigned int verts)
DO_INLINE void sub_lfvector_lfvector(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], unsigned int verts)
{
unsigned int i = 0;
@@ -302,7 +302,7 @@ static void print_bfmatrix(fmatrix3x3 *m)
{
int tot = m[0].vcount + m[0].scount;
int size = m[0].vcount * 3;
float *t = MEM_callocN(sizeof(float) * size*size, "bfmatrix");
float *t = MEM_callocN(sizeof(float) * size * size, "bfmatrix");
int q, i, j;
for (q = 0; q < tot; ++q) {
@@ -365,8 +365,8 @@ DO_INLINE void initdiag_fmatrixS(float to[3][3], float aS)
/* calculate determinant of 3x3 matrix */
DO_INLINE float det_fmatrix(float m[3][3])
{
return m[0][0]*m[1][1]*m[2][2] + m[1][0]*m[2][1]*m[0][2] + m[0][1]*m[1][2]*m[2][0] -
m[0][0]*m[1][2]*m[2][1] - m[0][1]*m[1][0]*m[2][2] - m[2][0]*m[1][1]*m[0][2];
return m[0][0] * m[1][1] * m[2][2] + m[1][0] * m[2][1] * m[0][2] + m[0][1] * m[1][2] * m[2][0] -
m[0][0] * m[1][2] * m[2][1] - m[0][1] * m[1][0] * m[2][2] - m[2][0] * m[1][1] * m[0][2];
}
DO_INLINE void inverse_fmatrix(float to[3][3], float from[3][3])
@@ -374,18 +374,18 @@ DO_INLINE void inverse_fmatrix(float to[3][3], float from[3][3])
unsigned int i, j;
float d;
if ((d=det_fmatrix(from)) == 0) {
if ((d = det_fmatrix(from)) == 0) {
printf("can't build inverse");
exit(0);
}
for (i=0;i<3;i++) {
for (j=0;j<3;j++) {
int i1=(i+1)%3;
int i2=(i+2)%3;
int j1=(j+1)%3;
int j2=(j+2)%3;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
int i1 = (i + 1) % 3;
int i2 = (i + 2) % 3;
int j1 = (j + 1) % 3;
int j2 = (j + 2) % 3;
/** Reverse indexes i&j to take transpose. */
to[j][i] = (from[i1][j1]*from[i2][j2]-from[i1][j2]*from[i2][j1])/d;
to[j][i] = (from[i1][j1] * from[i2][j2] - from[i1][j2] * from[i2][j1]) / d;
/**
* <pre>
* if (i == j) {
@@ -415,9 +415,9 @@ DO_INLINE void mul_fmatrix_S(float matrix[3][3], float scalar)
/* STATUS: verified */
DO_INLINE void mul_fvector_fmatrix(float *to, float *from, float matrix[3][3])
{
to[0] = matrix[0][0]*from[0] + matrix[1][0]*from[1] + matrix[2][0]*from[2];
to[1] = matrix[0][1]*from[0] + matrix[1][1]*from[1] + matrix[2][1]*from[2];
to[2] = matrix[0][2]*from[0] + matrix[1][2]*from[1] + matrix[2][2]*from[2];
to[0] = matrix[0][0] * from[0] + matrix[1][0] * from[1] + matrix[2][0] * from[2];
to[1] = matrix[0][1] * from[0] + matrix[1][1] * from[1] + matrix[2][1] * from[2];
to[2] = matrix[0][2] * from[0] + matrix[1][2] * from[1] + matrix[2][2] * from[2];
}
/* 3x3 matrix multiplied by a vector */
@@ -567,7 +567,7 @@ DO_INLINE void del_bfmatrix(fmatrix3x3 *matrix)
DO_INLINE void cp_bfmatrix(fmatrix3x3 *to, fmatrix3x3 *from)
{
// TODO bounds checking
memcpy(to, from, sizeof(fmatrix3x3) * (from[0].vcount+from[0].scount));
memcpy(to, from, sizeof(fmatrix3x3) * (from[0].vcount + from[0].scount));
}
/* init big matrix */
@@ -576,7 +576,7 @@ DO_INLINE void init_bfmatrix(fmatrix3x3 *matrix, float m3[3][3])
{
unsigned int i;
for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) {
for (i = 0; i < matrix[0].vcount + matrix[0].scount; i++) {
cp_fmatrix(matrix[i].m, m3);
}
}
@@ -591,14 +591,14 @@ DO_INLINE void initdiag_bfmatrix(fmatrix3x3 *matrix, float m3[3][3])
for (i = 0; i < matrix[0].vcount; i++) {
cp_fmatrix(matrix[i].m, m3);
}
for (j = matrix[0].vcount; j < matrix[0].vcount+matrix[0].scount; j++) {
for (j = matrix[0].vcount; j < matrix[0].vcount + matrix[0].scount; j++) {
cp_fmatrix(matrix[j].m, tmatrix);
}
}
/* SPARSE SYMMETRIC multiply big matrix with long vector*/
/* STATUS: verified */
DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector *fLongVector)
DO_INLINE void mul_bfmatrix_lfvector(float(*to)[3], fmatrix3x3 *from, lfVector *fLongVector)
{
unsigned int i = 0;
unsigned int vcount = from[0].vcount;
@@ -610,7 +610,7 @@ DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector
{
#pragma omp section
{
for (i = from[0].vcount; i < from[0].vcount+from[0].scount; i++) {
for (i = from[0].vcount; i < from[0].vcount + from[0].scount; i++) {
/* This is the lower triangle of the sparse matrix,
* therefore multiplication occurs with transposed submatrices. */
muladd_fmatrixT_fvector(to[from[i].c], from[i].m, fLongVector[from[i].r]);
@@ -618,7 +618,7 @@ DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector
}
#pragma omp section
{
for (i = 0; i < from[0].vcount+from[0].scount; i++) {
for (i = 0; i < from[0].vcount + from[0].scount; i++) {
muladd_fmatrix_fvector(temp[from[i].r], from[i].m, fLongVector[from[i].c]);
}
}
@@ -631,12 +631,12 @@ DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector
/* SPARSE SYMMETRIC sub big matrix with big matrix*/
/* A -= B * float + C * float --> for big matrix */
/* VERIFIED */
DO_INLINE void subadd_bfmatrixS_bfmatrixS( fmatrix3x3 *to, fmatrix3x3 *from, float aS, fmatrix3x3 *matrix, float bS)
DO_INLINE void subadd_bfmatrixS_bfmatrixS(fmatrix3x3 *to, fmatrix3x3 *from, float aS, fmatrix3x3 *matrix, float bS)
{
unsigned int i = 0;
/* process diagonal elements */
for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) {
for (i = 0; i < matrix[0].vcount + matrix[0].scount; i++) {
subadd_fmatrixS_fmatrixS(to[i].m, from[i].m, aS, matrix[i].m, bS);
}
@@ -751,7 +751,7 @@ BLI_INLINE void root_to_world_m3(Implicit_Data *data, int index, float r[3][3],
DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
{
unsigned int i=0;
unsigned int i = 0;
for (i = 0; i < S[0].vcount; i++) {
mul_m3_v3(S[i].m, V[S[i].r]);
@@ -762,8 +762,8 @@ DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S)
{
// Solves for unknown X in equation AX=B
unsigned int conjgrad_loopcount=0, conjgrad_looplimit=100;
float conjgrad_epsilon=0.0001f /* , conjgrad_lasterror=0 */ /* UNUSED */;
unsigned int conjgrad_loopcount = 0, conjgrad_looplimit = 100;
float conjgrad_epsilon = 0.0001f /* , conjgrad_lasterror=0 */ /* UNUSED */;
lfVector *q, *d, *tmp, *r;
float s, starget, a, s_prev;
unsigned int numverts = lA[0].vcount;
@@ -789,13 +789,13 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z
s = dot_lfvector(r, r, numverts);
starget = s * sqrtf(conjgrad_epsilon);
while (s>starget && conjgrad_loopcount < conjgrad_looplimit) {
while (s > starget && conjgrad_loopcount < conjgrad_looplimit) {
// Mul(q, A, d); // q = A*d;
mul_bfmatrix_lfvector(q, lA, d);
filter(q, S);
a = s/dot_lfvector(d, q, numverts);
a = s / dot_lfvector(d, q, numverts);
// X = X + d*a;
add_lfvector_lfvectorS(ldV, ldV, d, a, numverts);
@@ -807,7 +807,7 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z
s = dot_lfvector(r, r, numverts);
//d = r+d*(s/s_prev);
add_lfvector_lfvectorS(d, r, d, (s/s_prev), numverts);
add_lfvector_lfvectorS(d, r, d, (s / s_prev), numverts);
filter(d, S);
@@ -821,15 +821,15 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z
del_lfvector(r);
// printf("W/O conjgrad_loopcount: %d\n", conjgrad_loopcount);
return conjgrad_loopcount<conjgrad_looplimit; // true means we reached desired accuracy in given time - ie stable
return conjgrad_loopcount < conjgrad_looplimit; // true means we reached desired accuracy in given time - ie stable
}
#endif
static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S, ImplicitSolverResult *result)
{
// Solves for unknown X in equation AX=B
unsigned int conjgrad_loopcount=0, conjgrad_looplimit=100;
float conjgrad_epsilon=0.01f;
unsigned int conjgrad_loopcount = 0, conjgrad_looplimit = 100;
float conjgrad_epsilon = 0.01f;
unsigned int numverts = lA[0].vcount;
lfVector *fB = create_lfvector(numverts);
@@ -846,7 +846,7 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z,
cp_lfvector(fB, lB, numverts);
filter(fB, S);
bnorm2 = dot_lfvector(fB, fB, numverts);
delta_target = conjgrad_epsilon*conjgrad_epsilon * bnorm2;
delta_target = conjgrad_epsilon * conjgrad_epsilon * bnorm2;
/* r = filter(B - A * dV) */
mul_bfmatrix_lfvector(AdV, lA, ldV);
@@ -921,7 +921,7 @@ DO_INLINE void BuildPPinv(fmatrix3x3 *lA, fmatrix3x3 *P, fmatrix3x3 *Pinv)
// Take only the diagonal blocks of A
// #pragma omp parallel for private(i) if (lA[0].vcount > CLOTH_OPENMP_LIMIT)
for (i = 0; i<lA[0].vcount; i++) {
for (i = 0; i < lA[0].vcount; i++) {
// block diagonalizer
cp_fmatrix(P[i].m, lA[i].m);
inverse_fmatrix(Pinv[i].m, P[i].m);
@@ -933,9 +933,9 @@ DO_INLINE void BuildPPinv(fmatrix3x3 *lA, fmatrix3x3 *P, fmatrix3x3 *Pinv)
// version 1.3
static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S, fmatrix3x3 *P, fmatrix3x3 *Pinv)
{
unsigned int numverts = lA[0].vcount, iterations = 0, conjgrad_looplimit=100;
unsigned int numverts = lA[0].vcount, iterations = 0, conjgrad_looplimit = 100;
float delta0 = 0, deltaNew = 0, deltaOld = 0, alpha = 0;
float conjgrad_epsilon=0.0001; // 0.2 is dt for steps=5
float conjgrad_epsilon = 0.0001; // 0.2 is dt for steps=5
lfVector *r = create_lfvector(numverts);
lfVector *p = create_lfvector(numverts);
lfVector *s = create_lfvector(numverts);
@@ -999,14 +999,14 @@ static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector
printf("iterations: %d\n", iterations);
return iterations<conjgrad_looplimit;
return iterations < conjgrad_looplimit;
}
#endif
// version 1.4
static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S, fmatrix3x3 *P, fmatrix3x3 *Pinv, fmatrix3x3 *bigI)
{
unsigned int numverts = lA[0].vcount, iterations = 0, conjgrad_looplimit=100;
unsigned int numverts = lA[0].vcount, iterations = 0, conjgrad_looplimit = 100;
float delta0 = 0, deltaNew = 0, deltaOld = 0, alpha = 0, tol = 0;
lfVector *r = create_lfvector(numverts);
lfVector *p = create_lfvector(numverts);
@@ -1065,9 +1065,9 @@ static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector
double start = PIL_check_seconds_timer();
#endif
tol = (0.01*0.2);
tol = (0.01 * 0.2);
while ((deltaNew > delta0*tol*tol) && (iterations < conjgrad_looplimit))
while ((deltaNew > delta0 * tol * tol) && (iterations < conjgrad_looplimit))
{
iterations++;
@@ -1107,7 +1107,7 @@ static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector
// printf("iterations: %d\n", iterations);
return iterations<conjgrad_looplimit;
return iterations < conjgrad_looplimit;
}
#endif
@@ -1120,11 +1120,11 @@ bool BPH_mass_spring_solve_velocities(Implicit_Data *data, float dt, ImplicitSol
cp_bfmatrix(data->A, data->M);
subadd_bfmatrixS_bfmatrixS(data->A, data->dFdV, dt, data->dFdX, (dt*dt));
subadd_bfmatrixS_bfmatrixS(data->A, data->dFdV, dt, data->dFdX, (dt * dt));
mul_bfmatrix_lfvector(dFdXmV, data->dFdX, data->V);
add_lfvectorS_lfvectorS(data->B, data->F, dt, dFdXmV, (dt*dt), numverts);
add_lfvectorS_lfvectorS(data->B, data->F, dt, dFdXmV, (dt * dt), numverts);
#ifdef DEBUG_TIME
double start = PIL_check_seconds_timer();
@@ -1406,7 +1406,7 @@ static float calc_nor_area_tri(float nor[3], const float v1[3], const float v2[3
}
/* XXX does not support force jacobians yet, since the effector system does not provide them either */
void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3, const float (*winvec)[3])
void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3])
{
const float effector_scale = 0.02f;
float win[3], nor[3], area;
@@ -1445,7 +1445,7 @@ static void edge_wind_vertex(const float dir[3], float length, float radius, con
mul_v3_v3fl(f, wind, density * cross_section);
}
void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float (*winvec)[3])
void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float(*winvec)[3])
{
float win[3], dir[3], length;
float f[3], dfdx[3][3], dfdv[3][3];
@@ -1462,7 +1462,7 @@ void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float
add_v3_v3(data->F[v2], f);
}
void BPH_mass_spring_force_vertex_wind(Implicit_Data *data, int v, float UNUSED(radius), const float (*winvec)[3])
void BPH_mass_spring_force_vertex_wind(Implicit_Data *data, int v, float UNUSED(radius), const float(*winvec)[3])
{
const float density = 0.01f; /* XXX arbitrary value, corresponds to effect of air density */
@@ -1481,7 +1481,7 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl
outerproduct(to, dir, dir);
sub_m3_m3m3(to, I, to);
mul_m3_fl(to, (L/length));
mul_m3_fl(to, (L / length));
sub_m3_m3m3(to, to, I);
mul_m3_fl(to, k);
}
@@ -1494,7 +1494,7 @@ BLI_INLINE void dfdx_damp(float to[3][3], const float dir[3], float length, cons
// return (I-outerprod(dir, dir)) * (-damping * -(dot(dir, vel)/Max(length, rest)));
mul_fvectorT_fvector(to, dir, dir);
sub_fmatrix_fmatrix(to, I, to);
mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel)/MAX2(length, rest))));
mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel) / MAX2(length, rest))));
}
#endif
@@ -1516,7 +1516,7 @@ BLI_INLINE float fb(float length, float L)
BLI_INLINE float fbderiv(float length, float L)
{
float x = length/L;
float x = length / L;
float xx = x * x;
float xxx = xx * x;
return (-46.164f * xxx + 102.579f * xx - 78.166f * x + 23.116f);
@@ -1543,7 +1543,7 @@ BLI_INLINE float fbstar_jacobi(float length, float L, float kb, float cb)
return -cb;
}
else {
return -kb * fbderiv(length, L);
return -kb *fbderiv(length, L);
}
}
@@ -1558,7 +1558,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[
#if 0
if (length > L) {
if ((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) &&
( ((length-L)*100.0f/L) > clmd->sim_parms->maxspringlen ))
( ((length - L) * 100.0f / L) > clmd->sim_parms->maxspringlen))
{
// cut spring!
s->flags |= CSPRING_FLAG_DEACTIVATE;
@@ -1566,7 +1566,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[
}
}
#endif
mul_v3_v3fl(r_dir, r_extent, 1.0f/(*r_length));
mul_v3_v3fl(r_dir, r_extent, 1.0f / (*r_length));
}
else {
zero_v3(r_dir);

View File

@@ -110,7 +110,7 @@ public:
coeffRef(k) = v[k];
}
fVector& operator = (const ctype &v)
fVector& operator =(const ctype &v)
{
for (int k = 0; k < 3; ++k)
coeffRef(k) = v[k];
@@ -141,7 +141,7 @@ public:
coeffRef(l, k) = v[k][l];
}
fMatrix& operator = (const ctype &v)
fMatrix& operator =(const ctype &v)
{
for (int k = 0; k < 3; ++k)
for (int l = 0; l < 3; ++l)
@@ -167,18 +167,18 @@ public:
}
template <typename T>
lVector& operator = (T rhs)
lVector& operator =(T rhs)
{
base_t::operator=(rhs);
return *this;
}
float* v3(int vertex)
float *v3(int vertex)
{
return &coeffRef(3 * vertex);
}
const float* v3(int vertex) const
const float *v3(int vertex) const
{
return &coeffRef(3 * vertex);
}
@@ -516,10 +516,10 @@ bool BPH_mass_spring_solve_velocities(Implicit_Data *data, float dt, ImplicitSol
cg.filter() = data->S;
#endif
data->A = data->M - dt * data->dFdV - dt*dt * data->dFdX;
data->A = data->M - dt * data->dFdV - dt * dt * data->dFdX;
cg.compute(data->A);
data->B = dt * data->F + dt*dt * data->dFdX * data->V;
data->B = dt * data->F + dt * dt * data->dFdX * data->V;
#ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
printf("==== A ====\n");
@@ -786,7 +786,7 @@ static float calc_nor_area_tri(float nor[3], const float v1[3], const float v2[3
}
/* XXX does not support force jacobians yet, since the effector system does not provide them either */
void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3, const float (*winvec)[3])
void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3])
{
const float effector_scale = 0.02f;
float win[3], nor[3], area;
@@ -806,7 +806,7 @@ void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3
madd_v3_v3fl(data->F.v3(v3), nor, factor * dot_v3v3(win, nor));
}
void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, const float (*winvec)[3])
void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, const float(*winvec)[3])
{
const float effector_scale = 0.01;
float win[3], dir[3], nor[3], length;
@@ -830,7 +830,7 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl
outerproduct(to, dir, dir);
sub_m3_m3m3(to, I, to);
mul_m3_fl(to, (L/length));
mul_m3_fl(to, (L / length));
sub_m3_m3m3(to, to, I);
mul_m3_fl(to, k);
}
@@ -843,7 +843,7 @@ BLI_INLINE void dfdx_damp(float to[3][3], const float dir[3], float length, cons
// return (I-outerprod(dir, dir)) * (-damping * -(dot(dir, vel)/Max(length, rest)));
mul_fvectorT_fvector(to, dir, dir);
sub_fmatrix_fmatrix(to, I, to);
mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel)/MAX2(length, rest))));
mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel) / MAX2(length, rest))));
}
#endif
@@ -862,7 +862,7 @@ BLI_INLINE float fb(float length, float L)
BLI_INLINE float fbderiv(float length, float L)
{
float x = length/L;
float x = length / L;
return (-46.164f * powf(x, 3) + 102.579f * powf(x, 2) - 78.166f * x + 23.116f);
}
@@ -888,7 +888,7 @@ BLI_INLINE float fbstar_jacobi(float length, float L, float kb, float cb)
return -cb;
}
else {
return -kb * fbderiv(length, L);
return -kb *fbderiv(length, L);
}
}
@@ -903,7 +903,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[
#if 0
if (length > L) {
if ((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) &&
( ((length-L)*100.0f/L) > clmd->sim_parms->maxspringlen ))
( ((length - L) * 100.0f / L) > clmd->sim_parms->maxspringlen))
{
// cut spring!
s->flags |= CSPRING_FLAG_DEACTIVATE;
@@ -911,7 +911,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[
}
}
#endif
mul_v3_v3fl(r_dir, r_extent, 1.0f/(*r_length));
mul_v3_v3fl(r_dir, r_extent, 1.0f / (*r_length));
}
else {
zero_v3(r_dir);