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
loopTempA2.reverse()
loopTempB2.append(vertTemp2)
loopJoint4.extend(reversed(loopTempB2))
loopJoint4.extend(loopTempA2)
# Create end circle (1. branching pipe)
baseEndLocX = -branch1Length * sin(angle1)
baseEndLocZ = branch1Length * cos(angle1)
for vertIdx in range(div):
curVertAngle = vertIdx * (2.0 * pi / div)
# Create circle
locX = sin(curVertAngle) * radius
locY = cos(curVertAngle) * radius
locZ = 0.0
# Rotate circle
locZ = locX * cos(pi / 2.0 - angle1)
locX = locX * sin(pi / 2.0 - angle1)
loopArm1.append(len(verts))
# Add translated circle.
verts.append([baseEndLocX + locX, locY, baseEndLocZ + locZ])
# Create end circle (2. branching pipe)
baseEndLocX = branch2Length * sin(angle2)
baseEndLocZ = branch2Length * cos(angle2)
for vertIdx in range(div):
curVertAngle = vertIdx * (2.0 * pi / div)
# Create circle
locX = sin(curVertAngle) * radius
locY = cos(curVertAngle) * radius
locZ = 0.0
# Rotate circle
locZ = locX * cos(pi / 2.0 + angle2)
locX = locX * sin(pi / 2.0 + angle2)
loopArm2.append(len(verts))
# Add translated circle
verts.append([baseEndLocX + locX, locY, baseEndLocZ + locZ])
# Create end circle (center pipe)
baseEndLocX = branch3Length * sin(angle3)
baseEndLocZ = branch3Length * cos(angle3)
for vertIdx in range(div):
curVertAngle = vertIdx * (2.0 * pi / div)
# Create circle
locX = sin(curVertAngle) * radius
locY = cos(curVertAngle) * radius
locZ = 0.0
# Rotate circle
locZ = locX * cos(pi / 2.0 + angle3)
locX = locX * sin(pi / 2.0 + angle3)
loopArm3.append(len(verts))
# Add translated circle
verts.append([baseEndLocX + locX, locY, baseEndLocZ + locZ])
# Create faces
faces.extend(createFaces(loopMainStart, loopJoint1, closed=True))
faces.extend(createFaces(loopJoint2, loopArm1, closed=True))
faces.extend(createFaces(loopJoint3, loopArm2, closed=True))
faces.extend(createFaces(loopJoint4, loopArm3, closed=True))
"Cross Joint", edit, self.align_matrix)
self.align_matrix = align_matrix(context)
self.execute(context)
return {'FINISHED'}
class AddNJoint(bpy.types.Operator):
'''Add a N-Joint mesh'''
# Create the vertices and polygons for a regular n-joint.
bl_idname = "mesh.primitive_n_joint_add"
bl_label = "Add Pipe N-Joint"
bl_options = {'REGISTER', 'UNDO'}
# edit - Whether to add or update.
edit = BoolProperty(name="",
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
radius = FloatProperty(name="Radius",
description="The radius of the pipe.",
default=1.0,
min=0.01,
max=100.0,
unit="LENGTH")
div = IntProperty(name="Divisions",
description="Number of vertices (divisions).",
default=32,
min=4,
max=256)
number = IntProperty(name="Arms/Joints",
description="Number of joints/arms",
default=5,
min=2,
max=99999)
length = FloatProperty(name="Length",
description="Length of each joint/arm",
default=3.0,
min=0.01,
max=100.0,
unit="LENGTH")
def execute(self, context):
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
radius = self.properties.radius
div = self.properties.div
number = self.properties.number
length = self.properties.length
if (div % 2):
# Odd vertice number not supported (yet).
return {'CANCELLED'}
if (number < 2):
return {'CANCELLED'}
verts = []
faces = []
loopsEndCircles = []
loopsJointsTemp = []
loopsJoints = []
vertTemp1 = None
vertTemp2 = None
angleDiv = (2.0 * pi / number)
# Create vertices for the end circles.
for num in range(number):
circle = []
# Create start circle
angle = num * angleDiv
baseEndLocX = length * sin(angle)
baseEndLocZ = length * cos(angle)
for vertIdx in range(div):
curVertAngle = vertIdx * (2.0 * pi / div)
# Create circle
locX = sin(curVertAngle) * radius
locY = cos(curVertAngle) * radius
locZ = 0.0
# Rotate circle
locZ = locX * cos(pi / 2.0 + angle)
locX = locX * sin(pi / 2.0 + angle)
circle.append(len(verts))
# Add translated circle
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],
obj = create_mesh_object(context, verts, [], faces, "N Joint", edit, self.align_matrix)
self.align_matrix = align_matrix(context)
self.execute(context)
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"))
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
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()