[Bf-blender-cvs] [d9b7f73] hair_immediate_fixes: Shape key infrastructure for hair.

Lukas Tönne noreply at git.blender.org
Fri Oct 3 14:20:29 CEST 2014


Commit: d9b7f7305ad1585f7893b882278e9c58b7c986b9
Author: Lukas Tönne
Date:   Thu Oct 2 19:04:59 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rBd9b7f7305ad1585f7893b882278e9c58b7c986b9

Shape key infrastructure for hair.

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

M	release/scripts/startup/bl_ui/properties_particle.py
M	source/blender/blenkernel/BKE_key.h
M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/physics/CMakeLists.txt
A	source/blender/editors/physics/particle_key.c
M	source/blender/editors/physics/physics_intern.h
M	source/blender/editors/physics/physics_ops.c
M	source/blender/makesdna/DNA_particle_types.h
M	source/blender/makesrna/intern/rna_particle.c

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

diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py
index de0921d..375f8db 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -18,7 +18,7 @@
 
 # <pep8 compliant>
 import bpy
-from bpy.types import Panel
+from bpy.types import Panel, UIList
 from rna_prop_ui import PropertyPanel
 from bpy.app.translations import pgettext_iface as iface_
 
@@ -333,6 +333,118 @@ class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
             box.label("Error: %.5f .. %.5f (avg. %.5f)" % (result.min_error, result.max_error, result.avg_error))
 
 
