[Bf-blender-cvs] [0e8edbbc01c] blender2.8: Add utility functions to get different "levels" of evaluated/original mesh

Sergey Sharybin noreply at git.blender.org
Mon Jun 4 15:50:07 CEST 2018


Commit: 0e8edbbc01c0514ffb2c4abb8c5652b0d5fdb979
Author: Sergey Sharybin
Date:   Mon Jun 4 15:48:37 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB0e8edbbc01c0514ffb2c4abb8c5652b0d5fdb979

Add utility functions to get different "levels" of evaluated/original mesh

===================================================================

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 3929a97ab65..ded6aa425d8 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -274,6 +274,9 @@ void BKE_object_sculpt_modifiers_changed(struct Object *ob);
 int BKE_object_obdata_texspace_get(struct Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot);
 
 struct Mesh *BKE_object_get_evaluated_mesh(const struct Depsgraph *depsgraph, struct Object *ob);
+struct Mesh *BKE_object_get_final_mesh(struct Object *object);
+struct Mesh *BKE_object_get_unmodified_mesh(struct Object *object);
+struct Mesh *BKE_object_get_original_mesh(struct Object *object);
 
 int BKE_object_insert_ptcache(struct Object *ob);
 void BKE_object_delete_ptcache(struct Object *ob, int index);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 6003b730176..6da8d7fc154 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2851,6 +2851,62 @@ Mesh *BKE_object_get_evaluated_mesh(const Depsgraph *depsgraph, Object *ob)
 	return ob_eval->runtime.mesh_eval;
 }
 
+/* Get object's mesh with all modifiers applied. */
+Mesh *BKE_object_get_final_mesh(Object *object)
+{
+	if (object->runtime.mesh_eval != NULL) {
+		BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0);
+		BLI_assert(object->runtime.mesh_eval == object->data);
+		BLI_assert((object->runtime.mesh_eval->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) != 0);
+		return object->runtime.mesh_eval;
+	}
+	/* Wasn't evaluated yet. */
+	return object->data;
+}
+
+/* Get mesh which is not affected by modifiers:
+ * - For original objects it will be same as object->data, and it is a mesh
+ *   which is in the corresponding bmain.
+ * - For copied-on-write objects it will give pointer to a copied-on-write
+ *   mesh which corresponds to original object's mesh.
+ */
+Mesh *BKE_object_get_unmodified_mesh(Object *object)
+{
+	if (object->runtime.mesh_orig != NULL) {
+		BLI_assert(object->id.tag & LIB_TAG_COPIED_ON_WRITE);
+		BLI_assert(object->id.orig_id != NULL);
+		BLI_assert(object->runtime.mesh_orig->id.orig_id ==
+		           ((Object*)object->id.orig_id)->data);
+		Mesh *result = object->runtime.mesh_orig;
+		BLI_assert((result->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0);
+		BLI_assert((result->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) == 0);
+		return result;
+	}
+	BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0);
+	return object->data;
+}
+
+/* Get a mesh which corresponds to very very original mesh from bmain.
+ * - For original objects it will be object->data.
+ * - For evaluated objects it will be same mesh as corresponding original
+ *   object uses as data.
+ */
+Mesh *BKE_object_get_original_mesh(Object *object)
+{
+	Mesh *result = NULL;
+	if (object->id.orig_id == NULL) {
+		BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0);
+		result = object->data;
+	}
+	else {
+		BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0);
+		result = ((Object*)object->id.orig_id)->data;
+	}
+	BLI_assert(result != NULL);
+	BLI_assert((result->id.tag & (LIB_TAG_COPIED_ON_WRITE | LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT)) == 0);
+	return result;
+}
+
 static int pc_cmp(const void *a, const void *b)
 {
 	const LinkData *ad = a, *bd = b;



More information about the Bf-blender-cvs mailing list