Skip to content
Snippets Groups Projects
add_mesh_pipe_joint.py 38.7 KiB
Newer Older
  • Learn to ignore specific revisions
  •         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],
    
    Martin Buerbaum's avatar
    Martin Buerbaum committed
                    loopsEndCircles[loopIdx], closed=True))
    
            base = create_mesh_object(context, 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",
    
    
    ################################
    
    import space_info
    
    
    # Define "Pipe Joints" menu
    
    def menu_func(self, context):
        self.layout.menu("INFO_MT_mesh_pipe_joints_add", icon="PLUGIN")
    
    
    
    def register():
        # Add "Pipe Joints" menu to the "Add Mesh" menu
        space_info.INFO_MT_mesh_add.append(menu_func)
    
    
    def unregister():
        # Remove "Pipe Joints" menu from the "Add Mesh" menu.
    
        space_info.INFO_MT_mesh_add.remove(menu_func)
    
    
    if __name__ == "__main__":
        register()