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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2007-11-09 13:29:19 +0300
committerCampbell Barton <ideasman42@gmail.com>2007-11-09 13:29:19 +0300
commitddf2336084e7d9c2b1b07897acca2db5cb02fc95 (patch)
tree253150e45d2ee42f997219eae382871fa5ef113b
parent95661081f9e25011a91e6263e83501ad74085bf8 (diff)
curve2tree - animation settings - speed and magnitude
Python api - texture.evaluate can now accept tuples of numbers as well as vectors
-rw-r--r--release/scripts/wizard_curve2tree.py76
-rw-r--r--source/blender/python/api2_2x/Texture.c33
-rw-r--r--source/blender/python/api2_2x/doc/Texture.py2
3 files changed, 76 insertions, 35 deletions
diff --git a/release/scripts/wizard_curve2tree.py b/release/scripts/wizard_curve2tree.py
index 087e79c8322..9814c114087 100644
--- a/release/scripts/wizard_curve2tree.py
+++ b/release/scripts/wizard_curve2tree.py
@@ -624,10 +624,14 @@ class tree:
return self.armature
- def toAction(self, ob_arm, texture):
+ def toAction(self, ob_arm, texture, anim_speed=1.0, anim_magnitude=1.0, anim_speed_size_scale=True):
# Assume armature
- action = bpy.data.actions.new()
- ob_arm.action = action
+ action = ob_arm.action
+ if not action:
+ action = bpy.data.actions.new()
+ action.fakeUser = False # so we dont get masses of bad data
+ ob_arm.action = action
+
# Blender.Armature.NLA.ob_arm.
pose = ob_arm.getPose()
@@ -639,8 +643,21 @@ class tree:
ipo_dict = action.getAllChannelIpos()
# print ipo_dict
+ # Sicne its per frame, it increases very fast. scale it down a bit
+ anim_speed = anim_speed/10
+
+ anim_speed_final = anim_speed
# Assign drivers to them all
for name, ipo in ipo_dict.iteritems():
+ tex_str = 'b.Texture.Get("%s")' % texture.name
+
+ if anim_speed_size_scale:
+ # Adjust the speed by the bone size.
+ # get the point from the name. a bit ugly but works fine ;) - Just dont mess the index up!
+ lookup = [int(val) for val in name.split('_')]
+ pt = self.branches_all[ lookup[0] ].bpoints[ lookup[1] ]
+ anim_speed_final = anim_speed / (1+pt.radius)
+
#for cu in ipo:
# #cu.delBezier(0)
# #cu.driver = 2 # Python expression
@@ -648,21 +665,20 @@ class tree:
cu = ipo[Blender.Ipo.PO_QUATX]
cu.delBezier(0)
cu.driver = 2 # Python expression
- cu.driverExpression = '(b.Texture.Get("' + texture.name + '").evaluate(b.Mathutils.Vector(b.Get("curframe")/20.0, 0, 0)).w-0.5)/3'
-
+ cu.driverExpression = '(%s.evaluate((b.Get("curframe")*%.3f,0,0)).w-0.5)*%.3f' % (tex_str, anim_speed_final, anim_magnitude)
cu = ipo[Blender.Ipo.PO_QUATY]
cu.delBezier(0)
cu.driver = 2 # Python expression
- cu.driverExpression = '(b.Texture.Get("' + texture.name + '").evaluate(b.Mathutils.Vector(0,b.Get("curframe")/20.0, 0)).w-0.5)/3'
+ cu.driverExpression = '(%s.evaluate((0,b.Get("curframe")*%.3f,0)).w-0.5)*%.3f' % (tex_str, anim_speed_final, anim_magnitude)
cu = ipo[Blender.Ipo.PO_QUATZ]
cu.delBezier(0)
cu.driver = 2 # Python expression
- cu.driverExpression = '(b.Texture.Get("' + texture.name + '").evaluate(b.Mathutils.Vector(0,0,b.Get("curframe")/20.0)).w-0.5)/3'
-
+ cu.driverExpression = '(%s.evaluate(0,0,(b.Get("curframe")*%.3f)).w-0.5)*%.3f' % (tex_str, anim_speed_final, anim_magnitude)
+ #(%s.evaluate((b.Get("curframe")*%.3f,0,0)).w-0.5)*%.3f
zup = Vector(0,0,1)
@@ -1277,6 +1293,10 @@ PREFS['do_anim'] = Draw.Create(1)
try: PREFS['anim_tex'] = Draw.Create([tex for tex in bpy.data.textures][0].name)
except: PREFS['anim_tex'] = Draw.Create('')
+PREFS['anim_speed'] = Draw.Create(0.2)
+PREFS['anim_magnitude'] = Draw.Create(0.2)
+PREFS['anim_speed_size_scale'] = Draw.Create(1)
+
GLOBAL_PREFS = {}
@@ -1380,10 +1400,10 @@ def buildTree(ob):
Blender.Draw.PupMenu('error no texture, cannot animate bones')
if tex:
- t.toAction(ob_arm, tex)
-
-
-
+ t.toAction(ob_arm, tex,\
+ anim_speed = PREFS['anim_speed'].val,\
+ anim_magnitude = PREFS['anim_magnitude'].val,\
+ anim_speed_size_scale= PREFS['anim_speed_size_scale'])
# Add subsurf last it needed. so armature skinning is done first.
# Do subsurf?
@@ -1527,25 +1547,31 @@ def gui():
xtmp = x
# ---------- ---------- ---------- ----------
if PREFS['do_armature'].val:
- PREFS['do_anim'] = Draw.Toggle('Texture Anim', EVENT_NONE, xtmp, y, but_width*2, but_height, PREFS['do_anim'].val, 'Use a texture to animate the bones'); xtmp += but_width*2;
+ PREFS['do_anim'] = Draw.Toggle('Texture Anim', EVENT_REDRAW, xtmp, y, but_width*2, but_height, PREFS['do_anim'].val, 'Use a texture to animate the bones'); xtmp += but_width*2;
- PREFS['anim_tex'] = Draw.String('TEX: ', EVENT_NONE, xtmp, y, but_width*2, but_height, PREFS['anim_tex'].val, 64, 'Texture to use for the IPO Driver animation', do_tex_check); xtmp += but_width*2;
-
- y-=but_height+MARGIN
- xtmp = x
-
-
-
+ if PREFS['do_anim'].val:
+
+ PREFS['anim_tex'] = Draw.String('TEX: ', EVENT_NONE, xtmp, y, but_width*2, but_height, PREFS['anim_tex'].val, 64, 'Texture to use for the IPO Driver animation', do_tex_check); xtmp += but_width*2;
+ y-=but_height
+ xtmp = x
+ # ---------- ---------- ---------- ----------
+
+ PREFS['anim_speed'] = Draw.Number('Speed', EVENT_NONE, xtmp, y, but_width*2, but_height, PREFS['anim_speed'].val, 0.001, 10.0, 'Animate the movement faster with a higher value'); xtmp += but_width*2;
+ PREFS['anim_magnitude'] = Draw.Number('Magnitude', EVENT_NONE, xtmp, y, but_width*2, but_height, PREFS['anim_magnitude'].val, 0.001, 10.0, 'Animate with more motion with a higher value'); xtmp += but_width*2;
+ y-=but_height
+ xtmp = x
+ # ---------- ---------- ---------- ----------
+
+ PREFS['anim_speed_size_scale'] = Draw.Toggle('Branch Size Scales Speed', EVENT_NONE, xtmp, y, but_width*4, but_height, PREFS['anim_speed_size_scale'].val, 'Use the branch size as a factor when calculating speed'); xtmp += but_width*4;
+
+ y-=but_height+MARGIN
+ xtmp = x
Draw.PushButton('Exit', EVENT_EXIT, xtmp, y, but_width*2, but_height, '', do_active_image); xtmp += but_width*2;
Draw.PushButton('Generate', EVENT_REDRAW, xtmp, y, but_width*2, but_height, 'Generate mesh', do_tree_generate); xtmp += but_width*2;
-
- # PREFS['do_uv_scalewidth'] = Draw.Number('Scale:', EVENT_NONE, x+20, y+120, but_width, but_height, PREFS['do_uv_scalewidth'].val, 0.01, 1000.0, 'Scale all data, (Note! some imports dont support scaled armatures)')
-
- #v = Draw.Toggle('UVs', EVENT_NONE, x, y, 60, 20, v.val, 'Calculate UVs coords')
-
+
if __name__ == '__main__':
Draw.Register(gui, evt, bevt)
diff --git a/source/blender/python/api2_2x/Texture.c b/source/blender/python/api2_2x/Texture.c
index 34906757ebd..e21d486a2ab 100644
--- a/source/blender/python/api2_2x/Texture.c
+++ b/source/blender/python/api2_2x/Texture.c
@@ -504,7 +504,7 @@ static int Texture_setNoiseBasis2( BPy_Texture *self, PyObject *args,
static PyObject *Texture_getColorband( BPy_Texture * self);
int Texture_setColorband( BPy_Texture * self, PyObject * value);
-static PyObject *Texture_evaluate( BPy_Texture *self, VectorObject *vec_in );
+static PyObject *Texture_evaluate( BPy_Texture *self, PyObject *value );
static PyObject *Texture_copy( BPy_Texture *self );
/*****************************************************************************/
@@ -2472,19 +2472,34 @@ int Texture_setColorband( BPy_Texture * self, PyObject * value)
return EXPP_Colorband_fromPyList( &self->texture->coba, value );
}
-static PyObject *Texture_evaluate( BPy_Texture * self, VectorObject * vec_in )
+static PyObject *Texture_evaluate( BPy_Texture * self, PyObject * value )
{
TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
float vec[4];
/* int rgbnor; dont use now */
- if(!VectorObject_Check(vec_in) || vec_in->size < 3)
- return EXPP_ReturnPyObjError(PyExc_TypeError,
- "expects a 3D vector object");
-
- /* rgbnor = .. we don't need this now */
- multitex_ext(self->texture, vec_in->vec, NULL, NULL, 1, &texres);
-
+ if (VectorObject_Check(value)) {
+ if(((VectorObject *)value)->size < 3)
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "expects a 3D vector object or a tuple of 3 numbers");
+
+ /* rgbnor = .. we don't need this now */
+ multitex_ext(self->texture, ((VectorObject *)value)->vec, NULL, NULL, 1, &texres);
+ } else {
+ float vec_in[3];
+ if (!PyTuple_Check(value) || PyTuple_Size(value) < 3)
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "expects a 3D vector object or a tuple of 3 numbers");
+
+ vec_in[0] = PyFloat_AsDouble(PyTuple_GET_ITEM(value, 0));
+ vec_in[1] = PyFloat_AsDouble(PyTuple_GET_ITEM(value, 1));
+ vec_in[2] = PyFloat_AsDouble(PyTuple_GET_ITEM(value, 2));
+ if (PyErr_Occurred())
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "expects a 3D vector object or a tuple of 3 numbers");
+
+ multitex_ext(self->texture, vec_in, NULL, NULL, 1, &texres);
+ }
vec[0] = texres.tr;
vec[1] = texres.tg;
vec[2] = texres.tb;
diff --git a/source/blender/python/api2_2x/doc/Texture.py b/source/blender/python/api2_2x/doc/Texture.py
index 004cd2df274..823f34b14bd 100644
--- a/source/blender/python/api2_2x/doc/Texture.py
+++ b/source/blender/python/api2_2x/doc/Texture.py
@@ -480,7 +480,7 @@ class Texture:
The return value is a 4D vector where (x,y,z,w) are (red, green, blue, intensity)
For greyscale textures, often intensity only will be used.
- @type coord: vector
+ @type coord: vector or tuple of 3 numbers
"""
import id_generics