+class PARTICLE_UL_shape_keys(UIList):
+    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
+        # assert(isinstance(item, bpy.types.ShapeKey))
+        obj = active_data
+        # key = data
+        key_block = item
+        if self.layout_type in {'DEFAULT', 'COMPACT'}:
+            split = layout.split(0.66, False)
+            split.prop(key_block, "name", text="", emboss=False, icon_value=icon)
+            row = split.row(align=True)
+            if key_block.mute or (obj.mode == 'PARTICLE_EDIT' and not obj.use_shape_key_edit_mode):
+                row.active = False
+            if not item.id_data.use_relative:
+                row.prop(key_block, "frame", text="", emboss=False)
+            elif index > 0:
+                row.prop(key_block, "value", text="", emboss=False)
+            else:
+                row.label(text="")
+            row.prop(key_block, "mute", text="", emboss=False)
+        elif self.layout_type in {'GRID'}:
+            layout.alignment = 'CENTER'
+            layout.label(text="", icon_value=icon)
+
+
+class PARTICLE_PT_shape_keys(ParticleButtonsPanel, Panel):
+    bl_label = "Shape Keys"
+    COMPAT_ENGINES = {'BLENDER_RENDER'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        ob = context.object
+        psys = context.particle_system
+        key = psys.shape_keys
+        kb = psys.active_shape_key
+
+        enable_edit = ob.mode != 'PARTICLE_EDIT'
+
+        if ob.show_only_shape_key is False:
+            if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
+                enable_edit_value = True
+
+        row = layout.row()
+
+        rows = 2
+        if kb:
+            rows = 4
+        row.template_list("PARTICLE_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
+
+        col = row.column()
+
+        sub = col.column(align=True)
+        sub.operator("particle.shape_key_add", icon='ZOOMIN', text="").from_mix = False
+        sub.operator("particle.shape_key_remove", icon='ZOOMOUT', text="").all = False
+        #sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
+
+        if kb:
+            col.separator()
+
+            sub = col.column(align=True)
+            sub.operator("particle.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
+            sub.operator("particle.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
+
+            split = layout.split(percentage=0.4)
+            row = split.row()
+            row.enabled = enable_edit
+            row.prop(key, "use_relative")
+
+            row = split.row()
+            row.alignment = 'RIGHT'
+
+            sub = row.row(align=True)
+            sub.label()  # XXX, for alignment only
+            subsub = sub.row(align=True)
+            subsub.active = enable_edit_value
+            subsub.prop(ob, "show_only_shape_key", text="")
+            sub.prop(ob, "use_shape_key_edit_mode", text="")
+
+            sub = row.row()
+            if key.use_relative:
+                sub.operator("particle.shape_key_clear", icon='X', text="")
+            else:
+                sub.operator("particle.shape_key_retime", icon='RECOVER_LAST', text="")
+
+            if key.use_relative:
+                if ob.active_shape_key_index != 0:
+                    row = layout.row()
+                    row.active = enable_edit_value
+                    row.prop(kb, "value")
+
+                    split = layout.split()
+
+                    col = split.column(align=True)
+                    col.active = enable_edit_value
+                    col.label(text="Range:")
+                    col.prop(kb, "slider_min", text="Min")
+                    col.prop(kb, "slider_max", text="Max")
+
+                    col = split.column(align=True)
+                    col.active = enable_edit_value
+                    col.label(text="Blend:")
+                    col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="")
+                    col.prop_search(kb, "relative_key", key, "key_blocks", text="")
+
+            else:
+                layout.prop(kb, "interpolation")
+                row = layout.column()
+                row.active = enable_edit_value
+                row.prop(key, "eval_time")
+                row.prop(key, "slurph")
+
+
 class PARTICLE_PT_cache(ParticleButtonsPanel, Panel):
     bl_label = "Cache"
     bl_options = {'DEFAULT_CLOSED'}
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 6183df8..be0ee05 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -41,6 +41,7 @@ struct Object;
 struct Scene;
 struct Lattice;
 struct Mesh;
+struct ParticleSystem;
 struct WeightsArrayCache;
 
 /* Kernel prototypes */
@@ -51,6 +52,7 @@ extern "C" {
 void        BKE_key_free(struct Key *sc);
 void        BKE_key_free_nolib(struct Key *key);
 struct Key *BKE_key_add(struct ID *id);
+struct Key *BKE_key_add_particles(struct ID *id);
 struct Key *BKE_key_copy(struct Key *key);
 struct Key *BKE_key_copy_nolib(struct Key *key);
 void        BKE_key_make_local(struct Key *key);
@@ -67,6 +69,8 @@ float *BKE_key_evaluate_object(struct Scene *scene, struct Object *ob, int *r_to
 struct Key      *BKE_key_from_object(struct Object *ob);
 struct KeyBlock *BKE_keyblock_from_object(struct Object *ob);
 struct KeyBlock *BKE_keyblock_from_object_reference(struct Object *ob);
+struct KeyBlock *BKE_keyblock_from_particles(struct ParticleSystem *psys);
+struct KeyBlock *BKE_keyblock_from_particles_reference(struct ParticleSystem *psys);
 
 struct KeyBlock *BKE_keyblock_add(struct Key *key, const char *name);
 struct KeyBlock *BKE_keyblock_add_ctime(struct Key *key, const char *name, const bool do_force);
@@ -96,6 +100,8 @@ void    BKE_key_convert_from_curve(struct Curve *cu, struct KeyBlock *kb, struct
 float (*BKE_key_convert_to_vertcos(struct Object *ob, struct KeyBlock *kb))[3];
 void    BKE_key_convert_from_vertcos(struct Object *ob, struct KeyBlock *kb, float (*vertCos)[3]);
 void    BKE_key_convert_from_offset(struct Object *ob, struct KeyBlock *kb, float (*ofs)[3]);
+void    BKE_key_convert_to_hair_keys(struct KeyBlock *kb, struct Object *ob, struct ParticleSystem *psys);
+void    BKE_key_convert_from_hair_keys(struct Object *ob, struct ParticleSystem *psys, struct KeyBlock *kb);
 
 /* key.c */
 extern int slurph_opt;
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index f84a637..606f808 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -295,6 +295,8 @@ int psys_check_edited(struct ParticleSystem *psys);
 void psys_check_group_weights(struct ParticleSettings *part);
 int psys_uses_gravity(struct ParticleSimulationData *sim);
 
+struct KeyBlock *BKE_psys_insert_shape_key(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, const char *name, const bool from_mix);
+
 /* free */
 void BKE_particlesettings_free(struct ParticleSettings *part);
 void psys_free_path_cache(struct ParticleSystem *psys, struct PTCacheEdit *edit);
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 2dc615c..26ad4ff 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -48,6 +48,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
+#include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
 
 #include "BKE_animsys.h"
@@ -150,6 +151,30 @@ Key *BKE_key_add(ID *id)    /* common function */
 	return key;
 }
 
+Key *BKE_key_add_particles(ID *id)    /* particles are "special" */
+{
+	Key *key;
+	char *el;
+	
+	key = BKE_libblock_alloc(G.main, ID_KE, "Key");
+	
+	key->type = KEY_NORMAL;
+	key->from = id;
+	
+	key->uidgen = 1;
+	
+	BLI_assert(GS(id->name) == ID_OB);
+	el = key->elemstr;
+	
+	el[0] = 3;
+	el[1] = IPO_FLOAT;
+	el[2] = 0;
+	
+	key->elemsize = 12;
+	
+	return key;
+}
+
 Key *BKE_key_copy(Key *key)
 {
 	Key *keyn;
@@ -1604,6 +1629,29 @@ KeyBlock *BKE_keyblock_from_object_reference(Object *ob)
 	return NULL;
 }
 
+/* only the active keyblock */
+KeyBlock *BKE_keyblock_from_particles(ParticleSystem *psys) 
+{
+	Key *key = psys->key;
+	
+	if (key) {
+		KeyBlock *kb = BLI_findlink(&key->block, psys->shapenr - 1);
+		return kb;
+	}
+
+	return NULL;
+}
+
+KeyBlock *BKE_keyblock_from_particles_reference(ParticleSystem *psys)
+{
+	Key *key = psys->key;
+	
+	if (key)
+		return key->refkey;
+
+	return NULL;
+}
+
 /* get the appropriate KeyBlock given an index */
 KeyBlock *BKE_keyblock_from_key(Key *key, int index)
 {
@@ -2055,3 +2103,33 @@ void BKE_key_convert_from_offset(Object *ob, KeyBlock *kb, float (*ofs)[3])
 		}
 	}
 }
+
+/************************* Mesh ************************/
+
+void BKE_key_convert_to_hair_keys(struct KeyBlock *kb, struct Object *ob, struct ParticleSystem *psys)
+{
+}
+
+void BKE_key_convert_from_hair_keys(struct Object *ob, struct ParticleSystem *psys, struct KeyBlock *kb)
+{
+#if 0
+	ParticleData *pa;
+	MVert *mvert;
+	float *fp;
+	int a;
+
+	if (me->totvert == 0) return;
+
+	if (kb->data) MEM_freeN(kb->data);
+
+	kb->data = MEM_mallocN(me->key->elemsize * me->totvert, "kb->data");
+	kb->totelem = me->totvert;
+
+	mvert = me->mvert;
+	fp = kb->data;
+	for (a = 0; a < kb->totelem; a++, fp += 3, mvert++) {
+		copy_v3_v3(fp, mvert->co);
+
+	}
+#endif
+}
diff --git a/source/blender/blenkernel/intern/

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list