From 318112379d6d251334b8f3d2a20b935210446b4f Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 27 Feb 2020 11:23:15 +0100 Subject: Objects: make evaluated data runtime storage usable for types other than mesh This is in preparation of new object types. This only changes mesh_eval, we may do the same for mesh_deform_eval and other areas in the future if there is a need for it. This previously caused a bug in T74283, that should be fixed now. Differential Revision: https://developer.blender.org/D6695 --- source/blender/makesrna/intern/rna_object_api.c | 27 +++++++++++-------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'source/blender/makesrna/intern/rna_object_api.c') diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 5552de00be8..cbeb8f17991 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -487,7 +487,7 @@ static Object *eval_object_ensure(Object *ob, ReportList *reports, PointerRNA *rnaptr_depsgraph) { - if (ob->runtime.mesh_eval == NULL) { + if (ob->runtime.data_eval == NULL) { Object *ob_orig = ob; Depsgraph *depsgraph = rnaptr_depsgraph != NULL ? rnaptr_depsgraph->data : NULL; if (depsgraph == NULL) { @@ -496,7 +496,7 @@ static Object *eval_object_ensure(Object *ob, if (depsgraph != NULL) { ob = DEG_get_evaluated_object(depsgraph, ob); } - if (ob == NULL || ob->runtime.mesh_eval == NULL) { + if (ob == NULL || BKE_object_get_evaluated_mesh(ob) == NULL) { BKE_reportf( reports, RPT_ERROR, "Object '%s' has no evaluated mesh data", ob_orig->id.name + 2); return NULL; @@ -521,8 +521,7 @@ static void rna_Object_ray_cast(Object *ob, /* TODO(sergey): This isn't very reliable check. It is possible to have non-NULL pointer * but which is out of date, and possibly dangling one. */ - if (ob->runtime.mesh_eval == NULL && - (ob = eval_object_ensure(ob, C, reports, rnaptr_depsgraph)) == NULL) { + if ((ob = eval_object_ensure(ob, C, reports, rnaptr_depsgraph)) == NULL) { return; } @@ -538,7 +537,8 @@ static void rna_Object_ray_cast(Object *ob, /* No need to managing allocation or freeing of the BVH data. * This is generated and freed as needed. */ - BKE_bvhtree_from_mesh_get(&treeData, ob->runtime.mesh_eval, BVHTREE_FROM_LOOPTRI, 4); + Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob); + BKE_bvhtree_from_mesh_get(&treeData, mesh_eval, BVHTREE_FROM_LOOPTRI, 4); /* may fail if the mesh has no faces, in that case the ray-cast misses */ if (treeData.tree != NULL) { @@ -559,8 +559,7 @@ static void rna_Object_ray_cast(Object *ob, copy_v3_v3(r_location, hit.co); copy_v3_v3(r_normal, hit.no); - *r_index = mesh_looptri_to_poly_index(ob->runtime.mesh_eval, - &treeData.looptri[hit.index]); + *r_index = mesh_looptri_to_poly_index(mesh_eval, &treeData.looptri[hit.index]); } } @@ -589,14 +588,14 @@ static void rna_Object_closest_point_on_mesh(Object *ob, { BVHTreeFromMesh treeData = {NULL}; - if (ob->runtime.mesh_eval == NULL && - (ob = eval_object_ensure(ob, C, reports, rnaptr_depsgraph)) == NULL) { + if ((ob = eval_object_ensure(ob, C, reports, rnaptr_depsgraph)) == NULL) { return; } /* No need to managing allocation or freeing of the BVH data. * this is generated and freed as needed. */ - BKE_bvhtree_from_mesh_get(&treeData, ob->runtime.mesh_eval, BVHTREE_FROM_LOOPTRI, 4); + Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob); + BKE_bvhtree_from_mesh_get(&treeData, mesh_eval, BVHTREE_FROM_LOOPTRI, 4); if (treeData.tree == NULL) { BKE_reportf(reports, @@ -617,8 +616,7 @@ static void rna_Object_closest_point_on_mesh(Object *ob, copy_v3_v3(r_location, nearest.co); copy_v3_v3(r_normal, nearest.no); - *r_index = mesh_looptri_to_poly_index(ob->runtime.mesh_eval, - &treeData.looptri[nearest.index]); + *r_index = mesh_looptri_to_poly_index(mesh_eval, &treeData.looptri[nearest.index]); goto finally; } @@ -659,8 +657,7 @@ void rna_Object_me_eval_info( switch (type) { case 1: case 2: - if (ob->runtime.mesh_eval == NULL && - (ob = eval_object_ensure(ob, C, NULL, rnaptr_depsgraph)) == NULL) { + if ((ob = eval_object_ensure(ob, C, NULL, rnaptr_depsgraph)) == NULL) { return; } } @@ -675,7 +672,7 @@ void rna_Object_me_eval_info( me_eval = ob->runtime.mesh_deform_eval; break; case 2: - me_eval = ob->runtime.mesh_eval; + me_eval = BKE_object_get_evaluated_mesh(ob); break; } -- cgit v1.2.3