diff options
-rw-r--r-- | add_curve_sapling/utils.py | 944 | ||||
-rw-r--r-- | add_mesh_BoltFactory/Boltfactory.py | 4 | ||||
-rw-r--r-- | add_mesh_BoltFactory/createMesh.py | 48 | ||||
-rw-r--r-- | add_mesh_extra_objects/add_mesh_pyramid.py | 186 | ||||
-rw-r--r-- | curve_simplify.py | 2 | ||||
-rw-r--r-- | io_coat3D/coat.py | 5 | ||||
-rw-r--r-- | io_coat3D/tex.py | 16 | ||||
-rw-r--r-- | io_export_unreal_psk_psa.py | 18 | ||||
-rw-r--r-- | io_import_scene_dxf.py | 32 | ||||
-rw-r--r-- | io_import_scene_unreal_psk.py | 78 | ||||
-rw-r--r-- | io_scene_fbx/export_fbx.py | 16 | ||||
-rw-r--r-- | io_scene_obj/import_obj.py | 92 | ||||
-rw-r--r-- | mesh_bsurfaces.py | 6 | ||||
-rw-r--r-- | mocap/mocap_constraints.py | 10 | ||||
-rw-r--r-- | mocap/mocap_tools.py | 138 | ||||
-rw-r--r-- | mocap/retarget.py | 10 | ||||
-rw-r--r-- | netrender/master.py | 48 | ||||
-rw-r--r-- | object_cloud_gen.py | 132 | ||||
-rw-r--r-- | object_fracture/fracture_ops.py | 42 | ||||
-rw-r--r-- | space_view3d_copy_attributes.py | 2 | ||||
-rw-r--r-- | space_view3d_spacebar_menu.py | 4 | ||||
-rw-r--r-- | texture_paint_layer_manager.py | 2 |
22 files changed, 935 insertions, 900 deletions
diff --git a/add_curve_sapling/utils.py b/add_curve_sapling/utils.py index 16a4509e..f74fcef3 100644 --- a/add_curve_sapling/utils.py +++ b/add_curve_sapling/utils.py @@ -402,369 +402,369 @@ def genLeafMesh(leafScale,leafScaleX,loc,quat,index,downAngle,downAngleV,rotate, return vertsList,facesList,oldRot def addTree(props): - global splitError - #startTime = time.time() - # Set the seed for repeatable results - seed(props.seed)# - - # Set all other variables - levels = props.levels# - length = props.length# - lengthV = props.lengthV# - branches = props.branches# - curveRes = props.curveRes# - curve = toRad(props.curve)# - curveV = toRad(props.curveV)# - curveBack = toRad(props.curveBack)# - baseSplits = props.baseSplits# - segSplits = props.segSplits# - splitAngle = toRad(props.splitAngle)# - splitAngleV = toRad(props.splitAngleV)# - scale = props.scale# - scaleV = props.scaleV# - attractUp = props.attractUp# - shape = int(props.shape)# - baseSize = props.baseSize - ratio = props.ratio - taper = props.taper# - ratioPower = props.ratioPower# - downAngle = toRad(props.downAngle)# - downAngleV = toRad(props.downAngleV)# - rotate = toRad(props.rotate)# - rotateV = toRad(props.rotateV)# - scale0 = props.scale0# - scaleV0 = props.scaleV0# - prune = props.prune# - pruneWidth = props.pruneWidth# - pruneWidthPeak = props.pruneWidthPeak# - prunePowerLow = props.prunePowerLow# - prunePowerHigh = props.prunePowerHigh# - pruneRatio = props.pruneRatio# - leafScale = props.leafScale# - leafScaleX = props.leafScaleX# - leafShape = props.leafShape - bend = props.bend# - leafDist = int(props.leafDist)# - bevelRes = props.bevelRes# - resU = props.resU# - useArm = props.useArm - - frameRate = props.frameRate - windSpeed = props.windSpeed - windGust = props.windGust - armAnim = props.armAnim - - leafObj = None - - # Some effects can be turned ON and OFF, the necessary variables are changed here - if not props.bevel: - bevelDepth = 0.0 - else: - bevelDepth = 1.0 - - if not props.showLeaves: - leaves = 0 - else: - leaves = props.leaves - - if props.handleType == '0': - handles = 'AUTO' - else: - handles = 'VECTOR' + global splitError + #startTime = time.time() + # Set the seed for repeatable results + seed(props.seed)# + + # Set all other variables + levels = props.levels# + length = props.length# + lengthV = props.lengthV# + branches = props.branches# + curveRes = props.curveRes# + curve = toRad(props.curve)# + curveV = toRad(props.curveV)# + curveBack = toRad(props.curveBack)# + baseSplits = props.baseSplits# + segSplits = props.segSplits# + splitAngle = toRad(props.splitAngle)# + splitAngleV = toRad(props.splitAngleV)# + scale = props.scale# + scaleV = props.scaleV# + attractUp = props.attractUp# + shape = int(props.shape)# + baseSize = props.baseSize + ratio = props.ratio + taper = props.taper# + ratioPower = props.ratioPower# + downAngle = toRad(props.downAngle)# + downAngleV = toRad(props.downAngleV)# + rotate = toRad(props.rotate)# + rotateV = toRad(props.rotateV)# + scale0 = props.scale0# + scaleV0 = props.scaleV0# + prune = props.prune# + pruneWidth = props.pruneWidth# + pruneWidthPeak = props.pruneWidthPeak# + prunePowerLow = props.prunePowerLow# + prunePowerHigh = props.prunePowerHigh# + pruneRatio = props.pruneRatio# + leafScale = props.leafScale# + leafScaleX = props.leafScaleX# + leafShape = props.leafShape + bend = props.bend# + leafDist = int(props.leafDist)# + bevelRes = props.bevelRes# + resU = props.resU# + useArm = props.useArm + + frameRate = props.frameRate + windSpeed = props.windSpeed + windGust = props.windGust + armAnim = props.armAnim + + leafObj = None + + # Some effects can be turned ON and OFF, the necessary variables are changed here + if not props.bevel: + bevelDepth = 0.0 + else: + bevelDepth = 1.0 - for ob in bpy.data.objects: - ob.select = False + if not props.showLeaves: + leaves = 0 + else: + leaves = props.leaves - childP = [] - stemList = [] - - # Initialise the tree object and curve and adjust the settings - cu = bpy.data.curves.new('tree','CURVE') - treeOb = bpy.data.objects.new('tree',cu) - bpy.context.scene.objects.link(treeOb) - - cu.dimensions = '3D' - cu.fill_mode = 'FULL' - cu.bevel_depth = bevelDepth - cu.bevel_resolution = bevelRes - - # Fix the scale of the tree now - scaleVal = scale + uniform(-scaleV,scaleV) - - # If pruning is turned on we need to draw the pruning envelope - if prune: - enHandle = 'VECTOR' - enNum = 128 - enCu = bpy.data.curves.new('envelope','CURVE') - enOb = bpy.data.objects.new('envelope',enCu) - enOb.parent = treeOb - bpy.context.scene.objects.link(enOb) - newSpline = enCu.splines.new('BEZIER') + if props.handleType == '0': + handles = 'AUTO' + else: + handles = 'VECTOR' + + for ob in bpy.data.objects: + ob.select = False + + childP = [] + stemList = [] + + # Initialise the tree object and curve and adjust the settings + cu = bpy.data.curves.new('tree','CURVE') + treeOb = bpy.data.objects.new('tree',cu) + bpy.context.scene.objects.link(treeOb) + + cu.dimensions = '3D' + cu.fill_mode = 'FULL' + cu.bevel_depth = bevelDepth + cu.bevel_resolution = bevelRes + + # Fix the scale of the tree now + scaleVal = scale + uniform(-scaleV,scaleV) + + # If pruning is turned on we need to draw the pruning envelope + if prune: + enHandle = 'VECTOR' + enNum = 128 + enCu = bpy.data.curves.new('envelope','CURVE') + enOb = bpy.data.objects.new('envelope',enCu) + enOb.parent = treeOb + bpy.context.scene.objects.link(enOb) + newSpline = enCu.splines.new('BEZIER') + newPoint = newSpline.bezier_points[-1] + newPoint.co = Vector((0,0,scaleVal)) + (newPoint.handle_right_type,newPoint.handle_left_type) = (enHandle,enHandle) + # Set the coordinates by varying the z value, envelope will be aligned to the x-axis + for c in range(enNum): + newSpline.bezier_points.add() newPoint = newSpline.bezier_points[-1] - newPoint.co = Vector((0,0,scaleVal)) + ratioVal = (c+1)/(enNum) + zVal = scaleVal - scaleVal*(1-baseSize)*ratioVal + newPoint.co = Vector((scaleVal*pruneWidth*shapeRatio(8,ratioVal,pruneWidthPeak,prunePowerHigh,prunePowerLow),0,zVal)) (newPoint.handle_right_type,newPoint.handle_left_type) = (enHandle,enHandle) - # Set the coordinates by varying the z value, envelope will be aligned to the x-axis - for c in range(enNum): - newSpline.bezier_points.add() - newPoint = newSpline.bezier_points[-1] - ratioVal = (c+1)/(enNum) - zVal = scaleVal - scaleVal*(1-baseSize)*ratioVal - newPoint.co = Vector((scaleVal*pruneWidth*shapeRatio(8,ratioVal,pruneWidthPeak,prunePowerHigh,prunePowerLow),0,zVal)) - (newPoint.handle_right_type,newPoint.handle_left_type) = (enHandle,enHandle) - newSpline = enCu.splines.new('BEZIER') + newSpline = enCu.splines.new('BEZIER') + newPoint = newSpline.bezier_points[-1] + newPoint.co = Vector((0,0,scaleVal)) + (newPoint.handle_right_type,newPoint.handle_left_type) = (enHandle,enHandle) + # Create a second envelope but this time on the y-axis + for c in range(enNum): + newSpline.bezier_points.add() newPoint = newSpline.bezier_points[-1] - newPoint.co = Vector((0,0,scaleVal)) + ratioVal = (c+1)/(enNum) + zVal = scaleVal - scaleVal*(1-baseSize)*ratioVal + newPoint.co = Vector((0,scaleVal*pruneWidth*shapeRatio(8,ratioVal,pruneWidthPeak,prunePowerHigh,prunePowerLow),zVal)) (newPoint.handle_right_type,newPoint.handle_left_type) = (enHandle,enHandle) - # Create a second envelope but this time on the y-axis - for c in range(enNum): - newSpline.bezier_points.add() - newPoint = newSpline.bezier_points[-1] - ratioVal = (c+1)/(enNum) - zVal = scaleVal - scaleVal*(1-baseSize)*ratioVal - newPoint.co = Vector((0,scaleVal*pruneWidth*shapeRatio(8,ratioVal,pruneWidthPeak,prunePowerHigh,prunePowerLow),zVal)) - (newPoint.handle_right_type,newPoint.handle_left_type) = (enHandle,enHandle) - - leafVerts = [] - leafFaces = [] - levelCount = [] - - splineToBone = deque(['']) - addsplinetobone = splineToBone.append - - # Each of the levels needed by the user we grow all the splines - for n in range(levels): - storeN = n - stemList = deque() - addstem = stemList.append - # If n is used as an index to access parameters for the tree it must be at most 3 or it will reference outside the array index - n = min(3,n) - vertAtt = attractUp - splitError = 0.0 - # If this is the first level of growth (the trunk) then we need some special work to begin the tree - if n == 0: - vertAtt = 0.0 + + leafVerts = [] + leafFaces = [] + levelCount = [] + + splineToBone = deque(['']) + addsplinetobone = splineToBone.append + + # Each of the levels needed by the user we grow all the splines + for n in range(levels): + storeN = n + stemList = deque() + addstem = stemList.append + # If n is used as an index to access parameters for the tree it must be at most 3 or it will reference outside the array index + n = min(3,n) + vertAtt = attractUp + splitError = 0.0 + # If this is the first level of growth (the trunk) then we need some special work to begin the tree + if n == 0: + 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)) + # If this isn't the trunk then we may have multiple stem to intialise + else: + # Store the old rotation to allow new stems to be rotated away from the previous one. + oldRotate = 0 + # For each of the points defined in the list of stem starting points we need to grow a stem. + 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 = 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.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,'X') + tempPos.rotate(downRotMat) + # If the -ve flag for rotate is used we need to find which side of the stem the last child point was and then grow in the opposite direction. + if rotate[n] < 0.0: + oldRotate = -copysign(rotate[n] + uniform(-rotateV[n],rotateV[n]),oldRotate) + # Otherwise just generate a random number in the specified range + else: + oldRotate += rotate[n]+uniform(-rotateV[n],rotateV[n]) + # Rotate the direction of growth and set the new point coordinates + rotMat = Matrix.Rotation(oldRotate,3,'Z') + tempPos.rotate(rotMat) + tempPos.rotate(p.quat) + newPoint.handle_right = p.co + tempPos + # If this is the first level of branching then upward attraction has no effect and a special formula is used to find branch length and the number of child stems + if n == 1: + vertAtt = 0.0 + lMax = length[1] + uniform(-lengthV[1],lengthV[1]) + branchL = p.lengthPar*lMax*shapeRatio(shape,(p.lengthPar - p.offset)/(p.lengthPar - baseSize*scaleVal)) + childStems = branches[2]*(0.2 + 0.8*(branchL/p.lengthPar)/lMax) + elif storeN <= levels - 2: + branchL = (length[n] + uniform(-lengthV[n],lengthV[n]))*(p.lengthPar - 0.6*p.offset) + childStems = branches[min(3,n+1)]*(1.0 - 0.5*p.offset/p.lengthPar) + # If this is the last level before leaves then we need to generate the child points differently + else: + branchL = (length[n] + uniform(-lengthV[n],lengthV[n]))*(p.lengthPar - 0.6*p.offset) + if leaves < 0: + childStems = False + else: + childStems = leaves*shapeRatio(leafDist,p.offset/p.lengthPar) + # Determine the starting and ending radii of the stem using the tapering of the stem + startRad = min(p.radiusPar[0]*((branchL/p.lengthPar)**ratioPower), p.radiusPar[1]) + endRad = startRad*(1 - taper[n]) newPoint.radius = startRad - addstem(stemSpline(newSpline,curve[0]/curveRes[0],curveV[0]/curveRes[0],0,curveRes[0],branchL/curveRes[0],childStems,startRad,endRad,0)) - # If this isn't the trunk then we may have multiple stem to intialise - else: - # Store the old rotation to allow new stems to be rotated away from the previous one. - oldRotate = 0 - # For each of the points defined in the list of stem starting points we need to grow a stem. - for p in childP: - # Add a spline and set the coordinate of the first point. + # If curveBack is used then the curviness of the stem is different for the first half + if curveBack[n] == 0: + curveVal = curve[n]/curveRes[n] + else: + curveVal = 2*curve[n]/curveRes[n] + # Add the new stem to list of stems to grow and define which bone it will be parented to + addstem(stemSpline(newSpline,curveVal,curveV[n]/curveRes[n],0,curveRes[n],branchL/curveRes[n],childStems,startRad,endRad,len(cu.splines)-1)) + addsplinetobone(p.parBone) + + childP = [] + # Now grow each of the stems in the list of those to be extended + for st in stemList: + # When using pruning, we need to ensure that the random effects will be the same for each iteration to make sure the problem is linear. + randState = getstate() + startPrune = True + lengthTest = 0.0 + # Store all the original values for the stem to make sure we have access after it has been modified by pruning + originalLength = st.segL + originalCurv = st.curv + originalCurvV = st.curvV + originalSeg = st.seg + originalHandleR = st.p.handle_right.copy() + originalHandleL = st.p.handle_left.copy() + originalCo = st.p.co.copy() + currentMax = 1.0 + currentMin = 0.0 + currentScale = 1.0 + oldMax = 1.0 + deleteSpline = False + orginalSplineToBone = copy.copy(splineToBone) + forceSprout = False + # Now do the iterative pruning, this uses a binary search and halts once the difference between upper and lower bounds of the search are less than 0.005 + while startPrune and ((currentMax - currentMin) > 0.005): + setstate(randState) + + # If the search will halt after this iteration, then set the adjustment of stem length to take into account the pruning ratio + if (currentMax - currentMin) < 0.01: + currentScale = (currentScale - 1)*pruneRatio + 1 + startPrune = False + forceSprout = True + # Change the segment length of the stem by applying some scaling + st.segL = originalLength*currentScale + # To prevent millions of splines being created we delete any old ones and replace them with only their first points to begin the spline again + if deleteSpline: + for x in splineList: + cu.splines.remove(x.spline) 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,'X') - tempPos.rotate(downRotMat) - # If the -ve flag for rotate is used we need to find which side of the stem the last child point was and then grow in the opposite direction. - if rotate[n] < 0.0: - oldRotate = -copysign(rotate[n] + uniform(-rotateV[n],rotateV[n]),oldRotate) - # Otherwise just generate a random number in the specified range - else: - oldRotate += rotate[n]+uniform(-rotateV[n],rotateV[n]) - # Rotate the direction of growth and set the new point coordinates - rotMat = Matrix.Rotation(oldRotate,3,'Z') - tempPos.rotate(rotMat) - tempPos.rotate(p.quat) - newPoint.handle_right = p.co + tempPos - # If this is the first level of branching then upward attraction has no effect and a special formula is used to find branch length and the number of child stems - if n == 1: - vertAtt = 0.0 - lMax = length[1] + uniform(-lengthV[1],lengthV[1]) - branchL = p.lengthPar*lMax*shapeRatio(shape,(p.lengthPar - p.offset)/(p.lengthPar - baseSize*scaleVal)) - childStems = branches[2]*(0.2 + 0.8*(branchL/p.lengthPar)/lMax) - elif storeN <= levels - 2: - branchL = (length[n] + uniform(-lengthV[n],lengthV[n]))*(p.lengthPar - 0.6*p.offset) - childStems = branches[min(3,n+1)]*(1.0 - 0.5*p.offset/p.lengthPar) - # If this is the last level before leaves then we need to generate the child points differently - else: - branchL = (length[n] + uniform(-lengthV[n],lengthV[n]))*(p.lengthPar - 0.6*p.offset) - if leaves < 0: - childStems = False + newPoint.co = originalCo + newPoint.handle_right = originalHandleR + newPoint.handle_left = originalHandleL + (newPoint.handle_left_type,newPoint.handle_right_type) = ('VECTOR','VECTOR') + st.spline = newSpline + st.curv = originalCurv + st.curvV = originalCurvV + st.seg = originalSeg + st.p = newPoint + newPoint.radius = st.radS + splineToBone = orginalSplineToBone + + # Initialise the spline list for those contained in the current level of branching + splineList = [st] + # For each of the segments of the stem which must be grown we have to add to each spline in splineList + for k in range(curveRes[n]): + # Make a copy of the current list to avoid continually adding to the list we're iterating over + tempList = splineList[:] + #print('Leng: ',len(tempList)) + # For each of the splines in this list set the number of splits and then grow it + for spl in tempList: + if k == 0: + numSplit = 0 + elif (k == 1) and (n == 0): + numSplit = baseSplits else: - childStems = leaves*shapeRatio(leafDist,p.offset/p.lengthPar) - # Determine the starting and ending radii of the stem using the tapering of the stem - startRad = min(p.radiusPar[0]*((branchL/p.lengthPar)**ratioPower), p.radiusPar[1]) - endRad = startRad*(1 - taper[n]) - newPoint.radius = startRad - # If curveBack is used then the curviness of the stem is different for the first half - if curveBack[n] == 0: - curveVal = curve[n]/curveRes[n] - else: - curveVal = 2*curve[n]/curveRes[n] - # Add the new stem to list of stems to grow and define which bone it will be parented to - addstem(stemSpline(newSpline,curveVal,curveV[n]/curveRes[n],0,curveRes[n],branchL/curveRes[n],childStems,startRad,endRad,len(cu.splines)-1)) - addsplinetobone(p.parBone) - - childP = [] - # Now grow each of the stems in the list of those to be extended - for st in stemList: - # When using pruning, we need to ensure that the random effects will be the same for each iteration to make sure the problem is linear. - randState = getstate() - startPrune = True - lengthTest = 0.0 - # Store all the original values for the stem to make sure we have access after it has been modified by pruning - originalLength = st.segL - originalCurv = st.curv - originalCurvV = st.curvV - originalSeg = st.seg - originalHandleR = st.p.handle_right.copy() - originalHandleL = st.p.handle_left.copy() - originalCo = st.p.co.copy() - currentMax = 1.0 - currentMin = 0.0 - currentScale = 1.0 - oldMax = 1.0 - deleteSpline = False - orginalSplineToBone = copy.copy(splineToBone) - forceSprout = False - # Now do the iterative pruning, this uses a binary search and halts once the difference between upper and lower bounds of the search are less than 0.005 - while startPrune and ((currentMax - currentMin) > 0.005): - setstate(randState) - - # If the search will halt after this iteration, then set the adjustment of stem length to take into account the pruning ratio - if (currentMax - currentMin) < 0.01: - currentScale = (currentScale - 1)*pruneRatio + 1 - startPrune = False - forceSprout = True - # Change the segment length of the stem by applying some scaling - st.segL = originalLength*currentScale - # To prevent millions of splines being created we delete any old ones and replace them with only their first points to begin the spline again - if deleteSpline: - for x in splineList: - cu.splines.remove(x.spline) - newSpline = cu.splines.new('BEZIER') - newPoint = newSpline.bezier_points[-1] - newPoint.co = originalCo - newPoint.handle_right = originalHandleR - newPoint.handle_left = originalHandleL - (newPoint.handle_left_type,newPoint.handle_right_type) = ('VECTOR','VECTOR') - st.spline = newSpline - st.curv = originalCurv - st.curvV = originalCurvV - st.seg = originalSeg - st.p = newPoint - newPoint.radius = st.radS - splineToBone = orginalSplineToBone - - # Initialise the spline list for those contained in the current level of branching - splineList = [st] - # For each of the segments of the stem which must be grown we have to add to each spline in splineList - for k in range(curveRes[n]): - # Make a copy of the current list to avoid continually adding to the list we're iterating over - tempList = splineList[:] - #print('Leng: ',len(tempList)) - # For each of the splines in this list set the number of splits and then grow it - for spl in tempList: - if k == 0: - numSplit = 0 - elif (k == 1) and (n == 0): - numSplit = baseSplits - else: - numSplit = splits(segSplits[n]) - if (k == int(curveRes[n]/2)) and (curveBack[n] != 0): - spl.curvAdd(-2*curve[n]/curveRes[n] + 2*curveBack[n]/curveRes[n]) - growSpline(spl,numSplit,splitAngle[n],splitAngleV[n],splineList,vertAtt,handles,splineToBone)# Add proper refs for radius and attractUp - - # If pruning is enabled then we must to the check to see if the end of the spline is within the evelope - if prune: - # Check each endpoint to see if it is inside - for s in splineList: - coordMag = (s.spline.bezier_points[-1].co.xy).length - ratio = (scaleVal - s.spline.bezier_points[-1].co.z)/(scaleVal*(1 - baseSize)) - # Don't think this if part is needed - if (n == 0) and (s.spline.bezier_points[-1].co.z < baseSize*scaleVal): - pass#insideBool = True - else: - insideBool = ((coordMag/scaleVal) < pruneWidth*shapeRatio(8,ratio,pruneWidthPeak,prunePowerHigh,prunePowerLow)) - # If the point is not inside then we adjust the scale and current search bounds - if not insideBool: - oldMax = currentMax - currentMax = currentScale - currentScale = 0.5*(currentMax + currentMin) - break - # If the scale is the original size and the point is inside then we need to make sure it won't be pruned or extended to the edge of the envelope - if insideBool and (currentScale != 1): - currentMin = currentScale - currentMax = oldMax + numSplit = splits(segSplits[n]) + if (k == int(curveRes[n]/2)) and (curveBack[n] != 0): + spl.curvAdd(-2*curve[n]/curveRes[n] + 2*curveBack[n]/curveRes[n]) + growSpline(spl,numSplit,splitAngle[n],splitAngleV[n],splineList,vertAtt,handles,splineToBone)# Add proper refs for radius and attractUp + + # If pruning is enabled then we must to the check to see if the end of the spline is within the evelope + if prune: + # Check each endpoint to see if it is inside + for s in splineList: + coordMag = (s.spline.bezier_points[-1].co.xy).length + ratio = (scaleVal - s.spline.bezier_points[-1].co.z)/(scaleVal*(1 - baseSize)) + # Don't think this if part is needed + if (n == 0) and (s.spline.bezier_points[-1].co.z < baseSize*scaleVal): + pass#insideBool = True + else: + insideBool = ((coordMag/scaleVal) < pruneWidth*shapeRatio(8,ratio,pruneWidthPeak,prunePowerHigh,prunePowerLow)) + # If the point is not inside then we adjust the scale and current search bounds + if not insideBool: + oldMax = currentMax + currentMax = currentScale currentScale = 0.5*(currentMax + currentMin) - if insideBool and ((currentMax - currentMin) == 1): - currentMin = 1 - # If the search will halt on the next iteration then we need to make sure we sprout child points to grow the next splines or leaves - if (((currentMax - currentMin) < 0.005) or not prune) or forceSprout: - tVals = findChildPoints(splineList,st.children) - # If leaves is -ve then we need to make sure the only point which sprouts is the end of the spline - #if not st.children: - if not st.children: - tVals = [0.9] - # If this is the trunk then we need to remove some of the points because of baseSize - if n == 0: - trimNum = int(baseSize*(len(tVals)+1)) - tVals = tVals[trimNum:] - - # For all the splines, we interpolate them and add the new points to the list of child points - for s in splineList: - #print(str(n)+'level: ',s.segMax*s.segL) - childP.extend(interpStem(s,tVals,s.segMax*s.segL,s.radS)) - - # Force the splines to be deleted - deleteSpline = True - # If pruning isn't enabled then make sure it doesn't loop - if not prune: - startPrune = False - - levelCount.append(len(cu.splines)) - # If we need to add leaves, we do it here - if (storeN == levels-1) and leaves: - oldRot = 0.0 - n = min(3,n+1) - # For each of the child points we add leaves - for cp in childP: - # If the special flag is set then we need to add several leaves at the same location - if leaves < 0: - oldRot = -rotate[n]/2 - for g in range(abs(leaves)): - (vertTemp,faceTemp,oldRot) = genLeafMesh(leafScale,leafScaleX,cp.co,cp.quat,len(leafVerts),downAngle[n],downAngleV[n],rotate[n],rotateV[n],oldRot,bend,leaves, leafShape) - leafVerts.extend(vertTemp) - leafFaces.extend(faceTemp) - # Otherwise just add the leaves like splines. - else: + break + # If the scale is the original size and the point is inside then we need to make sure it won't be pruned or extended to the edge of the envelope + if insideBool and (currentScale != 1): + currentMin = currentScale + currentMax = oldMax + currentScale = 0.5*(currentMax + currentMin) + if insideBool and ((currentMax - currentMin) == 1): + currentMin = 1 + # If the search will halt on the next iteration then we need to make sure we sprout child points to grow the next splines or leaves + if (((currentMax - currentMin) < 0.005) or not prune) or forceSprout: + tVals = findChildPoints(splineList,st.children) + # If leaves is -ve then we need to make sure the only point which sprouts is the end of the spline + #if not st.children: + if not st.children: + tVals = [0.9] + # If this is the trunk then we need to remove some of the points because of baseSize + if n == 0: + trimNum = int(baseSize*(len(tVals)+1)) + tVals = tVals[trimNum:] + + # For all the splines, we interpolate them and add the new points to the list of child points + for s in splineList: + #print(str(n)+'level: ',s.segMax*s.segL) + childP.extend(interpStem(s,tVals,s.segMax*s.segL,s.radS)) + + # Force the splines to be deleted + deleteSpline = True + # If pruning isn't enabled then make sure it doesn't loop + if not prune: + startPrune = False + + levelCount.append(len(cu.splines)) + # If we need to add leaves, we do it here + if (storeN == levels-1) and leaves: + oldRot = 0.0 + n = min(3,n+1) + # For each of the child points we add leaves + for cp in childP: + # If the special flag is set then we need to add several leaves at the same location + if leaves < 0: + oldRot = -rotate[n]/2 + for g in range(abs(leaves)): (vertTemp,faceTemp,oldRot) = genLeafMesh(leafScale,leafScaleX,cp.co,cp.quat,len(leafVerts),downAngle[n],downAngleV[n],rotate[n],rotateV[n],oldRot,bend,leaves, leafShape) leafVerts.extend(vertTemp) leafFaces.extend(faceTemp) - # Create the leaf mesh and object, add geometry using from_pydata, edges are currently added by validating the mesh which isn't great - leafMesh = bpy.data.meshes.new('leaves') - leafObj = bpy.data.objects.new('leaves',leafMesh) - bpy.context.scene.objects.link(leafObj) - leafObj.parent = treeOb - leafMesh.from_pydata(leafVerts,(),leafFaces) - leafMesh.validate() - - if leafShape == 'rect': - uv = leafMesh.uv_textures.new("leafUV") - for tf in uv.data: - tf.uv1, tf.uv2, tf.uv3, tf.uv4 = Vector((1, 0)), Vector((1, 1)), Vector((1 - leafScaleX, 1)), Vector((1 - leafScaleX, 0)) + # Otherwise just add the leaves like splines. + else: + (vertTemp,faceTemp,oldRot) = genLeafMesh(leafScale,leafScaleX,cp.co,cp.quat,len(leafVerts),downAngle[n],downAngleV[n],rotate[n],rotateV[n],oldRot,bend,leaves, leafShape) + leafVerts.extend(vertTemp) + leafFaces.extend(faceTemp) + # Create the leaf mesh and object, add geometry using from_pydata, edges are currently added by validating the mesh which isn't great + leafMesh = bpy.data.meshes.new('leaves') + leafObj = bpy.data.objects.new('leaves',leafMesh) + bpy.context.scene.objects.link(leafObj) + leafObj.parent = treeOb + leafMesh.from_pydata(leafVerts,(),leafFaces) + leafMesh.validate() + + if leafShape == 'rect': + uv = leafMesh.uv_textures.new("leafUV") + for tf in uv.data: + tf.uv1, tf.uv2, tf.uv3, tf.uv4 = Vector((1, 0)), Vector((1, 1)), Vector((1 - leafScaleX, 1)), Vector((1 - leafScaleX, 0)) # This can be used if we need particle leaves # if (storeN == levels-1) and leaves: @@ -793,136 +793,136 @@ def addTree(props): # leafMesh.from_pydata(leafVerts,edgeList,()) # leafMesh.vertices.foreach_set('normal',normalList) - # If we need and armature we add it - if useArm: - # Create the armature and objects - 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 + # If we need and armature we add it + if useArm: + # Create the armature and objects + 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 + 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 - - # 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 + # Make sure all objects are deselected (may not be required?) + for ob in bpy.data.objects: + ob.select = False - # 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] + # 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) + # 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) - # 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 - #print(time.time()-startTime) + 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 + #print(time.time()-startTime) diff --git a/add_mesh_BoltFactory/Boltfactory.py b/add_mesh_BoltFactory/Boltfactory.py index c5fa403f..d0734f4a 100644 --- a/add_mesh_BoltFactory/Boltfactory.py +++ b/add_mesh_BoltFactory/Boltfactory.py @@ -229,8 +229,8 @@ class add_mesh_bolt(bpy.types.Operator): if self.bf_Bit_Type == 'bf_Bit_None': pass elif self.bf_Bit_Type == 'bf_Bit_Allen': - col.prop(self, 'bf_Allen_Bit_Depth') - col.prop(self, 'bf_Allen_Bit_Flat_Distance') + col.prop(self, 'bf_Allen_Bit_Depth') + col.prop(self, 'bf_Allen_Bit_Flat_Distance') elif self.bf_Bit_Type == 'bf_Bit_Philips': col.prop(self, 'bf_Phillips_Bit_Depth') col.prop(self, 'bf_Philips_Bit_Dia') diff --git a/add_mesh_BoltFactory/createMesh.py b/add_mesh_BoltFactory/createMesh.py index e7594151..6dae7b4c 100644 --- a/add_mesh_BoltFactory/createMesh.py +++ b/add_mesh_BoltFactory/createMesh.py @@ -72,27 +72,27 @@ disadvantage of not being able to interactively change the properties. def RemoveDoubles(verts,faces,Decimal_Places = 4): - new_verts = [] - new_faces = [] - dict_verts = {} - Rounded_Verts = [] - - for v in verts: - Rounded_Verts.append([round(v[0],Decimal_Places),round(v[1],Decimal_Places),round(v[2],Decimal_Places)]) - - for face in faces: - new_face = [] - for vert_index in face: - Real_co = tuple(verts[vert_index]) - Rounded_co = tuple(Rounded_Verts[vert_index]) - - if Rounded_co not in dict_verts: - dict_verts[Rounded_co] = len(dict_verts) - new_verts.append(Real_co) - if dict_verts[Rounded_co] not in new_face: - new_face.append(dict_verts[Rounded_co]) - if len(new_face) == 3 or len(new_face) == 4: - new_faces.append(new_face) + new_verts = [] + new_faces = [] + dict_verts = {} + Rounded_Verts = [] + + for v in verts: + Rounded_Verts.append([round(v[0],Decimal_Places),round(v[1],Decimal_Places),round(v[2],Decimal_Places)]) + + for face in faces: + new_face = [] + for vert_index in face: + Real_co = tuple(verts[vert_index]) + Rounded_co = tuple(Rounded_Verts[vert_index]) + + if Rounded_co not in dict_verts: + dict_verts[Rounded_co] = len(dict_verts) + new_verts.append(Real_co) + if dict_verts[Rounded_co] not in new_face: + new_face.append(dict_verts[Rounded_co]) + if len(new_face) == 3 or len(new_face) == 4: + new_faces.append(new_face) return new_verts,new_faces @@ -183,7 +183,7 @@ def SpinDup(VERTS,FACES,DEGREE,DIVISIONS,AXIS): faces=[] if DIVISIONS == 0: - DIVISIONS = 1 + DIVISIONS = 1 step = DEGREE/DIVISIONS # set step so pieces * step = degrees in arc @@ -1341,7 +1341,7 @@ def Create_Thread_End_Verts(INNER_DIA,OUTTER_DIA,PITCH,CREST_PERCENT,ROOT_PERCEN z = max(z,Max_Height) Tapper_Radius = OUTTER_RADIUS - (Tapper_Height_Start - z) if Tapper_Radius > INNER_RADIUS: - Tapper_Radius = INNER_RADIUS + Tapper_Radius = INNER_RADIUS x = sin(radians(i*Deg_Step))*(Tapper_Radius) y = cos(radians(i*Deg_Step))*(Tapper_Radius) @@ -1355,7 +1355,7 @@ def Create_Thread_End_Verts(INNER_DIA,OUTTER_DIA,PITCH,CREST_PERCENT,ROOT_PERCEN z = max(z,Max_Height) Tapper_Radius = OUTTER_RADIUS - (Tapper_Height_Start - z) if Tapper_Radius > INNER_RADIUS: - Tapper_Radius = INNER_RADIUS + Tapper_Radius = INNER_RADIUS x = sin(radians(i*Deg_Step))*(Tapper_Radius) y = cos(radians(i*Deg_Step))*(Tapper_Radius) diff --git a/add_mesh_extra_objects/add_mesh_pyramid.py b/add_mesh_extra_objects/add_mesh_pyramid.py index 92f7f851..5ea2a5e6 100644 --- a/add_mesh_extra_objects/add_mesh_pyramid.py +++ b/add_mesh_extra_objects/add_mesh_pyramid.py @@ -1,5 +1,3 @@ -# add_mesh_pyramid.py (c) 2011 Phil Cote (cotejrp1) -# # ***** BEGIN GPL LICENSE BLOCK ***** # # @@ -18,106 +16,144 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ***** END GPL LICENCE BLOCK ***** -''' + +# (c) 2011 Phil Cote (cotejrp1) + bl_info = { 'name': 'Mesh Pyramid', 'author': 'Phil Cote, cotejrp1, (http://www.blenderaddons.com)', - 'version': (0,1), - "blender": (2, 5, 7), - "api": 35853, + 'version': (0, 3), + "blender": (2, 5, 8), + "api": 37702, 'location': 'View3D > Add > Mesh', 'description': 'Create an egyption-style step pyramid', - 'warning': '', # used for warning icon and text in addons panel + 'warning': '', # used for warning icon and text in addons panel 'category': 'Add Mesh'} -''' + import bpy -from bpy.props import FloatVectorProperty, IntProperty, FloatProperty +from bpy.props import (FloatVectorProperty, + IntProperty, + FloatProperty, + BoolProperty) + from add_utils import AddObjectHelper, add_object_data from mathutils import Vector -def makePyramid( initialSize, stepHeight, stepWidth, numberSteps ): - - vertList = [] - faceList = [] - - curSize = initialSize # how large each step will be overall - + +def makePyramid(initial_size, step_height, step_width, number_steps): + + vert_list = [] + face_list = [] + + cur_size = initial_size # how large each step will be overall + # b = buttom, t = top, f = front, b = back, l = left, r = right x = y = z = 0 - voffset = 0 # refers relative vert indices to help make faces fo each step - sn = 0 # step number - - while sn < numberSteps: - # bottom verts for this iteration - bfl = (x,y,z) - bfr = (x+curSize, y, z) - bbl = (x,y+curSize,z) - bbr = (x+curSize, y+curSize, z) - + voffset = 0 # relative vert indices to help make faces fo each step + sn = 0 # step number + + while sn < number_steps: + # bottom verts for this iteration + bfl = (x, y, z) + bfr = (x + cur_size, y, z) + bbl = (x, y + cur_size, z) + bbr = (x + cur_size, y + cur_size, z) + # top verts for this iteration. - tfl = (x,y,z+stepHeight) - tfr = (x+curSize, y, z+stepHeight) - tbl = (x,y+curSize,z+stepHeight) - tbr = (x+curSize, y+curSize, z+stepHeight) - + tfl = (x, y, z + step_height) + tfr = (x + cur_size, y, z + step_height) + tbl = (x, y + cur_size, z + step_height) + tbr = (x + cur_size, y + cur_size, z + step_height) + # add to the vert buffer - vertList.extend( ( bfl, bfr, bbl, bbr, tfl, tfr, tbl, tbr, ) ) - + vert_list.extend((bfl, bfr, bbl, bbr, tfl, tfr, tbl, tbr,)) + # side faces - faceList.extend( ( ( voffset+4, voffset+5, voffset+1, voffset+0 ), ) )# front - faceList.extend( ( ( voffset+6, voffset+7, voffset+3, voffset+2 ), ) )# back - faceList.extend( ( ( voffset+2, voffset+6, voffset+4, voffset+0 ), ) ) # left - faceList.extend( ( ( voffset+3, voffset+7, voffset+5, voffset+1 ), ) ) # right - - - # horizontal connecting faces ( note: not applicable for the first iteration ). + face_list.extend(( + (voffset + 4, voffset + 5, voffset + 1, voffset + 0), # back + (voffset + 6, voffset + 7, voffset + 3, voffset + 2), # front + (voffset + 2, voffset + 6, voffset + 4, voffset + 0), # left + (voffset + 3, voffset + 7, voffset + 5, voffset + 1), # right + )) + + # horizontal connecting faces ( note: n/a for the first iteration ). if voffset > 0: - faceList.extend( ( (voffset-4, voffset-3, voffset+1, voffset+0 ), ) ) # connector front - faceList.extend( ( (voffset-2, voffset-1, voffset+3, voffset+2 ), ) ) # back - faceList.extend( ( (voffset-4, voffset-2, voffset+2, voffset+0 ), ) ) # left - faceList.extend( ( (voffset-3, voffset-1, voffset+3, voffset+1 ), ) ) # right - - + face_list.extend(( + (voffset - 4, voffset - 3, voffset + 1, voffset + 0), # connector front + (voffset - 2, voffset - 1, voffset + 3, voffset + 2), # back + (voffset - 4, voffset - 2, voffset + 2, voffset + 0), # left + (voffset - 3, voffset - 1, voffset + 3, voffset + 1), # right + )) + # set up parameters for the next iteration - curSize = curSize - ( stepWidth * 2 ) - x = x + stepWidth - y = y + stepWidth - z = z + stepHeight + cur_size = cur_size - (step_width * 2) + x = x + step_width + y = y + step_width + z = z + step_height sn = sn + 1 voffset = voffset + 8 - - - # cap the top. - voffset = voffset - 8 # corrects for the unnecessary voffset change done final iteration - faceList.extend( ( (voffset+6, voffset+7, voffset+5, voffset+4), ) ) - - # cap the bottom. - faceList.extend( ( ( 2, 3, 1, 0), ) ) - return vertList, faceList - - -def add_pyramid_object( self, context ): - verts, faces = makePyramid( self.initialSize, self.stepHeight, self.stepWidth, self.numberSteps ) - mesh_data = bpy.data.meshes.new( name = "Pyramid" ) - mesh_data.from_pydata( verts, [], faces ) + + voffset = voffset - 8 # remove extra voffset done on final iteration + face_list.extend(( + (voffset + 6, voffset + 7, voffset + 5, voffset + 4), # cap the top. + (2, 3, 1, 0), # cap the bottom. + )) + + return vert_list, face_list + + +def add_pyramid_object(self, context): + verts, faces = makePyramid(self.initial_size, self.step_height, + self.step_width, self.number_steps) + + mesh_data = bpy.data.meshes.new(name="Pyramid") + mesh_data.from_pydata(verts, [], faces) mesh_data.update() - res = add_object_data( context, mesh_data, operator=self ) - - + res = add_object_data(context, mesh_data, operator=self) + + class OBJECT_OT_add_pyramid(bpy.types.Operator, AddObjectHelper): """Add a Mesh Object""" - bl_idname = "mesh.primative_step_pyramid_add" + bl_idname = "mesh.step_pyramid_add" bl_label = "Pyramid" bl_description = "Create a Pyramid Mesh" bl_options = {'REGISTER', 'UNDO'} - - initialSize = FloatProperty( name="Initial Size", default=2.0, min=0.0, max=20.0 ) - stepHeight= FloatProperty( name="Step Height", default=0.2, min=0.0, max=10.0 ) - stepWidth= FloatProperty( name="Step Width", default=0.2, min=0.0, max=10.0 ) - numberSteps= IntProperty( name="Number Steps", default=5, min=1, max=20 ) - + + initial_size = FloatProperty(name="Initial Size", default=2.0, + min=0.0, max=20.0, + description="Set the initial size at the pyramid base") + + step_height = FloatProperty(name="Step Height", default=0.1, + min=0.0, max=10.0, + description="How tall each of the steps will be") + + step_width = FloatProperty(name="Step Width", default=0.1, + min=0.0, max=10.0, + description="How wide each step will be") + + number_steps = IntProperty(name="Number Steps", default=10, + min=1, max=20, + description="Total number of steps") def execute(self, context): add_pyramid_object(self, context) return {'FINISHED'} + + +def menu_func(self, context): + self.layout.operator(OBJECT_OT_add_pyramid.bl_idname, + text="Pyramid", icon="PLUGIN") + + +def register(): + bpy.utils.register_class(OBJECT_OT_add_pyramid) + bpy.types.INFO_MT_mesh_add.append(menu_func) + + +def unregister(): + bpy.utils.unregister_class(OBJECT_OT_add_pyramid) + bpy.types.INFO_MT_mesh_add.remove(menu_func) + +if __name__ == "__main__": + register() diff --git a/curve_simplify.py b/curve_simplify.py index a749de3c..cecc230a 100644 --- a/curve_simplify.py +++ b/curve_simplify.py @@ -165,7 +165,7 @@ def iterate(points, newVerts, error): if alti > alti_store: alti_store = alti if alti_store >= error: - bigVert = i+1+newVerts[newIndex] + bigVert = i+1+newVerts[newIndex] if bigVert: new.append(bigVert) if new == []: diff --git a/io_coat3D/coat.py b/io_coat3D/coat.py index f7684a24..ffe7fa93 100644 --- a/io_coat3D/coat.py +++ b/io_coat3D/coat.py @@ -532,8 +532,7 @@ class VIEW3D_MT_Coat_Dynamic_Menu(bpy.types.Menu): layout.operator("import3b_applink.pilgway_3d_coat", text="Bring from 3D-Coat") layout.separator() else: - if(os.path.isfile(Blender_export)): - + if(os.path.isfile(Blender_export)): layout.operator("import3b_applink.pilgway_3d_coat", text="Bring from 3D-Coat") layout.separator() @@ -561,7 +560,7 @@ class VIEW3D_MT_ExportMenu(bpy.types.Menu): layout.operator_context = 'INVOKE_REGION_WIN' layout.prop(coat3D,"exportover") if(coat3D.exportover): - layout.prop(coat3D,"exportmod") + layout.prop(coat3D,"exportmod") class VIEW3D_MT_ExtraMenu(bpy.types.Menu): bl_label = "Extra" diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py index cd3c6e74..2e1d9f14 100644 --- a/io_coat3D/tex.py +++ b/io_coat3D/tex.py @@ -21,12 +21,12 @@ import bpy import os def find_index(objekti): - luku = 0 - for tex in objekti.active_material.texture_slots: - if(not(hasattr(tex,'texture'))): - break - luku = luku +1 - return luku + luku = 0 + for tex in objekti.active_material.texture_slots: + if(not(hasattr(tex,'texture'))): + break + luku = luku +1 + return luku def gettex(mat_list, objekti, scene,export): @@ -67,9 +67,9 @@ def gettex(mat_list, objekti, scene,export): tex_slot.texture.image.reload() else: if(os.sys.platform == 'win32'): - osoite = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3DC2Blender' + os.sep + 'Textures' + os.sep + soite = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3DC2Blender' + os.sep + 'Textures' + os.sep else: - osoite = os.path.expanduser("~") + os.sep + '3DC2Blender' + os.sep + 'Textures' + os.sep + osoite = os.path.expanduser("~") + os.sep + '3DC2Blender' + os.sep + 'Textures' + os.sep ki = os.path.split(coa.applink_name)[1] ko = os.path.splitext(ki)[0] just_nimi = ko + '_' diff --git a/io_export_unreal_psk_psa.py b/io_export_unreal_psk_psa.py index 46feffde..b04ab260 100644 --- a/io_export_unreal_psk_psa.py +++ b/io_export_unreal_psk_psa.py @@ -887,7 +887,7 @@ def parse_meshes(blender_meshes, psk_file): for point in points.items(): psk_file.AddPoint(point) if len(points.dict) > 32767: - raise RuntimeError("Vertex point reach max limited 32767 in pack data. Your",len(points.dict)) + raise RuntimeError("Vertex point reach max limited 32767 in pack data. Your",len(points.dict)) print (" -- Dumping Mesh Wedge -- LEN:",len(wedges.dict)) for wedge in wedges.items(): @@ -1089,15 +1089,15 @@ def parse_armature(blender_armature, psk_file, psa_file): raise RuntimeError("Warning add two bones else it will crash the unreal editor.") if len(current_armature.bones) == 1: raise RuntimeError("Warning add one more bone else it will crash the unreal editor.") - + mainbonecount = 0; for current_bone in current_armature.bones: #list the bone. #note this will list all the bones. if(current_bone.parent is None): mainbonecount += 1 print("Main Bone",mainbonecount) if mainbonecount > 1: - #print("Warning there no main bone.") - raise RuntimeError("There too many Main bones. Number main bones:",mainbonecount) + #print("Warning there no main bone.") + raise RuntimeError("There too many Main bones. Number main bones:",mainbonecount) for current_bone in current_armature.bones: #list the bone. #note this will list all the bones. if(current_bone.parent is None): parse_bone(current_bone, psk_file, psa_file, 0, 0, current_obj.matrix_local, None) @@ -1161,7 +1161,7 @@ def parse_animation(blender_scene, blender_armatures, psa_file): #for bone in action.groups: #print("> Name: ",bone.name) #print(dir(bone)) - + amatureobject = None #this is the armature set to none bonenames = [] #bone name of the armature bones list @@ -2041,10 +2041,10 @@ class VIEW3D_PT_unrealtools_objectmode(bpy.types.Panel): ArmatureSelect = None for obj in bpy.data.objects: - if obj.type == 'ARMATURE' and obj.select == True: - #print("Armature Name:",obj.name) - ArmatureSelect = obj - break + if obj.type == 'ARMATURE' and obj.select == True: + #print("Armature Name:",obj.name) + ArmatureSelect = obj + break #display armature actions list if ArmatureSelect != None and rd.unrealdisplayactionsets == True: layout.label(("Selected: "+ArmatureSelect.name)) diff --git a/io_import_scene_dxf.py b/io_import_scene_dxf.py index f04d5575..342fe115 100644 --- a/io_import_scene_dxf.py +++ b/io_import_scene_dxf.py @@ -1224,22 +1224,22 @@ class CText(CEntity): def drawText(text, loc, size, spacing, angle, shear, normal=Vector((0,0,1))): - #print('angle_deg=',angle) - bpy.ops.object.text_add( - view_align=False, - enter_editmode=False, - location= loc, - #rotation=(0, 0, angle), #need radians here - ) - cu = bpy.context.object.data - cu.body = text - cu.size = size #up 2.56 - cu.space_word = spacing #up 2.56 - cu.shear = shear - if angle!=0.0 or normal!=Vector((0,0,1)): - obj = bpy.context.object - transform(normal, angle, obj) - return + #print('angle_deg=',angle) + bpy.ops.object.text_add( + view_align=False, + enter_editmode=False, + location= loc, + #rotation=(0, 0, angle), #need radians here + ) + cu = bpy.context.object.data + cu.body = text + cu.size = size #up 2.56 + cu.space_word = spacing #up 2.56 + cu.shear = shear + if angle!=0.0 or normal!=Vector((0,0,1)): + obj = bpy.context.object + transform(normal, angle, obj) + return # # class CTolerance(CEntity): diff --git a/io_import_scene_unreal_psk.py b/io_import_scene_unreal_psk.py index 4d60dd46..2451b4b1 100644 --- a/io_import_scene_unreal_psk.py +++ b/io_import_scene_unreal_psk.py @@ -625,46 +625,46 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures): #psktexname="psk" + str(countm) #me_ob.uv_textures.new(name=psktexname) for countm in range(len(me_ob.uv_textures)): - me_ob.update() - #print(dir(me_ob.uv_textures)) - #psktexname="psk" + str(countm) - uvtex = me_ob.uv_textures[countm] #add one uv texture - me_ob.update() - #print("UV TEXTURE NAME:",uvtex.name) - if (len(faceuv) > 0): - # counttex = 0 # UNUSED - countm = 0 - for countm in range(len(me_ob.uv_textures)): - me_ob.update() - #print(dir(me_ob.uv_textures)) - psktexname="psk" + str(countm) - uvtex = me_ob.uv_textures[countm] #add one uv texture - me_ob.update() - #print("UV TEXTURE NAME:",uvtex.name) - for i, face in enumerate(me_ob.faces): - blender_tface = uvtex.data[i] #face - mfaceuv = faceuv[i] - #print("---------------------------------------") - #print(faceuv[i][1]) - #print(dir(face)) + me_ob.update() + #print(dir(me_ob.uv_textures)) + #psktexname="psk" + str(countm) + uvtex = me_ob.uv_textures[countm] #add one uv texture + me_ob.update() + #print("UV TEXTURE NAME:",uvtex.name) + if (len(faceuv) > 0): + # counttex = 0 # UNUSED + countm = 0 + for countm in range(len(me_ob.uv_textures)): + me_ob.update() + #print(dir(me_ob.uv_textures)) + psktexname="psk" + str(countm) + uvtex = me_ob.uv_textures[countm] #add one uv texture + me_ob.update() + #print("UV TEXTURE NAME:",uvtex.name) + for i, face in enumerate(me_ob.faces): + blender_tface = uvtex.data[i] #face + mfaceuv = faceuv[i] + #print("---------------------------------------") + #print(faceuv[i][1]) + #print(dir(face)) + face.material_index = faceuv[i][1] + if countm == faceuv[i][1]: face.material_index = faceuv[i][1] - if countm == faceuv[i][1]: - face.material_index = faceuv[i][1] - blender_tface.uv1 = mfaceuv[0][0] #uv = (0,0) - blender_tface.uv2 = mfaceuv[0][1] #uv = (0,0) - blender_tface.uv3 = mfaceuv[0][2] #uv = (0,0) - else: - #set uv to zero (0,0) - #print("--------------------") - #print(blender_tface.uv1) - #print(blender_tface.uv2) - #print(blender_tface.uv2) - blender_tface.uv1 = [0,0] - #print(blender_tface.uv1) - blender_tface.uv2 = [0,0] - blender_tface.uv3 = [0,0] - - texture.append(uvtex) + blender_tface.uv1 = mfaceuv[0][0] #uv = (0,0) + blender_tface.uv2 = mfaceuv[0][1] #uv = (0,0) + blender_tface.uv3 = mfaceuv[0][2] #uv = (0,0) + else: + #set uv to zero (0,0) + #print("--------------------") + #print(blender_tface.uv1) + #print(blender_tface.uv2) + #print(blender_tface.uv2) + blender_tface.uv1 = [0,0] + #print(blender_tface.uv1) + blender_tface.uv2 = [0,0] + blender_tface.uv3 = [0,0] + + texture.append(uvtex) print("UV TEXTURE LEN:",len(texture)) #for tex in me_ob.uv_textures: #print("mesh tex:",dir(tex)) diff --git a/io_scene_fbx/export_fbx.py b/io_scene_fbx/export_fbx.py index af4c7e6a..89bc275b 100644 --- a/io_scene_fbx/export_fbx.py +++ b/io_scene_fbx/export_fbx.py @@ -1431,15 +1431,15 @@ def save_single(operator, scene, filepath="", fw('\n\t\tEdges: ') i = -1 for ed in me_edges: - if i == -1: - fw('%i,%i' % (ed.vertices[0], ed.vertices[1])) + if i == -1: + fw('%i,%i' % (ed.vertices[0], ed.vertices[1])) + i = 0 + else: + if i == 13: + fw('\n\t\t') i = 0 - else: - if i == 13: - fw('\n\t\t') - i = 0 - fw(',%i,%i' % (ed.vertices[0], ed.vertices[1])) - i += 1 + fw(',%i,%i' % (ed.vertices[0], ed.vertices[1])) + i += 1 fw('\n\t\tGeometryVersion: 124') diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py index 02e8dfdb..ae3b87a2 100644 --- a/io_scene_obj/import_obj.py +++ b/io_scene_obj/import_obj.py @@ -591,56 +591,56 @@ def create_mesh(new_objects, edges.append(face[0]) else: - blender_face = me.faces[i] + blender_face = me.faces[i] - (face_vert_loc_indices, - face_vert_tex_indices, - context_material, - context_smooth_group, - context_object, - ) = face + (face_vert_loc_indices, + face_vert_tex_indices, + context_material, + context_smooth_group, + context_object, + ) = face - if context_smooth_group: - blender_face.use_smooth = True + if context_smooth_group: + blender_face.use_smooth = True + + if context_material: + if context_material_old is not context_material: + mat = material_mapping[context_material] + context_material_old = context_material + + blender_face.material_index = mat +# blender_face.mat= mat + + if verts_tex: + + blender_tface = me.uv_textures[0].data[i] if context_material: - if context_material_old is not context_material: - mat = material_mapping[context_material] - context_material_old = context_material - - blender_face.material_index = mat -# blender_face.mat= mat - - if verts_tex: - - blender_tface = me.uv_textures[0].data[i] - - if context_material: - image, has_data = unique_material_images[context_material] - if image: # Can be none if the material dosnt have an image. - blender_tface.image = image - if has_data and image.depth == 32: - blender_tface.alpha_blend = 'ALPHA' - - # BUG - Evil eekadoodle problem where faces that have vert index 0 location at 3 or 4 are shuffled. - if len(face_vert_loc_indices) == 4: - if face_vert_loc_indices[2] == 0 or face_vert_loc_indices[3] == 0: - face_vert_tex_indices = face_vert_tex_indices[2], face_vert_tex_indices[3], face_vert_tex_indices[0], face_vert_tex_indices[1] - else: # length of 3 - if face_vert_loc_indices[2] == 0: - face_vert_tex_indices = face_vert_tex_indices[1], face_vert_tex_indices[2], face_vert_tex_indices[0] - # END EEEKADOODLE FIX - - # assign material, uv's and image - blender_tface.uv1 = verts_tex[face_vert_tex_indices[0]] - blender_tface.uv2 = verts_tex[face_vert_tex_indices[1]] - blender_tface.uv3 = verts_tex[face_vert_tex_indices[2]] - - if len(face_vert_loc_indices) == 4: - blender_tface.uv4 = verts_tex[face_vert_tex_indices[3]] - -# for ii, uv in enumerate(blender_face.uv): -# uv.x, uv.y= verts_tex[face_vert_tex_indices[ii]] + image, has_data = unique_material_images[context_material] + if image: # Can be none if the material dosnt have an image. + blender_tface.image = image + if has_data and image.depth == 32: + blender_tface.alpha_blend = 'ALPHA' + + # BUG - Evil eekadoodle problem where faces that have vert index 0 location at 3 or 4 are shuffled. + if len(face_vert_loc_indices) == 4: + if face_vert_loc_indices[2] == 0 or face_vert_loc_indices[3] == 0: + face_vert_tex_indices = face_vert_tex_indices[2], face_vert_tex_indices[3], face_vert_tex_indices[0], face_vert_tex_indices[1] + else: # length of 3 + if face_vert_loc_indices[2] == 0: + face_vert_tex_indices = face_vert_tex_indices[1], face_vert_tex_indices[2], face_vert_tex_indices[0] + # END EEEKADOODLE FIX + + # assign material, uv's and image + blender_tface.uv1 = verts_tex[face_vert_tex_indices[0]] + blender_tface.uv2 = verts_tex[face_vert_tex_indices[1]] + blender_tface.uv3 = verts_tex[face_vert_tex_indices[2]] + + if len(face_vert_loc_indices) == 4: + blender_tface.uv4 = verts_tex[face_vert_tex_indices[3]] + +# for ii, uv in enumerate(blender_face.uv): +# uv.x, uv.y= verts_tex[face_vert_tex_indices[ii]] del me_faces # del ALPHA diff --git a/mesh_bsurfaces.py b/mesh_bsurfaces.py index 308ff4da..b49f0360 100644 --- a/mesh_bsurfaces.py +++ b/mesh_bsurfaces.py @@ -486,7 +486,7 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN') for i in range(0, int(bpy.context.scene.SURFSK_precision)): - bpy.ops.curve.subdivide('INVOKE_REGION_WIN') + bpy.ops.curve.subdivide('INVOKE_REGION_WIN') bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN') # Proportions U. @@ -606,7 +606,7 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): bpy.ops.curve.spline_type_set('INVOKE_REGION_WIN', type='BEZIER') bpy.ops.curve.handle_type_set('INVOKE_REGION_WIN', type='AUTOMATIC') for i in range(0, int(bpy.context.scene.SURFSK_precision)): - bpy.ops.curve.subdivide('INVOKE_REGION_WIN') + bpy.ops.curve.subdivide('INVOKE_REGION_WIN') bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN') @@ -631,7 +631,7 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN') for i in range(0, int(bpy.context.scene.SURFSK_precision)): - bpy.ops.curve.subdivide('INVOKE_REGION_WIN') + bpy.ops.curve.subdivide('INVOKE_REGION_WIN') bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN') for sp_idx in range(0, len(surface_splines)): diff --git a/mocap/mocap_constraints.py b/mocap/mocap_constraints.py index a8d88c3a..d9f41ea1 100644 --- a/mocap/mocap_constraints.py +++ b/mocap/mocap_constraints.py @@ -363,11 +363,11 @@ def bakeAllConstraints(obj, s_frame, e_frame, bones): ik = retarget.hasIKConstraint(end_bone) cons_obj = getConsObj(end_bone) if ik: - #If it's an auto generated IK: - if ik.chain_count == 0: - selectedBones += bones # Chain len 0, bake everything - else: - selectedBones += [end_bone] + end_bone.parent_recursive[:ik.chain_count - 1] # Bake the chain + #If it's an auto generated IK: + if ik.chain_count == 0: + selectedBones += bones # Chain len 0, bake everything + else: + selectedBones += [end_bone] + end_bone.parent_recursive[:ik.chain_count - 1] # Bake the chain else: #It's either an FK bone which we should just bake #OR a user created IK target bone diff --git a/mocap/mocap_tools.py b/mocap/mocap_tools.py index 35376e0a..5d852052 100644 --- a/mocap/mocap_tools.py +++ b/mocap/mocap_tools.py @@ -631,80 +631,80 @@ def rotate_fix_armature(arm_data): #Roughly scales the performer armature to match the enduser armature #IN: perfromer_obj, enduser_obj, Blender objects whose .data is an armature. def scale_fix_armature(performer_obj, enduser_obj): - perf_bones = performer_obj.data.bones - end_bones = enduser_obj.data.bones - - def calculateBoundingRadius(bones): - center = Vector() - for bone in bones: - center += bone.head_local - center /= len(bones) - radius = 0 - for bone in bones: - dist = (bone.head_local - center).length - if dist > radius: - radius = dist - return radius - - perf_rad = calculateBoundingRadius(performer_obj.data.bones) - end_rad = calculateBoundingRadius(enduser_obj.data.bones) - #end_avg = enduser_obj.dimensions - factor = end_rad / perf_rad * 1.2 - performer_obj.scale *= factor + perf_bones = performer_obj.data.bones + end_bones = enduser_obj.data.bones + + def calculateBoundingRadius(bones): + center = Vector() + for bone in bones: + center += bone.head_local + center /= len(bones) + radius = 0 + for bone in bones: + dist = (bone.head_local - center).length + if dist > radius: + radius = dist + return radius + + perf_rad = calculateBoundingRadius(performer_obj.data.bones) + end_rad = calculateBoundingRadius(enduser_obj.data.bones) + #end_avg = enduser_obj.dimensions + factor = end_rad / perf_rad * 1.2 + performer_obj.scale *= factor #Guess Mapping #Given a performer and enduser armature, attempts to guess the hiearchy mapping def guessMapping(performer_obj, enduser_obj): - perf_bones = performer_obj.data.bones - end_bones = enduser_obj.data.bones - - root = perf_bones[0] - - def findBoneSide(bone): - if "Left" in bone: - return "Left", bone.replace("Left", "").lower().replace(".", "") - if "Right" in bone: - return "Right", bone.replace("Right", "").lower().replace(".", "") - if "L" in bone: - return "Left", bone.replace("Left", "").lower().replace(".", "") - if "R" in bone: - return "Right", bone.replace("Right", "").lower().replace(".", "") - return "", bone - - def nameMatch(bone_a, bone_b): - # nameMatch - recieves two strings, returns 2 if they are relatively the same, 1 if they are the same but R and L and 0 if no match at all - side_a, noside_a = findBoneSide(bone_a) - side_b, noside_b = findBoneSide(bone_b) - if side_a == side_b: - if noside_a in noside_b or noside_b in noside_a: - return 2 - else: - if noside_a in noside_b or noside_b in noside_a: - return 1 - return 0 - - def guessSingleMapping(perf_bone): - possible_bones = [end_bones[0]] - - while possible_bones: - for end_bone in possible_bones: - match = nameMatch(perf_bone.name, end_bone.name) - if match == 2 and not perf_bone.map: - perf_bone.map = end_bone.name - #~ elif match == 1 and not perf_bone.map: - #~ oppo = perf_bones[oppositeBone(perf_bone)].map - # if oppo: - # perf_bone = oppo - newPossibleBones = [] - for end_bone in possible_bones: - newPossibleBones += list(end_bone.children) - possible_bones = newPossibleBones - - for child in perf_bone.children: - guessSingleMapping(child) - - guessSingleMapping(root) + perf_bones = performer_obj.data.bones + end_bones = enduser_obj.data.bones + + root = perf_bones[0] + + def findBoneSide(bone): + if "Left" in bone: + return "Left", bone.replace("Left", "").lower().replace(".", "") + if "Right" in bone: + return "Right", bone.replace("Right", "").lower().replace(".", "") + if "L" in bone: + return "Left", bone.replace("Left", "").lower().replace(".", "") + if "R" in bone: + return "Right", bone.replace("Right", "").lower().replace(".", "") + return "", bone + + def nameMatch(bone_a, bone_b): + # nameMatch - recieves two strings, returns 2 if they are relatively the same, 1 if they are the same but R and L and 0 if no match at all + side_a, noside_a = findBoneSide(bone_a) + side_b, noside_b = findBoneSide(bone_b) + if side_a == side_b: + if noside_a in noside_b or noside_b in noside_a: + return 2 + else: + if noside_a in noside_b or noside_b in noside_a: + return 1 + return 0 + + def guessSingleMapping(perf_bone): + possible_bones = [end_bones[0]] + + while possible_bones: + for end_bone in possible_bones: + match = nameMatch(perf_bone.name, end_bone.name) + if match == 2 and not perf_bone.map: + perf_bone.map = end_bone.name + #~ elif match == 1 and not perf_bone.map: + #~ oppo = perf_bones[oppositeBone(perf_bone)].map + # if oppo: + # perf_bone = oppo + newPossibleBones = [] + for end_bone in possible_bones: + newPossibleBones += list(end_bone.children) + possible_bones = newPossibleBones + + for child in perf_bone.children: + guessSingleMapping(child) + + guessSingleMapping(root) # Creates limit rotation constraints on the enduser armature based on range of motion (max min of fcurves) of the performer. diff --git a/mocap/retarget.py b/mocap/retarget.py index 410ea0be..d8dae356 100644 --- a/mocap/retarget.py +++ b/mocap/retarget.py @@ -76,11 +76,11 @@ def createIntermediate(performer_obj, enduser_obj, root, s_frame, e_frame, scene #Simple 1to1 retarget of a bone def singleBoneRetarget(inter_bone, perf_bone): - perf_world_rotation = perf_bone.matrix - inter_world_base_rotation = inter_bone.bone.matrix_local - inter_world_base_inv = inter_world_base_rotation.inverted() - bake_matrix = (inter_world_base_inv.to_3x3() * perf_world_rotation.to_3x3()) - return bake_matrix.to_4x4() + perf_world_rotation = perf_bone.matrix + inter_world_base_rotation = inter_bone.bone.matrix_local + inter_world_base_inv = inter_world_base_rotation.inverted() + bake_matrix = (inter_world_base_inv.to_3x3() * perf_world_rotation.to_3x3()) + return bake_matrix.to_4x4() #uses 1to1 and interpolation/averaging to match many to 1 retarget def manyPerfToSingleInterRetarget(inter_bone, performer_bones_s): diff --git a/netrender/master.py b/netrender/master.py index 66a5d4bd..c2f46c17 100644 --- a/netrender/master.py +++ b/netrender/master.py @@ -1036,35 +1036,35 @@ def saveMaster(path, httpd): pickle.dump((httpd.path, httpd.jobs, httpd.slaves), f, pickle.HIGHEST_PROTOCOL) def runMaster(address, broadcast, clear, path, update_stats, test_break): - httpd = createMaster(address, clear, path) - httpd.timeout = 1 - httpd.stats = update_stats + httpd = createMaster(address, clear, path) + httpd.timeout = 1 + httpd.stats = update_stats - if broadcast: - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + if broadcast: + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) - start_time = time.time() - 2 + start_time = time.time() - 2 - while not test_break(): - try: - httpd.handle_request() - except select.error: - pass + while not test_break(): + try: + httpd.handle_request() + except select.error: + pass - if time.time() - start_time >= 2: # need constant here - httpd.timeoutSlaves() + if time.time() - start_time >= 2: # need constant here + httpd.timeoutSlaves() - httpd.updateUsage() + httpd.updateUsage() - if broadcast: - print("broadcasting address") - s.sendto(bytes("%i" % address[1], encoding='utf8'), 0, ('<broadcast>', 8000)) - start_time = time.time() + if broadcast: + print("broadcasting address") + s.sendto(bytes("%i" % address[1], encoding='utf8'), 0, ('<broadcast>', 8000)) + start_time = time.time() - httpd.server_close() - if clear: - clearMaster(httpd.path) - else: - saveMaster(path, httpd) + httpd.server_close() + if clear: + clearMaster(httpd.path) + else: + saveMaster(path, httpd) diff --git a/object_cloud_gen.py b/object_cloud_gen.py index 4054a90c..3228ef6c 100644 --- a/object_cloud_gen.py +++ b/object_cloud_gen.py @@ -254,18 +254,18 @@ def combineObjects(scene, combined, listobjs): scene.objects.active = combined # Add data - if (len(listobjs) > 0): - for i in listobjs: - # Add a modifier - bpy.ops.object.modifier_add(type='BOOLEAN') + if len(listobjs) > 0: + for i in listobjs: + # Add a modifier + bpy.ops.object.modifier_add(type='BOOLEAN') - union = combined.modifiers - union[0].name = "AddEmUp" - union[0].object = i - union[0].operation = 'UNION' + union = combined.modifiers + union[0].name = "AddEmUp" + union[0].object = i + union[0].operation = 'UNION' - # Apply modifier - bpy.ops.object.modifier_apply(apply_as='DATA', modifier=union[0].name) + # Apply modifier + bpy.ops.object.modifier_apply(apply_as='DATA', modifier=union[0].name) # Returns the action we want to take def getActionToDo(obj): @@ -366,65 +366,65 @@ class GenerateCloud(bpy.types.Operator): WhatToDo = getActionToDo(active_object) if WhatToDo == 'DEGENERATE': - # Degenerate Cloud - mainObj = active_object - - cloudMembers = active_object.children - - createdObjects = [] - definitionObjects = [] - for member in cloudMembers: - applyScaleRotLoc(scene, member) - if (member["CloudMember"] == "CreatedObj"): - createdObjects.append(member) - else: - definitionObjects.append(member) - - for defObj in definitionObjects: - #Delete cloudmember data from objects - if "CloudMember" in defObj: - del(defObj["CloudMember"]) - - for createdObj in createdObjects: - totallyDeleteObject(scene, createdObj) - - # Delete the blend_data object - totallyDeleteObject(scene, mainObj) - - # Select all of the left over boxes so people can immediately - # press generate again if they want. - for eachMember in definitionObjects: - eachMember.draw_type = 'SOLID' - eachMember.select = True - eachMember.hide_render = False - + # Degenerate Cloud + mainObj = active_object + + cloudMembers = active_object.children + + createdObjects = [] + definitionObjects = [] + for member in cloudMembers: + applyScaleRotLoc(scene, member) + if member["CloudMember"] == "CreatedObj": + createdObjects.append(member) + else: + definitionObjects.append(member) + + for defObj in definitionObjects: + # Delete cloudmember data from objects + if "CloudMember" in defObj: + del(defObj["CloudMember"]) + + for createdObj in createdObjects: + totallyDeleteObject(scene, createdObj) + + # Delete the blend_data object + totallyDeleteObject(scene, mainObj) + + # Select all of the left over boxes so people can immediately + # press generate again if they want. + for eachMember in definitionObjects: + eachMember.draw_type = 'SOLID' + eachMember.select = True + eachMember.hide_render = False + elif WhatToDo == 'CLOUD_CONVERT_TO_MESH': + + cloudParticles = active_object.particle_systems.active - cloudParticles = active_object.particle_systems.active - - bounds = active_object.parent - - ###############Create CloudPnts for putting points in######### - # Create a new object cloudPnts - cloudPnts = addNewObject(scene, "CloudPoints", bounds) - cloudPnts["CloudMember"] = "CreatedObj" - cloudPnts.draw_type = 'WIRE' - cloudPnts.hide_render = True - - makeParent(bounds, cloudPnts, scene) + bounds = active_object.parent - convertParticlesToMesh(scene, cloudParticles, cloudPnts, True) - - removeParticleSystemFromObj(scene, active_object) - - pDensity = getpdensitytexture(bounds) - pDensity.point_density.point_source = 'OBJECT' - pDensity.point_density.object = cloudPnts - - #Let's resize the bound box to be more accurate. - how_much_bigger = pDensity.point_density.radius - makeObjectIntoBoundBox(scene, bounds, how_much_bigger, cloudPnts) - + ###############Create CloudPnts for putting points in######### + # Create a new object cloudPnts + cloudPnts = addNewObject(scene, "CloudPoints", bounds) + cloudPnts["CloudMember"] = "CreatedObj" + cloudPnts.draw_type = 'WIRE' + cloudPnts.hide_render = True + + makeParent(bounds, cloudPnts, scene) + + convertParticlesToMesh(scene, cloudParticles, cloudPnts, True) + + removeParticleSystemFromObj(scene, active_object) + + pDensity = getpdensitytexture(bounds) + pDensity.point_density.point_source = 'OBJECT' + pDensity.point_density.object = cloudPnts + + #Let's resize the bound box to be more accurate. + how_much_bigger = pDensity.point_density.radius + makeObjectIntoBoundBox(scene, bounds, how_much_bigger, cloudPnts) + else: # Generate Cloud diff --git a/object_fracture/fracture_ops.py b/object_fracture/fracture_ops.py index c9fcdecb..fb609b67 100644 --- a/object_fracture/fracture_ops.py +++ b/object_fracture/fracture_ops.py @@ -424,27 +424,27 @@ class FractureGroup(bpy.types.Operator): # Import Functions def import_object(obname): - opath = "//data.blend\\Object\\" + obname - s = os.sep - dpath = bpy.utils.script_paths()[0] + \ - '%saddons%sobject_fracture%sdata.blend\\Object\\' % (s, s, s) - - # DEBUG - #print('import_object: ' + opath) - - bpy.ops.wm.link_append( - filepath=opath, - filename=obname, - directory=dpath, - filemode=1, - link=False, - autoselect=True, - active_layer=True, - instance_groups=True, - relative_path=True) - - for ob in bpy.context.selected_objects: - ob.location = bpy.context.scene.cursor_location + opath = "//data.blend\\Object\\" + obname + s = os.sep + dpath = bpy.utils.script_paths()[0] + \ + '%saddons%sobject_fracture%sdata.blend\\Object\\' % (s, s, s) + + # DEBUG + #print('import_object: ' + opath) + + bpy.ops.wm.link_append( + filepath=opath, + filename=obname, + directory=dpath, + filemode=1, + link=False, + autoselect=True, + active_layer=True, + instance_groups=True, + relative_path=True) + + for ob in bpy.context.selected_objects: + ob.location = bpy.context.scene.cursor_location class ImportFractureRecorder(bpy.types.Operator): diff --git a/space_view3d_copy_attributes.py b/space_view3d_copy_attributes.py index d7e8569a..3551e108 100644 --- a/space_view3d_copy_attributes.py +++ b/space_view3d_copy_attributes.py @@ -700,7 +700,7 @@ class MESH_OT_CopyFaceSettings(bpy.types.Operator): layers = mesh.uv_textures act_layer = mesh.uv_textures.active if not layers or (layername and not layername in layers): - return _end({'CANCELLED'}) + return _end({'CANCELLED'}) from_data = layers[layername or act_layer.name].data to_data = act_layer.data from_face = from_data[mesh.faces.active] diff --git a/space_view3d_spacebar_menu.py b/space_view3d_spacebar_menu.py index 52f8085a..66afe7b9 100644 --- a/space_view3d_spacebar_menu.py +++ b/space_view3d_spacebar_menu.py @@ -849,8 +849,8 @@ class VIEW3D_MT_SelectEditMenu(bpy.types.Menu): layout.operator("mesh.select_by_number_vertices", text="Quads").type = 'QUADS' if context.scene.tool_settings.mesh_select_mode[2] == False: - layout.operator("mesh.select_non_manifold", - text="Non Manifold") + layout.operator("mesh.select_non_manifold", + text="Non Manifold") layout.operator("mesh.select_by_number_vertices", text="Loose Verts/Edges").type = 'OTHER' layout.operator("mesh.select_similar", text="Similar") diff --git a/texture_paint_layer_manager.py b/texture_paint_layer_manager.py index 0a8a332e..6773c6dc 100644 --- a/texture_paint_layer_manager.py +++ b/texture_paint_layer_manager.py @@ -185,7 +185,7 @@ class OBJECT_PT_Texture_paint_layers(bpy.types.Panel): ic = 'RESTRICT_VIEW_ON' row.prop(t,'use', text = "",icon = ic) except: - continue + continue |