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
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))
faces.extend(createFaces(loopJoint2, loopArm1))
faces.extend(createFaces(loopJoint3, loopArm2))
faces.extend(createFaces(loopJoint4, loopArm3))
obj = createObject(context, verts, faces, "Cross Joint", edit)
# Store 'recall' properties in the object.
recall_prop_list = {
"radius": radius,
"div": div,
"angle1": angle1,
"angle2": angle2,
"angle3": angle3,
"startLength": startLength,
"branch1Length": branch1Length,
"branch2Length": branch2Length,
"branch3Length": branch3Length}
obj_store_recall_properties(obj, self, recall_prop_list)
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="",
description="",
default=False,
options={'HIDDEN'})
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
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):
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
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
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
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],
loopsEndCircles[loopIdx]))
obj = createObject(context, verts, faces, "N Joint", edit)
# Store 'recall' properties in the object.
recall_prop_list = {
"radius": radius,
"div": div,
"number": number,
"length": length}
obj_store_recall_properties(obj, self, recall_prop_list)
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
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"))
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
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()