[Bf-blender-cvs] [026ffaf] fracture_modifier: Bake modifier simulation to keyframed objects directly
Martin Felke
noreply at git.blender.org
Sat Nov 1 01:28:32 CET 2014
Commit: 026ffafb1b4916d714621ec3fea4519244b20a8c
Author: Martin Felke
Date: Sat Nov 1 01:28:20 2014 +0100
Branches: fracture_modifier
https://developer.blender.org/rB026ffafb1b4916d714621ec3fea4519244b20a8c
Bake modifier simulation to keyframed objects directly
===================================================================
M release/scripts/startup/bl_ui/properties_physics_fracture.py
M source/blender/blenkernel/BKE_rigidbody.h
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/editors/object/object_intern.h
M source/blender/editors/object/object_modifier.c
M source/blender/editors/object/object_ops.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/modifiers/intern/MOD_fracture.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index d8b9958..f43e368 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -155,6 +155,7 @@ class PHYSICS_PT_fracture_simulation(PhysicButtonsPanel, Panel):
if not(md.refresh):
box.prop(md, "execute_threaded")
box.operator("object.rigidbody_convert_to_objects", text = "Convert To Objects")
+ box.operator("object.rigidbody_convert_to_keyframes", text = "Convert To Keyframed Objects")
if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__)
diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h
index eef355c..7607370 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -82,7 +82,7 @@ void BKE_rigidbody_validate_sim_shard(struct RigidBodyWorld *rbw, struct MeshIsl
void BKE_rigidbody_validate_sim_shard_shape(struct MeshIsland *mi, struct Object *ob, short rebuild);
/* move the islands of the visible mesh according to shard rigidbody movement */
-void BKE_rigidbody_update_cell(struct MeshIsland *mi, struct Object* ob, float loc[3], float rot[4], struct FractureModifierData *rmd);
+void BKE_rigidbody_update_cell(struct MeshIsland *mi, struct Object* ob, float loc[3], float rot[4], struct FractureModifierData *rmd, int frame);
void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_com[3]);
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 4dd39fc..a073705 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -66,6 +66,7 @@
#include "BKE_rigidbody.h"
#include "BKE_modifier.h"
#include "BKE_depsgraph.h"
+#include "BKE_scene.h"
#include "RNA_access.h"
@@ -390,11 +391,11 @@ static void initNormals(struct MeshIsland *mi, Object *ob, FractureModifierData
}
}
-void BKE_rigidbody_update_cell(struct MeshIsland *mi, Object *ob, float loc[3], float rot[4], FractureModifierData *rmd)
+void BKE_rigidbody_update_cell(struct MeshIsland *mi, Object *ob, float loc[3], float rot[4], FractureModifierData *rmd, int frame)
{
float startco[3], centr[3], size[3];
short startno[3];
- int j;
+ int j, i, n;
bool invalidData;
/* hrm have to init Normals HERE, because we cant do this in readfile.c in case the file is loaded (have no access to the Object there)*/
@@ -410,6 +411,26 @@ void BKE_rigidbody_update_cell(struct MeshIsland *mi, Object *ob, float loc[3],
invert_m4_m4(ob->imat, ob->obmat);
mat4_to_size(size, ob->obmat);
+
+ n = frame - mi->start_frame + 1;
+
+ if (mi->frame_count >= 0 && mi->frame_count < n)
+ {
+ mi->locs = MEM_reallocN(mi->locs, sizeof(float) * 3 * (mi->frame_count+1));
+ mi->rots = MEM_reallocN(mi->rots, sizeof(float) * 4 * (mi->frame_count+1));
+
+ i = mi->frame_count;
+ mi->locs[i*3] = loc[0];
+ mi->locs[i*3+1] = loc[1];
+ mi->locs[i*3+2] = loc[2];
+
+ mi->rots[i*4] = rot[0];
+ mi->rots[i*4+1] = rot[1];
+ mi->rots[i*4+2] = rot[2];
+ mi->rots[i*4+3] = rot[3];
+
+ mi->frame_count = n;
+ }
for (j = 0; j < mi->vertex_count; j++) {
struct MVert *vert;
@@ -2663,6 +2684,8 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime)
}
for (mi = rmd->meshIslands.first; mi; mi = mi->next) {
+ int frame;
+
rbo = mi->rigidbody;
if (!rbo) {
continue;
@@ -2685,7 +2708,9 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime)
mul_qt_v3(rbo->orn, centr);
add_v3_v3(rbo->pos, centr);
}
- BKE_rigidbody_update_cell(mi, ob, rbo->pos, rbo->orn, rmd);
+
+ //frame = (int)BKE_scene_frame_get(md->scene);
+ BKE_rigidbody_update_cell(mi, ob, rbo->pos, rbo->orn, rmd, (int)ctime);
}
break;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index ca3b6f3..7ebd778 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4695,6 +4695,9 @@ static void read_meshIsland(FileData *fd, MeshIsland **address)
mi->bb = newdataadr(fd, mi->bb);
mi->vertex_indices = newdataadr(fd, mi->vertex_indices);
+ mi->locs = newdataadr(fd, mi->locs);
+ mi->rots = newdataadr(fd, mi->rots);
+
/* will be refreshed on the fly */
mi->participating_constraint_count = 0;
mi->participating_constraints = NULL;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 7b8abde..dade6d8 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1511,6 +1511,9 @@ static void write_meshIsland(WriteData* wd, MeshIsland* mi)
writedata(wd, DATA, sizeof(int) * mi->neighbor_count, mi->neighbor_ids);
writestruct(wd, DATA, "BoundBox", 1, mi->bb);
writedata(wd, DATA, sizeof(int) * mi->vertex_count, mi->vertex_indices);
+
+ writedata(wd, DATA, sizeof(float) * 3 * mi->frame_count, mi->locs);
+ writedata(wd, DATA, sizeof(float) * 4 * mi->frame_count, mi->rots);
}
static void write_modifiers(WriteData *wd, ListBase *modbase)
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index 344c5bf..6d45594 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -174,6 +174,7 @@ void OBJECT_OT_ocean_bake(struct wmOperatorType *ot);
void OBJECT_OT_fracture_refresh(struct wmOperatorType *ot);
void OBJECT_OT_rigidbody_constraints_refresh(struct wmOperatorType *ot);
void OBJECT_OT_rigidbody_convert_to_objects(struct wmOperatorType *ot);
+void OBJECT_OT_rigidbody_convert_to_keyframes(struct wmOperatorType *ot);
void OBJECT_OT_skin_root_mark(struct wmOperatorType *ot);
void OBJECT_OT_skin_loose_mark_clear(struct wmOperatorType *ot);
void OBJECT_OT_skin_radii_equalize(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index b168297..7b6779e 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -44,6 +44,7 @@
#include "DNA_scene_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_fracture_types.h"
+#include "DNA_group_types.h"
#include "BLI_bitmap.h"
#include "BLI_math.h"
@@ -2674,3 +2675,144 @@ void OBJECT_OT_rigidbody_convert_to_objects(wmOperatorType *ot)
edit_modifier_properties(ot);
}
+static void convert_modifier_to_keyframes(bContext* C, wmOperator *op, FractureModifierData* fmd)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = ED_object_active_context(C);
+ Main *bmain = CTX_data_main(C);
+ Group *gr = BKE_group_add(bmain, "Converted");
+
+ MeshIsland *mi = NULL;
+ for (mi = fmd->meshIslands.first; mi; mi = mi->next)
+ {
+ int i = 0;
+ Object* ob_new;
+ Mesh* me;
+ Base *bas;
+ float cent[3];
+ float origmat[4][4];
+ float origloc[3];
+
+ int start = 1;
+ int end = 250;
+
+ ob_new = BKE_object_add(G.main, scene, OB_MESH);
+ assign_matarar(ob_new, give_matarar(ob), *give_totcolp(ob));
+
+ bas = BKE_scene_base_find(scene, ob_new);
+ BKE_group_object_add(gr, ob_new, scene, bas);
+
+ ED_base_object_activate(C, bas);
+
+ me = (Mesh*)ob_new->data;
+ me->edit_btmesh = NULL;
+
+ DM_to_mesh(mi->physics_mesh, me, ob_new, CD_MASK_MESH);
+
+ /*set origin to centroid*/
+ copy_v3_v3(cent, mi->centroid);
+ mul_m4_v3(ob_new->obmat, cent);
+ copy_v3_v3(ob_new->loc, cent);
+
+ start = RNA_int_get(op->ptr, "start_frame");
+ end = RNA_int_get(op->ptr, "end_frame");
+
+ if (start < mi->start_frame) {
+ start = mi->start_frame;
+ }
+
+ if (end > mi->start_frame + mi->frame_count) {
+ end = mi->start_frame + mi->frame_count;
+ }
+
+ copy_m4_m4(origmat, ob_new->obmat);
+ copy_v3_v3(origloc, ob_new->loc);
+ for (i = start+1; i < end-1; i++)
+ {
+ /*move object (loc, rot)*/
+
+ float loc[3], rot[4];
+ float mat[4][4];
+ float size[3] = {1.0f, 1.0f, 1.0f};
+
+ loc[0] = mi->locs[i*3];
+ loc[1] = mi->locs[i*3+1];
+ loc[2] = mi->locs[i*3+2];
+
+ rot[0] = mi->rots[i*4];
+ rot[1] = mi->rots[i*4+1];
+ rot[2] = mi->rots[i*4+2];
+ rot[3] = mi->rots[i*4+3];
+
+ loc_quat_size_to_mat4(mat, loc, rot, size);
+
+ BKE_scene_frame_set(scene, (double)i);
+
+ copy_m4_m4(ob_new->obmat, mat);
+
+ //copy_v3_v3(cent, mi->centroid);
+ //mul_m4_v3(ob_new->obmat, cent);
+ copy_v3_v3(ob_new->loc, loc);
+ copy_qt_qt(ob_new->quat, rot);
+ quat_to_eul(ob_new->rot, rot);
+
+ /*Location, builtin = -1*/
+ /*Rotation, builtin = -2*/
+ RNA_enum_set(op->ptr, "type", -1);
+ WM_operator_name_call(C, "ANIM_OT_keyframe_insert_menu", WM_OP_EXEC_DEFAULT, op->ptr);
+
+ RNA_enum_set(op->ptr, "type", -2);
+ WM_operator_name_call(C, "ANIM_OT_keyframe_insert_menu", WM_OP_EXEC_DEFAULT, op->ptr);
+ }
+
+ /*back to start*/
+ //copy_m4_m4(ob_new->obmat, origmat);
+ //copy_v3_v3(ob_new->loc, origloc);
+ }
+}
+
+static int rigidbody_convert_keyframes_exec(bContext *C, wmOperator *op)
+{
+ Object *obact = ED_object_active_context(C);
+ FractureModifierData *rmd;
+
+ rmd = (FractureModifierData *)modifiers_findByType(obact, eModifierType_Fracture);
+ if (rmd && rmd->refresh) {
+ return OPERATOR_CANCELLED;
+ }
+
+ if (rmd) {
+ convert_modifier_to_keyframes(C, op, rmd);
+ return OPERATOR_FINISHED;
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_rigidbody_convert_to_keyframes(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ ot->name = "Convert To Keyframed Objects";
+ ot->description = "Convert the Rigid Body modifier shards to keyframed real objects";
+ ot->idname = "OBJECT_OT_rigidbody_convert_to_keyframes";
+
+ ot->poll = fracture_poll;
+ //ot->invoke = rigidbody_convert_invoke;
+ ot->exec = rigidbody_convert_keyframes_exec;
+
+ RNA_def_int(ot->srna, "start_frame", 1, 0, 100000, "Start Frame", "", 0, 100000);
+ RNA_def_int(ot->srna, "end_frame", 250, 0, 100000, "End Frame", "", 0,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list