Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pointcloud.c
| Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | if (reference) { | ||||
| flags |= LIB_ID_COPY_CD_REFERENCE; | flags |= LIB_ID_COPY_CD_REFERENCE; | ||||
| } | } | ||||
| PointCloud *result; | PointCloud *result; | ||||
| BKE_id_copy_ex(NULL, &pointcloud_src->id, (ID **)&result, flags); | BKE_id_copy_ex(NULL, &pointcloud_src->id, (ID **)&result, flags); | ||||
| return result; | return result; | ||||
| } | } | ||||
| static PointCloud *pointcloud_evaluate_modifiers(struct Depsgraph *UNUSED(depsgraph), | static PointCloud *pointcloud_evaluate_modifiers(struct Depsgraph *depsgraph, | ||||
| struct Scene *UNUSED(scene), | struct Scene *scene, | ||||
| Object *UNUSED(object), | Object *object, | ||||
| PointCloud *pointcloud_input) | PointCloud *pointcloud_input) | ||||
| { | { | ||||
| return pointcloud_input; | PointCloud *pointcloud = pointcloud_input; | ||||
| /* Modifier evaluation modes. */ | |||||
| const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); | |||||
| const int required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime; | |||||
| ModifierApplyFlag appflag = use_render ? MOD_APPLY_RENDER : MOD_APPLY_USECACHE; | |||||
| const ModifierEvalContext mectx = {depsgraph, object, appflag}; | |||||
| /* Get effective list of modifiers to execute. Some effects like shape keys | |||||
| * are added as virtual modifiers before the user created modifiers. */ | |||||
| VirtualModifierData virtualModifierData; | |||||
| ModifierData *md = modifiers_getVirtualModifierList(object, &virtualModifierData); | |||||
| /* Evaluate modifiers. */ | |||||
| for (; md; md = md->next) { | |||||
| const ModifierTypeInfo *mti = modifierType_getInfo(md->type); | |||||
| if (!modifier_isEnabled(scene, md, required_mode)) { | |||||
| continue; | |||||
| } | |||||
| if ((mti->type == eModifierTypeType_OnlyDeform) && | |||||
| (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) { | |||||
| /* Ensure we are not modifying the input. */ | |||||
| if (pointcloud == pointcloud_input) { | |||||
| pointcloud = BKE_pointcloud_copy_for_eval(pointcloud, true); | |||||
| } | |||||
| /* Ensure we are not overwriting referenced data. */ | |||||
| CustomData_duplicate_referenced_layer(&pointcloud->pdata, CD_LOCATION, pointcloud->totpoint); | |||||
| BKE_pointcloud_update_customdata_pointers(pointcloud); | |||||
| /* Created deformed coordinates array on demand. */ | |||||
| mti->deformVerts(md, &mectx, NULL, pointcloud->co, pointcloud->totpoint); | |||||
| } | |||||
| else if (mti->modifyPointCloud) { | |||||
| /* Ensure we are not modifying the input. */ | |||||
| if (pointcloud == pointcloud_input) { | |||||
| pointcloud = BKE_pointcloud_copy_for_eval(pointcloud, true); | |||||
| } | |||||
| PointCloud *pointcloud_next = mti->modifyPointCloud(md, &mectx, pointcloud); | |||||
JacquesLucke: Is the modifier responsible for calling `CustomData_duplicate_referenced_layer`, when it wants… | |||||
brechtAuthorUnsubmitted Done Inline ActionsModifiers are expected to use either BKE_pointcloud_new_for_eval or BKE_pointcloud_copy_for_eval, which has a reference parameter. When creating a copy referencing data layers, then indeed CustomData_duplicate_referenced_layer should be used before modifying them. brecht: Modifiers are expected to use either `BKE_pointcloud_new_for_eval` or… | |||||
JacquesLuckeUnsubmitted Not Done Inline ActionsI see, so we create potentially two (shallow) copies of the point cloud for every modifier? JacquesLucke: I see, so we create potentially two (shallow) copies of the point cloud for every modifier? | |||||
JacquesLuckeUnsubmitted Not Done Inline ActionsAh, my fault. I just overlooked pointcloud == pointcloud_input. JacquesLucke: Ah, my fault. I just overlooked `pointcloud == pointcloud_input`. | |||||
| if (pointcloud_next && pointcloud_next != pointcloud) { | |||||
| /* If the modifier returned a new pointcloud, release the old one. */ | |||||
| if (pointcloud != pointcloud_input) { | |||||
| BKE_id_free(NULL, pointcloud); | |||||
| } | |||||
| pointcloud = pointcloud_next; | |||||
| } | |||||
| } | |||||
| } | |||||
| return pointcloud; | |||||
| } | } | ||||
| void BKE_pointcloud_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Object *object) | void BKE_pointcloud_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Object *object) | ||||
| { | { | ||||
| /* Free any evaluated data and restore original data. */ | /* Free any evaluated data and restore original data. */ | ||||
| BKE_object_free_derived_caches(object); | BKE_object_free_derived_caches(object); | ||||
| /* Evaluate modifiers. */ | /* Evaluate modifiers. */ | ||||
| Show All 26 Lines | |||||
Is the modifier responsible for calling CustomData_duplicate_referenced_layer, when it wants to change the positions?