Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
verts.append([baseEndLocX + locX, locY, baseEndLocZ + locZ])
loopsEndCircles.append(circle)
# Create vertices for the joint circles.
loopJoint = []
for vertIdx in range(div):
curVertAngle = vertIdx * (2.0 * pi / div)
locX = sin(curVertAngle)
locY = cos(curVertAngle)
skipVert = False
# Store pole vertices
if vertIdx == 0:
if (num == 0):
vertTemp2 = len(verts)
else:
skipVert = True
elif vertIdx == div / 2:
# @todo: This will possibly break if we
# ever support odd divisions.
if (num == 0):
vertTemp1 = len(verts)
else:
skipVert = True
if not skipVert:
if (vertIdx > div / 2):
locZ = -locX * tan((pi - angleDiv) / 2.0)
loopJoint.append(len(verts))
# Rotate the vert
cosAng = cos(-angle)
sinAng = sin(-angle)
LocXnew = locX * cosAng - locZ * sinAng
LocZnew = locZ * cosAng + locX * sinAng
locZ = LocZnew
locX = LocXnew
verts.append([
locX * radius,
locY * radius,
locZ * radius])
else:
# These two vertices will only be
# added the very first time.
if vertIdx == 0 or vertIdx == div / 2:
verts.append([locX * radius, locY * radius, locZ])
loopsJointsTemp.append(loopJoint)
# Create complete loops (loopsJoints) out of the
# double number of half loops in loopsJointsTemp.
for halfLoopIdx in range(len(loopsJointsTemp)):
if (halfLoopIdx == len(loopsJointsTemp) - 1):
idx1 = halfLoopIdx
idx2 = 0
else:
idx1 = halfLoopIdx
idx2 = halfLoopIdx + 1
loopJoint = []
loopJoint.append(vertTemp2)
loopJoint.extend(reversed(loopsJointsTemp[idx2]))
loopJoint.append(vertTemp1)
loopJoint.extend(loopsJointsTemp[idx1])
loopsJoints.append(loopJoint)
# Create faces from the two
# loop arrays (loopsJoints -> loopsEndCircles).
for loopIdx in range(len(loopsEndCircles)):
faces.extend(
createFaces(loopsJoints[loopIdx],
loopsEndCircles[loopIdx]))
createObject(context.scene, verts, faces, "N Joint")
return {'FINISHED'}
class INFO_MT_mesh_pipe_joints_add(bpy.types.Menu):
# Define the "Pipe Joints" menu
bl_idname = "INFO_MT_mesh_pipe_joints_add"
bl_label = "Pipe Joints"
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_elbow_joint_add",
text="Pipe Elbow")
layout.operator("mesh.primitive_tee_joint_add",
text="Pipe T-Joint")
layout.operator("mesh.primitive_wye_joint_add",
text="Pipe Y-Joint")
layout.operator("mesh.primitive_cross_joint_add",
text="Pipe Cross-Joint")
layout.operator("mesh.primitive_n_joint_add",
text="Pipe N-Joint")
################################
import space_info
# Define "Pipe Joints" menu
menu_func = (lambda self,
context: self.layout.menu("INFO_MT_mesh_pipe_joints_add", icon="PLUGIN"))
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
def register():
# Register the operators/menus.
bpy.types.register(AddElbowJoint)
bpy.types.register(AddTeeJoint)
bpy.types.register(AddWyeJoint)
bpy.types.register(AddCrossJoint)
bpy.types.register(AddNJoint)
bpy.types.register(INFO_MT_mesh_pipe_joints_add)
# Add "Pipe Joints" menu to the "Add Mesh" menu
space_info.INFO_MT_mesh_add.append(menu_func)
def unregister():
# Unregister the operators/menus.
bpy.types.unregister(AddElbowJoint)
bpy.types.unregister(AddTeeJoint)
bpy.types.unregister(AddWyeJoint)
bpy.types.unregister(AddCrossJoint)
bpy.types.unregister(AddNJoint)
bpy.types.unregister(INFO_MT_mesh_pipe_joints_add)
# Remove "Pipe Joints" menu from the "Add Mesh" menu.
space_info.INFO_MT_mesh_add.remove(menu_func)
if __name__ == "__main__":
register()