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>2020-08-13 08:46:46 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-08-13 08:46:46 +0300
commitf875d3e504db422a6d58230b9a9012f004562032 (patch)
tree9752a714447e6c2ebedc50dcef7767d3dc9a9474 /source/blender/blenkernel/intern/object_dupli.c
parent536b6b6376bb933860d2dc8491e945076aaf0a82 (diff)
parent9bf8b6799dd1eced15fa9dfcb15bf49bb21e2241 (diff)
Merge branch 'blender-v2.90-release' into master
Diffstat (limited to 'source/blender/blenkernel/intern/object_dupli.c')
-rw-r--r--source/blender/blenkernel/intern/object_dupli.c354
1 files changed, 181 insertions, 173 deletions
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index de14d2ceff6..d91b2284142 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -84,11 +84,11 @@ typedef struct DupliContext {
const struct DupliGenerator *gen;
/** Result containers. */
- ListBase *duplilist; /* legacy doubly-linked list */
+ ListBase *duplilist; /* Legacy doubly-linked list. */
} DupliContext;
typedef struct DupliGenerator {
- short type; /* dupli type */
+ short type; /* Dupli Type, see members of #OB_DUPLI. */
void (*make_duplis)(const DupliContext *ctx);
} DupliGenerator;
@@ -160,7 +160,7 @@ static DupliObject *make_dupli(const DupliContext *ctx,
DupliObject *dob;
int i;
- /* add a DupliObject instance to the result container */
+ /* Add a #DupliObject instance to the result container. */
if (ctx->duplilist) {
dob = MEM_callocN(sizeof(DupliObject), "dupli object");
BLI_addtail(ctx->duplilist, dob);
@@ -173,28 +173,28 @@ static DupliObject *make_dupli(const DupliContext *ctx,
mul_m4_m4m4(dob->mat, (float(*)[4])ctx->space_mat, mat);
dob->type = ctx->gen->type;
- /* set persistent id, which is an array with a persistent index for each level
+ /* Set persistent id, which is an array with a persistent index for each level
* (particle number, vertex number, ..). by comparing this we can find the same
- * dupli object between frames, which is needed for motion blur. last level
- * goes first in the array. */
+ * dupli-object between frames, which is needed for motion blur.
+ * The last level is ordered first in the array. */
dob->persistent_id[0] = index;
for (i = 1; i < ctx->level + 1; i++) {
dob->persistent_id[i] = ctx->persistent_id[ctx->level - i];
}
- /* fill rest of values with INT_MAX which index will never have as value */
+ /* Fill rest of values with #INT_MAX which index will never have as value. */
for (; i < MAX_DUPLI_RECUR; i++) {
dob->persistent_id[i] = INT_MAX;
}
- /* metaballs never draw in duplis, they are instead merged into one by the basis
- * mball outside of the group. this does mean that if that mball is not in the
+ /* Meta-balls never draw in duplis, they are instead merged into one by the basis
+ * meta-ball outside of the group. this does mean that if that meta-ball is not in the
* scene, they will not show up at all, limitation that should be solved once. */
if (ob->type == OB_MBALL) {
dob->no_draw = true;
}
- /* random number */
- /* the logic here is designed to match Cycles */
+ /* Random number.
+ * The logic here is designed to match Cycles. */
dob->random_id = BLI_hash_string(dob->ob->id.name + 2);
if (dob->persistent_id[0] != INT_MAX) {
@@ -214,16 +214,16 @@ static DupliObject *make_dupli(const DupliContext *ctx,
}
/**
- * Recursive dupli objects.
+ * Recursive dupli-objects.
*
- * \param space_mat: is the local dupli space (excluding dupli #Object.obmat).
+ * \param space_mat: is the local dupli-space (excluding dupli #Object.obmat).
*/
static void make_recursive_duplis(const DupliContext *ctx,
Object *ob,
const float space_mat[4][4],
int index)
{
- /* simple preventing of too deep nested collections with MAX_DUPLI_RECUR */
+ /* Simple preventing of too deep nested collections with #MAX_DUPLI_RECUR. */
if (ctx->level < MAX_DUPLI_RECUR) {
DupliContext rctx;
copy_dupli_context(&rctx, ctx, ob, space_mat, index);
@@ -269,9 +269,9 @@ static void make_child_duplis(const DupliContext *ctx,
DupliContext pctx;
copy_dupli_context(&pctx, ctx, ctx->object, NULL, _base_id);
- /* metaballs have a different dupli handling */
+ /* Meta-balls have a different dupli handling. */
if (ob->type != OB_MBALL) {
- ob->flag |= OB_DONE; /* doesn't render */
+ ob->flag |= OB_DONE; /* Doesn't render. */
}
make_child_duplis_cb(&pctx, userdata, ob);
}
@@ -287,9 +287,9 @@ static void make_child_duplis(const DupliContext *ctx,
DupliContext pctx;
copy_dupli_context(&pctx, ctx, ctx->object, NULL, baseid);
- /* metaballs have a different dupli handling */
+ /* Meta-balls have a different dupli-handling. */
if (ob->type != OB_MBALL) {
- ob->flag |= OB_DONE; /* doesn't render */
+ ob->flag |= OB_DONE; /* Doesn't render. */
}
make_child_duplis_cb(&pctx, userdata, ob);
@@ -301,6 +301,37 @@ static void make_child_duplis(const DupliContext *ctx,
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Internal Data Access Utilities
+ * \{ */
+
+static Mesh *mesh_data_from_duplicator_object(Object *ob, BMEditMesh **r_em)
+{
+ /* Gather mesh info. */
+ BMEditMesh *em = BKE_editmesh_from_object(ob);
+ Mesh *me_eval;
+
+ *r_em = NULL;
+
+ /* We do not need any render-specific handling anymore, depsgraph takes care of that. */
+ /* NOTE: Do direct access to the evaluated mesh: this function is used
+ * during meta balls evaluation. But even without those all the objects
+ * which are needed for correct instancing are already evaluated. */
+ if (em != NULL) {
+ *r_em = em;
+
+ /* Note that this will only show deformation if #eModifierMode_OnCage is enabled.
+ * We could change this but it matches 2.7x behavior. */
+ me_eval = em->mesh_eval_cage;
+ }
+ else {
+ me_eval = BKE_object_get_evaluated_mesh(ob);
+ }
+ return me_eval;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Dupli-Collection Implementation (#OB_DUPLICOLLECTION)
* \{ */
@@ -315,23 +346,23 @@ static void make_duplis_collection(const DupliContext *ctx)
}
collection = ob->instance_collection;
- /* combine collection offset and obmat */
+ /* Combine collection offset and `obmat`. */
unit_m4(collection_mat);
sub_v3_v3(collection_mat[3], collection->instance_offset);
mul_m4_m4m4(collection_mat, ob->obmat, collection_mat);
- /* don't access 'ob->obmat' from now on. */
+ /* Don't access 'ob->obmat' from now on. */
eEvaluationMode mode = DEG_get_mode(ctx->depsgraph);
FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (collection, cob, mode) {
if (cob != ob) {
float mat[4][4];
- /* collection dupli offset, should apply after everything else */
+ /* Collection dupli-offset, should apply after everything else. */
mul_m4_m4m4(mat, collection_mat, cob->obmat);
make_dupli(ctx, cob, mat, _base_id);
- /* recursion */
+ /* Recursion. */
make_recursive_duplis(ctx, cob, collection_mat, _base_id);
}
}
@@ -350,61 +381,63 @@ static const DupliGenerator gen_dupli_collection = {
* \{ */
typedef struct VertexDupliData {
- Mesh *me_eval;
- BMEditMesh *edit_mesh;
int totvert;
- float (*orco)[3];
+ const MVert *mvert;
+
+ const float (*orco)[3];
bool use_rotation;
const DupliContext *ctx;
- Object *inst_ob; /* object to instantiate (argument for vertex map callback) */
+ /* Object to instantiate (argument for vertex map callback). */
+ Object *inst_ob;
float child_imat[4][4];
} VertexDupliData;
+/**
+ * \param no: The direction,
+ * currently this is copied from a `short[3]` normal without division.
+ */
static void get_duplivert_transform(const float co[3],
- const short no[3],
- bool use_rotation,
- short axis,
- short upflag,
- float mat[4][4])
+ const float no[3],
+ const bool use_rotation,
+ const short axis,
+ const short upflag,
+ float r_mat[4][4])
{
float quat[4];
const float size[3] = {1.0f, 1.0f, 1.0f};
if (use_rotation) {
- /* construct rotation matrix from normals */
- float nor_f[3];
- nor_f[0] = (float)-no[0];
- nor_f[1] = (float)-no[1];
- nor_f[2] = (float)-no[2];
- vec_to_quat(quat, nor_f, axis, upflag);
+ /* Construct rotation matrix from normals. */
+ float no_flip[3];
+ negate_v3_v3(no_flip, no);
+ vec_to_quat(quat, no_flip, axis, upflag);
}
else {
unit_qt(quat);
}
- loc_quat_size_to_mat4(mat, co, quat, size);
+ loc_quat_size_to_mat4(r_mat, co, quat, size);
}
static void vertex_dupli(const VertexDupliData *vdd,
int index,
const float co[3],
- const short no[3])
+ const float no[3])
{
Object *inst_ob = vdd->inst_ob;
DupliObject *dob;
float obmat[4][4], space_mat[4][4];
- /* obmat is transform to vertex */
+ /* `obmat` is transform to vertex. */
get_duplivert_transform(co, no, vdd->use_rotation, inst_ob->trackflag, inst_ob->upflag, obmat);
- /* make offset relative to inst_ob using relative child transform */
- mul_mat3_m4_v3((float(*)[4])vdd->child_imat, obmat[3]);
- /* apply obmat _after_ the local vertex transform */
+ /* Make offset relative to inst_ob using relative child transform. */
+ mul_mat3_m4_v3(vdd->child_imat, obmat[3]);
+ /* Apply `obmat` _after_ the local vertex transform. */
mul_m4_m4m4(obmat, inst_ob->obmat, obmat);
- /* space matrix is constructed by removing obmat transform,
- * this yields the worldspace transform for recursive duplis
- */
+ /* Space matrix is constructed by removing `obmat` transform,
+ * this yields the world-space transform for recursive duplis. */
mul_m4_m4m4(space_mat, obmat, inst_ob->imat);
dob = make_dupli(vdd->ctx, vdd->inst_ob, obmat, index);
@@ -413,23 +446,23 @@ static void vertex_dupli(const VertexDupliData *vdd,
copy_v3_v3(dob->orco, vdd->orco[index]);
}
- /* recursion */
+ /* Recursion. */
make_recursive_duplis(vdd->ctx, vdd->inst_ob, space_mat, index);
}
-static void make_child_duplis_verts(const DupliContext *ctx, void *userdata, Object *child)
+static void make_child_duplis_verts(const DupliContext *ctx, void *userdata, Object *inst_ob)
{
VertexDupliData *vdd = userdata;
- Mesh *me_eval = vdd->me_eval;
- vdd->inst_ob = child;
- invert_m4_m4(child->imat, child->obmat);
- /* relative transform from parent to child space */
- mul_m4_m4m4(vdd->child_imat, child->imat, ctx->object->obmat);
+ vdd->inst_ob = inst_ob;
+ invert_m4_m4(inst_ob->imat, inst_ob->obmat);
+ /* Relative transform from parent to child space. */
+ mul_m4_m4m4(vdd->child_imat, inst_ob->imat, ctx->object->obmat);
- const MVert *mvert = me_eval->mvert;
- for (int i = 0; i < me_eval->totvert; i++) {
- vertex_dupli(vdd, i, mvert[i].co, mvert[i].no);
+ const MVert *mv = vdd->mvert;
+ for (int i = 0; i < vdd->totvert; i++, mv++) {
+ const float no[3] = {mv->no[0], mv->no[1], mv->no[2]};
+ vertex_dupli(vdd, i, mv->co, no);
}
}
@@ -441,32 +474,20 @@ static void make_duplis_verts(const DupliContext *ctx)
vdd.ctx = ctx;
vdd.use_rotation = parent->transflag & OB_DUPLIROT;
- /* gather mesh info */
- {
- vdd.edit_mesh = BKE_editmesh_from_object(parent);
-
- /* We do not need any render-specific handling anymore, depsgraph takes care of that. */
- /* NOTE: Do direct access to the evaluated mesh: this function is used
- * during meta balls evaluation. But even without those all the objects
- * which are needed for correct instancing are already evaluated. */
- if (vdd.edit_mesh != NULL) {
- vdd.me_eval = vdd.edit_mesh->mesh_eval_cage;
- }
- else {
- vdd.me_eval = BKE_object_get_evaluated_mesh(parent);
- }
-
- if (vdd.me_eval == NULL) {
- return;
- }
+ /* Gather mesh info. */
+ BMEditMesh *em = NULL;
+ Mesh *me_eval = mesh_data_from_duplicator_object(parent, &em);
+ if (me_eval == NULL) {
+ return;
+ }
- vdd.orco = CustomData_get_layer(&vdd.me_eval->vdata, CD_ORCO);
- vdd.totvert = vdd.me_eval->totvert;
+ {
+ vdd.orco = CustomData_get_layer(&me_eval->vdata, CD_ORCO);
+ vdd.mvert = me_eval->mvert;
+ vdd.totvert = me_eval->totvert;
}
make_child_duplis(ctx, &vdd, make_child_duplis_verts);
-
- vdd.me_eval = NULL;
}
static const DupliGenerator gen_dupli_verts = {
@@ -496,7 +517,7 @@ static Object *find_family_object(
ch_utf8_len = BLI_str_utf8_from_unicode(ch, ch_utf8);
ch_utf8[ch_utf8_len] = '\0';
- ch_utf8_len += 1; /* compare with null terminator */
+ ch_utf8_len += 1; /* Compare with null terminator. */
for (ob = bmain->objects.first; ob; ob = ob->id.next) {
if (STREQLEN(ob->id.name + 2 + family_len, ch_utf8, ch_utf8_len)) {
@@ -506,7 +527,7 @@ static Object *find_family_object(
}
}
- /* inserted value can be NULL, just to save searches in future */
+ /* Inserted value can be NULL, just to save searches in future. */
BLI_ghash_insert(family_gh, ch_key, ob);
}
@@ -526,14 +547,14 @@ static void make_duplis_font(const DupliContext *ctx)
const char32_t *text = NULL;
bool text_free = false;
- /* font dupliverts not supported inside collections */
+ /* Font dupli-verts not supported inside collections. */
if (ctx->collection) {
return;
}
copy_m4_m4(pmat, par->obmat);
- /* in par the family name is stored, use this to find the other objects */
+ /* In `par` the family name is stored, use this to find the other objects. */
BKE_vfont_to_curve_ex(
par, par->data, FO_DUPLI, NULL, &text, &text_len, &text_free, &chartransdata);
@@ -549,7 +570,7 @@ static void make_duplis_font(const DupliContext *ctx)
ct = chartransdata;
- /* cache result */
+ /* Cache result. */
family_len = strlen(cu->family);
family_gh = BLI_ghash_int_new_ex(__func__, 256);
@@ -559,9 +580,9 @@ static void make_duplis_font(const DupliContext *ctx)
/* Advance matching BLI_str_utf8_as_utf32. */
for (a = 0; a < text_len; a++, ct++) {
- /* XXX That G.main is *really* ugly, but not sure what to do here...
- * Definitively don't think it would be safe to put back Main *bmain pointer
- * in DupliContext as done in 2.7x? */
+ /* XXX That G.main is *really* ugly, but not sure what to do here.
+ * Definitively don't think it would be safe to put back `Main *bmain` pointer
+ * in #DupliContext as done in 2.7x? */
ob = find_family_object(G.main, cu->family, family_len, (unsigned int)text[a], family_gh);
if (is_eval_curve) {
@@ -675,25 +696,28 @@ static const DupliGenerator gen_dupli_verts_pointcloud = {
* \{ */
typedef struct FaceDupliData {
- Mesh *me_eval;
int totface;
- MPoly *mpoly;
- MLoop *mloop;
- MVert *mvert;
- float (*orco)[3];
- MLoopUV *mloopuv;
+ const MPoly *mpoly;
+ const MLoop *mloop;
+ const MVert *mvert;
+ const float (*orco)[3];
+ const MLoopUV *mloopuv;
bool use_scale;
} FaceDupliData;
-static void get_dupliface_transform(
- MPoly *mpoly, MLoop *mloop, MVert *mvert, bool use_scale, float scale_fac, float mat[4][4])
+static void get_dupliface_transform(const MPoly *mpoly,
+ const MLoop *mloop,
+ const MVert *mvert,
+ const bool use_scale,
+ const float scale_fac,
+ float r_mat[4][4])
{
float loc[3], quat[4], scale, size[3];
float f_no[3];
- /* location */
+ /* Location. */
BKE_mesh_calc_poly_center(mpoly, mloop, mvert, loc);
- /* rotation */
+ /* Rotation. */
{
const float *v1, *v2, *v3;
BKE_mesh_calc_poly_normal(mpoly, mloop, mvert, f_no);
@@ -702,7 +726,7 @@ static void get_dupliface_transform(
v3 = mvert[mloop[2].v].co;
tri_to_quat_ex(quat, v1, v2, v3, f_no);
}
- /* scale */
+ /* Scale. */
if (use_scale) {
float area = BKE_mesh_calc_poly_area(mpoly, mloop, mvert);
scale = sqrtf(area) * scale_fac;
@@ -712,55 +736,48 @@ static void get_dupliface_transform(
}
size[0] = size[1] = size[2] = scale;
- loc_quat_size_to_mat4(mat, loc, quat, size);
+ loc_quat_size_to_mat4(r_mat, loc, quat, size);
}
static void make_child_duplis_faces(const DupliContext *ctx, void *userdata, Object *inst_ob)
{
FaceDupliData *fdd = userdata;
- MPoly *mpoly = fdd->mpoly, *mp;
- MLoop *mloop = fdd->mloop;
- MVert *mvert = fdd->mvert;
- float(*orco)[3] = fdd->orco;
- MLoopUV *mloopuv = fdd->mloopuv;
+ const MPoly *mpoly = fdd->mpoly, *mp;
+ const MLoop *mloop = fdd->mloop;
+ const MVert *mvert = fdd->mvert;
+ const float(*orco)[3] = fdd->orco;
+ const MLoopUV *mloopuv = fdd->mloopuv;
int a, totface = fdd->totface;
float child_imat[4][4];
DupliObject *dob;
invert_m4_m4(inst_ob->imat, inst_ob->obmat);
- /* relative transform from parent to child space */
+ /* Relative transform from parent to child space. */
mul_m4_m4m4(child_imat, inst_ob->imat, ctx->object->obmat);
for (a = 0, mp = mpoly; a < totface; a++, mp++) {
- MLoop *loopstart = mloop + mp->loopstart;
+ const MLoop *loopstart = mloop + mp->loopstart;
float space_mat[4][4], obmat[4][4];
- if (UNLIKELY(mp->totloop < 3)) {
- continue;
- }
-
- /* obmat is transform to face */
+ /* `obmat` is transform to face. */
get_dupliface_transform(
mp, loopstart, mvert, fdd->use_scale, ctx->object->instance_faces_scale, obmat);
- /* make offset relative to inst_ob using relative child transform */
+ /* Make offset relative to inst_ob using relative child transform. */
mul_mat3_m4_v3(child_imat, obmat[3]);
- /* XXX ugly hack to ensure same behavior as in master
- * this should not be needed, parentinv is not consistent
- * outside of parenting.
- */
+ /* XXX ugly hack to ensure same behavior as in master.
+ * This should not be needed, `parentinv` is not consistent outside of parenting. */
{
float imat[3][3];
copy_m3_m4(imat, inst_ob->parentinv);
mul_m4_m3m4(obmat, imat, obmat);
}
- /* apply obmat _after_ the local face transform */
+ /* Apply `obmat` _after_ the local face transform. */
mul_m4_m4m4(obmat, inst_ob->obmat, obmat);
- /* space matrix is constructed by removing obmat transform,
- * this yields the worldspace transform for recursive duplis
- */
+ /* Space matrix is constructed by removing `obmat` transform,
+ * this yields the world-space transform for recursive duplis. */
mul_m4_m4m4(space_mat, obmat, inst_ob->imat);
dob = make_dupli(ctx, inst_ob, obmat, a);
@@ -777,7 +794,7 @@ static void make_child_duplis_faces(const DupliContext *ctx, void *userdata, Obj
}
}
- /* recursion */
+ /* Recursion. */
make_recursive_duplis(ctx, inst_ob, space_mat, a);
}
}
@@ -789,38 +806,25 @@ static void make_duplis_faces(const DupliContext *ctx)
fdd.use_scale = ((parent->transflag & OB_DUPLIFACES_SCALE) != 0);
- /* gather mesh info */
- {
- BMEditMesh *em = BKE_editmesh_from_object(parent);
-
- /* We do not need any render-smecific handling anymore, depsgraph takes care of that. */
- /* NOTE: Do direct access to the evaluated mesh: this function is used
- * during meta balls evaluation. But even without those all the objects
- * which are needed for correct instancing are already evaluated. */
- if (em != NULL) {
- fdd.me_eval = em->mesh_eval_cage;
- }
- else {
- fdd.me_eval = BKE_object_get_evaluated_mesh(parent);
- }
-
- if (fdd.me_eval == NULL) {
- return;
- }
-
- fdd.orco = CustomData_get_layer(&fdd.me_eval->vdata, CD_ORCO);
- const int uv_idx = CustomData_get_render_layer(&fdd.me_eval->ldata, CD_MLOOPUV);
- fdd.mloopuv = CustomData_get_layer_n(&fdd.me_eval->ldata, CD_MLOOPUV, uv_idx);
+ /* Gather mesh info. */
+ BMEditMesh *em = NULL;
+ Mesh *me_eval = mesh_data_from_duplicator_object(parent, &em);
+ if (me_eval == NULL) {
+ return;
+ }
- fdd.totface = fdd.me_eval->totpoly;
- fdd.mpoly = fdd.me_eval->mpoly;
- fdd.mloop = fdd.me_eval->mloop;
- fdd.mvert = fdd.me_eval->mvert;
+ {
+ fdd.orco = CustomData_get_layer(&me_eval->vdata, CD_ORCO);
+ const int uv_idx = CustomData_get_render_layer(&me_eval->ldata, CD_MLOOPUV);
+ fdd.mloopuv = CustomData_get_layer_n(&me_eval->ldata, CD_MLOOPUV, uv_idx);
+
+ fdd.totface = me_eval->totpoly;
+ fdd.mpoly = me_eval->mpoly;
+ fdd.mloop = me_eval->mloop;
+ fdd.mvert = me_eval->mvert;
}
make_child_duplis(ctx, &fdd, make_child_duplis_faces);
-
- fdd.me_eval = NULL;
}
static const DupliGenerator gen_dupli_faces = {
@@ -874,7 +878,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
no_draw_flag |= PARS_NO_DISP;
}
- /* NOTE: in old animsys, used parent object's timeoffset... */
+ /* NOTE: in old animation system, used parent object's time-offset. */
ctime = DEG_get_ctime(ctx->depsgraph);
totpart = psys->totpart;
@@ -888,16 +892,16 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
sim.ob = par;
sim.psys = psys;
sim.psmd = psys_get_modifier(par, psys);
- /* make sure emitter imat is in global coordinates instead of render view coordinates */
+ /* Make sure emitter `imat` is in global coordinates instead of render view coordinates. */
invert_m4_m4(par->imat, par->obmat);
- /* first check for loops (particle system object used as dupli object) */
+ /* First check for loops (particle system object used as dupli-object). */
if (part->ren_as == PART_DRAW_OB) {
if (ELEM(part->instance_object, NULL, par)) {
return;
}
}
- else { /*PART_DRAW_GR */
+ else { /* #PART_DRAW_GR. */
if (part->instance_collection == NULL) {
return;
}
@@ -913,7 +917,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
}
}
- /* if we have a hair particle system, use the path cache */
+ /* If we have a hair particle system, use the path cache. */
if (part->type == PART_HAIR) {
if (psys->flag & PSYS_HAIR_DONE) {
hair = (totchild == 0 || psys->childcache) && psys->pathcache;
@@ -922,7 +926,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
return;
}
- /* we use cache, update totchild according to cached data */
+ /* We use cache, update `totchild` according to cached data. */
totchild = psys->totchildcache;
totpart = psys->totcached;
}
@@ -931,7 +935,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
- /* gather list of objects or single object */
+ /* Gather list of objects or single object. */
int totcollection = 0;
const bool use_whole_collection = part->draw & PART_DRAW_WHOLE_GR;
@@ -1000,23 +1004,27 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
for (pa = psys->particles; a < totpart + totchild; a++, pa++) {
if (a < totpart) {
- /* handle parent particle */
+ /* Handle parent particle. */
if (pa->flag & no_draw_flag) {
continue;
}
- /* pa_num = pa->num; */ /* UNUSED */
+#if 0 /* UNUSED */
+ pa_num = pa->num;
+#endif
size = pa->size;
}
else {
- /* handle child particle */
+ /* Handle child particle. */
cpa = &psys->child[a - totpart];
- /* pa_num = a; */ /* UNUSED */
+#if 0 /* UNUSED */
+ pa_num = a;
+#endif
size = psys_get_child_size(psys, cpa, ctime, NULL);
}
- /* some hair paths might be non-existent so they can't be used for duplication */
+ /* Some hair paths might be non-existent so they can't be used for duplication. */
if (hair && psys->pathcache &&
((a < totpart && psys->pathcache[a]->segments < 0) ||
(a >= totpart && psys->childcache[a - totpart]->segments < 0))) {
@@ -1024,12 +1032,12 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
}
if (part->ren_as == PART_DRAW_GR) {
- /* prevent divide by zero below [#28336] */
+ /* Prevent divide by zero below T28336. */
if (totcollection == 0) {
continue;
}
- /* for collections, pick the object based on settings */
+ /* For collections, pick the object based on settings. */
if (part->draw & PART_DRAW_RAND_GR && !use_whole_collection) {
b = BLI_rng_get_int(rng) % totcollection;
}
@@ -1041,7 +1049,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
}
if (hair) {
- /* hair we handle separate and compute transform based on hair keys */
+ /* Hair we handle separate and compute transform based on hair keys. */
if (a < totpart) {
cache = psys->pathcache[a];
psys_get_dupli_path_transform(&sim, pa, NULL, cache, pamat, &scale);
@@ -1055,7 +1063,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
pamat[3][3] = 1.0f;
}
else {
- /* first key */
+ /* First key. */
state.time = ctime;
if (psys_get_particle_state(&sim, a, &state, 0) == 0) {
continue;
@@ -1074,16 +1082,16 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
part->instance_collection, object, mode) {
copy_m4_m4(tmat, oblist[b]->obmat);
- /* apply particle scale */
+ /* Apply particle scale. */
mul_mat3_m4_fl(tmat, size * scale);
mul_v3_fl(tmat[3], size * scale);
- /* collection dupli offset, should apply after everything else */
+ /* Collection dupli-offset, should apply after everything else. */
if (!is_zero_v3(part->instance_collection->instance_offset)) {
sub_v3_v3(tmat[3], part->instance_collection->instance_offset);
}
- /* individual particle transform */
+ /* Individual particle transform. */
mul_m4_m4m4(mat, pamat, tmat);
dob = make_dupli(ctx, object, mat, a);
@@ -1117,13 +1125,13 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
quat_to_mat4(obmat, q);
obmat[3][3] = 1.0f;
- /* add scaling if requested */
+ /* Add scaling if requested. */
if ((part->draw & PART_DRAW_NO_SCALE_OB) == 0) {
mul_m4_m4m4(obmat, obmat, size_mat);
}
}
else if (part->draw & PART_DRAW_NO_SCALE_OB) {
- /* remove scaling */
+ /* Remove scaling. */
float size_mat[4][4], original_size[3];
mat4_to_size(original_size, obmat);
@@ -1151,7 +1159,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
BLI_rng_free(rng);
}
- /* clean up */
+ /* Clean up. */
if (oblist) {
MEM_freeN(oblist);
}
@@ -1167,9 +1175,9 @@ static void make_duplis_particles(const DupliContext *ctx)
ParticleSystem *psys;
int psysid;
- /* particle system take up one level in id, the particles another */
+ /* Particle system take up one level in id, the particles another. */
for (psys = ctx->object->particlesystem.first, psysid = 0; psys; psys = psys->next, psysid++) {
- /* particles create one more level for persistent psys index */
+ /* Particles create one more level for persistent `psys` index. */
DupliContext pctx;
copy_dupli_context(&pctx, ctx, ctx->object, NULL, psysid);
make_duplis_particle_system(&pctx, psys);
@@ -1196,7 +1204,7 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx)
return NULL;
}
- /* Should the dupli's be generated for this object? - Respect restrict flags */
+ /* Should the dupli's be generated for this object? - Respect restrict flags. */
if (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER ? (restrictflag & OB_RESTRICT_RENDER) :
(restrictflag & OB_RESTRICT_VIEWPORT)) {
return NULL;