[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12572] branches/pynodes: * merge trunk r12546:r12571
Nathan Letwory
jesterking at letwory.net
Mon Nov 12 22:54:09 CET 2007
Revision: 12572
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12572
Author: jesterking
Date: 2007-11-12 22:54:09 +0100 (Mon, 12 Nov 2007)
Log Message:
-----------
* merge trunk r12546:r12571
Modified Paths:
--------------
branches/pynodes/release/scripts/weightpaint_normalize.py
branches/pynodes/release/scripts/wizard_curve2tree.py
branches/pynodes/source/blender/blenkernel/intern/action.c
branches/pynodes/source/blender/blenkernel/intern/constraint.c
branches/pynodes/source/blender/blenkernel/intern/curve.c
branches/pynodes/source/blender/blenkernel/intern/image.c
branches/pynodes/source/blender/blenkernel/intern/ipo.c
branches/pynodes/source/blender/blenkernel/intern/modifier.c
branches/pynodes/source/blender/blenlib/intern/util.c
branches/pynodes/source/blender/blenloader/intern/readfile.c
branches/pynodes/source/blender/blenloader/intern/writefile.c
branches/pynodes/source/blender/include/BIF_usiblender.h
branches/pynodes/source/blender/include/butspace.h
branches/pynodes/source/blender/makesdna/DNA_constraint_types.h
branches/pynodes/source/blender/makesdna/DNA_ipo_types.h
branches/pynodes/source/blender/makesdna/DNA_modifier_types.h
branches/pynodes/source/blender/python/api2_2x/Blender.c
branches/pynodes/source/blender/python/api2_2x/CurNurb.c
branches/pynodes/source/blender/python/api2_2x/doc/Curve.py
branches/pynodes/source/blender/render/intern/source/shadeoutput.c
branches/pynodes/source/blender/src/buttons_editing.c
branches/pynodes/source/blender/src/buttons_object.c
branches/pynodes/source/blender/src/drawview.c
branches/pynodes/source/blender/src/editimasel.c
branches/pynodes/source/blender/src/editipo_lib.c
branches/pynodes/source/blender/src/editmesh_add.c
branches/pynodes/source/blender/src/editseq.c
branches/pynodes/source/blender/src/filesel.c
branches/pynodes/source/blender/src/header_info.c
branches/pynodes/source/blender/src/meshlaplacian.c
branches/pynodes/source/blender/src/toets.c
branches/pynodes/source/blender/src/usiblender.c
branches/pynodes/source/blender/src/view.c
branches/pynodes/source/creator/creator.c
Modified: branches/pynodes/release/scripts/weightpaint_normalize.py
===================================================================
--- branches/pynodes/release/scripts/weightpaint_normalize.py 2007-11-12 20:08:48 UTC (rev 12571)
+++ branches/pynodes/release/scripts/weightpaint_normalize.py 2007-11-12 21:54:09 UTC (rev 12572)
@@ -40,55 +40,101 @@
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
-from Blender import Scene, Draw
+from Blender import Scene, Draw, Object, Modifier
import BPyMesh
SMALL_NUM= 0.000001
-def actWeightNormalize(me, PREF_PEAKWEIGHT, PREF_KEEP_PROPORTION):
+
+def getArmatureGroups(ob, me):
+ arm_obs = []
+
+ arm = ob.parent
+ if arm and arm.type == 'Armature' and ob.parentType == Object.ParentTypes.ARMATURE:
+ arm_obs.append(arm)
+
+ for m in ob.modifiers:
+ if m.type== Modifier.Types.ARMATURE:
+ arm = m[Modifier.Settings.OBJECT]
+ if arm:
+ arm_obs.append(arm)
+
+ # convert to a dict and back, should be a set! :/ - python 2.3 dosnt like.
+ return dict([ (bonename, None) for arm in arm_obs for bonename in arm.data.bones.keys() ]).keys()
+
+
+
+def actWeightNormalize(me, ob, PREF_PEAKWEIGHT, PREF_ACTIVE_ONLY, PREF_ARMATURE_ONLY, PREF_KEEP_PROPORTION):
+
groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
new_weight= max_weight= -1.0
act_group= me.activeGroup
- vWeightDictUsed=[False] * len(vWeightDict)
+ if PREF_ACTIVE_ONLY:
+ normalizeGroups = [act_group]
+ else:
+ normalizeGroups = groupNames[:]
- for i, wd in enumerate(vWeightDict):
- try:
- new_weight= wd[act_group]
- if new_weight > max_weight:
- max_weight= new_weight
- vWeightDictUsed[i]=wd
- except:
- pass
+ if PREF_ARMATURE_ONLY:
+
+ armature_groups = getArmatureGroups(ob, me)
+
+ i = len(normalizeGroups)
+ while i:
+ i-=1
+ if not normalizeGroups[i] in armature_groups:
+ del normalizeGroups[i]
- if max_weight < SMALL_NUM or new_weight == -1:
- Draw.PupMenu('No verts to normalize. exiting.')
- return
- if abs(max_weight-PREF_PEAKWEIGHT) < SMALL_NUM:
- Draw.PupMenu('Vert Weights are alredy normalized.')
- return
-
- max_weight= max_weight/PREF_PEAKWEIGHT
-
- if PREF_KEEP_PROPORTION:
- # TODO, PROPORTIONAL WEIGHT SCALING.
- for wd in vWeightDictUsed:
- if wd: # not false.
- if len(wd) == 1:
- # Only 1 group for thsi vert. Simple
- wd[act_group] /= max_weight
- else:
- # More then 1 group. will need to scale all users evenly.
- local_maxweight= max(wd.itervalues()) / PREF_PEAKWEIGHT
- for weight in wd.iterkeys():
- wd[weight] /= local_maxweight
+ for act_group in normalizeGroups:
+ vWeightDictUsed=[False] * len(vWeightDict)
+
+ for i, wd in enumerate(vWeightDict):
+ try:
+ new_weight= wd[act_group]
+ if new_weight > max_weight:
+ max_weight= new_weight
+ vWeightDictUsed[i]=wd
+ except:
+ pass
-
- else: # Simple, just scale the weights up.
- for wd in vWeightDictUsed:
- if wd: # not false.
- wd[act_group] /= max_weight
+ # These can be skipped for now, they complicate things when using multiple vgroups,
+ '''
+ if max_weight < SMALL_NUM or new_weight == -1:
+ Draw.PupMenu('No verts to normalize. exiting.')
+ #return
+ if abs(max_weight-PREF_PEAKWEIGHT) < SMALL_NUM:
+ Draw.PupMenu('Vert Weights are alredy normalized.')
+ #return
+ '''
+ max_weight= max_weight/PREF_PEAKWEIGHT
+
+ if PREF_KEEP_PROPORTION:
+ # TODO, PROPORTIONAL WEIGHT SCALING.
+ for wd in vWeightDictUsed:
+ if wd: # not false.
+ if len(wd) == 1:
+ # Only 1 group for thsi vert. Simple
+ wd[act_group] /= max_weight
+ else:
+ # More then 1 group. will need to scale all users evenly.
+ if PREF_ARMATURE_ONLY:
+ local_maxweight= max([v for k, v in wd.iteritems() if k in armature_groups]) / PREF_PEAKWEIGHT
+ if local_maxweight > 0.0:
+ # So groups that are not used in any bones are ignored.
+ for weight in wd.iterkeys():
+ if weight in armature_groups:
+ wd[weight] /= local_maxweight
+ else:
+ local_maxweight= max(wd.itervalues()) / PREF_PEAKWEIGHT
+ for weight in wd.iterkeys():
+ wd[weight] /= local_maxweight
+
+ else: # Simple, just scale the weights up. we alredy know this is in an armature group (if needed)
+ for wd in vWeightDictUsed:
+ if wd: # not false.
+ wd[act_group] /= max_weight
+
# Copy weights back to the mesh.
BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
@@ -104,17 +150,21 @@
me= ob.getData(mesh=1)
PREF_PEAKWEIGHT= Draw.Create(1.0)
+ PREF_ACTIVE_ONLY= Draw.Create(1)
PREF_KEEP_PROPORTION= Draw.Create(1)
+ PREF_ARMATURE_ONLY= Draw.Create(0)
pup_block= [\
('Peak Weight:', PREF_PEAKWEIGHT, 0.01, 1.0, 'Upper weight for normalizing.'),\
+ ('Active Only', PREF_ACTIVE_ONLY, 'Only Normalize groups that have matching bones in an armature (when an armature is used).'),\
('Proportional', PREF_KEEP_PROPORTION, 'Scale other weights so verts (Keep weights with other groups in proportion).'),\
+ ('Armature Only', PREF_ARMATURE_ONLY, 'Only Normalize groups that have matching bones in an armature (when an armature is used).'),\
]
if not Draw.PupBlock('Clean Selected Meshes...', pup_block):
return
- actWeightNormalize(me, PREF_PEAKWEIGHT.val, PREF_KEEP_PROPORTION.val)
+ actWeightNormalize(me, ob, PREF_PEAKWEIGHT.val, PREF_ACTIVE_ONLY.val, PREF_ARMATURE_ONLY.val, PREF_KEEP_PROPORTION.val)
if __name__=='__main__':
main()
\ No newline at end of file
Modified: branches/pynodes/release/scripts/wizard_curve2tree.py
===================================================================
--- branches/pynodes/release/scripts/wizard_curve2tree.py 2007-11-12 20:08:48 UTC (rev 12571)
+++ branches/pynodes/release/scripts/wizard_curve2tree.py 2007-11-12 21:54:09 UTC (rev 12572)
@@ -14,11 +14,66 @@
"""
+# --------------------------------------------------------------------------
+# Tree from Curves v0.1 by Campbell Barton (AKA Ideasman42)
+# --------------------------------------------------------------------------
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+# --------------------------------------------------------------------------
+
import bpy
import Blender
from Blender.Mathutils import Vector, CrossVecs, AngleBetweenVecs, LineIntersect, TranslationMatrix, ScaleMatrix
from Blender.Geometry import ClosestPointOnLine
+GLOBALS = {}
+GLOBALS['non_bez_error'] = 0
+
+# Copied from blender, we could wrap this! - BKE_curve.c
+# But probably not toooo bad in python
+def forward_diff_bezier(q0, q1, q2, q3, pointlist, steps, axis):
+ f= float(steps)
+ rt0= q0
+ rt1= 3.0*(q1-q0)/f
+ f*= f
+ rt2= 3.0*(q0-2.0*q1+q2)/f
+ f*= steps
+ rt3= (q3-q0+3.0*(q1-q2))/f
+
+ q0= rt0
+ q1= rt1+rt2+rt3
+ q2= 2*rt2+6*rt3
+ q3= 6*rt3
+ if axis == None:
+ for a in xrange(steps+1):
+ pointlist[a] = q0
+ q0+= q1
+ q1+= q2
+ q2+= q3;
+
+ else:
+ for a in xrange(steps+1):
+ pointlist[a][axis] = q0
+ q0+= q1
+ q1+= q2
+ q2+= q3;
+
+
def debug_pt(co):
Blender.Window.SetCursorPos(tuple(co))
Blender.Window.RedrawAll()
@@ -28,10 +83,12 @@
best= -1
best_dist = 100000000
for i, vec_test in enumerate(vecls):
- dist = (vec-vec_test).length
- if dist < best_dist:
- best = i
- best_dist = dist
+ # Dont use yet, we may want to tho
+ if vec_test: # Seems odd, but use this so we can disable some verts in the list.
+ dist = (vec-vec_test).length
+ if dist < best_dist:
+ best = i
+ best_dist = dist
return best
@@ -58,10 +115,11 @@
s += str(brch)
return s
-
def fromCurve(self, object):
+ # Now calculate the normals
self.object = object
curve = object.data
+ steps = curve.resolu # curve resolution
# Set the curve object scale
if curve.bevob:
@@ -69,119 +127,61 @@
bb = curve.bevob.boundingBox
# self.limbScale = (bb[0] - bb[7]).length / 2.825 # THIS IS GOOD WHEN NON SUBSURRFED
self.limbScale = (bb[0] - bb[7]).length / 1.8
- # end
- # Get the curve points as bpoints
+ # forward_diff_bezier will fill in the blanks
+ # nice we can reuse these for every curve segment :)
+ pointlist = [[None, None, None] for i in xrange(steps+1)]
+ radlist = [ None for i in xrange(steps+1) ]
+
+
for spline in curve:
- brch = branch()
- self.branches_all.append(brch)
- brch.bpoints = [ bpoint(brch, Vector(bez.vec[1]), Vector(), bez.radius * self.limbScale) for bez in spline ]
-
- # Get the curve as a mesh. - for inbetween points
- tmpme = bpy.data.meshes.new()
-
- # remove/backup bevel ob
- bev_back = curve.bevob
- if bev_back: curve.bevob = None
-
- # get the curve mesh data
- tmpob = bpy.data.scenes.active.objects.new( curve )
- tmpme.getFromObject(object)
- bpy.data.scenes.active.objects.unlink(tmpob)
-
- # restore bevel ob
- if bev_back:
- curve.bevob = bev_back
- # Guess the size of the curve object if you have one. This is not perfect but good enough
- bb = bev_back.boundingBox
- self.limbScale = (bb[0] - bb[7]).length / 2.825
+ if len(spline) < 2: # Ignore single point splines
+ continue
+ if spline.type != 1: # 0 poly, 1 bez, 4 nurbs
+ GLOBALS['non_bez_error'] = 1
+ continue
-
- # TEMP FOR TESTING
- # bpy.data.scenes.active.objects.new(tmpme)
-
- vecs = [ tuple(v.co) for v in tmpme.verts ]
- del tmpme
-
- # for branch
- #used_points = set()
- for brch in self.branches_all:
- offset = 0
- for i in xrange(1, len(brch.bpoints)):
- # find the start/end points
- start_pt = brch.bpoints[offset+i-1]
- end_pt = brch.bpoints[offset+i]
- start = end = None
- for j, co in enumerate(vecs):
- if start == None:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list