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
path: root/source
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2015-03-18 21:22:38 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2015-03-26 16:13:39 +0300
commitc5d1d174f2bb9f55a258adcff4cbf736c0481541 (patch)
tree518a8ca2b2410ad7960e6fbea6fa43e4cd423d20 /source
parentaebc98e06179647e0f45a1d12f7289534f0edfdd (diff)
Cycles support for dupli caches.
If a cache is read-enabled cycles will now use the cached mesh data instead of dupli results.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_mesh.h2
-rw-r--r--source/blender/blenkernel/intern/mesh.c60
-rw-r--r--source/blender/makesrna/intern/rna_main_api.c21
-rw-r--r--source/blender/makesrna/intern/rna_object.c11
-rw-r--r--source/blender/makesrna/intern/rna_object_api.c20
5 files changed, 114 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 1f3458c06c2..a694c913faf 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -41,6 +41,7 @@ struct BLI_Stack;
struct MemArena;
struct BMEditMesh;
struct BMesh;
+struct DupliObjectData;
struct Main;
struct Mesh;
struct MPoly;
@@ -135,6 +136,7 @@ void BKE_mesh_split_faces(struct Mesh *mesh);
struct Mesh *BKE_mesh_new_from_object(struct Main *bmain, struct Scene *sce, struct Object *ob,
int apply_modifiers, int settings, int calc_tessface, int calc_undeformed);
+struct Mesh *BKE_mesh_new_from_dupli_cache(struct Main *bmain, struct DupliObjectData *data, bool calc_tessface, bool calc_undeformed);
/* vertex level transformations & checks (no derived mesh) */
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 8ebc318ff9e..751b67a18aa 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -2479,3 +2479,63 @@ Mesh *BKE_mesh_new_from_object(
return tmpmesh;
}
+
+/* settings: 1 - preview, 2 - render */
+Mesh *BKE_mesh_new_from_dupli_cache(
+ Main *bmain, DupliObjectData *data,
+ bool calc_tessface, bool calc_undeformed)
+{
+ Object *ob = data->ob;
+ DerivedMesh *dm = data->cache_dm;
+ CustomDataMask mask;
+
+ Mesh *tmpmesh;
+
+ if (!ob || !dm)
+ return NULL;
+
+ mask = CD_MASK_MESH; /* this seems more suitable, exporter,
+ * for example, needs CD_MASK_MDEFORMVERT */
+ if (calc_undeformed)
+ mask |= CD_MASK_ORCO;
+
+ tmpmesh = BKE_mesh_add(bmain, "Mesh");
+ DM_to_mesh(dm, tmpmesh, ob, mask, true);
+
+ /* BKE_mesh_add/copy gives us a user count we don't need */
+ tmpmesh->id.us--;
+
+ /* Copy materials to new mesh */
+ switch (ob->type) {
+ case OB_MESH: {
+ Mesh *origmesh = ob->data;
+ int i;
+
+ tmpmesh->flag = origmesh->flag;
+ tmpmesh->mat = MEM_dupallocN(origmesh->mat);
+ tmpmesh->totcol = origmesh->totcol;
+ tmpmesh->smoothresh = origmesh->smoothresh;
+ if (origmesh->mat) {
+ for (i = origmesh->totcol; i-- > 0; ) {
+ /* are we an object material or data based? */
+ tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : origmesh->mat[i];
+
+ if (tmpmesh->mat[i]) {
+ tmpmesh->mat[i]->id.us++;
+ }
+ }
+ }
+ break;
+ }
+ } /* end copy materials */
+
+ if (calc_tessface) {
+ /* cycles and exporters rely on this still */
+ BKE_mesh_tessface_ensure(tmpmesh);
+ }
+
+ /* make sure materials get updated in objects */
+ test_object_materials(bmain, &tmpmesh->id);
+
+ return tmpmesh;
+}
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index b922f6c70da..13307a1a2be 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -48,6 +48,7 @@
#ifdef RNA_RUNTIME
#include "BKE_main.h"
+#include "BKE_anim.h"
#include "BKE_cache_library.h"
#include "BKE_camera.h"
#include "BKE_curve.h"
@@ -310,6 +311,15 @@ Mesh *rna_Main_meshes_new_from_object(
return BKE_mesh_new_from_object(bmain, sce, ob, apply_modifiers, settings, calc_tessface, calc_undeformed);
}
+/* copied from Mesh_getFromObject and adapted to RNA interface */
+/* settings: 1 - preview, 2 - render */
+Mesh *rna_Main_meshes_new_from_dupli_cache(
+ Main *bmain, ReportList *UNUSED(reports), DupliObjectData *data,
+ int calc_tessface, int calc_undeformed)
+{
+ return BKE_mesh_new_from_dupli_cache(bmain, data, calc_tessface, calc_undeformed);
+}
+
static void rna_Main_meshes_remove(Main *bmain, ReportList *reports, PointerRNA *mesh_ptr)
{
Mesh *mesh = mesh_ptr->data;
@@ -1057,6 +1067,17 @@ void RNA_def_main_meshes(BlenderRNA *brna, PropertyRNA *cprop)
"Mesh created from object, remove it if it is only used for export");
RNA_def_function_return(func, parm);
+ func = RNA_def_function(srna, "new_from_dupli_cache", "rna_Main_meshes_new_from_dupli_cache");
+ RNA_def_function_ui_description(func, "Add a new mesh created from dupli cache data");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "data", "DupliObjectData", "", "Dupli Object Data");
+ RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
+ RNA_def_boolean(func, "calc_tessface", true, "Calculate Tessellation", "Calculate tessellation faces");
+ RNA_def_boolean(func, "calc_undeformed", false, "Calculate Undeformed", "Calculate undeformed vertex coordinates");
+ parm = RNA_def_pointer(func, "mesh", "Mesh", "",
+ "Mesh created from object, remove it if it is only used for export");
+ RNA_def_function_return(func, parm);
+
func = RNA_def_function(srna, "remove", "rna_Main_meshes_remove");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Remove a mesh from the current blendfile");
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index f6daa6027ae..48b4e1c57cc 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -2871,6 +2871,16 @@ static void rna_def_dupli_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Dupli Type", "Duplicator type that generated this dupli object");
}
+static void rna_def_dupli_object_data(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "DupliObjectData", NULL);
+ RNA_def_struct_sdna(srna, "DupliObjectData");
+ RNA_def_struct_ui_text(srna, "Object Duplicate Data", "Override of object data for duplis");
+}
+
static void rna_def_object_base(BlenderRNA *brna)
{
StructRNA *srna;
@@ -2917,6 +2927,7 @@ void RNA_def_object(BlenderRNA *brna)
rna_def_vertex_group(brna);
rna_def_material_slot(brna);
rna_def_dupli_object(brna);
+ rna_def_dupli_object_data(brna);
RNA_define_animate_sdna(true);
rna_def_object_lodlevel(brna);
}
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index 9fe44511c8c..aebe673bf5c 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -222,6 +222,18 @@ static void rna_Object_free_duplilist(Object *ob)
}
}
+static PointerRNA rna_Object_find_dupli_cache(Object *ob, Object *dupob)
+{
+ DupliObjectData *data = NULL;
+ PointerRNA ptr;
+
+ if (ob->dup_cache)
+ data = BKE_dupli_cache_find_data(ob->dup_cache, dupob);
+
+ RNA_pointer_create((ID *)ob, &RNA_DupliObjectData, data, &ptr);
+ return ptr;
+}
+
static PointerRNA rna_Object_shape_key_add(Object *ob, bContext *C, ReportList *reports,
const char *name, int from_mix)
{
@@ -547,6 +559,14 @@ void RNA_api_object(StructRNA *srna)
func = RNA_def_function(srna, "dupli_list_clear", "rna_Object_free_duplilist");
RNA_def_function_ui_description(func, "Free the list of dupli objects");
+ func = RNA_def_function(srna, "find_dupli_cache", "rna_Object_find_dupli_cache");
+ RNA_def_function_ui_description(func, "Find cached data for a dupli object");
+ parm = RNA_def_pointer(func, "object", "Object", "", "Object data to look up");
+ RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
+ parm = RNA_def_pointer(func, "data", "DupliObjectData", "", "Cached object data");
+ RNA_def_property_flag(parm, PROP_RNAPTR);
+ RNA_def_function_return(func, parm);
+
/* Armature */
func = RNA_def_function(srna, "find_armature", "modifiers_isDeformedByArmature");
RNA_def_function_ui_description(func, "Find armature influencing this object as a parent or via a modifier");