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:
authorCampbell Barton <ideasman42@gmail.com>2015-07-19 22:19:47 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-07-19 22:30:08 +0300
commite58d788340a442b1584abbb36d3d2a01fda7f810 (patch)
treef74efa7fa91c88c18a86a82b43d52bb8604ca218 /source/blender/blenkernel
parent23a4f547e7cf22a5ea7a4ee9bf7de78e1eb41de1 (diff)
Cleanup: style
Also 'com' as abbreviation for center-of-mass is a bit confusing, rename to 'center'.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_mesh.h7
-rw-r--r--source/blender/blenkernel/BKE_rigidbody.h2
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c4
-rw-r--r--source/blender/blenkernel/intern/mesh_evaluate.c73
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c14
5 files changed, 57 insertions, 43 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index bed73469b5c..b20bca71c6d 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -272,9 +272,10 @@ bool BKE_mesh_center_bounds(const struct Mesh *me, float r_cent[3]);
bool BKE_mesh_center_centroid(const struct Mesh *me, float r_cent[3]);
void BKE_mesh_calc_volume(
- const struct MVert *mverts, const int numVerts,
- const struct MLoopTri *mlooptri, const int numTris,
- const struct MLoop *mloop, float *r_vol, float *r_com);
+ const struct MVert *mverts, const int mverts_num,
+ const struct MLoopTri *mlooptri, const int looptri_num,
+ const struct MLoop *mloop,
+ float *r_volume, float r_center[3]);
/* tessface */
void BKE_mesh_loops_to_mface_corners(
diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h
index b327f0c2574..a30ce6cda79 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -69,7 +69,7 @@ void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw);
void BKE_rigidbody_validate_sim_world(struct Scene *scene, struct RigidBodyWorld *rbw, bool rebuild);
void BKE_rigidbody_calc_volume(struct Object *ob, float *r_vol);
-void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_com[3]);
+void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_center[3]);
/* -------------- */
/* Utilities */
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 69c6c4ffcef..5553de4ead7 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -3157,8 +3157,8 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int
}
/*create new cddm*/
- cddm2 = (CDDerivedMesh *)CDDM_from_template((
- DerivedMesh *)cddm, STACK_SIZE(mvert), STACK_SIZE(medge), 0, STACK_SIZE(mloop), STACK_SIZE(mpoly));
+ cddm2 = (CDDerivedMesh *)CDDM_from_template(
+ (DerivedMesh *)cddm, STACK_SIZE(mvert), STACK_SIZE(medge), 0, STACK_SIZE(mloop), STACK_SIZE(mpoly));
/*update edge indices and copy customdata*/
med = medge;
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 73aba74c7f0..74c5fb8114d 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -2046,20 +2046,21 @@ bool BKE_mesh_center_centroid(const Mesh *me, float r_cent[3])
* \{ */
static bool mesh_calc_center_centroid_ex(
- const MVert *mverts, int UNUSED(numVerts),
- const MLoopTri *lt, int numTris,
+ const MVert *mverts, int UNUSED(mverts_num),
+ const MLoopTri *looptri, int looptri_num,
const MLoop *mloop, float r_center[3])
{
+ const MLoopTri *lt;
float totweight;
- int t;
+ int i;
zero_v3(r_center);
- if (numTris == 0)
+ if (looptri_num == 0)
return false;
totweight = 0.0f;
- for (t = 0; t < numTris; t++, lt++) {
+ for (i = 0, lt = looptri; i < looptri_num; i++, lt++) {
const MVert *v1 = &mverts[mloop[lt->tri[0]].v];
const MVert *v2 = &mverts[mloop[lt->tri[1]].v];
const MVert *v3 = &mverts[mloop[lt->tri[2]].v];
@@ -2079,40 +2080,52 @@ static bool mesh_calc_center_centroid_ex(
return true;
}
-void BKE_mesh_calc_volume(const MVert *mverts, const int numVerts,
- const MLoopTri *lt, const int numTris,
- const MLoop *mloop, float *r_vol, float *r_com)
+/**
+ * Calculate the volume and center.
+ *
+ * \param r_volume: Volume (unsigned).
+ * \param r_center: Center of mass.
+ */
+void BKE_mesh_calc_volume(
+ const MVert *mverts, const int mverts_num,
+ const MLoopTri *looptri, const int looptri_num,
+ const MLoop *mloop,
+ float *r_volume, float r_center[3])
{
+ const MLoopTri *lt;
float center[3];
float totvol;
- int f;
+ int i;
- if (r_vol) *r_vol = 0.0f;
- if (r_com) zero_v3(r_com);
+ if (r_volume)
+ *r_volume = 0.0f;
+ if (r_center)
+ zero_v3(r_center);
- if (numTris == 0)
+ if (looptri_num == 0)
return;
- if (!mesh_calc_center_centroid_ex(mverts, numVerts, lt, numTris, mloop, center))
+ if (!mesh_calc_center_centroid_ex(mverts, mverts_num, looptri, looptri_num, mloop, center))
return;
totvol = 0.0f;
- for (f = 0; f < numTris; f++, lt++) {
+
+ for (i = 0, lt = looptri; i < looptri_num; i++, lt++) {
const MVert *v1 = &mverts[mloop[lt->tri[0]].v];
const MVert *v2 = &mverts[mloop[lt->tri[1]].v];
const MVert *v3 = &mverts[mloop[lt->tri[2]].v];
float vol;
vol = volume_tetrahedron_signed_v3(center, v1->co, v2->co, v3->co);
- if (r_vol) {
+ if (r_volume) {
totvol += vol;
}
- if (r_com) {
+ if (r_center) {
/* averaging factor 1/4 is applied in the end */
- madd_v3_v3fl(r_com, center, vol); // XXX could extract this
- madd_v3_v3fl(r_com, v1->co, vol);
- madd_v3_v3fl(r_com, v2->co, vol);
- madd_v3_v3fl(r_com, v3->co, vol);
+ madd_v3_v3fl(r_center, center, vol); /* XXX could extract this */
+ madd_v3_v3fl(r_center, v1->co, vol);
+ madd_v3_v3fl(r_center, v2->co, vol);
+ madd_v3_v3fl(r_center, v3->co, vol);
}
}
@@ -2120,15 +2133,15 @@ void BKE_mesh_calc_volume(const MVert *mverts, const int numVerts,
* totvol can become negative even for a valid mesh.
* The true value is always the positive value.
*/
- if (r_vol) {
- *r_vol = fabsf(totvol);
+ if (r_volume) {
+ *r_volume = fabsf(totvol);
}
- if (r_com) {
+ if (r_center) {
/* Note: Factor 1/4 is applied once for all vertices here.
* This also automatically negates the vector if totvol is negative.
*/
if (totvol != 0.0f)
- mul_v3_fl(r_com, 0.25f / totvol);
+ mul_v3_fl(r_center, 0.25f / totvol);
}
}
@@ -2318,7 +2331,7 @@ int BKE_mesh_recalc_tessellation(
/* We abuse MFace->edcode to tag quad faces. See below for details. */
#define TESSFACE_IS_QUAD 1
- const int looptris_tot = poly_to_tri_count(totpoly, totloop);
+ const int looptri_num = poly_to_tri_count(totpoly, totloop);
MPoly *mp, *mpoly;
MLoop *ml, *mloop;
@@ -2335,9 +2348,9 @@ int BKE_mesh_recalc_tessellation(
/* allocate the length of totfaces, avoid many small reallocs,
* if all faces are tri's it will be correct, quads == 2x allocs */
/* take care. we are _not_ calloc'ing so be sure to initialize each field */
- mface_to_poly_map = MEM_mallocN(sizeof(*mface_to_poly_map) * (size_t)looptris_tot, __func__);
- mface = MEM_mallocN(sizeof(*mface) * (size_t)looptris_tot, __func__);
- lindices = MEM_mallocN(sizeof(*lindices) * (size_t)looptris_tot, __func__);
+ mface_to_poly_map = MEM_mallocN(sizeof(*mface_to_poly_map) * (size_t)looptri_num, __func__);
+ mface = MEM_mallocN(sizeof(*mface) * (size_t)looptri_num, __func__);
+ lindices = MEM_mallocN(sizeof(*lindices) * (size_t)looptri_num, __func__);
mface_index = 0;
mp = mpoly;
@@ -2497,10 +2510,10 @@ int BKE_mesh_recalc_tessellation(
CustomData_free(fdata, totface);
totface = mface_index;
- BLI_assert(totface <= looptris_tot);
+ BLI_assert(totface <= looptri_num);
/* not essential but without this we store over-alloc'd memory in the CustomData layers */
- if (LIKELY(looptris_tot != totface)) {
+ if (LIKELY(looptri_num != totface)) {
mface = MEM_reallocN(mface, sizeof(*mface) * (size_t)totface);
mface_to_poly_map = MEM_reallocN(mface_to_poly_map, sizeof(*mface_to_poly_map) * (size_t)totface);
}
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index fb96738449a..0c14cfa95a6 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -554,14 +554,14 @@ void BKE_rigidbody_calc_volume(Object *ob, float *r_vol)
if (r_vol) *r_vol = volume;
}
-void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3])
+void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3])
{
RigidBodyOb *rbo = ob->rigidbody_object;
float size[3] = {1.0f, 1.0f, 1.0f};
float height = 1.0f;
- zero_v3(r_com);
+ zero_v3(r_center);
/* if automatically determining dimensions, use the Object's boundbox
* - assume that all quadrics are standing upright on local z-axis
@@ -586,7 +586,7 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3])
/* cone is geometrically centered on the median,
* center of mass is 1/4 up from the base
*/
- r_com[2] = -0.25f * height;
+ r_center[2] = -0.25f * height;
break;
case RB_SHAPE_CONVEXH:
@@ -595,7 +595,7 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3])
if (ob->type == OB_MESH) {
DerivedMesh *dm = rigidbody_get_mesh(ob);
MVert *mvert;
- const MLoopTri* lt = NULL;
+ const MLoopTri *looptri = NULL;
int totvert, tottri = 0;
const MLoop* mloop = NULL;
@@ -607,12 +607,12 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3])
mvert = dm->getVertArray(dm);
totvert = dm->getNumVerts(dm);
- lt = dm->getLoopTriArray(dm);
+ looptri = dm->getLoopTriArray(dm);
tottri = dm->getNumLoopTri(dm);
mloop = dm->getLoopArray(dm);
if (totvert > 0 && tottri > 0) {
- BKE_mesh_calc_volume(mvert, totvert, lt, tottri, mloop, NULL, r_com);
+ BKE_mesh_calc_volume(mvert, totvert, looptri, tottri, mloop, NULL, r_center);
}
/* cleanup temp data */
@@ -1593,7 +1593,7 @@ struct RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob) { return NULL; }
void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc) {}
void BKE_rigidbody_validate_sim_world(Scene *scene, RigidBodyWorld *rbw, bool rebuild) {}
void BKE_rigidbody_calc_volume(Object *ob, float *r_vol) { if (r_vol) *r_vol = 0.0f; }
-void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3]) { zero_v3(r_com); }
+void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3]) { zero_v3(r_center); }
struct RigidBodyWorld *BKE_rigidbody_create_world(Scene *scene) { return NULL; }
struct RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw) { return NULL; }
void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw) {}