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:
Diffstat (limited to 'source/blender/blenkernel/intern/dynamicpaint.c')
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c135
1 files changed, 24 insertions, 111 deletions
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index 7557015be8e..dbf095d3832 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -103,8 +103,6 @@ static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1};
/* subframe_updateObject() flags */
#define SUBFRAME_RECURSION 5
-#define UPDATE_MESH (1 << 1)
-#define UPDATE_EVERYTHING (UPDATE_MESH) // | UPDATE_PARENTS
/* surface_getBrushFlags() return vals */
#define BRUSH_USES_VELOCITY (1 << 0)
/* brush mesh raycast status */
@@ -484,93 +482,6 @@ static float mixColors(float a_color[3], float a_weight, const float b_color[3],
return (1.0f - factor) * a_weight + factor * b_weight;
}
-/* set "ignore cache" flag for all caches on this object */
-static void object_cacheIgnoreClear(Object *ob, int state)
-{
- ListBase pidlist;
- PTCacheID *pid;
- BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
-
- for (pid = pidlist.first; pid; pid = pid->next) {
- if (pid->cache) {
- if (state)
- pid->cache->flag |= PTCACHE_IGNORE_CLEAR;
- else
- pid->cache->flag &= ~PTCACHE_IGNORE_CLEAR;
- }
- }
-
- BLI_freelistN(&pidlist);
-}
-
-static int subframe_updateObject(Scene *scene, Object *ob, int flags, int parent_recursion, float frame)
-{
- DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(ob, eModifierType_DynamicPaint);
- bConstraint *con;
-
- /* if other is dynamic paint canvas, don't update */
- if (pmd && pmd->canvas)
- return 1;
-
- /* if object has parents, update them too */
- if (parent_recursion) {
- int recursion = parent_recursion - 1;
- int is_canvas = 0;
- if (ob->parent) is_canvas += subframe_updateObject(scene, ob->parent, 0, recursion, frame);
- if (ob->track) is_canvas += subframe_updateObject(scene, ob->track, 0, recursion, frame);
-
- /* skip subframe if object is parented
- * to vertex of a dynamic paint canvas */
- if (is_canvas && (ob->partype == PARVERT1 || ob->partype == PARVERT3))
- return 0;
-
- /* also update constraint targets */
- for (con = ob->constraints.first; con; con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- ListBase targets = {NULL, NULL};
-
- if (cti && cti->get_constraint_targets) {
- bConstraintTarget *ct;
- cti->get_constraint_targets(con, &targets);
- for (ct = targets.first; ct; ct = ct->next) {
- if (ct->tar)
- subframe_updateObject(scene, ct->tar, 0, recursion, frame);
- }
- /* free temp targets */
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(con, &targets, 0);
- }
- }
- }
-
- /* was originally OB_RECALC_ALL - TODO - which flags are really needed??? */
- ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
- BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, frame, ADT_RECALC_ANIM);
- if (flags & UPDATE_MESH) {
- /* ignore cache clear during subframe updates
- * to not mess up cache validity */
- object_cacheIgnoreClear(ob, 1);
- BKE_object_handle_update(G.main->eval_ctx, scene, ob);
- object_cacheIgnoreClear(ob, 0);
- }
- else
- BKE_object_where_is_calc_time(scene, ob, frame);
-
- /* for curve following objects, parented curve has to be updated too */
- if (ob->type == OB_CURVE) {
- Curve *cu = ob->data;
- BKE_animsys_evaluate_animdata(scene, &cu->id, cu->adt, frame, ADT_RECALC_ANIM);
- }
- /* and armatures... */
- if (ob->type == OB_ARMATURE) {
- bArmature *arm = ob->data;
- BKE_animsys_evaluate_animdata(scene, &arm->id, arm->adt, frame, ADT_RECALC_ANIM);
- BKE_pose_where_is(scene, ob);
- }
-
- return 0;
-}
-
static void scene_setSubframe(Scene *scene, float subframe)
{
/* dynamic paint subframes must be done on previous frame */
@@ -1773,8 +1684,8 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd,
}
else {
col[l_index].r =
- col[l_index].g =
- col[l_index].b = FTOCHAR(pPoint[v_index].wetness);
+ col[l_index].g =
+ col[l_index].b = FTOCHAR(pPoint[v_index].wetness);
col[l_index].a = 255;
}
}
@@ -2278,8 +2189,10 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface)
tottri = dm->getNumLoopTri(dm);
/* get uv map */
- CustomData_validate_layer_name(&dm->loopData, CD_MLOOPUV, surface->uvlayer_name, uvname);
- mloopuv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, uvname);
+ if (CustomData_has_layer(&dm->loopData, CD_MLOOPUV)) {
+ CustomData_validate_layer_name(&dm->loopData, CD_MLOOPUV, surface->uvlayer_name, uvname);
+ mloopuv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, uvname);
+ }
/* Check for validity */
if (!mloopuv)
@@ -2536,11 +2449,11 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface)
/* Generate surface adjacency data. */
{
- int i, cursor = 0;
+ int cursor = 0;
/* Create a temporary array of final indexes (before unassigned
* pixels have been dropped) */
- for (i = 0; i < w * h; i++) {
+ for (int i = 0; i < w * h; i++) {
if (tempPoints[i].tri_index != -1) {
final_index[i] = cursor;
cursor++;
@@ -2556,13 +2469,13 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface)
for (ty = 0; ty < h; ty++) {
int tx;
for (tx = 0; tx < w; tx++) {
- int i, index = tx + w * ty;
+ int index = tx + w * ty;
if (tempPoints[index].tri_index != -1) {
ed->n_index[final_index[index]] = n_pos;
ed->n_num[final_index[index]] = 0;
- for (i = 0; i < 8; i++) {
+ for (int i = 0; i < 8; i++) {
/* Try to find a neighboring pixel in defined direction
* If not found, -1 is returned */
@@ -2806,13 +2719,13 @@ static void dynamicPaint_updateBrushMaterials(Object *brushOb, Material *ui_mat,
if (tot) {
bMats->ob_mats = MEM_callocN(sizeof(Material *) * (tot), "BrushMaterials");
for (i = 0; i < tot; i++) {
- bMats->ob_mats[i] = RE_init_sample_material(give_current_material(brushOb, (i + 1)), scene);
+ bMats->ob_mats[i] = RE_sample_material_init(give_current_material(brushOb, (i + 1)), scene);
}
}
bMats->tot = tot;
}
else {
- bMats->mat = RE_init_sample_material(ui_mat, scene);
+ bMats->mat = RE_sample_material_init(ui_mat, scene);
}
}
@@ -2823,12 +2736,12 @@ static void dynamicPaint_freeBrushMaterials(BrushMaterials *bMats)
if (bMats->ob_mats) {
int i;
for (i = 0; i < bMats->tot; i++) {
- RE_free_sample_material(bMats->ob_mats[i]);
+ RE_sample_material_free(bMats->ob_mats[i]);
}
MEM_freeN(bMats->ob_mats);
}
else if (bMats->mat) {
- RE_free_sample_material(bMats->mat);
+ RE_sample_material_free(bMats->mat);
}
}
@@ -3156,7 +3069,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy
scene->r.cfra = prev_fra;
scene->r.subframe = prev_sfra;
- subframe_updateObject(scene, ob, UPDATE_EVERYTHING, SUBFRAME_RECURSION, BKE_scene_frame_get(scene));
+ BKE_object_modifier_update_subframe(scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
dm_p = CDDM_copy(brush->dm);
numOfVerts_p = dm_p->getNumVerts(dm_p);
mvert_p = dm_p->getVertArray(dm_p);
@@ -3166,7 +3079,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy
scene->r.cfra = cur_fra;
scene->r.subframe = cur_sfra;
- subframe_updateObject(scene, ob, UPDATE_EVERYTHING, SUBFRAME_RECURSION, BKE_scene_frame_get(scene));
+ BKE_object_modifier_update_subframe(scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
dm_c = brush->dm;
numOfVerts_c = dm_c->getNumVerts(dm_c);
mvert_c = dm_p->getVertArray(dm_c);
@@ -3216,13 +3129,13 @@ static void dynamicPaint_brushObjectCalculateVelocity(Scene *scene, Object *ob,
/* previous frame dm */
scene->r.cfra = prev_fra;
scene->r.subframe = prev_sfra;
- subframe_updateObject(scene, ob, 0, SUBFRAME_RECURSION, BKE_scene_frame_get(scene));
+ BKE_object_modifier_update_subframe(scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
copy_m4_m4(prev_obmat, ob->obmat);
/* current frame dm */
scene->r.cfra = cur_fra;
scene->r.subframe = cur_sfra;
- subframe_updateObject(scene, ob, 0, SUBFRAME_RECURSION, BKE_scene_frame_get(scene));
+ BKE_object_modifier_update_subframe(scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
/* calculate speed */
mul_m4_v3(prev_obmat, prev_loc);
@@ -3363,7 +3276,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
add_v3_fl(ray_start, 0.001f);
hit.index = -1;
- hit.dist = 9999;
+ hit.dist = BVH_RAYCAST_DIST_MAX;
nearest.index = -1;
nearest.dist_sq = brush_radius * brush_radius; /* find_nearest uses squared distance */
@@ -3393,7 +3306,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
* point is at least surrounded by two brush faces */
negate_v3(ray_dir);
hit.index = -1;
- hit.dist = 9999;
+ hit.dist = BVH_RAYCAST_DIST_MAX;
BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_tris_spherecast_dp, &treeData);
@@ -3628,7 +3541,6 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface,
float timescale)
{
ParticleSettings *part = psys->part;
- ParticleData *pa = NULL;
PaintSurfaceData *sData = surface->data;
PaintBakeData *bData = sData->bData;
VolumeGrid *grid = bData->grid;
@@ -3654,7 +3566,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface,
tree = BLI_kdtree_new(psys->totpart);
/* loop through particles and insert valid ones to the tree */
- for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++) {
+ p = 0;
+ for (ParticleData *pa = psys->particles; p < psys->totpart; p++, pa++) {
/* Proceed only if particle is active */
if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) continue;
@@ -4947,7 +4860,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
/* update object data on this subframe */
if (subframe) {
scene_setSubframe(scene, subframe);
- subframe_updateObject(scene, brushObj, UPDATE_EVERYTHING, SUBFRAME_RECURSION, BKE_scene_frame_get(scene));
+ BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
}
/* Prepare materials if required */
if (brush_usesMaterial(brush, scene))
@@ -4981,7 +4894,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
if (subframe) {
scene->r.cfra = scene_frame;
scene->r.subframe = scene_subframe;
- subframe_updateObject(scene, brushObj, UPDATE_EVERYTHING, SUBFRAME_RECURSION, BKE_scene_frame_get(scene));
+ BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
}
/* process special brush effects, like smudge */