[Bf-extensions-cvs] [5b44b3f] dxf_import: fixes for T41099 and T38495 by purplefrog in irc, added warning "Armature Mode buggy"
Brendon Murphy
noreply at git.blender.org
Fri Aug 15 12:38:25 CEST 2014
Commit: 5b44b3f6117bcc45386e8f035c6d4ed4b6c21268
Author: Brendon Murphy
Date: Tue Aug 5 04:22:08 2014 +1000
Branches: dxf_import
https://developer.blender.org/rBA5b44b3f6117bcc45386e8f035c6d4ed4b6c21268
fixes for T41099 and T38495 by purplefrog in irc, added warning "Armature Mode buggy"
===================================================================
M add_curve_sapling/__init__.py
M add_curve_sapling/utils.py
===================================================================
diff --git a/add_curve_sapling/__init__.py b/add_curve_sapling/__init__.py
index 78f2ebb..a5739cb 100644
--- a/add_curve_sapling/__init__.py
+++ b/add_curve_sapling/__init__.py
@@ -25,7 +25,7 @@ bl_info = {
"description": ("Adds a parametric tree. The method is presented by "
"Jason Weber & Joseph Penn in their paper 'Creation and Rendering of "
"Realistic Trees'."),
- "warning": "",
+ "warning": "Armature Mode buggy",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/Curve/Sapling_Tree",
"category": "Add Curve",
@@ -323,8 +323,10 @@ class AddTree(bpy.types.Operator):
min=0.0,
max=1.0,
default=1.0, update=update_tree)
- leaves = IntProperty(name='Leaves',
+ leaves = FloatProperty(name='Leaves',
description='Maximum number of leaves per branch (Leaves)',
+ min=0,
+ max=50,
default=25, update=update_tree)
leafScale = FloatProperty(name='Leaf Scale',
description='The scaling applied to the whole leaf (LeafScale)',
diff --git a/add_curve_sapling/utils.py b/add_curve_sapling/utils.py
index 2ff8642..8f49eeb 100644
--- a/add_curve_sapling/utils.py
+++ b/add_curve_sapling/utils.py
@@ -338,7 +338,7 @@ def genLeafMesh(leafScale,leafScaleX,loc,quat,index,downAngle,downAngleV,rotate,
# If the special -ve flag is used we need a different rotation of the leaf geometry
if leaves < 0:
rotMat = Matrix.Rotation(oldRot,3,'Y')
- oldRot += rotate/(abs(leaves)-1)
+ oldRot += rotate/abs(leaves)
else:
oldRot += rotate+uniform(-rotateV,rotateV)
downRotMat = Matrix.Rotation(downAngle+uniform(-downAngleV,downAngleV),3,'X')
@@ -401,6 +401,330 @@ def genLeafMesh(leafScale,leafScaleX,loc,quat,index,downAngle,downAngleV,rotate,
facesList.append([f[0] + index,f[1] + index,f[2] + index,f[3] + index])
return vertsList,facesList,oldRot
+
+def create_armature(armAnim, childP, cu, frameRate, leafMesh, leafObj, leafShape, leaves, levelCount, splineToBone,
+ treeOb, windGust, windSpeed):
+ arm = bpy.data.armatures.new('tree')
+ armOb = bpy.data.objects.new('treeArm', arm)
+ bpy.context.scene.objects.link(armOb)
+ # Create a new action to store all animation
+ newAction = bpy.data.actions.new(name='windAction')
+ armOb.animation_data_create()
+ armOb.animation_data.action = newAction
+ arm.draw_type = 'STICK'
+ arm.use_deform_delay = True
+ # Add the armature modifier to the curve
+ armMod = treeOb.modifiers.new('windSway', 'ARMATURE')
+ # armMod.use_apply_on_spline = True
+ armMod.object = armOb
+ # If there are leaves then they need a modifier
+ if leaves:
+ armMod = leafObj.modifiers.new('windSway', 'ARMATURE')
+ armMod.object = armOb
+
+ # Make sure all objects are deselected (may not be required?)
+ for ob in bpy.data.objects:
+ ob.select = False
+
+ # Set the armature as active and go to edit mode to add bones
+ bpy.context.scene.objects.active = armOb
+ bpy.ops.object.mode_set(mode='EDIT')
+ masterBones = []
+ offsetVal = 0
+ # For all the splines in the curve we need to add bones at each bezier point
+ for i, parBone in enumerate(splineToBone):
+ s = cu.splines[i]
+ b = None
+ # Get some data about the spline like length and number of points
+ numPoints = len(s.bezier_points) - 1
+ splineL = numPoints * ((s.bezier_points[0].co - s.bezier_points[1].co).length)
+ # Set the random phase difference of the animation
+ bxOffset = uniform(0, 2 * pi)
+ byOffset = uniform(0, 2 * pi)
+ # Set the phase multiplier for the spline
+ bMult = (s.bezier_points[0].radius / splineL) * (1 / 15) * (1 / frameRate)
+ # For all the points in the curve (less the last) add a bone and name it by the spline it will affect
+ for n in range(numPoints):
+ oldBone = b
+ boneName = 'bone' + (str(i)).rjust(3, '0') + '.' + (str(n)).rjust(3, '0')
+ b = arm.edit_bones.new(boneName)
+ b.head = s.bezier_points[n].co
+ b.tail = s.bezier_points[n + 1].co
+
+ b.head_radius = s.bezier_points[n].radius
+ b.tail_radius = s.bezier_points[n + 1].radius
+ b.envelope_distance = 0.001 #0.001
+
+ # If there are leaves then we need a new vertex group so they will attach to the bone
+ if (len(levelCount) > 1) and (i >= levelCount[-2]) and leafObj:
+ leafObj.vertex_groups.new(boneName)
+ elif (len(levelCount) == 1) and leafObj:
+ leafObj.vertex_groups.new(boneName)
+ # If this is first point of the spline then it must be parented to the level above it
+ if n == 0:
+ if parBone:
+ b.parent = arm.edit_bones[parBone]
+ # if len(parBone) > 11:
+ # b.use_connect = True
+ # Otherwise, we need to attach it to the previous bone in the spline
+ else:
+ b.parent = oldBone
+ b.use_connect = True
+ # If there isn't a previous bone then it shouldn't be attached
+ if not oldBone:
+ b.use_connect = False
+ #tempList.append(b)
+
+ # Add the animation to the armature if required
+ if armAnim:
+ # Define all the required parameters of the wind sway by the dimension of the spline
+ a0 = 4 * splineL * (1 - n / (numPoints + 1)) / s.bezier_points[n].radius
+ a1 = (windSpeed / 50) * a0
+ a2 = (windGust / 50) * a0 + a1 / 2
+
+ # Add new fcurves for each sway as well as the modifiers
+ swayX = armOb.animation_data.action.fcurves.new('pose.bones["' + boneName + '"].rotation_euler', 0)
+ swayY = armOb.animation_data.action.fcurves.new('pose.bones["' + boneName + '"].rotation_euler', 2)
+
+ swayXMod1 = swayX.modifiers.new(type='FNGENERATOR')
+ swayXMod2 = swayX.modifiers.new(type='FNGENERATOR')
+
+ swayYMod1 = swayY.modifiers.new(type='FNGENERATOR')
+ swayYMod2 = swayY.modifiers.new(type='FNGENERATOR')
+
+ # Set the parameters for each modifier
+ swayXMod1.amplitude = radians(a1) / numPoints
+ swayXMod1.phase_offset = bxOffset
+ swayXMod1.phase_multiplier = degrees(bMult)
+
+ swayXMod2.amplitude = radians(a2) / numPoints
+ swayXMod2.phase_offset = 0.7 * bxOffset
+ swayXMod2.phase_multiplier = 0.7 * degrees(
+ bMult) # This shouldn't have to be in degrees but it looks much better in animation
+ swayXMod2.use_additive = True
+
+ swayYMod1.amplitude = radians(a1) / numPoints
+ swayYMod1.phase_offset = byOffset
+ swayYMod1.phase_multiplier = degrees(
+ bMult) # This shouldn't have to be in degrees but it looks much better in animation
+
+ swayYMod2.amplitude = radians(a2) / numPoints
+ swayYMod2.phase_offset = 0.7 * byOffset
+ swayYMod2.phase_multiplier = 0.7 * degrees(
+ bMult) # This shouldn't have to be in degrees but it looks much better in animation
+ swayYMod2.use_additive = True
+
+ # If there are leaves we need to assign vertices to their vertex groups
+ if leaves:
+ offsetVal = 0
+ leafVertSize = 6
+ if leafShape == 'rect':
+ leafVertSize = 4
+ for i, cp in enumerate(childP):
+ for v in leafMesh.vertices[leafVertSize * i:(leafVertSize * i + leafVertSize)]:
+ leafObj.vertex_groups[cp.parBone].add([v.index], 1.0, 'ADD')
+
+ # Now we need the rotation mode to be 'XYZ' to ensure correct rotation
+ bpy.ops.object.mode_set(mode='OBJECT')
+ for p in armOb.pose.bones:
+ p.rotation_mode = 'XYZ'
+ treeOb.parent = armOb
+
+
+def kickstart_trunk(addstem, branches, cu, curve, curveRes, curveV, length, lengthV, ratio, resU, scale0, scaleV0,
+ scaleVal, taper, vertAtt):
+ vertAtt = 0.0
+ newSpline = cu.splines.new('BEZIER')
+ cu.resolution_u = resU
+ newPoint = newSpline.bezier_points[-1]
+ newPoint.co = Vector((0, 0, 0))
+ newPoint.handle_right = Vector((0, 0, 1))
+ newPoint.handle_left = Vector((0, 0, -1))
+ # (newPoint.handle_right_type,newPoint.handle_left_type) = ('VECTOR','VECTOR')
+ branchL = (scaleVal) * (length[0] + uniform(-lengthV[0], lengthV[0]))
+ childStems = branches[1]
+ startRad = branchL * ratio * (scale0 + uniform(-scaleV0, scaleV0))
+ endRad = startRad * (1 - taper[0])
+ newPoint.radius = startRad
+ addstem(
+ stemSpline(newSpline, curve[0] / curveRes[0], curveV[0] / curveRes[0], 0, curveRes[0], branchL / curveRes[0],
+ childStems, startRad, endRad, 0))
+ return vertAtt
+
+
+def fabricate_stems(addsplinetobone, addstem, baseSize, branches, childP, cu, curve, curveBack, curveRes, curveV,
+ downAngle, downAngleV, leafDist, leaves, length, lengthV, levels, n, oldRotate, ratioPower, resU,
+ rotate, rotateV, scaleVal, shape, storeN, taper, vertAtt):
+ for p in childP:
+ # Add a spline and set the coordinate of the first point.
+ newSpline = cu.splines.new('BEZIER')
+ cu.resolution_u = resU
+ newPoint = newSpline.bezier_points[-1]
+ newPoint.co = p.co
+ tempPos = zAxis.copy()
+ # If the -ve flag for downAngle is used we need a special formula to find it
+ if downAngleV[n] < 0.0:
+ downV = downAngleV[n] * (
+ 1 - 2 * shapeRatio(0, (p.lengthPar - p.offset) / (p.lengthPar - baseSize * scaleVal)))
+ random()
+ # Otherwise just find a random value
+ else:
+ downV = uniform(-downAngleV[n], downAngleV[n])
+ downRotMat = Matrix.Rotation(downAngle[n] + downV, 3,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list