Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_convert.c
| Show First 20 Lines • Show All 582 Lines • ▼ Show 20 Lines | |||||
| void BKE_mesh_from_nurbs_displist(Main *bmain, | void BKE_mesh_from_nurbs_displist(Main *bmain, | ||||
| Object *ob, | Object *ob, | ||||
| ListBase *dispbase, | ListBase *dispbase, | ||||
| const bool use_orco_uv, | const bool use_orco_uv, | ||||
| const char *obdata_name, | const char *obdata_name, | ||||
| bool temporary) | bool temporary) | ||||
| { | { | ||||
| Object *ob1; | Object *ob1; | ||||
| Mesh *me_eval = ob->runtime.mesh_eval; | Mesh *me_eval = (Mesh *)ob->runtime.data_eval; | ||||
| Mesh *me; | Mesh *me; | ||||
| Curve *cu; | Curve *cu; | ||||
| MVert *allvert = NULL; | MVert *allvert = NULL; | ||||
| MEdge *alledge = NULL; | MEdge *alledge = NULL; | ||||
| MLoop *allloop = NULL; | MLoop *allloop = NULL; | ||||
| MLoopUV *alluv = NULL; | MLoopUV *alluv = NULL; | ||||
| MPoly *allpoly = NULL; | MPoly *allpoly = NULL; | ||||
| int totvert, totedge, totloop, totpoly; | int totvert, totedge, totloop, totpoly; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | void BKE_mesh_from_nurbs_displist(Main *bmain, | ||||
| else { | else { | ||||
| if (bmain != NULL) { | if (bmain != NULL) { | ||||
| me = BKE_mesh_add(bmain, obdata_name); | me = BKE_mesh_add(bmain, obdata_name); | ||||
| } | } | ||||
| else { | else { | ||||
| me = BKE_id_new_nomain(ID_ME, obdata_name); | me = BKE_id_new_nomain(ID_ME, obdata_name); | ||||
| } | } | ||||
| ob->runtime.mesh_eval = NULL; | ob->runtime.data_eval = NULL; | ||||
| BKE_mesh_nomain_to_mesh(me_eval, me, ob, &CD_MASK_MESH, true); | BKE_mesh_nomain_to_mesh(me_eval, me, ob, &CD_MASK_MESH, true); | ||||
| } | } | ||||
| me->totcol = cu->totcol; | me->totcol = cu->totcol; | ||||
| me->mat = cu->mat; | me->mat = cu->mat; | ||||
| /* Copy evaluated texture space from curve to mesh. | /* Copy evaluated texture space from curve to mesh. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 269 Lines • ▼ Show 20 Lines | static Object *object_for_curve_to_mesh_create(Object *object) | ||||
| * Note that there are extra fields in there like bevel and path, but those are not needed during | * Note that there are extra fields in there like bevel and path, but those are not needed during | ||||
| * conversion, so they are not copied to save unnecessary allocations. */ | * conversion, so they are not copied to save unnecessary allocations. */ | ||||
| if (object->runtime.curve_cache != NULL) { | if (object->runtime.curve_cache != NULL) { | ||||
| temp_object->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), | temp_object->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), | ||||
| "CurveCache for curve types"); | "CurveCache for curve types"); | ||||
| BKE_displist_copy(&temp_object->runtime.curve_cache->disp, &object->runtime.curve_cache->disp); | BKE_displist_copy(&temp_object->runtime.curve_cache->disp, &object->runtime.curve_cache->disp); | ||||
| } | } | ||||
| /* Constructive modifiers will use mesh to store result. */ | /* Constructive modifiers will use mesh to store result. */ | ||||
| if (object->runtime.mesh_eval != NULL) { | if (object->runtime.data_eval != NULL) { | ||||
| BKE_id_copy_ex(NULL, | BKE_id_copy_ex( | ||||
| &object->runtime.mesh_eval->id, | NULL, object->runtime.data_eval, &temp_object->runtime.data_eval, LIB_ID_COPY_LOCALIZE); | ||||
| (ID **)&temp_object->runtime.mesh_eval, | |||||
| LIB_ID_COPY_LOCALIZE); | |||||
| } | } | ||||
| /* Need to create copy of curve itself as well, it will be freed by underlying conversion | /* Need to create copy of curve itself as well, it will be freed by underlying conversion | ||||
| * functions. | * functions. | ||||
| * | * | ||||
| * NOTE: Copies the data, but not the shapekeys. */ | * NOTE: Copies the data, but not the shapekeys. */ | ||||
| BKE_id_copy_ex(NULL, object->data, (ID **)&temp_object->data, LIB_ID_COPY_LOCALIZE); | BKE_id_copy_ex(NULL, object->data, (ID **)&temp_object->data, LIB_ID_COPY_LOCALIZE); | ||||
| Curve *temp_curve = (Curve *)temp_object->data; | Curve *temp_curve = (Curve *)temp_object->data; | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | static void curve_to_mesh_eval_ensure(Object *object) | ||||
| /* NOTE: We don't have dependency graph or scene here, so we pass NULL. This is all fine since | /* NOTE: We don't have dependency graph or scene here, so we pass NULL. This is all fine since | ||||
| * they are only used for modifier stack, which we have explicitly disabled for all objects. | * they are only used for modifier stack, which we have explicitly disabled for all objects. | ||||
| * | * | ||||
| * TODO(sergey): This is a very fragile logic, but proper solution requires re-writing quite a | * TODO(sergey): This is a very fragile logic, but proper solution requires re-writing quite a | ||||
| * bit of internal functions (BKE_mesh_from_nurbs_displist, BKE_mesh_nomain_to_mesh) and also | * bit of internal functions (BKE_mesh_from_nurbs_displist, BKE_mesh_nomain_to_mesh) and also | ||||
| * Mesh From Curve operator. | * Mesh From Curve operator. | ||||
| * Brecht says hold off with that. */ | * Brecht says hold off with that. */ | ||||
| BKE_displist_make_curveTypes_forRender(NULL, | Mesh *mesh_eval = NULL; | ||||
| NULL, | BKE_displist_make_curveTypes_forRender( | ||||
| &remapped_object, | NULL, NULL, &remapped_object, &remapped_object.runtime.curve_cache->disp, &mesh_eval, false); | ||||
| &remapped_object.runtime.curve_cache->disp, | |||||
| &remapped_object.runtime.mesh_eval, | |||||
| false); | |||||
| /* Note: this is to be consistent with `BKE_displist_make_curveTypes()`, however that is not a | /* Note: this is to be consistent with `BKE_displist_make_curveTypes()`, however that is not a | ||||
| * real issue currently, code here is broken in more than one way, fix(es) will be done | * real issue currently, code here is broken in more than one way, fix(es) will be done | ||||
| * separately. */ | * separately. */ | ||||
| if (remapped_object.runtime.mesh_eval != NULL) { | if (mesh_eval != NULL) { | ||||
| remapped_object.runtime.mesh_eval->id.tag |= LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT; | BKE_object_eval_assign_data(&remapped_object, &mesh_eval->id, true); | ||||
| remapped_object.runtime.is_mesh_eval_owned = true; | |||||
| } | } | ||||
| BKE_object_free_curve_cache(&bevel_object); | BKE_object_free_curve_cache(&bevel_object); | ||||
| BKE_object_free_curve_cache(&taper_object); | BKE_object_free_curve_cache(&taper_object); | ||||
| } | } | ||||
| static Mesh *mesh_new_from_curve_type_object(Object *object) | static Mesh *mesh_new_from_curve_type_object(Object *object) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | if (DEG_is_original_id(&object->id)) { | ||||
| return mesh_new_from_mesh(object, (Mesh *)object->data); | return mesh_new_from_mesh(object, (Mesh *)object->data); | ||||
| } | } | ||||
| if (depsgraph == NULL) { | if (depsgraph == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| Object object_for_eval = *object; | Object object_for_eval = *object; | ||||
| if (object_for_eval.runtime.mesh_orig != NULL) { | if (object_for_eval.runtime.data_orig != NULL) { | ||||
| object_for_eval.data = object_for_eval.runtime.mesh_orig; | object_for_eval.data = object_for_eval.runtime.data_orig; | ||||
| } | } | ||||
| Scene *scene = DEG_get_evaluated_scene(depsgraph); | Scene *scene = DEG_get_evaluated_scene(depsgraph); | ||||
| CustomData_MeshMasks mask = CD_MASK_MESH; | CustomData_MeshMasks mask = CD_MASK_MESH; | ||||
| Mesh *result; | Mesh *result; | ||||
| if (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER) { | if (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER) { | ||||
| result = mesh_create_eval_final_render(depsgraph, scene, &object_for_eval, &mask); | result = mesh_create_eval_final_render(depsgraph, scene, &object_for_eval, &mask); | ||||
| ▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| Mesh *BKE_mesh_create_derived_for_modifier(struct Depsgraph *depsgraph, | Mesh *BKE_mesh_create_derived_for_modifier(struct Depsgraph *depsgraph, | ||||
| Scene *scene, | Scene *scene, | ||||
| Object *ob_eval, | Object *ob_eval, | ||||
| ModifierData *md_eval, | ModifierData *md_eval, | ||||
| int build_shapekey_layers) | int build_shapekey_layers) | ||||
| { | { | ||||
| Mesh *me = ob_eval->runtime.mesh_orig ? ob_eval->runtime.mesh_orig : ob_eval->data; | Mesh *me = ob_eval->runtime.data_orig ? ob_eval->runtime.data_orig : ob_eval->data; | ||||
| const ModifierTypeInfo *mti = modifierType_getInfo(md_eval->type); | const ModifierTypeInfo *mti = modifierType_getInfo(md_eval->type); | ||||
| Mesh *result; | Mesh *result; | ||||
| KeyBlock *kb; | KeyBlock *kb; | ||||
| ModifierEvalContext mectx = {depsgraph, ob_eval, 0}; | ModifierEvalContext mectx = {depsgraph, ob_eval, 0}; | ||||
| if (!(md_eval->mode & eModifierMode_Realtime)) { | if (!(md_eval->mode & eModifierMode_Realtime)) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines | |||||